mirror of https://github.com/0intro/libelf
add elfversion function
This commit is contained in:
parent
b609396e38
commit
5e69503ed0
|
@ -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
|
||||
|
|
1
elf.h
1
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);
|
||||
|
|
4
print.c
4
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);
|
||||
|
|
14
str.c
14
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";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue