diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | Makefile.in | 6 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | doc/file.man | 15 | ||||
-rw-r--r-- | doc/magic.man | 4 | ||||
-rw-r--r-- | src/ascmagic.c | 9 | ||||
-rw-r--r-- | src/file.c | 21 | ||||
-rw-r--r-- | src/file.h | 4 | ||||
-rw-r--r-- | src/patchlevel.h | 11 | ||||
-rw-r--r-- | src/readelf.c | 21 | ||||
-rw-r--r-- | src/softmagic.c | 9 |
12 files changed, 77 insertions, 29 deletions
diff --git a/Makefile.am b/Makefile.am index c26f6f93..46fd2ae9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -116,7 +116,6 @@ Magdir/ibm370 \ Magdir/ibm6000 \ Magdir/iff \ Magdir/images \ -Magdir/impulse \ Magdir/intel \ Magdir/interleaf \ Magdir/island \ diff --git a/Makefile.in b/Makefile.in index 19d74b75..8dd783a6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -86,7 +86,7 @@ EXTRA_DIST = LEGAL.NOTICE MAINT PORTING Makefile.std magic2mime Localstuff Head CLEANFILES = $(man_MANS) magic magic.mgc magic.mime.mgc -magic_FRAGMENTS = Magdir/acorn Magdir/adi Magdir/adventure Magdir/allegro Magdir/alliant Magdir/alpha Magdir/amanda Magdir/amigaos Magdir/animation Magdir/apl Magdir/apple Magdir/applix Magdir/archive Magdir/asterix Magdir/att3b Magdir/audio Magdir/blender Magdir/blit Magdir/bsdi Magdir/c-lang Magdir/cddb Magdir/chi Magdir/cisco Magdir/citrus Magdir/claris Magdir/clipper Magdir/commands Magdir/compress Magdir/console Magdir/convex Magdir/ctags Magdir/cvs Magdir/database Magdir/diamond Magdir/diff Magdir/digital Magdir/dolby Magdir/dump Magdir/dyadic Magdir/editors Magdir/elf Magdir/encore Magdir/epoc Magdir/filesystems Magdir/flash Magdir/fonts Magdir/frame Magdir/freebsd Magdir/fsav Magdir/gimp Magdir/gnu Magdir/grace Magdir/gringotts Magdir/hitachi-sh Magdir/hp Magdir/ibm370 Magdir/ibm6000 Magdir/iff Magdir/images Magdir/impulse Magdir/intel Magdir/interleaf Magdir/island Magdir/ispell Magdir/java Magdir/jpeg Magdir/karma Magdir/lecter Magdir/lex Magdir/lif Magdir/linux Magdir/lisp Magdir/mach Magdir/macintosh Magdir/magic Magdir/mail.news Magdir/maple Magdir/mathematica Magdir/mcrypt Magdir/mime Magdir/mips Magdir/mirage Magdir/mkid Magdir/mmdf Magdir/mlssa Magdir/modem Magdir/motorola Magdir/msdos Magdir/msvc Magdir/natinst Magdir/ncr Magdir/netbsd Magdir/netscape Magdir/news Magdir/nitpicker Magdir/octave Magdir/olf Magdir/os2 Magdir/os9 Magdir/osf1 Magdir/palm Magdir/parix Magdir/pbm Magdir/pdf Magdir/pdp Magdir/perl Magdir/pgp Magdir/pkgadd Magdir/plus5 Magdir/printer Magdir/project Magdir/psdbms Magdir/pulsar Magdir/pyramid Magdir/python Magdir/riff Magdir/rpm Magdir/rtf Magdir/sc Magdir/sccs Magdir/sendmail Magdir/sequent Magdir/sgml Magdir/sharc Magdir/sketch Magdir/smalltalk Magdir/sniffer Magdir/softquad Magdir/spectrum Magdir/sun Magdir/sysex Magdir/teapot Magdir/terminfo Magdir/tex Magdir/tgif Magdir/ti-8x Magdir/timezone Magdir/troff Magdir/tuxedo Magdir/typeset Magdir/unknown Magdir/uuencode Magdir/varied.out Magdir/vax Magdir/vicar Magdir/visx Magdir/vms Magdir/vmware Magdir/vorbis Magdir/vxl Magdir/wordperfect Magdir/xdelta Magdir/xenix Magdir/zilog Magdir/zyxel +magic_FRAGMENTS = Magdir/acorn Magdir/adi Magdir/adventure Magdir/allegro Magdir/alliant Magdir/alpha Magdir/amanda Magdir/amigaos Magdir/animation Magdir/apl Magdir/apple Magdir/applix Magdir/archive Magdir/asterix Magdir/att3b Magdir/audio Magdir/blender Magdir/blit Magdir/bsdi Magdir/c-lang Magdir/cddb Magdir/chi Magdir/cisco Magdir/citrus Magdir/claris Magdir/clipper Magdir/commands Magdir/compress Magdir/console Magdir/convex Magdir/ctags Magdir/cvs Magdir/database Magdir/diamond Magdir/diff Magdir/digital Magdir/dolby Magdir/dump Magdir/dyadic Magdir/editors Magdir/elf Magdir/encore Magdir/epoc Magdir/filesystems Magdir/flash Magdir/fonts Magdir/frame Magdir/freebsd Magdir/fsav Magdir/gimp Magdir/gnu Magdir/grace Magdir/gringotts Magdir/hitachi-sh Magdir/hp Magdir/ibm370 Magdir/ibm6000 Magdir/iff Magdir/images Magdir/intel Magdir/interleaf Magdir/island Magdir/ispell Magdir/java Magdir/jpeg Magdir/karma Magdir/lecter Magdir/lex Magdir/lif Magdir/linux Magdir/lisp Magdir/mach Magdir/macintosh Magdir/magic Magdir/mail.news Magdir/maple Magdir/mathematica Magdir/mcrypt Magdir/mime Magdir/mips Magdir/mirage Magdir/mkid Magdir/mmdf Magdir/mlssa Magdir/modem Magdir/motorola Magdir/msdos Magdir/msvc Magdir/natinst Magdir/ncr Magdir/netbsd Magdir/netscape Magdir/news Magdir/nitpicker Magdir/octave Magdir/olf Magdir/os2 Magdir/os9 Magdir/osf1 Magdir/palm Magdir/parix Magdir/pbm Magdir/pdf Magdir/pdp Magdir/perl Magdir/pgp Magdir/pkgadd Magdir/plus5 Magdir/printer Magdir/project Magdir/psdbms Magdir/pulsar Magdir/pyramid Magdir/python Magdir/riff Magdir/rpm Magdir/rtf Magdir/sc Magdir/sccs Magdir/sendmail Magdir/sequent Magdir/sgml Magdir/sharc Magdir/sketch Magdir/smalltalk Magdir/sniffer Magdir/softquad Magdir/spectrum Magdir/sun Magdir/sysex Magdir/teapot Magdir/terminfo Magdir/tex Magdir/tgif Magdir/ti-8x Magdir/timezone Magdir/troff Magdir/tuxedo Magdir/typeset Magdir/unknown Magdir/uuencode Magdir/varied.out Magdir/vax Magdir/vicar Magdir/visx Magdir/vms Magdir/vmware Magdir/vorbis Magdir/vxl Magdir/wordperfect Magdir/xdelta Magdir/xenix Magdir/zilog Magdir/zyxel ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -122,7 +122,7 @@ missing mkinstalldirs DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = gtar +TAR = tar GZIP_ENV = --best SOURCES = $(file_SOURCES) OBJECTS = $(file_OBJECTS) @@ -416,7 +416,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/config.h.in b/config.h.in index 9963fbf7..36e61edc 100644 --- a/config.h.in +++ b/config.h.in @@ -88,6 +88,9 @@ /* Define if you have the <getopt.h> header file. */ #undef HAVE_GETOPT_H +/* Define if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + /* Define if you have the <locale.h> header file. */ #undef HAVE_LOCALE_H diff --git a/configure.in b/configure.in index 7c5536bc..ac460e92 100644 --- a/configure.in +++ b/configure.in @@ -60,10 +60,10 @@ AC_HEADER_SYS_WAIT AC_HEADER_STDINT AC_CHECK_HEADERS(fcntl.h locale.h) AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h) +AC_CHECK_HEADERS(stdint.h inttypes.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(getopt.h) AC_CHECK_HEADERS(locale.h) -AC_CHECK_HEADERS(stdint.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git a/doc/file.man b/doc/file.man index de3e0a6e..f47509fb 100644 --- a/doc/file.man +++ b/doc/file.man @@ -1,18 +1,21 @@ .TH FILE __CSECTION__ "Copyright but distributable" -.\" $Id: file.man,v 1.42 2002/07/03 18:26:37 christos Exp $ +.\" $Id: file.man,v 1.43 2003/02/08 18:33:53 christos Exp $ .SH NAME file \- determine file type .SH SYNOPSIS .B file [ -.B \-bciknsvzL +.B \-bciknNsvzL ] [ .B \-f .I namefile ] [ +.B \-F +separator ] +[ .B \-m .I magicfiles ] @@ -172,6 +175,9 @@ Either or at least one filename argument must be present; to test the standard input, use ``\-'' as a filename argument. .TP 8 +.BI \-F " separator" +Use the specified separator character instead of ``:''. +.TP 8 .B \-i Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say @@ -195,6 +201,9 @@ Force stdout to be flushed after checking each file. This is only useful if checking a list of files. It is intended to be used by programs that want filetype output from a pipe. .TP 8 +.B \-N +Don't pad output to align filenames nicely. +.TP 8 .B \-v Print the version of the program and exit. .TP 8 @@ -228,7 +237,7 @@ to disregard the file size as reported by since on some systems it reports a zero size for raw disk partitions. .SH FILES .I __MAGIC__.mgc -\- defaults compiled list of magic numbers +\- default compiled list of magic numbers .PP .I __MAGIC__ \- default list of magic numbers diff --git a/doc/magic.man b/doc/magic.man index 81e5fb38..b07f5844 100644 --- a/doc/magic.man +++ b/doc/magic.man @@ -170,7 +170,7 @@ is used as an offset in the file. A byte, short or long is read at that offset depending on the .B [bslBSL] type specifier. The capitalized types interpret the number as a big endian -value, whereas the small letter versions interpet the number as a little +value, whereas the small letter versions interpret the number as a little endian value. To that number the value of .I y is added and the result is used as an offset in the file. The default type @@ -219,4 +219,4 @@ indirect offsets. .\" the changes I posted to the S5R2 version. .\" .\" Modified for Ian Darwin's version of the file command. -.\" @(#)$Id: magic.man,v 1.19 2002/07/03 18:26:38 christos Exp $ +.\" @(#)$Id: magic.man,v 1.20 2003/02/08 18:33:53 christos Exp $ diff --git a/src/ascmagic.c b/src/ascmagic.c index cbbcbe83..8217f194 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -45,7 +45,7 @@ #include "names.h" #ifndef lint -FILE_RCSID("@(#)$Id: ascmagic.c,v 1.32 2002/07/03 18:26:37 christos Exp $") +FILE_RCSID("@(#)$Id: ascmagic.c,v 1.33 2003/02/08 18:33:53 christos Exp $") #endif /* lint */ typedef unsigned long unichar; @@ -67,7 +67,7 @@ int ascmagic(unsigned char *buf, int nbytes) { int i; - char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */ + unsigned char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */ unichar ubuf[HOWMANY+1]; /* one extra for terminating '\0' */ int ulen; struct names *p; @@ -211,7 +211,8 @@ ascmagic(unsigned char *buf, int nbytes) * compare the word thus isolated against the token list */ for (p = names; p < names + NNAMES; p++) { - if (ascmatch(p->name, ubuf + i, end - i)) { + if (ascmatch((unsigned char *)p->name, ubuf + i, + end - i)) { subtype = types[p->type].human; subtype_mime = types[p->type].mime; goto subtype_identified; @@ -565,7 +566,7 @@ looks_unicode(const unsigned char *buf, int nbytes, unichar *ubuf, int *ulen) return 0; } - return 1; + return 1 + bigend; } #undef F @@ -58,7 +58,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.67 2002/07/09 14:12:40 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.68 2003/02/08 18:33:53 christos Exp $") #endif /* lint */ @@ -88,7 +88,8 @@ int /* Global command-line options */ zflag = 0, /* follow (uncompress) compressed files */ sflag = 0, /* read block special files */ iflag = 0, - nobuffer = 0, /* Do not buffer stdout */ + nopad = 0, /* Don't pad output */ + nobuffer = 0, /* Do not buffer stdout */ kflag = 0; /* Keep going after the first match */ int /* Misc globals */ @@ -99,6 +100,8 @@ struct magic *magic; /* array of magic entries */ const char *magicfile = 0; /* where the magic is */ const char *default_magicfile = MAGIC; +char separator = ':'; /* Default field separator */ + char *progname; /* used throughout */ int lineno; /* line number in the magic file */ @@ -125,7 +128,7 @@ main(int argc, char **argv) int action = 0, didsomefiles = 0, errflg = 0, ret = 0, app = 0; char *mime, *home, *usermagic; struct stat sb; -#define OPTSTRING "bcdf:ikm:nsvzCL" +#define OPTSTRING "bcdf:F:ikm:nNsvzCL" #ifdef HAVE_GETOPT_LONG int longindex; static struct option long_options[] = @@ -136,6 +139,7 @@ main(int argc, char **argv) {"checking-printout", 0, 0, 'c'}, {"debug", 0, 0, 'd'}, {"files-from", 1, 0, 'f'}, + {"separator", 1, 0, 'F'}, {"mime", 0, 0, 'i'}, {"keep-going", 0, 0, 'k'}, #ifdef S_IFLNK @@ -144,6 +148,7 @@ main(int argc, char **argv) {"magic-file", 1, 0, 'm'}, {"uncompress", 0, 0, 'z'}, {"no-buffer", 0, 0, 'n'}, + {"no-pad", 0, 0, 'N'}, {"special-files", 0, 0, 's'}, {"compile", 0, 0, 'C'}, {0, 0, 0, 0}, @@ -214,6 +219,9 @@ main(int argc, char **argv) unwrap(optarg); ++didsomefiles; break; + case 'F': + separator = *optarg; + break; case 'i': iflag++; if ((mime = malloc(strlen(magicfile) + 6)) != NULL) { @@ -231,6 +239,9 @@ main(int argc, char **argv) case 'n': ++nobuffer; break; + case 'N': + ++nopad; + break; case 's': sflag++; break; @@ -404,8 +415,8 @@ process(const char *inname, int wid) } if (wid > 0 && !bflag) - (void) printf("%s:%*s ", inname, - (int) (wid - strlen(inname)), ""); + (void) printf("%s%c%*s", inname, separator, + (int) (nopad ? 0 : 1 + (wid - strlen(inname))), ""); if (inname != stdname) { /* @@ -1,6 +1,6 @@ /* * file.h - definitions for file(1) program - * @(#)$Id: file.h,v 1.44 2002/07/09 14:12:40 christos Exp $ + * @(#)$Id: file.h,v 1.45 2003/02/08 18:33:53 christos Exp $ * * Copyright (c) Ian F. Darwin, 1987. * Written by Ian F. Darwin. @@ -43,6 +43,8 @@ #include <stdio.h> #ifdef HAVE_STDINT_H #include <stdint.h> +#elif defined(HAVE_INTTYPES_H) +#include <inttypes.h> #endif /* Do this here and now, because struct stat gets re-defined on solaris */ #include <sys/stat.h> diff --git a/src/patchlevel.h b/src/patchlevel.h index de8d598a..aba74611 100644 --- a/src/patchlevel.h +++ b/src/patchlevel.h @@ -1,11 +1,18 @@ #define FILE_VERSION_MAJOR 3 -#define patchlevel 39 +#define patchlevel 40 /* * Patchlevel file for Ian Darwin's MAGIC command. - * $Id: patchlevel.h,v 1.39 2002/07/03 18:57:52 christos Exp $ + * $Id: patchlevel.h,v 1.40 2003/02/08 18:33:53 christos Exp $ * * $Log: patchlevel.h,v $ + * Revision 1.40 2003/02/08 18:33:53 christos + * - detect inttypes.h too (Dave Love <d.love@dl.ac.uk>) + * - eliminate unsigned char warnings (Petter Reinholdtsen <pere@hungry.com>) + * - better elf PT_NOTE handling (Nalin Dahyabhai <nalin@redhat.com>) + * - add options to format the output differently + * - much more magic. + * * Revision 1.39 2002/07/03 18:57:52 christos * - ansify/c99ize * - more magic diff --git a/src/readelf.c b/src/readelf.c index 0ae8ef31..6e19167e 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -11,7 +11,7 @@ #include "readelf.h" #ifndef lint -FILE_RCSID("@(#)$Id: readelf.c,v 1.22 2002/07/03 18:26:38 christos Exp $") +FILE_RCSID("@(#)$Id: readelf.c,v 1.23 2003/02/08 18:33:53 christos Exp $") #endif #ifdef ELFCORE @@ -104,6 +104,9 @@ getu64(int swap, uint64_t value) #define ph_offset (class == ELFCLASS32 \ ? getu32(swap, ph32.p_offset) \ : getu64(swap, ph64.p_offset)) +#define ph_align (class == ELFCLASS32 \ + ? (ph32.p_align ? getu32(swap, ph32.p_align) : 4) \ + : (ph64.p_align ? getu64(swap, ph64.p_align) : 4)) #define nh_size (class == ELFCLASS32 \ ? sizeof *nh32 \ : sizeof *nh64) @@ -157,6 +160,7 @@ dophn_exec(int class, int swap, int fd, off_t off, int num, size_t size) char nbuf[BUFSIZ]; int bufsize; size_t offset, nameoffset; + off_t savedoffset; if (lseek(fd, off, SEEK_SET) == -1) error("lseek failed (%s).\n", strerror(errno)); @@ -164,6 +168,8 @@ dophn_exec(int class, int swap, int fd, off_t off, int num, size_t size) for ( ; num; num--) { if (read(fd, ph_addr, size) == -1) error("read failed (%s).\n", strerror(errno)); + if ((savedoffset = lseek(fd, 0, SEEK_CUR)) == -1) + error("lseek failed (%s).\n", strerror(errno)); switch (ph_type) { case PT_DYNAMIC: @@ -179,7 +185,7 @@ dophn_exec(int class, int swap, int fd, off_t off, int num, size_t size) */ if (lseek(fd, (off_t) ph_offset, SEEK_SET) == -1) error("lseek failed (%s).\n", strerror(errno)); - bufsize = read(fd, nbuf, BUFSIZ); + bufsize = read(fd, nbuf, sizeof(nbuf)); if (bufsize == -1) error(": " "read failed (%s).\n", strerror(errno)); @@ -202,7 +208,14 @@ dophn_exec(int class, int swap, int fd, off_t off, int num, size_t size) nameoffset = offset; offset += nh_namesz; - offset = ((offset + 3)/4)*4; + offset = ((offset+ph_align-1)/ph_align)*ph_align; + + if ((nh_namesz == 0) && (nh_descsz == 0)) { + /* + * We're out of note headers. + */ + break; + } if (offset + nh_descsz >= bufsize) break; @@ -277,6 +290,8 @@ dophn_exec(int class, int swap, int fd, off_t off, int num, size_t size) /* Content of note is always 0 */ } } + if ((lseek(fd, savedoffset + offset, SEEK_SET)) == -1) + error("lseek failed (%s).\n", strerror(errno)); break; } } diff --git a/src/softmagic.c b/src/softmagic.c index 891910c7..8ef5fbf3 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -34,7 +34,7 @@ #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.51 2002/07/03 18:26:38 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.52 2003/02/08 18:33:53 christos Exp $") #endif /* lint */ static int match(struct magic *, uint32_t, unsigned char *, int); @@ -564,9 +564,10 @@ mget(union VALUETYPE *p, unsigned char *s, struct magic *m, int nbytes) * offset is interpreted as last line to search, * (starting at 1), not as bytes-from start-of-file */ - char *last = NULL; - p->buf = s; - for (; offset && (s = strchr(s, '\n')) != NULL; offset--, s++) + unsigned char *last = NULL; + p->buf = (char *)s; + for (; offset && (s = (unsigned char *)strchr(s, '\n')) != NULL; + offset--, s++) last = s; if (last != NULL) *last = '\0'; |