]> granicus.if.org Git - file/commitdiff
Segregate elf stuff.
authorChristos Zoulas <christos@zoulas.com>
Sat, 5 Oct 1996 18:13:57 +0000 (18:13 +0000)
committerChristos Zoulas <christos@zoulas.com>
Sat, 5 Oct 1996 18:13:57 +0000 (18:13 +0000)
src/Makefile
src/file.c

index ebfcd91ea9512e058730497076bef3760c08abd2..e5cabfbe53508c69993856ae04e27e230cc29ee7 100644 (file)
@@ -1,6 +1,6 @@
 # Makefile for file(1) cmd. 
 # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
-# @(#)$Id: Makefile,v 1.51 1996/06/22 22:05:07 christos Exp $
+# @(#)$Id: Makefile,v 1.52 1996/10/05 18:13:57 christos Exp $
 #
 # This software is not subject to any license of the American Telephone
 # and Telegraph Company or of the Regents of the University of California.
@@ -25,7 +25,7 @@ VERSION       = 3.20
 SHELL  = /bin/sh
 #MAGIC = /etc/magic
 MAGIC  = /usr/local/etc/magic
-DEFS   = -DMAGIC='"$(MAGIC)"' # -Dvoid=int
+DEFS   = -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF # -Dvoid=int
 CC     = cc
 COPTS  = -O -g         # newer compilers allow both; else drop -O
 # For truly antique environments, use this for (dummy) include files:
@@ -70,10 +70,10 @@ LOCALOBJS = # localsrc/getopt.o localsrc/strtol.o \
 LOCALINC = # localinc/*.h localinc/sys/*.h
 
 SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \
-       compress.c is_tar.c \
+       compress.c is_tar.c readelf.c \
        print.c $(LOCALSRCS) $(LOCALINC)
 OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o \
-       compress.o is_tar.o \
+       compress.o is_tar.o readelf.o \
        print.o $(LOCALOBJS)
 
 ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) *.h \
index 37c63964f532484f8412fb118586c7d37825f322..3b6b1ca94d48c9cde8127fe9b8fa385f1c64fe32 100644 (file)
@@ -26,7 +26,7 @@
  */
 #ifndef        lint
 static char *moduleid = 
-       "@(#)$Id: file.c,v 1.35 1996/06/22 22:04:22 christos Exp $";
+       "@(#)$Id: file.c,v 1.36 1996/10/05 18:13:57 christos Exp $";
 #endif /* lint */
 
 #include <stdio.h>
@@ -43,7 +43,6 @@ static char *moduleid =
 #endif
 #include <unistd.h>    /* for read() */
 
-#include "readelf.h"
 #include <netinet/in.h>                /* for byte swapping */
 
 #include "patchlevel.h"
@@ -335,59 +334,10 @@ int wid;
                match = tryit(buf, nbytes, zflag);
        }
 
-       /*
-        * ELF executables have multiple section headers in arbitrary
-        * file locations and thus file(1) cannot determine it from easily.
-        * Instead we traverse thru all section headers until a symbol table
-        * one is found or else the binary is stripped.
-        */
-
-       if (match == 's' && nbytes > sizeof (Elf32_Ehdr) &&
-           buf[EI_MAG0] == ELFMAG0 &&
-           buf[EI_MAG1] == ELFMAG1 &&
-           buf[EI_MAG2] == ELFMAG2 &&
-           buf[EI_MAG3] == ELFMAG3) {
-
-               union {
-                       int l;
-                       char c[sizeof (int)];
-               } u;
-
-               Elf32_Ehdr elfhdr;
-               int stripped = 1;
-               int be,same;
-               short shnum;
-
-               u.l = 1;
-               (void) memcpy(&elfhdr, buf, sizeof elfhdr);
-
-               /*
-                * If the system byteorder does not equal the object byteorder
-                * then need to do byte-swapping.
-                */
-               be = u.c[sizeof(int) - 1] == 1; /* are we big endian? */
-               same = (u.c[sizeof(int) - 1] + 1) == elfhdr.e_ident[5];
-                               /* are we the same endianness? */;
-
-               if (lseek(fd, byteconv4(elfhdr.e_shoff,same,be), SEEK_SET)<0)
-                       error("lseek failed (%s).\n", strerror(errno));
-
-               for (shnum = byteconv2(elfhdr.e_shnum,same,be);
-                    shnum; shnum--) {
-                   if (read(fd, buf,
-                            byteconv2(elfhdr.e_shentsize,same,be))<0)
-                       error("read failed (%s).\n", strerror(errno));
-                   if (byteconv4(((Elf32_Shdr *)buf)->sh_type,same,be)
-                       == SHT_SYMTAB) {
-                       stripped = 0;
-                       break;
-                   }
-               }
-               if (stripped)
-                   (void) printf (", stripped");
-               else
-                   (void) printf (", not stripped");
-       }
+#ifdef BUILTIN_ELF
+       if (match == 's' && nbytes > 5)
+               tryelf(fd, buf, nbytes);
+#endif
 
        if (inname != stdname) {
                /*