mirror of
https://github.com/0intro/libelf
synced 2025-03-12 17:42:59 +03:00
add elftype function
This commit is contained in:
parent
d0f39cd69b
commit
c5f6f3db4a
@ -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);
|
||||
char* elftype(uint16_t type);
|
||||
```
|
||||
|
||||
Example
|
||||
|
1
elf.h
1
elf.h
@ -50,3 +50,4 @@ struct Fhdr {
|
||||
int readelf(FILE*, Fhdr*);
|
||||
uint8_t* readelfsection(FILE*, char*, uint64_t*, Fhdr*);
|
||||
void freeelf(Fhdr*);
|
||||
char* elftype(uint16_t);
|
||||
|
4
print.c
4
print.c
@ -13,7 +13,7 @@ printelf32ehdr(Elf32_Ehdr *e, Fhdr *fp)
|
||||
printf("ident %.2x %c %c %c %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
|
||||
e->ident[0], e->ident[1], e->ident[2], e->ident[3], e->ident[4], e->ident[5], e->ident[6], e->ident[7],
|
||||
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 %u\n", e->type);
|
||||
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("entry 0x%.8x\n", e->entry);
|
||||
@ -36,7 +36,7 @@ printelf64ehdr(Elf64_Ehdr *e, Fhdr *fp)
|
||||
printf("ident %.2x %c %c %c %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
|
||||
e->ident[0], e->ident[1], e->ident[2], e->ident[3], e->ident[4], e->ident[5], e->ident[6], e->ident[7],
|
||||
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 %u\n", e->type);
|
||||
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("entry 0x%.16" PRIx64 "\n", e->entry);
|
||||
|
23
str.c
23
str.c
@ -187,6 +187,29 @@ char *machinestr[] = {
|
||||
[EM_RISCV] = "RISC-V"
|
||||
};
|
||||
|
||||
char *typestr[] = {
|
||||
[ET_NONE] = "No file type",
|
||||
[ET_REL] = "Relocatable file",
|
||||
[ET_EXEC] = "Executable file",
|
||||
[ET_DYN] = "Shared object file",
|
||||
[ET_CORE] = "Core file",
|
||||
};
|
||||
|
||||
char*
|
||||
elftype(uint16_t type)
|
||||
{
|
||||
if(type < nelem(typestr) && typestr[type])
|
||||
return typestr[type];
|
||||
|
||||
if (type >= ET_LOOS && type <= ET_HIOS)
|
||||
return "Operating system-specific";
|
||||
|
||||
if (type >= ET_LOPROC)
|
||||
return "Processor-specific";
|
||||
|
||||
return "Unknown type";
|
||||
}
|
||||
|
||||
char*
|
||||
elfmachine(uint16_t machine)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user