add printelfhdr function

This commit is contained in:
David du Colombier 2017-07-27 23:38:26 +02:00
parent face69c37e
commit 37a97ee463
3 changed files with 15 additions and 0 deletions

View File

@ -66,6 +66,7 @@ Functions
int readelf(FILE *f, Fhdr *fp);
uint8_t* readelfsection(FILE *f, char *name, uint64_t *size, Fhdr *fp);
void freeelf(Fhdr *fp);
void printelfhdr(Fhdr *fp);
char* elfclass(uint8_t class);
char* elfdata(uint8_t data);
char* elfosabi(uint8_t osabi);

1
elf.h
View File

@ -50,6 +50,7 @@ struct Fhdr {
int readelf(FILE*, Fhdr*);
uint8_t* readelfsection(FILE*, char*, uint64_t*, Fhdr*);
void freeelf(Fhdr*);
void printelfhdr(Fhdr*);
char* elfclass(uint8_t);
char* elfdata(uint8_t);
char* elfosabi(uint8_t);

13
print.c
View File

@ -127,3 +127,16 @@ printelf64phdr(Elf64_Phdr *ph, Fhdr *fp)
printf("align 0x%.16" PRIx64 "\n", ph->align);
printf("\n");
}
void
printelfhdr(Fhdr *fp)
{
printident(fp);
printf("type %s (0x%.4x)\n", elftype(fp->type), fp->type);
printf("machine %s (0x%.4x)\n", elfmachine(fp->machine), fp->machine);
printf("version %s (%u)\n", elfversion(fp->version), fp->version);
if (fp->class == ELFCLASS32)
printf("entry 0x%.4ux\n", (uint32_t)fp->entry);
if (fp->class == ELFCLASS64)
printf("entry 0x%.8" PRIx64 "\n", fp->entry);
}