add elfclass function

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

View File

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

1
elf.h
View File

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

15
str.c
View File

@ -2,6 +2,21 @@
#include "dat.h" #include "dat.h"
static char* classstr[] = {
[ELFCLASSNONE] = "Invalid class",
[ELFCLASS32] = "32-bit objects",
[ELFCLASS64] = "64-bit objects",
};
char*
elfclass(uint8_t class)
{
if(class < nelem(classstr) && classstr[class])
return classstr[class];
return "Unknown class";
}
char *machinestr[] = { char *machinestr[] = {
[EM_NONE] = "No machine", [EM_NONE] = "No machine",
[EM_M32] = "AT&T WE 32100", [EM_M32] = "AT&T WE 32100",