]> granicus.if.org Git - file/commitdiff
handle dynamic objects like executables, that they are.
authorChristos Zoulas <christos@zoulas.com>
Thu, 27 Dec 2007 16:13:26 +0000 (16:13 +0000)
committerChristos Zoulas <christos@zoulas.com>
Thu, 27 Dec 2007 16:13:26 +0000 (16:13 +0000)
src/readelf.c
src/readelf.h

index 4f176e2035d199552e80dec74e3a569f17ce1d9c..966ac133d387ab706c16265b24573fac1a5454b4 100644 (file)
@@ -37,7 +37,7 @@
 #include "readelf.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.66 2007/11/07 21:26:32 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.67 2007/11/17 17:08:27 christos Exp $")
 #endif
 
 #ifdef ELFCORE
@@ -894,6 +894,8 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
                                return -1;
                        }
                        break;
+               default:
+                       break;
                }
        }
        if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries)
@@ -945,6 +947,8 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 
        if (class == ELFCLASS32) {
                Elf32_Ehdr elfhdr;
+               uint16_t type;
+
                if (nbytes <= sizeof (Elf32_Ehdr))
                        return 0;
 
@@ -953,33 +957,36 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
                (void) memcpy(&elfhdr, buf, sizeof elfhdr);
                swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
 
-               if (getu16(swap, elfhdr.e_type) == ET_CORE) {
+               type = getu16(swap, elfhdr.e_type);
+               switch (type) {
 #ifdef ELFCORE
+               case ET_CORE:
                        if (dophn_core(ms, class, swap, fd,
                            (off_t)getu32(swap, elfhdr.e_phoff),
                            getu16(swap, elfhdr.e_phnum), 
                            (size_t)getu16(swap, elfhdr.e_phentsize),
                            fsize, &flags) == -1)
                                return -1;
-#else
-                       ;
+                       break;
 #endif
-               } else {
-                       if (getu16(swap, elfhdr.e_type) == ET_EXEC) {
-                               if (dophn_exec(ms, class, swap,
-                                   fd, (off_t)getu32(swap, elfhdr.e_phoff),
-                                   getu16(swap, elfhdr.e_phnum), 
-                                   (size_t)getu16(swap, elfhdr.e_phentsize),
-                                   fsize, &flags)
-                                   == -1)
-                                       return -1;
-                       }
+               case ET_EXEC:
+               case ET_DYN:
+                       if (dophn_exec(ms, class, swap,
+                           fd, (off_t)getu32(swap, elfhdr.e_phoff),
+                           getu16(swap, elfhdr.e_phnum), 
+                           (size_t)getu16(swap, elfhdr.e_phentsize),
+                           fsize, &flags) == -1)
+                               return -1;
                        if (doshn(ms, class, swap, fd,
                            (off_t)getu32(swap, elfhdr.e_shoff),
                            getu16(swap, elfhdr.e_shnum),
                            (size_t)getu16(swap, elfhdr.e_shentsize),
                            &flags) == -1)
                                return -1;
+                       break;
+
+               default:
+                       break;
                }
                return 1;
        }
index 40d26e7537c79caadd7567be68991952acccd20c..610c310c82a832a504d33a2e19d1483dd00bc7c6 100644 (file)
@@ -97,6 +97,7 @@ typedef struct {
 
 /* e_type */
 #define ET_EXEC                2
+#define ET_DYN         3
 #define ET_CORE                4
 
 /* sh_type */