diff --git a/README.md b/README.md index c44fb5d..5dce839 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ uint8_t* readelfsection(FILE *f, char *name, uint64_t *size, Fhdr *fp); void freeelf(Fhdr *fp); char* elftype(uint16_t type); char* elfmachine(uint16_t machine); +char* elfversion(uint8_t version); ``` Example diff --git a/elf.h b/elf.h index 9ab3e52..4972436 100644 --- a/elf.h +++ b/elf.h @@ -52,3 +52,4 @@ uint8_t* readelfsection(FILE*, char*, uint64_t*, Fhdr*); void freeelf(Fhdr*); char* elftype(uint16_t); char* elfmachine(uint16_t); +char* elfversion(uint8_t); diff --git a/print.c b/print.c index 01930b0..a6be83b 100644 --- a/print.c +++ b/print.c @@ -15,7 +15,7 @@ printelf32ehdr(Elf32_Ehdr *e, Fhdr *fp) e->ident[8], e->ident[9], e->ident[10], e->ident[11], e->ident[12], e->ident[13], e->ident[14], e->ident[15]); printf("type %s (0x%.4x)\n", elftype(e->type), e->type); printf("machine %s (0x%.4x)\n", elfmachine(e->machine), e->machine); - printf("version %u\n", e->version); + printf("version %s (%u)\n", elfversion(e->version), e->version); printf("entry 0x%.8x\n", e->entry); printf("phoff %u\n", e->phoff); printf("shoff %u\n", e->shoff); @@ -38,7 +38,7 @@ printelf64ehdr(Elf64_Ehdr *e, Fhdr *fp) e->ident[8], e->ident[9], e->ident[10], e->ident[11], e->ident[12], e->ident[13], e->ident[14], e->ident[15]); printf("type %s (0x%.4x)\n", elftype(e->type), e->type); printf("machine %s (0x%.4x)\n", elfmachine(e->machine), e->machine); - printf("version %u\n", e->version); + printf("version %s (%u)\n", elfversion(e->version), e->version); printf("entry 0x%.16" PRIx64 "\n", e->entry); printf("phoff %" PRIu64 "\n", e->phoff); printf("shoff %" PRIu64 "\n", e->shoff); diff --git a/str.c b/str.c index 47e8fca..db39ef0 100644 --- a/str.c +++ b/str.c @@ -218,3 +218,17 @@ elfmachine(uint16_t machine) return "Unknown machine"; } + +char *versionstr[] = { + [EV_NONE] = "Invalid", + [EV_CURRENT] = "Current", +}; + +char* +elfversion(uint8_t version) +{ + if(version < nelem(versionstr) && versionstr[version]) + return versionstr[version]; + + return "Unknown version"; +}