All pastes #57093 Raw Edit

Untitled

public c v1 · immutable
#57093 ·published 2006-05-19 13:10 UTC
rendered paste body
#include <stdlib.h>#include <stdio.h>#include <libelf.h>#include <errno.h>#include <fcntl.h>int main(){  char *fileName = "/home/ajocksch/src/asmtest/core.8675";  errno = 0;  int fd = open (fileName, O_RDONLY);  if(errno != 0){    perror("Couldn't open file");    exit(1);  }	  if(elf_version(EV_CURRENT) == EV_NONE){    fprintf(stderr, "Incorrect version");    exit(1);  }    errno = 0;	  Elf* new_elf = elf_begin (fd, (Elf_Cmd) 1, (Elf*) 0);	  if(errno != 0 || !new_elf){    perror("Couldn't create elf file!");    exit(1);  }  printf("Getting header...\n");  Elf32_Ehdr * header = elf32_getehdr(new_elf);  printf("Number of setions: %d\n", (int) header->e_shnum);  printf("Trying to get sections...\n");	  Elf_Scn *section = elf_nextscn(new_elf, (Elf_Scn*) 0);  int count = 1;  while(section){    printf("Found section #%d at %lx\n", count, (long*) section);    section = elf_nextscn(new_elf, section);  }  printf("Closing elf file\n");    elf_end(new_elf);  return 0;}