add elfdata function

This commit is contained in:
David du Colombier 2017-07-27 23:36:34 +02:00
parent 8ccad71508
commit 859ed02491
3 changed files with 17 additions and 0 deletions

View File

@ -67,6 +67,7 @@ int readelf(FILE *f, Fhdr *fp);
uint8_t* readelfsection(FILE *f, char *name, uint64_t *size, Fhdr *fp);
void freeelf(Fhdr *fp);
char* elfclass(uint8_t class);
char* elfdata(uint8_t data);
char* elftype(uint16_t type);
char* elfmachine(uint16_t machine);
char* elfversion(uint8_t version);

1
elf.h
View File

@ -51,6 +51,7 @@ int readelf(FILE*, Fhdr*);
uint8_t* readelfsection(FILE*, char*, uint64_t*, Fhdr*);
void freeelf(Fhdr*);
char* elfclass(uint8_t);
char* elfdata(uint8_t);
char* elftype(uint16_t);
char* elfmachine(uint16_t);
char* elfversion(uint8_t);

15
str.c
View File

@ -17,6 +17,21 @@ elfclass(uint8_t class)
return "Unknown class";
}
static char* datastr[] = {
[ELFDATANONE] = "Invalid data encoding",
[ELFDATA2LSB] = "Litte-endian",
[ELFDATA2MSB] = "Big-endian",
};
char*
elfdata(uint8_t data)
{
if(data < nelem(datastr) && datastr[data])
return datastr[data];
return "Unknown data";
}
char *machinestr[] = {
[EM_NONE] = "No machine",
[EM_M32] = "AT&T WE 32100",