From: Christos Zoulas Date: Sat, 5 Oct 1996 18:13:57 +0000 (+0000) Subject: Segregate elf stuff. X-Git-Tag: FILE3_27~73 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddd982c5def3d0e7807b73e8c6326a4c21bc4725;p=file Segregate elf stuff. --- diff --git a/src/Makefile b/src/Makefile index ebfcd91e..e5cabfbe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 \ diff --git a/src/file.c b/src/file.c index 37c63964..3b6b1ca9 100644 --- a/src/file.c +++ b/src/file.c @@ -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 @@ -43,7 +43,6 @@ static char *moduleid = #endif #include /* for read() */ -#include "readelf.h" #include /* 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) { /*