From: Christos Zoulas Date: Sat, 12 Sep 1998 13:17:52 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: FILE3_27~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=065c33d0d602f572be4c134a094c500617d287bf;p=file *** empty log message *** --- diff --git a/Makefile.in b/Makefile.in index 24b63729..74e1e765 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ # Makefile for file(1) cmd. # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE. -# @(#)$Id: Makefile.in,v 1.4 1998/06/27 14:01:39 christos Exp $ +# @(#)$Id: Makefile.in,v 1.5 1998/09/12 13:17:52 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. @@ -21,14 +21,14 @@ # ever read sources, credits must appear in the documentation. # # 4. This notice may not be removed or altered. -VERSION = 3.25 +VERSION = 3.26 SHELL = /bin/sh #MAGIC = /etc/magic prefix = @prefix@ INSTALLCMD = @INSTALL@ MAGICDIR = @datadir@ MAGIC = $(MAGICDIR)/magic -DEFS = -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF -DHAVE_CONFIG_H +DEFS = -DMAGIC='"$(MAGIC)"' -DBUILTIN_ELF -DELFCORE -DHAVE_CONFIG_H CPPFLAGS = $(DEFS) CC = @CC@ #COPTS = -O -g # newer compilers allow both; else drop -O @@ -84,8 +84,9 @@ HDRS = file.h names.h patchlevel.h readelf.h tar.h AUTOSRC=configure configure.in install-sh config.h.in Makefile.in ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \ - Makefile.std file.man magic.man magic2mime $(AUTOSRC) -ALLMAGIC = Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]* + Makefile.std file.man magic.man magic2mime $(AUTOSRC) \ + Localstuff Header +ALLMAGIC = Magdir/[a-z]* all: file magic file.${MANCEXT} magic.${MANFEXT} @@ -101,9 +102,8 @@ file: $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ lint: $(SRCS) lint -ha $(DEFS) $(SRCS) | tee $@ -magic: Magdir -# Magdir/Makefile's "install" mv's magic to here for testing. - cd Magdir; $(MAKE) install +magic: Header Localstuff Magdir + cat Header Localstuff Magdir/[a-z]* > $@ ascmagic.o: names.h diff --git a/src/Makefile.std b/src/Makefile.std index 9022de63..c67a2402 100644 --- a/src/Makefile.std +++ b/src/Makefile.std @@ -1,6 +1,6 @@ # Makefile for file(1) cmd. # Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE. -# @(#)$Id: Makefile.std,v 1.4 1998/06/27 14:01:39 christos Exp $ +# @(#)$Id: Makefile.std,v 1.5 1998/09/12 13:17:52 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. @@ -21,7 +21,7 @@ # ever read sources, credits must appear in the documentation. # # 4. This notice may not be removed or altered. -VERSION = 3.25 +VERSION = 3.26 SHELL = /bin/sh #MAGIC = /etc/magic MAGIC = /usr/local/etc/magic @@ -79,8 +79,9 @@ HDRS = file.h names.h patchlevel.h readelf.h tar.h AUTOSRC=configure configure.in install-sh config.h.in Makefile.in ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) $(HDRS) \ - Makefile.std file.man magic.man magic2mime $(AUTOSRC) -ALLMAGIC = Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]* + Makefile.std file.man magic.man magic2mime $(AUTOSRC) \ + Localstuff Header +ALLMAGIC = Magdir/[a-z]* all: file magic file.${MANCEXT} magic.${MANFEXT} @@ -96,9 +97,8 @@ file: $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ lint: $(SRCS) lint -ha $(DEFS) $(SRCS) | tee $@ -magic: Magdir -# Magdir/Makefile's "install" mv's magic to here for testing. - cd Magdir; $(MAKE) install +magic: Localstuff Header Magdir + cat Header Localstuff Magdir/[a-z] > $@ ascmagic.o: names.h diff --git a/src/apprentice.c b/src/apprentice.c index eb50b337..d1dcd336 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -33,7 +33,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.27 1998/06/27 13:57:23 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.28 1998/09/12 13:17:52 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -228,16 +228,25 @@ int *ndx, check; */ if (*l == '.') { l++; - switch (LOWCASE(*l)) { + switch (*l) { case 'l': - m->in.type = LONG; + m->in.type = LELONG; + break; + case 'L': + m->in.type = BELONG; break; case 'h': case 's': - m->in.type = SHORT; + m->in.type = LESHORT; + break; + case 'H': + case 'S': + m->in.type = BESHORT; break; case 'c': case 'b': + case 'C': + case 'B': m->in.type = BYTE; break; default: diff --git a/src/file.c b/src/file.c index e4040ea8..ed102b65 100644 --- a/src/file.c +++ b/src/file.c @@ -31,13 +31,15 @@ #include /* for MAXPATHLEN */ #include #include /* for open() */ -#if (__COHERENT__ >= 0x420) -# include -#else -# ifdef USE_UTIMES -# include +#ifdef RESTORE_TIME +# if (__COHERENT__ >= 0x420) +# include # else -# include +# ifdef USE_UTIMES +# include +# else +# include +# endif # endif #endif #include /* for read() */ @@ -48,7 +50,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.41 1998/06/27 13:57:23 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.42 1998/09/12 13:17:52 christos Exp $") #endif /* lint */ @@ -356,6 +358,9 @@ int wid; #ifdef RESTORE_TIME /* * Try to restore access, modification times if read it. + * This is really *bad* because it will modify the status + * time of the file... And of course this will affect + * backup programs */ # ifdef USE_UTIMES struct timeval utsbuf[2]; diff --git a/src/names.h b/src/names.h index a9abb5e5..9090652d 100644 --- a/src/names.h +++ b/src/names.h @@ -10,7 +10,7 @@ * * See LEGAL.NOTICE * - * $Id: names.h,v 1.14 1998/06/27 13:57:23 christos Exp $ + * $Id: names.h,v 1.15 1998/09/12 13:17:52 christos Exp $ */ /* these types are used to index the table 'types': keep em in sync! */ @@ -26,6 +26,7 @@ #define L_NEWS 9 /* Usenet Netnews */ #define L_JAVA 10 /* Java code */ #define L_HTML 11 /* HTML */ +#define L_BCPL 12 /* BCPL */ static const char *types[] = { "C program text", @@ -40,6 +41,7 @@ static const char *types[] = { "news text", "Java program text", "HTML document text", + "BCPL program text", "can't happen error on names.h/types", 0}; @@ -86,6 +88,8 @@ static struct names { /* These must be sorted by eye for optimal hit rate */ /* Add to this list only after substantial meditation */ {"import", L_JAVA}, + {"\"libhdr\"", L_BCPL}, + {"\"LIBHDR\"", L_BCPL}, {"//", L_CC}, {"template", L_CC}, {"virtual", L_CC}, diff --git a/src/readelf.c b/src/readelf.c index 157485d1..bc0fef96 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -9,15 +9,21 @@ #include #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include "readelf.h" #include "file.h" #ifndef lint -FILE_RCSID("@(#)$Id: readelf.c,v 1.8 1998/06/27 13:57:23 christos Exp $") +FILE_RCSID("@(#)$Id: readelf.c,v 1.9 1998/09/12 13:21:01 christos Exp $") #endif +#ifdef ELFCORE +static void dophn_core __P((int, off_t, int, size_t, char *)); +#endif +static void dophn_exec __P((int, off_t, int, size_t, char *)); +static void doshn __P((int, off_t, int, size_t, char *)); + static void doshn(fd, off, num, size, buf) int fd; @@ -65,6 +71,8 @@ dophn_exec(fd, off, num, size, buf) { /* I am not sure if this works for 64 bit elf formats */ Elf32_Phdr *ph = (Elf32_Phdr *) buf; + char *linking_style = "statically"; + char *shared_libraries = ""; if (lseek(fd, off, SEEK_SET) == -1) error("lseek failed (%s).\n", strerror(errno)); @@ -72,18 +80,20 @@ dophn_exec(fd, off, num, size, buf) for ( ; num; num--) { if (read(fd, buf, size) == -1) error("read failed (%s).\n", strerror(errno)); - if (ph->p_type == PT_INTERP) { - /* - * Has an interpreter - must be a dynamically-linked - * executable. - */ - printf(", dynamically linked"); - return; + + switch (ph->p_type) { + case PT_DYNAMIC: + linking_style = "dynamically"; + break; + case PT_INTERP: + shared_libraries = " (uses shared libs)"; + break; } } - printf(", statically linked"); + printf(", %s linked%s", linking_style, shared_libraries); } +#ifdef ELFCORE size_t prpsoffsets[] = { 84, /* SunOS 5.x */ 32, /* Linux */ @@ -221,6 +231,7 @@ dophn_core(fd, off, num, size, buf) } } } +#endif void tryelf(fd, buf, nbytes) @@ -262,13 +273,18 @@ tryelf(fd, buf, nbytes) */ if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) { if (elfhdr.e_type == ET_CORE) +#ifdef ELFCORE dophn_core(fd, elfhdr.e_phoff, elfhdr.e_phnum, elfhdr.e_phentsize, buf); +#else + ; +#endif else { if (elfhdr.e_type == ET_EXEC) { - dophn_exec(fd, elfhdr.e_phoff, - elfhdr.e_phnum, - elfhdr.e_phentsize, buf); + dophn_exec(fd, + elfhdr.e_phoff, + elfhdr.e_phnum, + elfhdr.e_phentsize, buf); } doshn(fd, elfhdr.e_shoff, elfhdr.e_shnum, elfhdr.e_shentsize, buf); @@ -294,22 +310,37 @@ tryelf(fd, buf, nbytes) * byte order.... */ if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) { -#ifdef notyet if (elfhdr.e_type == ET_CORE) - dophn_core(fd, elfhdr.e_phoff[1], +#ifdef ELFCORE + dophn_core(fd, +#ifndef __GNUC__ + elfhdr.e_phoff[1], +#else + elfhdr.e_phoff, +#endif elfhdr.e_phnum, elfhdr.e_phentsize, buf); - else +#else + ; #endif + else { -#ifdef notyet if (elfhdr.e_type == ET_EXEC) { - dophn_exec(fd, elfhdr.e_phoff[1], + dophn_exec(fd, +#ifndef __GNUC__ + elfhdr.e_phoff[1], +#else + elfhdr.e_phoff, +#endif elfhdr.e_phnum, elfhdr.e_phentsize, buf); } + doshn(fd, +#ifndef __GNUC__ + elfhdr.e_shoff[1], +#else + elfhdr.e_shoff, #endif - doshn(fd, elfhdr.e_shoff[1], elfhdr.e_shnum, elfhdr.e_shentsize, buf); } diff --git a/src/readelf.h b/src/readelf.h index 9b63498b..511f5f85 100644 --- a/src/readelf.h +++ b/src/readelf.h @@ -1,6 +1,6 @@ /* * readelf.h - * @(#)$Id: readelf.h,v 1.5 1998/06/27 13:57:23 christos Exp $ + * @(#)$Id: readelf.h,v 1.6 1998/09/12 13:21:01 christos Exp $ * * Provide elf data structures for non-elf machines, allowing file * non-elf hosts to determine if an elf binary is stripped. @@ -10,15 +10,20 @@ #define __fake_elf_h__ typedef unsigned int Elf32_Addr; -typedef unsigned short Elf32_Half; typedef unsigned int Elf32_Off; +typedef unsigned short Elf32_Half; typedef unsigned int Elf32_Word; typedef unsigned char Elf32_Char; +#ifdef __GNUC__ +typedef unsigned long long Elf64_Addr; +typedef unsigned long long Elf64_Off; +#else /* XXX: We need 64 bit numbers here */ typedef unsigned int Elf64_Addr[2]; -typedef unsigned short Elf64_Half; typedef unsigned int Elf64_Off[2]; +#endif +typedef unsigned short Elf64_Half; typedef unsigned int Elf64_Word; typedef unsigned char Elf64_Char; diff --git a/src/softmagic.c b/src/softmagic.c index cfb4d6aa..572f3162 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -37,7 +37,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.37 1998/06/27 13:23:39 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.38 1998/09/12 13:21:01 christos Exp $") #endif /* lint */ static int match __P((unsigned char *, int)); @@ -349,18 +349,33 @@ int nbytes; mdump(m); } - if (!mconvert(p, m)) - return 0; - if (m->flag & INDIR) { switch (m->in.type) { case BYTE: offset = p->b + m->in.offset; break; + case BESHORT: + offset = (short)((p->hs[0]<<8)|(p->hs[1]))+ + m->in.offset; + break; + case LESHORT: + offset = (short)((p->hs[1]<<8)|(p->hs[0]))+ + m->in.offset; + break; case SHORT: offset = p->h + m->in.offset; break; + case BELONG: + offset = (int32)((p->hl[0]<<24)|(p->hl[1]<<16)| + (p->hl[2]<<8)|(p->hl[3]))+ + m->in.offset; + break; + case LELONG: + offset = (int32)((p->hl[3]<<24)|(p->hl[2]<<16)| + (p->hl[1]<<8)|(p->hl[0]))+ + m->in.offset; + break; case LONG: offset = p->l + m->in.offset; break; @@ -375,10 +390,9 @@ int nbytes; mdebug(offset, (char *) p, sizeof(union VALUETYPE)); mdump(m); } - - if (!mconvert(p, m)) - return 0; } + if (!mconvert(p, m)) + return 0; return 1; }