commit:     244969d6eaa011c87bcba5d1f982d546de715f08
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jan  3 23:50:11 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jan  3 23:50:11 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=244969d6

misc/elf-abi: read() gets the correct endian order

---
 misc/elf-abi/elf-abi.c | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/misc/elf-abi/elf-abi.c b/misc/elf-abi/elf-abi.c
index 589d458..32e3851 100644
--- a/misc/elf-abi/elf-abi.c
+++ b/misc/elf-abi/elf-abi.c
@@ -103,7 +103,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 +146,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 +196,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 +213,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 +270,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 +279,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 +288,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);
+}

Reply via email to