Logo  

CS471/571 - Operating Systems

Displaying exercises/e7/files/elf.c

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <elf.h>

/**
 * Should open and mmap the file into the processes address space and return
 * a pointer to the memory or NULL on failure.
 */
void *mapfile(char *filename)
{

}

/**
 * Should print the ELF header pointed to by 'hdr'
 * Read the manual for elf(5) (i.e.: man 5 elf)
 * The output should be equivalent to 'readelf -h <file>'
 */
void header(Elf64_Ehdr *hdr)
{

}


int main(int argc, char *argv[])
{
  if (argc < 2) {
    printf("Usage: elf <elf-file>\n");
    return 0;
  }

  void *memory = mapfile(argv[1]);
  if (memory == NULL) return 1;

  header(memory);

  return 0;
}