diff options
author | Rob Landley <rob@landley.net> | 2017-11-26 05:33:35 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-11-26 05:33:35 -0600 |
commit | a9111bd499622577c3acd6565f02d6efdd16b44c (patch) | |
tree | b1155f7d34b155530e2ea33f362ab0291fc07d78 /toys/posix | |
parent | 95942749b049cd0749bd8cab0cf6afb71cb4ac03 (diff) | |
download | toybox-a9111bd499622577c3acd6565f02d6efdd16b44c.tar.gz |
Use endianness info to read executable type.
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/file.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/toys/posix/file.c b/toys/posix/file.c index 5e5c15bc..b84eece6 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -30,7 +30,7 @@ GLOBALS( static void do_elf_file(int fd, struct stat *sb) { int endian = toybuf[5], bits = toybuf[4], i, j; - int64_t (*elf_int)(void *ptr, unsigned size) = peek_le; + int64_t (*elf_int)(void *ptr, unsigned size); // Values from include/linux/elf-em.h (plus arch/*/include/asm/elf.h) // Names are linux/arch/ directory (sometimes before 32/64 bit merges) struct {int val; char *name;} type[] = {{0x9026, "alpha"}, {93, "arc"}, @@ -53,9 +53,10 @@ static void do_elf_file(int fd, struct stat *sb) int phentsize, phnum, shsize, shnum; printf("ELF "); + elf_int = (endian==2) ? peek_be : peek_le; - // executable (ELF says this is short but reality says byte, not MSB swapped) - i = toybuf[16]; + // executable type + i = elf_int(toybuf+16, 2); if (i == 1) printf("relocatable"); else if (i == 2) printf("executable"); else if (i == 3) printf("shared object"); @@ -73,10 +74,8 @@ static void do_elf_file(int fd, struct stat *sb) // "LSB" if (endian == 1) printf("LSB "); - else if (endian == 2) { - printf("MSB "); - elf_int = peek_be; - } else { + else if (endian == 2) printf("MSB "); + else { printf("(bad endian %d) \n", endian); endian = 0; } |