From 859ed02491d888317019cd24a7da6e1126c11d86 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 27 Jul 2017 23:36:34 +0200 Subject: [PATCH] add elfdata function --- README.md | 1 + elf.h | 1 + str.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 2c2dfb0..77e2b5e 100644 --- a/README.md +++ b/README.md @@ -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); diff --git a/elf.h b/elf.h index 2fb4f91..20ae3c5 100644 --- a/elf.h +++ b/elf.h @@ -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); diff --git a/str.c b/str.c index 4dd0dfc..b7cd050 100644 --- a/str.c +++ b/str.c @@ -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",