aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2015-01-03 18:50:11 -0500
committerAnthony G. Basile <blueness@gentoo.org>2015-01-03 18:53:43 -0500
commit55440d11bbf3fd36388ab9135d640f66bd4d1ce9 (patch)
tree1f9049f3fc5d5387514ebce18ee2da30f60b1db7 /misc
parentmisc/elf-abi: read arch:abi:endian from an ELF, bug #534206 (diff)
downloadelfix-55440d11bbf3fd36388ab9135d640f66bd4d1ce9.tar.gz
elfix-55440d11bbf3fd36388ab9135d640f66bd4d1ce9.tar.bz2
elfix-55440d11bbf3fd36388ab9135d640f66bd4d1ce9.zip
misc/elf-abi: read() gets the correct endian order
Diffstat (limited to 'misc')
-rw-r--r--misc/elf-abi/elf-abi.c38
1 files changed, 10 insertions, 28 deletions
diff --git a/misc/elf-abi/elf-abi.c b/misc/elf-abi/elf-abi.c
index 589d458..aa383c4 100644
--- a/misc/elf-abi/elf-abi.c
+++ b/misc/elf-abi/elf-abi.c
@@ -62,7 +62,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
-#include <endian.h>
/* We steal this from <elf.h> but don't include it so as to not increase our dependancies. */
#define ELFMAG "\177ELF"
@@ -103,7 +102,6 @@ E_MIPS_ABI_EABI64 = 0x00004000
#define EF_ARM_NEW_ABI 0x80
#define EF_ARM_OLD_ABI 0x100
-
/*
def compute_suffix_mips(elf_header):
name = None
@@ -147,15 +145,6 @@ def compute_multilib_id(elf_header):
return multilib_id
*/
-
-#define bswap_16(x) ((uint16_t)((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
-
-/*
-#define bswap_32(x) \
- ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
-*/
-
#define MAX_IDENT 32
int
@@ -206,7 +195,7 @@ main(int argc, char* argv[])
printf("Unknown bit\n");
}
- /* Little or Big Endian */
+ /* Little or Big Endian? */
if (read(fd, &ei_data, 1) == -1)
err(1, "read() ei_data failed");
switch (ei_data) {
@@ -223,17 +212,13 @@ main(int argc, char* argv[])
printf("Unknown Endian\n");
}
- /* seek to e_macine = 16 bytes (e_ident[])) + 2 bytes (e_type which is Elf32_Half/Elf64_Half) */
+ /* Seek to e_macine = 16 bytes (e_ident[])) + 2 bytes (e_type which is Elf32_Half/Elf64_Half) */
if (lseek(fd, 18, SEEK_SET) == -1)
err(1, "lseek() e_machine failed");
/* What is the arch? */
if (read(fd, &e_machine, 2) == -1)
err(1, "read() e_machine failed");
- //if (endian == 0)
- // e_machine = bswap_16(e_machine);
- printf("Machine =%d\n", e_machine);
-
switch(e_machine) {
case EM_ALPHA:
case EM_FAKE_ALPHA:
@@ -284,10 +269,8 @@ main(int argc, char* argv[])
default:
arch = "unknown";
}
-
printf("%s\n", arch);
-
/*
e_data_offset =
if (lseek(fd, 18, SEEK_SET) == -1)
@@ -295,14 +278,7 @@ main(int argc, char* argv[])
if (read(fd, &e_flags, 2) == -1)
err(1, "read() e_machine failed");
*/
-
- memset(ident, 0, MAX_IDENT);
-
- close(fd);
- exit(EXIT_SUCCESS);
-}
-
-/*
+ /*
# E_ENTRY + 3 * sizeof(uintN)
e_flags_offset = E_ENTRY + 3 * width // 8
f.seek(e_flags_offset)
@@ -311,4 +287,10 @@ main(int argc, char* argv[])
return _elf_header(ei_class, ei_data, e_machine, e_flags)
multilib_id = compute_multilib_id(elf_header)
-*/
+ */
+
+ memset(ident, 0, MAX_IDENT);
+
+ close(fd);
+ exit(EXIT_SUCCESS);
+}