summaryrefslogtreecommitdiffstats
path: root/usr.bin/file
diff options
context:
space:
mode:
authormpp <mpp@FreeBSD.org>1996-01-23 12:40:36 +0000
committermpp <mpp@FreeBSD.org>1996-01-23 12:40:36 +0000
commit7e3b21a299153c576c06d09f9b4dabd3063315f8 (patch)
tree6cc6a8b30063115a67cc5c6db8c16fd98f1c4d77 /usr.bin/file
parentbed6c740ce8181de2bc93f03538f1e7a09689ece (diff)
downloadFreeBSD-src-7e3b21a299153c576c06d09f9b4dabd3063315f8.zip
FreeBSD-src-7e3b21a299153c576c06d09f9b4dabd3063315f8.tar.gz
Merged changes to resolve conflicts with file 3.19 import.
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/Magdir/pgp13
-rw-r--r--usr.bin/file/Magdir/zyxel17
-rw-r--r--usr.bin/file/apprentice.c129
-rw-r--r--usr.bin/file/ascmagic.c43
-rw-r--r--usr.bin/file/compress.c17
-rw-r--r--usr.bin/file/file.155
-rw-r--r--usr.bin/file/file.c127
-rw-r--r--usr.bin/file/file.h9
-rw-r--r--usr.bin/file/fsmagic.c4
-rw-r--r--usr.bin/file/magic.516
-rw-r--r--usr.bin/file/names.h2
-rw-r--r--usr.bin/file/patchlevel.h42
-rw-r--r--usr.bin/file/print.c10
-rw-r--r--usr.bin/file/softmagic.c28
14 files changed, 357 insertions, 155 deletions
diff --git a/usr.bin/file/Magdir/pgp b/usr.bin/file/Magdir/pgp
index eb10f21..aaff0e9 100644
--- a/usr.bin/file/Magdir/pgp
+++ b/usr.bin/file/Magdir/pgp
@@ -1,11 +1,12 @@
-#
-# PGP (Pretty Good Privacy)
+
+#------------------------------------------------------------------------------
+# pgp: file(1) magic for Pretty Good Privacy
#
0 beshort 0x9900 PGP key public ring
0 beshort 0x9501 PGP key security ring
0 beshort 0x9500 PGP key security ring
0 string -----BEGIN\040PGP PGP armored data
->15 string PUBLIC\040KEY\040BLOCK- (public key block)
->15 string MESSAGE- (message)
->15 string SIGNED\040MESSAGE- (signed message)
->15 string PGP\040SIGNATURE- (signature)
+>15 string PUBLIC\040KEY\040BLOCK- public key block
+>15 string MESSAGE- message
+>15 string SIGNED\040MESSAGE- signed message
+>15 string PGP\040SIGNATURE- signature
diff --git a/usr.bin/file/Magdir/zyxel b/usr.bin/file/Magdir/zyxel
index 410e93c..12a6abd 100644
--- a/usr.bin/file/Magdir/zyxel
+++ b/usr.bin/file/Magdir/zyxel
@@ -1,11 +1,16 @@
+
+#------------------------------------------------------------------------------
+# zyxel: file(1) magic for ZyXEL modems
+#
# From <rob@pe1chl.ampr.org>
# These are the /etc/magic entries to decode datafiles as used for the
# ZyXEL U-1496E DATA/FAX/VOICE modems. (This header conforms to a
# ZyXEL-defined standard)
-0 string ZyXEL\002 ZyXEL voice data
->10 byte 0 - CELP encoding
->10 byte 1 - ADPCM2 encoding
->10 byte 2 - ADPCM3 encoding
->10 byte 3 - ADPCM4 encoding
-
+0 string ZyXEL\002 ZyXEL voice data
+>10 byte 0 - CELP encoding
+>10 byte&0x0B 1 - ADPCM2 encoding
+>10 byte&0x0B 2 - ADPCM3 encoding
+>10 byte&0x0B 3 - ADPCM4 encoding
+>10 byte&0x0B 8 - New ADPCM3 encoding
+>10 byte&0x04 4 with resync
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c
index 6cdacaa..0eb1983 100644
--- a/usr.bin/file/apprentice.c
+++ b/usr.bin/file/apprentice.c
@@ -29,56 +29,92 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include "file.h"
#ifndef lint
static char *moduleid =
- "@(#)$Id: apprentice.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $";
+ "@(#)$Id: apprentice.c,v 1.2 1995/05/30 06:29:58 rgrimes Exp $";
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
isspace((unsigned char) *l)) ++l;}
+#define LOWCASE(l) (isupper((unsigned char) (l)) ? \
+ tolower((unsigned char) (l)) : (l))
static int getvalue __P((struct magic *, char **));
static int hextoint __P((int));
static char *getstr __P((char *, char *, int, int *));
static int parse __P((char *, int *, int));
+static void eatsize __P((char **));
static int maxmagic = 0;
+static int apprentice_1 __P((char *, int));
+
int
apprentice(fn, check)
-char *fn; /* name of magic file */
+char *fn; /* list of magic files */
int check; /* non-zero? checking-only run. */
{
- FILE *f;
- char line[BUFSIZ+1];
- int errs = 0;
-
- f = fopen(fn, "r");
- if (f==NULL) {
- (void) fprintf(stderr, "%s: can't read magic file %s\n",
- progname, fn);
- if (check)
- return -1;
- else
- exit(1);
- }
+ char *p, *mfn;
+ int file_err, errs = -1;
maxmagic = MAXMAGIS;
- if ((magic = (struct magic *) calloc(sizeof(struct magic), maxmagic))
- == NULL) {
+ magic = (struct magic *) calloc(sizeof(struct magic), maxmagic);
+ mfn = malloc(strlen(fn)+1);
+ if (magic == NULL || mfn == NULL) {
(void) fprintf(stderr, "%s: Out of memory.\n", progname);
if (check)
return -1;
else
exit(1);
}
+ fn = strcpy(mfn, fn);
+
+ while (fn) {
+ p = strchr(fn, ':');
+ if (p)
+ *p++ = '\0';
+ file_err = apprentice_1(fn, check);
+ if (file_err > errs)
+ errs = file_err;
+ fn = p;
+ }
+ if (errs == -1)
+ (void) fprintf(stderr, "%s: couldn't find any magic files!\n",
+ progname);
+ if (!check && errs)
+ exit(1);
+
+ free(mfn);
+ return errs;
+}
+
+static int
+apprentice_1(fn, check)
+char *fn; /* name of magic file */
+int check; /* non-zero? checking-only run. */
+{
+ static const char hdr[] =
+ "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
+ FILE *f;
+ char line[BUFSIZ+1];
+ int errs = 0;
+
+ f = fopen(fn, "r");
+ if (f==NULL) {
+ if (errno != ENOENT)
+ (void) fprintf(stderr,
+ "%s: can't read magic file %s (%s)\n",
+ progname, fn, strerror(errno));
+ return -1;
+ }
/* parse it */
if (check) /* print silly verbose header for USG compat. */
- (void) printf("cont\toffset\ttype\topcode\tmask\tvalue\tdesc\n");
+ (void) printf("%s\n", hdr);
for (lineno = 1;fgets(line, BUFSIZ, f) != NULL; lineno++) {
if (line[0]=='#') /* comment, do not parse */
@@ -87,11 +123,11 @@ int check; /* non-zero? checking-only run. */
continue;
line[strlen(line)-1] = '\0'; /* delete newline */
if (parse(line, &nmagic, check) != 0)
- ++errs;
+ errs = 1;
}
(void) fclose(f);
- return errs ? -1 : 0;
+ return errs;
}
/*
@@ -147,10 +183,11 @@ int *ndx, check;
struct magic *m;
char *t, *s;
+#define ALLOC_INCR 20
if (nd+1 >= maxmagic){
- maxmagic += 20;
- if ((magic = (struct magic *) realloc(magic,
- sizeof(struct magic) *
+ maxmagic += ALLOC_INCR;
+ if ((magic = (struct magic *) realloc(magic,
+ sizeof(struct magic) *
maxmagic)) == NULL) {
(void) fprintf(stderr, "%s: Out of memory.\n", progname);
if (check)
@@ -158,6 +195,7 @@ int *ndx, check;
else
exit(1);
}
+ memset(&magic[*ndx], 0, sizeof(struct magic) * ALLOC_INCR);
}
m = &magic[*ndx];
m->flag = 0;
@@ -174,7 +212,7 @@ int *ndx, check;
}
/* get offset, then skip over it */
- m->offset = (int) strtol(l,&t,0);
+ m->offset = (int) strtoul(l,&t,0);
if (l == t)
magwarn("offset %s invalid", l);
l = t;
@@ -186,13 +224,16 @@ int *ndx, check;
* read [.lbs][+-]nnnnn)
*/
if (*l == '.') {
- switch (*++l) {
+ l++;
+ switch (LOWCASE(*l)) {
case 'l':
m->in.type = LONG;
break;
+ case 'h':
case 's':
m->in.type = SHORT;
break;
+ case 'c':
case 'b':
m->in.type = BYTE;
break;
@@ -205,7 +246,7 @@ int *ndx, check;
s = l;
if (*l == '+' || *l == '-') l++;
if (isdigit((unsigned char)*l)) {
- m->in.offset = strtol(l, &t, 0);
+ m->in.offset = strtoul(l, &t, 0);
if (*s == '-') m->in.offset = - m->in.offset;
}
else
@@ -278,7 +319,8 @@ int *ndx, check;
/* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */
if (*l == '&') {
++l;
- m->mask = signextend(m, strtol(l, &l, 0));
+ m->mask = signextend(m, strtoul(l, &l, 0));
+ eatsize(&l);
} else
m->mask = ~0L;
EATAB;
@@ -360,8 +402,10 @@ char **p;
*p = getstr(*p, m->value.s, sizeof(m->value.s), &slen);
m->vallen = slen;
} else
- if (m->reln != 'x')
- m->value.l = signextend(m, strtol(*p, p, 0));
+ if (m->reln != 'x') {
+ m->value.l = signextend(m, strtoul(*p, p, 0));
+ eatsize(p);
+ }
return 0;
}
@@ -549,3 +593,30 @@ int len;
}
}
}
+
+/*
+ * eatsize(): Eat the size spec from a number [eg. 10UL]
+ */
+static void
+eatsize(p)
+char **p;
+{
+ char *l = *p;
+
+ if (LOWCASE(*l) == 'u')
+ l++;
+
+ switch (LOWCASE(*l)) {
+ case 'l': /* long */
+ case 's': /* short */
+ case 'h': /* short */
+ case 'b': /* char/byte */
+ case 'c': /* char/byte */
+ l++;
+ /*FALLTHROUGH*/
+ default:
+ break;
+ }
+
+ *p = l;
+}
diff --git a/usr.bin/file/ascmagic.c b/usr.bin/file/ascmagic.c
index 0edb0ca..4280b51 100644
--- a/usr.bin/file/ascmagic.c
+++ b/usr.bin/file/ascmagic.c
@@ -1,5 +1,5 @@
/*
- * Ascii magic -- file types that we know based on keywords
+ * ASCII magic -- file types that we know based on keywords
* that can appear anywhere in the file.
*
* Copyright (c) Ian F. Darwin, 1987.
@@ -36,7 +36,7 @@
#ifndef lint
static char *moduleid =
- "@(#)$Id: ascmagic.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $";
+ "@(#)$Id: ascmagic.c,v 1.2 1995/05/30 06:29:59 rgrimes Exp $";
#endif /* lint */
/* an optimisation over plain strcmp() */
@@ -47,13 +47,24 @@ ascmagic(buf, nbytes)
unsigned char *buf;
int nbytes; /* size actually read */
{
- int i, isblock, has_escapes = 0;
+ int i, has_escapes = 0;
unsigned char *s;
char nbuf[HOWMANY+1]; /* one extra for terminating '\0' */
char *token;
register struct names *p;
- /* these are easy, do them first */
+ /*
+ * Do the tar test first, because if the first file in the tar
+ * archive starts with a dot, we can confuse it with an nroff file.
+ */
+ switch (is_tar(buf, nbytes)) {
+ case 1:
+ ckfputs("tar archive", stdout);
+ return 1;
+ case 2:
+ ckfputs("POSIX tar archive", stdout);
+ return 1;
+ }
/*
* for troff, look for . + letter + letter or .\";
@@ -66,13 +77,13 @@ int nbytes; /* size actually read */
while (isascii(*tp) && isspace(*tp))
++tp; /* skip leading whitespace */
if ((isascii(*tp) && (isalnum(*tp) || *tp=='\\') &&
- isascii(*(tp+1)) && (isalnum(*(tp+1)) || *tp=='"'))) {
+ isascii(tp[1]) && (isalnum(tp[1]) || tp[1] == '"'))) {
ckfputs("troff or preprocessor input text", stdout);
return 1;
}
}
- if ((*buf == 'c' || *buf == 'C') &&
- isascii(*(buf + 1)) && isspace(*(buf + 1))) {
+ if ((*buf == 'c' || *buf == 'C') &&
+ isascii(buf[1]) && isspace(buf[1])) {
ckfputs("fortran program text", stdout);
return 1;
}
@@ -82,7 +93,7 @@ int nbytes; /* size actually read */
s = (unsigned char*) memcpy(nbuf, buf, nbytes);
s[nbytes] = '\0';
has_escapes = (memchr(s, '\033', nbytes) != NULL);
- while ((token = strtok((char*)s, " \t\n\r\f")) != NULL) {
+ while ((token = strtok((char *) s, " \t\n\r\f")) != NULL) {
s = NULL; /* make strtok() keep on tokin' */
for (p = names; p < names + NNAMES; p++) {
if (STREQ(p->name, token)) {
@@ -95,22 +106,14 @@ int nbytes; /* size actually read */
}
}
- switch (is_tar(buf, nbytes)) {
- case 1:
- ckfputs("tar archive", stdout);
- return 1;
- case 2:
- ckfputs("POSIX tar archive", stdout);
- return 1;
- }
for (i = 0; i < nbytes; i++) {
- if (!isascii(*(buf+i)))
- return 0; /* not all ascii */
+ if (!isascii(buf[i]))
+ return 0; /* not all ASCII */
}
- /* all else fails, but it is ascii... */
- ckfputs("ascii text", stdout);
+ /* all else fails, but it is ASCII... */
+ ckfputs("ASCII text", stdout);
if (has_escapes) {
ckfputs(" (with escape sequences)", stdout);
}
diff --git a/usr.bin/file/compress.c b/usr.bin/file/compress.c
index 1c0d824..a648429 100644
--- a/usr.bin/file/compress.c
+++ b/usr.bin/file/compress.c
@@ -4,7 +4,7 @@
* information if recognized
* uncompress(method, old, n, newch) - uncompress old into new,
* using method, return sizeof new
- * $Id: compress.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $
+ * $Id: compress.c,v 1.2 1995/05/30 06:30:00 rgrimes Exp $
*/
#include <stdio.h>
#include <stdlib.h>
@@ -20,13 +20,12 @@ static struct {
char *argv[3];
int silent;
} compr[] = {
- { "\037\235", 2, { "uncompress", "-c", NULL }, 0 },
- { "\037\213", 2, { "gzip", "-dq", NULL }, 1 },
- /*
- * XXX pcat does not work, cause I don't know how to make it read stdin,
- * so we use gzip
- */
- { "\037\036", 2, { "gzip", "-dq", NULL }, 0 },
+ { "\037\235", 2, { "uncompress", "-c", NULL }, 0 }, /* compressed */
+ { "\037\213", 2, { "gzip", "-cdq", NULL }, 1 }, /* gzipped */
+ { "\037\236", 2, { "gzip", "-cdq", NULL }, 1 }, /* frozen */
+ { "\037\240", 2, { "gzip", "-cdq", NULL }, 1 }, /* SCO LZH */
+ /* the standard pack utilities do not accept standard input */
+ { "\037\036", 2, { "gzip", "-cdq", NULL }, 0 }, /* packed */
};
static int ncompr = sizeof(compr) / sizeof(compr[0]);
@@ -121,5 +120,3 @@ int n;
return n;
}
}
-
-
diff --git a/usr.bin/file/file.1 b/usr.bin/file/file.1
index 555261f..0b849e2 100644
--- a/usr.bin/file/file.1
+++ b/usr.bin/file/file.1
@@ -1,25 +1,19 @@
.TH FILE 1 "Copyright but distributable"
-.\# $Id: file.man,v 1.23 1993/09/24 18:50:48 christos Exp $
+.\# $Id: file.1,v 1.2 1994/09/03 19:31:15 csgr Exp $
.SH NAME
-.I file
+file
\- determine file type
.SH SYNOPSIS
.B file
[
-.B \-c
-]
-[
-.B \-z
-]
-[
-.B \-L
+.B \-vczL
]
[
.B \-f
namefile ]
[
.B \-m
-magicfile ]
+magicfiles ]
file ...
.SH DESCRIPTION
.I File
@@ -101,42 +95,45 @@ The language test routines also test for some miscellany
.I tar
archives) and determine whether an unknown file should be
labelled as `ascii text' or `data'.
-.PP
-Use
-.B \-m
-.I file
-to specify an alternate file of magic numbers.
-.PP
-The
+.SH OPTIONS
+.TP 8
+.B \-v
+Print the version of the program and exit.
+.TP 8
+.B \-m list
+Specify an alternate list of files containing magic numbers.
+This can be a single file, or a colon-separated list of files.
+.TP 8
.B \-z
-tries to look inside compressed files.
-.PP
-The
+Try to look inside compressed files.
+.TP 8
.B \-c
-option causes a checking printout of the parsed form of the magic file.
+Cause a checking printout of the parsed form of the magic file.
This is usually used in conjunction with
.B \-m
to debug a new magic file before installing it.
-.PP
-The
-.B \-f
-.I namefile
-option specifies that the names of the files to be examined
-are to be read (one per line) from
+.TP 8
+.B \-f namefile
+Read the names of the files to be examined from
.I namefile
+(one per line)
before the argument list.
Either
.I namefile
or at least one filename argument must be present;
to test the standard input, use ``-'' as a filename argument.
-.PP
-The
+.TP 8
.B \-L
option causes symlinks to be followed, as the like-named option in
.IR ls (1).
+(on systems that support symbolic links).
.SH FILES
.I /etc/magic
\- default list of magic numbers
+.SH ENVIRONMENT
+The environment variable
+.B MAGIC
+can be used to set the default magic number files.
.SH SEE ALSO
.IR magic (5)
\- description of magic file format.
diff --git a/usr.bin/file/file.c b/usr.bin/file/file.c
index 4b12a9a..5814255 100644
--- a/usr.bin/file/file.c
+++ b/usr.bin/file/file.c
@@ -26,7 +26,7 @@
*/
#ifndef lint
static char *moduleid =
- "@(#)$Id: file.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $";
+ "@(#)$Id: file.c,v 1.2 1995/05/30 06:30:01 rgrimes Exp $";
#endif /* lint */
#include <stdio.h>
@@ -36,15 +36,24 @@ static char *moduleid =
#include <sys/param.h> /* for MAXPATHLEN */
#include <sys/stat.h>
#include <fcntl.h> /* for open() */
+#if (__COHERENT__ >= 0x420)
+#include <sys/utime.h>
+#else
#include <utime.h>
+#endif
#include <unistd.h> /* for read() */
+#ifdef __ELF__
+#include <elf.h>
+#endif
+
+#include "patchlevel.h"
#include "file.h"
#ifdef S_IFLNK
-# define USAGE "Usage: %s [-czL] [-f namefile] [-m magicfile] file...\n"
+# define USAGE "Usage: %s [-vczL] [-f namefile] [-m magicfiles] file...\n"
#else
-# define USAGE "Usage: %s [-cz] [-f namefile] [-m magicfile] file...\n"
+# define USAGE "Usage: %s [-vcz] [-f namefile] [-m magicfiles] file...\n"
#endif
#ifndef MAGIC
@@ -61,7 +70,7 @@ int /* Misc globals */
struct magic *magic; /* array of magic entries */
-char *magicfile = MAGIC;/* where magic be found */
+char *magicfile; /* where magic be found */
char *progname; /* used throughout */
int lineno; /* line number in the magic file */
@@ -78,15 +87,22 @@ int argc;
char *argv[];
{
int c;
- int check = 0, didsomefiles = 0, errflg = 0, ret = 0;
+ int check = 0, didsomefiles = 0, errflg = 0, ret = 0, app = 0;
if ((progname = strrchr(argv[0], '/')) != NULL)
progname++;
else
progname = argv[0];
- while ((c = getopt(argc, argv, "cdf:Lm:z")) != EOF)
+ if (!(magicfile = getenv("MAGIC")))
+ magicfile = MAGIC;
+
+ while ((c = getopt(argc, argv, "vcdf:Lm:z")) != EOF)
switch (c) {
+ case 'v':
+ (void) fprintf(stdout, "%s-%d.%d\n", progname,
+ FILE_VERSION_MAJOR, patchlevel);
+ return 1;
case 'c':
++check;
break;
@@ -94,6 +110,12 @@ char *argv[];
++debug;
break;
case 'f':
+ if (!app) {
+ ret = apprentice(magicfile, check);
+ if (check)
+ exit(ret);
+ app = 1;
+ }
unwrap(optarg);
++didsomefiles;
break;
@@ -113,14 +135,18 @@ char *argv[];
errflg++;
break;
}
+
if (errflg) {
(void) fprintf(stderr, USAGE, progname);
exit(2);
}
- ret = apprentice(magicfile, check);
- if (check)
- exit(ret);
+ if (!app) {
+ ret = apprentice(magicfile, check);
+ if (check)
+ exit(ret);
+ app = 1;
+ }
if (optind == argc) {
if (!didsomefiles) {
@@ -190,6 +216,7 @@ int wid;
struct utimbuf utbuf;
struct stat sb;
int nbytes = 0; /* number of bytes read from a datafile */
+ char match = '\0';
if (strcmp("-", inname) == 0) {
if (fstat(0, &sb)<0) {
@@ -236,8 +263,55 @@ int wid;
ckfputs("empty", stdout);
else {
buf[nbytes++] = '\0'; /* null-terminate it */
- tryit(buf, nbytes, zflag);
+ match = tryit(buf, nbytes, zflag);
}
+#ifdef __ELF__
+ /*
+ * 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.
+ * XXX: This will not work for binaries of a different byteorder.
+ * Should come up with a better fix.
+ */
+
+ if (match == 's' && nbytes > sizeof (Elf32_Ehdr) &&
+ buf[EI_MAG0] == ELFMAG0 &&
+ buf[EI_MAG1] == ELFMAG1 &&
+ buf[EI_MAG2] == ELFMAG2 &&
+ buf[EI_MAG3] == ELFMAG3) {
+
+ union {
+ long l;
+ char c[sizeof (long)];
+ } u;
+ Elf32_Ehdr elfhdr;
+ int stripped = 1;
+
+ u.l = 1;
+ (void) memcpy(&elfhdr, buf, sizeof elfhdr);
+
+ /*
+ * If the system byteorder does not equal the object byteorder
+ * then don't test.
+ */
+ if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
+ if (lseek(fd, elfhdr.e_shoff, SEEK_SET)<0)
+ error("lseek failed (%s).\n", strerror(errno));
+
+ for ( ; elfhdr.e_shnum ; elfhdr.e_shnum--) {
+ if (read(fd, buf, elfhdr.e_shentsize)<0)
+ error("read failed (%s).\n", strerror(errno));
+ if (((Elf32_Shdr *)&buf)->sh_type == SHT_SYMTAB) {
+ stripped = 0;
+ break;
+ }
+ }
+ if (stripped)
+ (void) printf (", stripped");
+ }
+ }
+#endif
if (inname != stdname) {
/*
@@ -252,25 +326,24 @@ int wid;
}
-void
+int
tryit(buf, nb, zflag)
unsigned char *buf;
int nb, zflag;
{
- /*
- * Try compression stuff
- */
- if (!zflag || zmagic(buf, nb) != 1)
- /*
- * try tests in /etc/magic (or surrogate magic file)
- */
- if (softmagic(buf, nb) != 1)
- /*
- * try known keywords, check for ascii-ness too.
- */
- if (ascmagic(buf, nb) != 1)
- /*
- * abandon hope, all ye who remain here
- */
- ckfputs("data", stdout);
+ /* try compression stuff */
+ if (zflag && zmagic(buf, nb))
+ return 'z';
+
+ /* try tests in /etc/magic (or surrogate magic file) */
+ if (softmagic(buf, nb))
+ return 's';
+
+ /* try known keywords, check whether it is ASCII */
+ if (ascmagic(buf, nb))
+ return 'a';
+
+ /* abandon hope, all ye who remain here */
+ ckfputs("data", stdout);
+ return '\0';
}
diff --git a/usr.bin/file/file.h b/usr.bin/file/file.h
index a92c9ff..5c9888d 100644
--- a/usr.bin/file/file.h
+++ b/usr.bin/file/file.h
@@ -1,6 +1,6 @@
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.1.1.1 1994/09/03 19:16:23 csgr Exp $
+ * @(#)$Id: file.h,v 1.2 1995/05/30 06:30:02 rgrimes Exp $
*
* Copyright (c) Ian F. Darwin, 1987.
* Written by Ian F. Darwin.
@@ -26,7 +26,9 @@
* 4. This notice may not be removed or altered.
*/
-#define HOWMANY 8192 /* how much of the file to look at */
+#ifndef HOWMANY
+# define HOWMANY 8192 /* how much of the file to look at */
+#endif
#define MAXMAGIS 1000 /* max entries in /etc/magic */
#define MAXDESC 50 /* max leng of text description */
#define MAXstring 32 /* max leng of "string" types */
@@ -92,7 +94,7 @@ extern void mdump __P((struct magic *));
extern void process __P((const char *, int));
extern void showstr __P((FILE *, const char *, int));
extern int softmagic __P((unsigned char *, int));
-extern void tryit __P((unsigned char *, int, int));
+extern int tryit __P((unsigned char *, int, int));
extern int zmagic __P((unsigned char *, int));
extern void ckfprintf __P((FILE *, const char *, ...));
extern unsigned long signextend __P((struct magic *, unsigned long));
@@ -121,6 +123,7 @@ extern int sys_nerr;
extern char *sys_errlist[];
#define strerror(e) \
(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
+#define strtoul(a, b, c) strtol(a, b, c)
#endif
#ifndef MAXPATHLEN
diff --git a/usr.bin/file/fsmagic.c b/usr.bin/file/fsmagic.c
index 5a66d31..ae020a0 100644
--- a/usr.bin/file/fsmagic.c
+++ b/usr.bin/file/fsmagic.c
@@ -46,7 +46,7 @@
#ifndef lint
static char *moduleid =
- "@(#)$Id: fsmagic.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $";
+ "@(#)$Id: fsmagic.c,v 1.2 1995/05/30 06:30:03 rgrimes Exp $";
#endif /* lint */
int
@@ -151,10 +151,12 @@ struct stat *sb;
return 1;
#endif
#ifdef S_IFSOCK
+#ifndef __COHERENT__
case S_IFSOCK:
ckfputs("socket", stdout);
return 1;
#endif
+#endif
case S_IFREG:
break;
default:
diff --git a/usr.bin/file/magic.5 b/usr.bin/file/magic.5
index 6c6f3ef..73c28e0 100644
--- a/usr.bin/file/magic.5
+++ b/usr.bin/file/magic.5
@@ -79,10 +79,13 @@ value,
.BR & ,
to specify that the value from the file must have set all of the bits
that are set in the specified value,
-or
.BR ^ ,
to specify that the value from the file must have clear any of the bits
-that are set in the specified value.
+that are set in the specified value, or
+.BR x ,
+to specify that any value will match. If the character is omitted,
+it is assumed to be
+.BR = .
.IP
Numeric values are specified in C form; e.g.
.B 13
@@ -91,9 +94,6 @@ is decimal,
is octal, and
.B 0x13
is hexadecimal.
-to specify that any value will match. If the character
-is omitted, it is assumed to be
-.BR = .
.IP
For string values, the byte string from the
file must match the specified byte string.
@@ -143,7 +143,7 @@ If the first character following the last
is a
.B (
then the string after the parenthesis is interpreted as an indirect offset.
-That means that the number after the parenthesis is used as a offset in
+That means that the number after the parenthesis is used as an offset in
the file. The value at that offset is read, and is used again as an offset
in the file. Indirect offsets are of the form:
.BI (( x [.[bsl]][+-][ y ]).
@@ -168,7 +168,7 @@ The formats
.IR bedate ,
and
.I ledate
-are system-dependant; perhaps they should be specified as a number
+are system-dependent; perhaps they should be specified as a number
of bytes (2B, 4B, etc),
since the files being recognized typically come from
a system on which the lengths are invariant.
@@ -191,4 +191,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.11 1994/05/03 17:58:23 christos Exp $
+.\" @(#)$Id: magic.5,v 1.2 1994/09/03 19:31:16 csgr Exp $
diff --git a/usr.bin/file/names.h b/usr.bin/file/names.h
index 86633dd..eba0b51 100644
--- a/usr.bin/file/names.h
+++ b/usr.bin/file/names.h
@@ -10,7 +10,7 @@
*
* See LEGAL.NOTICE
*
- * $Id: names.h,v 1.12 1995/04/28 17:29:13 christos Exp $
+ * $Id: names.h,v 1.1.1.2 1996/01/22 22:31:42 mpp Exp $
*/
/* these types are used to index the table 'types': keep em in sync! */
diff --git a/usr.bin/file/patchlevel.h b/usr.bin/file/patchlevel.h
index b33a113..15241eb 100644
--- a/usr.bin/file/patchlevel.h
+++ b/usr.bin/file/patchlevel.h
@@ -1,11 +1,17 @@
#define FILE_VERSION_MAJOR 3
-#define patchlevel 14
+#define patchlevel 19
/*
* Patchlevel file for Ian Darwin's MAGIC command.
- * $Id: patchlevel.h,v 1.1.1.1 1994/09/03 19:16:23 csgr Exp $
+ * $Id: patchlevel.h,v 1.2 1995/05/30 06:30:06 rgrimes Exp $
*
* $Log: patchlevel.h,v $
+ * Revision 1.2 1995/05/30 06:30:06 rgrimes
+ * Remove trailing whitespace.
+ *
+ * Revision 1.1.1.2 1996/01/22 22:31:44 mpp
+ * Upgrade to file version 3.19.
+ *
* Revision 1.1.1.1 1994/09/03 19:16:23 csgr
* Bring in file 3.14 by Ian Darwin (and Christos Zoulas)
*
@@ -16,6 +22,38 @@
* The following file was removed:
* - Magdir/Makefile
*
+ * Revision 1.19 1995/10/27 23:14:46 christos
+ * Ability to parse colon separated list of magic files
+ * New LEGAL.NOTICE
+ * Various magic file changes
+ *
+ * Revision 1.18 1995/05/20 22:09:21 christos
+ * Passed incorrect argument to eatsize().
+ * Use %ld and %lx where appropriate.
+ * Remove unused variables
+ * ELF support for both big and little endian
+ * Fixes for small files again.
+ *
+ * Revision 1.17 1995/04/28 17:29:13 christos
+ * - Incorrect nroff detection fix from der Mouse
+ * - Lost and incorrect magic entries.
+ * - Added ELF stripped binary detection [in C; ugh]
+ * - Look for $MAGIC to find the magic file.
+ * - Eat trailing size specifications from numbers i.e. ignore 10L
+ * - More fixes for very short files
+ *
+ * Revision 1.16 1995/03/25 22:06:45 christos
+ * - use strtoul() where it exists.
+ * - fix sign-extend bug
+ * - try to detect tar archives before nroff files, otherwise
+ * tar files where the first file starts with a . will not work
+ *
+ * Revision 1.15 1995/01/21 21:03:35 christos
+ * Added CSECTION for the file man page
+ * Added version flag -v
+ * Fixed bug with -f input flag (from iorio@violet.berkeley.edu)
+ * Lots of magic fixes and reorganization...
+ *
* Revision 1.14 1994/05/03 17:58:23 christos
* changes from mycroft@gnu.ai.mit.edu (Charles Hannum) for unsigned
*
diff --git a/usr.bin/file/print.c b/usr.bin/file/print.c
index 44a079e..c65d97f 100644
--- a/usr.bin/file/print.c
+++ b/usr.bin/file/print.c
@@ -40,7 +40,7 @@
#ifndef lint
static char *moduleid =
- "@(#)$Id: print.c,v 1.1.1.1 1994/09/03 19:16:22 csgr Exp $";
+ "@(#)$Id: print.c,v 1.2 1995/05/30 06:30:08 rgrimes Exp $";
#endif /* lint */
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
@@ -58,8 +58,8 @@ struct magic *m;
m->offset);
if (m->flag & INDIR)
- (void) fprintf(stderr, "(%s,%d),",
- (m->in.type >= 0 && m->in.type < SZOF(typ)) ?
+ (void) fprintf(stderr, "(%s,%ld),",
+ (m->in.type >= 0 && m->in.type < SZOF(typ)) ?
typ[(unsigned char) m->in.type] :
"*bad*",
m->in.offset);
@@ -69,7 +69,7 @@ struct magic *m;
typ[(unsigned char) m->type] :
"*bad*");
if (m->mask != ~0L)
- (void) fprintf(stderr, " & %.8x", m->mask);
+ (void) fprintf(stderr, " & %.8lx", m->mask);
(void) fprintf(stderr, ",%c", m->reln);
@@ -82,7 +82,7 @@ struct magic *m;
case LELONG:
case BESHORT:
case BELONG:
- (void) fprintf(stderr, "%d", m->value.l);
+ (void) fprintf(stderr, "%ld", m->value.l);
break;
case STRING:
showstr(stderr, m->value.s, -1);
diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c
index 737e6d6..489f13b 100644
--- a/usr.bin/file/softmagic.c
+++ b/usr.bin/file/softmagic.c
@@ -34,7 +34,7 @@
#ifndef lint
static char *moduleid =
- "@(#)$Id: softmagic.c,v 1.2 1995/05/24 02:54:30 ache Exp $";
+ "@(#)$Id: softmagic.c,v 1.3 1995/05/30 06:30:09 rgrimes Exp $";
#endif /* lint */
static int match __P((unsigned char *, int));
@@ -179,18 +179,24 @@ struct magic *m;
switch (m->type) {
case BYTE:
v = p->b;
+ v = signextend(m, v) & m->mask;
+ (void) printf(m->desc, (unsigned char) v);
break;
case SHORT:
case BESHORT:
case LESHORT:
v = p->h;
+ v = signextend(m, v) & m->mask;
+ (void) printf(m->desc, (unsigned short) v);
break;
case LONG:
case BELONG:
case LELONG:
v = p->l;
+ v = signextend(m, v) & m->mask;
+ (void) printf(m->desc, (unsigned long) v);
break;
case STRING:
@@ -214,9 +220,6 @@ struct magic *m;
error("invalid m->type (%d) in mprint().\n", m->type);
/*NOTREACHED*/
}
-
- v = signextend(m, v) & m->mask;
- (void) printf(m->desc, v);
}
/*
@@ -270,7 +273,7 @@ long offset;
char *str;
int len;
{
- (void) fprintf(stderr, "mget @%d: ", offset);
+ (void) fprintf(stderr, "mget @%ld: ", offset);
showstr(stderr, (char *) str, len);
(void) fputc('\n', stderr);
(void) fputc('\n', stderr);
@@ -284,11 +287,20 @@ struct magic *m;
int nbytes;
{
long offset = m->offset;
- if (offset + sizeof(union VALUETYPE) > nbytes)
- return 0;
+ if (offset + sizeof(union VALUETYPE) <= nbytes)
+ memcpy(p, s + offset, sizeof(union VALUETYPE));
+ else {
+ /*
+ * the usefulness of padding with zeroes eludes me, it
+ * might even cause problems
+ */
+ long have = nbytes - offset;
+ memset(p, 0, sizeof(union VALUETYPE));
+ if (have > 0)
+ memcpy(p, s + offset, have);
+ }
- memcpy(p, s + offset, sizeof(union VALUETYPE));
if (debug) {
mdebug(offset, (char *) p, sizeof(union VALUETYPE));
OpenPOWER on IntegriCloud