]> granicus.if.org Git - file/commitdiff
*** empty log message ***
authorChristos Zoulas <christos@zoulas.com>
Sat, 12 Sep 1998 13:17:52 +0000 (13:17 +0000)
committerChristos Zoulas <christos@zoulas.com>
Sat, 12 Sep 1998 13:17:52 +0000 (13:17 +0000)
Makefile.in
src/Makefile.std
src/apprentice.c
src/file.c
src/names.h
src/readelf.c
src/readelf.h
src/softmagic.c

index 24b63729f5a84f0d72fc172749a70d8c6b8a8b07..74e1e765d1ecfd51397af52c10788b0208d4ce7e 100644 (file)
@@ -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.
 #    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
 
index 9022de6359b6bd9313d7b424eea56242a5a4b51d..c67a24029d330f5b32c2c2ee27ee52e407bc67a6 100644 (file)
@@ -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
 
index eb50b3371e68c395da20011ae80416848f2122ef..d1dcd3367b375d0e2f6545a2c932776e29e00aef 100644 (file)
@@ -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:
index e4040ea8f8e68885f95f9071fcbd72927d01576e..ed102b658e411ce9677c9f420404517683982fa3 100644 (file)
 #include <sys/param.h> /* for MAXPATHLEN */
 #include <sys/stat.h>
 #include <fcntl.h>     /* for open() */
-#if (__COHERENT__ >= 0x420)
-# include <sys/utime.h>
-#else
-# ifdef USE_UTIMES
-#  include <sys/time.h>
+#ifdef RESTORE_TIME
+# if (__COHERENT__ >= 0x420)
+#  include <sys/utime.h>
 # else
-#  include <utime.h>
+#  ifdef USE_UTIMES
+#   include <sys/time.h>
+#  else
+#   include <utime.h>
+#  endif
 # endif
 #endif
 #include <unistd.h>    /* 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];
index a9abb5e57423e6b4a737a666725098fa3449b3d7..9090652d56b7d0791896f2bce1bc678d3552fd7a 100644 (file)
@@ -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},
index 157485d11c666f58645658725dc2fa06c0ff108f..bc0fef963c9f6d3505e2fa1c4b04c8f74b845a23 100644 (file)
@@ -9,15 +9,21 @@
 #include <errno.h>
 
 #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);
                        }
index 9b63498b0a8b2e22c6d63a517f55a3ebd08945a0..511f5f85c13affe4042e90d68d626f8a4f44bb03 100644 (file)
@@ -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.
 #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;
 
index cfb4d6aa0f91ba569767425366f931bc0508d5e9..572f316224e45ba2648d36cf3f1707e7bf22068f 100644 (file)
@@ -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;
 }