mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-01 08:27:59 +00:00
Merge to resolve conflicts with file 3.22 merge.
This commit is contained in:
parent
1c147cc352
commit
76918e1ad4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23995
@ -16,6 +16,10 @@
|
||||
>12 belong 6 32-bit IEEE floating point,
|
||||
>12 belong 7 64-bit IEEE floating point,
|
||||
>12 belong 23 8-bit ISDN u-law compressed (CCITT G.721 ADPCM voice data encoding),
|
||||
>12 belong 24 compressed (8-bit G.722 ADPCM)
|
||||
>12 belong 25 compressed (3-bit G.723 ADPCM),
|
||||
>12 belong 26 compressed (5-bit G.723 ADPCM),
|
||||
>12 belong 27 8-bit A-law,
|
||||
>20 belong 1 mono,
|
||||
>20 belong 2 stereo,
|
||||
>20 belong 4 quad,
|
||||
@ -54,14 +58,15 @@
|
||||
>4 belong x - version %ld
|
||||
|
||||
# Microsoft WAVE format (*.wav)
|
||||
# [GRR 950115: probably all of the shorts and longs should be leshort/lelong]
|
||||
0 string RIFF Microsoft RIFF
|
||||
>8 string WAVE \b, WAVE audio data
|
||||
>34 short >0 \b, %d bit
|
||||
>22 short =1 \b, mono
|
||||
>22 short =2 \b, stereo
|
||||
>22 short >2 \b, %d channels
|
||||
>24 long >0 %d Hz
|
||||
>>34 leshort >0 \b, %d bit
|
||||
>>22 leshort =1 \b, mono
|
||||
>>22 leshort =2 \b, stereo
|
||||
>>22 leshort >2 \b, %d channels
|
||||
>>24 lelong >0 %d Hz
|
||||
# AVI == Audio Video Interleave
|
||||
>8 string AVI\ \b, AVI data
|
||||
|
||||
# Extended MOD format (*.emd) (Greg Roelofs, newt@uchicago.edu); NOT TESTED
|
||||
# [based on posting 940824 by "Dirk/Elastik", husberg@lehtori.cc.tut.fi]
|
||||
@ -72,6 +77,18 @@
|
||||
>83 byte 0 (module)
|
||||
>83 byte 1 (song)
|
||||
|
||||
# Real Audio (Magic .ra\0375)
|
||||
0 belong 0x2e7261fd realaudio sound file
|
||||
|
||||
# MTM/669/FAR/S3M/ULT/XM format checking [Aaron Eppert, aeppert@dialin.ind.net]
|
||||
# Oct 31, 1995
|
||||
0 string MTM MultiTracker Module sound file
|
||||
0 string if Composer 669 Module sound data
|
||||
0 string FAR Module sound data
|
||||
0 string MAS_U ULT(imate) Module sound data
|
||||
0x2c string SCRM ScreamTracker III Module sound data
|
||||
0 string Extended Module Extended Module sound data
|
||||
|
||||
# Gravis UltraSound patches
|
||||
# From <ache@nagual.ru>
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
# We have to check the byte order flag to see what byte order all the
|
||||
# other stuff in the header is in.
|
||||
#
|
||||
# Byte order is probably big-endian for MIPS RS3000 and Amdahl.
|
||||
# MIPS RS3000 may also be for MIPS RS2000.
|
||||
# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?
|
||||
#
|
||||
# updated by Daniel Quinlan (quinlan@yggdrasil.com)
|
||||
0 string \177ELF ELF
|
||||
@ -19,7 +19,9 @@
|
||||
>>16 leshort 1 relocatable,
|
||||
>>16 leshort 2 executable,
|
||||
>>16 leshort 3 shared object,
|
||||
>>16 leshort 4 core file,
|
||||
# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
|
||||
>>16 leshort 4 core file
|
||||
>>>400 lelong >0 (signal %d),
|
||||
>>16 leshort &0xff00 processor-specific,
|
||||
>>18 leshort 0 no machine,
|
||||
>>18 leshort 1 AT&T WE32100 - invalid byte order,
|
||||
@ -29,8 +31,16 @@
|
||||
>>18 leshort 5 Motorola 88000 - invalid byte order,
|
||||
>>18 leshort 6 Intel 80486,
|
||||
>>18 leshort 7 Intel 80860,
|
||||
>>18 leshort 8 MIPS RS3000,
|
||||
>>18 leshort 9 Amdahl,
|
||||
>>18 leshort 8 MIPS RS3000_BE - invalid byte order,
|
||||
>>18 leshort 9 Amdahl - invalid byte order,
|
||||
>>18 leshort 10 MIPS RS3000_LE,
|
||||
>>18 leshort 11 RS6000 - invalid byte order,
|
||||
>>18 leshort 15 PA_RISC - invalid byte order,
|
||||
>>18 leshort 16 nCUBE,
|
||||
>>18 leshort 17 VPP500,
|
||||
>>18 leshort 18 SPARC32PLUS,
|
||||
>>18 leshort 20 PowerPC,
|
||||
>>18 leshort 0x9026 Alpha,
|
||||
>>20 lelong 0 invalid version
|
||||
>>20 lelong 1 version 1
|
||||
>>36 lelong 1 MathCoPro/FPU/MAU Required
|
||||
@ -40,6 +50,7 @@
|
||||
>>16 beshort 2 executable,
|
||||
>>16 beshort 3 shared object,
|
||||
>>16 beshort 4 core file,
|
||||
>>>400 lelong >0 (signal %d),
|
||||
>>16 beshort &0xff00 processor-specific,
|
||||
>>18 beshort 0 no machine,
|
||||
>>18 beshort 1 AT&T WE32100,
|
||||
@ -49,8 +60,16 @@
|
||||
>>18 beshort 5 Motorola 88000,
|
||||
>>18 beshort 6 Intel 80486 - invalid byte order,
|
||||
>>18 beshort 7 Intel 80860,
|
||||
>>18 beshort 8 MIPS RS3000,
|
||||
>>18 leshort 9 Amdahl,
|
||||
>>18 beshort 8 MIPS RS3000_BE,
|
||||
>>18 beshort 9 Amdahl,
|
||||
>>18 beshort 10 MIPS RS3000_LE - invalid byte order,
|
||||
>>18 beshort 11 RS6000,
|
||||
>>18 beshort 15 PA_RISC,
|
||||
>>18 beshort 16 nCUBE,
|
||||
>>18 beshort 17 VPP500,
|
||||
>>18 beshort 18 SPARC32PLUS,
|
||||
>>18 beshort 20 PowerPC,
|
||||
>>18 beshort 0x9026 Alpha,
|
||||
>>20 belong 0 invalid version
|
||||
>>20 belong 1 version 1
|
||||
>>36 belong 1 MathCoPro/FPU/MAU Required
|
||||
|
@ -1,6 +1,79 @@
|
||||
# the following are for BSD/i386 (FreeBSD, NetBSD, etc.)
|
||||
|
||||
0 lelong&0377777777 041400407 BSD/i386
|
||||
#------------------------------------------------------------------------------
|
||||
# freebsd: file(1) magic for FreeBSD objects
|
||||
#
|
||||
# All new-style FreeBSD magic numbers are in host byte order (i.e.,
|
||||
# little-endian on x86).
|
||||
#
|
||||
# XXX - this comes from the file "freebsd" in a recent FreeBSD version of
|
||||
# "file"; it, and the NetBSD stuff in "netbsd", appear to use different
|
||||
# schemes for distinguishing between executable images, shared libraries,
|
||||
# and object files.
|
||||
#
|
||||
# FreeBSD says:
|
||||
#
|
||||
# Regardless of whether it's pure, demand-paged, or none of the
|
||||
# above:
|
||||
#
|
||||
# if the entry point is < 4096, then it's a shared library if
|
||||
# the "has run-time loader information" bit is set, and is
|
||||
# position-independent if the "is position-independent" bit
|
||||
# is set;
|
||||
#
|
||||
# if the entry point is >= 4096 (or >4095, same thing), then it's
|
||||
# an executable, and is dynamically-linked if the "has run-time
|
||||
# loader information" bit is set.
|
||||
#
|
||||
# On x86, NetBSD says:
|
||||
#
|
||||
# If it's neither pure nor demand-paged:
|
||||
#
|
||||
# if it has the "has run-time loader information" bit set, it's
|
||||
# a dynamically-linked executable;
|
||||
#
|
||||
# if it doesn't have that bit set, then:
|
||||
#
|
||||
# if it has the "is position-independent" bit set, it's
|
||||
# position-independent;
|
||||
#
|
||||
# if the entry point is non-zero, it's an executable, otherwise
|
||||
# it's an object file.
|
||||
#
|
||||
# If it's pure:
|
||||
#
|
||||
# if it has the "has run-time loader information" bit set, it's
|
||||
# a dynamically-linked executable, otherwise it's just an
|
||||
# executable.
|
||||
#
|
||||
# If it's demand-paged:
|
||||
#
|
||||
# if it has the "has run-time loader information" bit set,
|
||||
# then:
|
||||
#
|
||||
# if the entry point is < 4096, it's a shared library;
|
||||
#
|
||||
# if the entry point is = 4096 or > 4096 (i.e., >= 4096),
|
||||
# it's a dynamically-linked executable);
|
||||
#
|
||||
# if it doesn't have the "has run-time loader information" bit
|
||||
# set, then it's just an executable.
|
||||
#
|
||||
# (On non-x86, NetBSD does much the same thing, except that it uses
|
||||
# 8192 on 68K - except for "68k4k", which is presumably "68K with 4K
|
||||
# pages - SPARC, and MIPS, presumably because Sun-3's and Sun-4's
|
||||
# had 8K pages; dunno about MIPS.)
|
||||
#
|
||||
# I suspect the two will differ only in perverse and uninteresting cases
|
||||
# ("shared" libraries that aren't demand-paged and whose pages probably
|
||||
# won't actually be shared, executables with entry points <4096).
|
||||
#
|
||||
# I leave it to those more familiar with FreeBSD and NetBSD to figure out
|
||||
# what the right answer is (although using ">4095", FreeBSD-style, is
|
||||
# probably better than separately checking for "=4096" and ">4096",
|
||||
# NetBSD-style). (The old "netbsd" file analyzed FreeBSD demand paged
|
||||
# executables using the NetBSD technique.)
|
||||
#
|
||||
0 lelong&0377777777 041400407 FreeBSD/i386
|
||||
>20 lelong <4096
|
||||
>>3 byte&0xC0 &0x80 shared library
|
||||
>>3 byte&0xC0 0x40 PIC object
|
||||
@ -10,7 +83,7 @@
|
||||
>>3 byte&0x80 0x00 executable
|
||||
>16 lelong >0 not stripped
|
||||
|
||||
0 lelong&0377777777 041400410 BSD/i386 pure
|
||||
0 lelong&0377777777 041400410 FreeBSD/i386 pure
|
||||
>20 lelong <4096
|
||||
>>3 byte&0xC0 &0x80 shared library
|
||||
>>3 byte&0xC0 0x40 PIC object
|
||||
@ -20,7 +93,7 @@
|
||||
>>3 byte&0x80 0x00 executable
|
||||
>16 lelong >0 not stripped
|
||||
|
||||
0 lelong&0377777777 041400413 BSD/i386 demand paged
|
||||
0 lelong&0377777777 041400413 FreeBSD/i386 demand paged
|
||||
>20 lelong <4096
|
||||
>>3 byte&0xC0 &0x80 shared library
|
||||
>>3 byte&0xC0 0x40 PIC object
|
||||
@ -30,7 +103,7 @@
|
||||
>>3 byte&0x80 0x00 executable
|
||||
>16 lelong >0 not stripped
|
||||
|
||||
0 lelong&0377777777 041400314 BSD/i386 compact demand paged
|
||||
0 lelong&0377777777 041400314 FreeBSD/i386 compact demand paged
|
||||
>20 lelong <4096
|
||||
>>3 byte&0xC0 &0x80 shared library
|
||||
>>3 byte&0xC0 0x40 PIC object
|
||||
@ -40,46 +113,6 @@
|
||||
>>3 byte&0x80 0x00 executable
|
||||
>16 lelong >0 not stripped
|
||||
|
||||
0 belong&0377777777 041400407 BSD/i386
|
||||
>20 belong <4096
|
||||
>>0 byte&0xC0 &0x80 shared library
|
||||
>>0 byte&0xC0 0x40 PIC object
|
||||
>>0 byte&0xC0 0x00 object
|
||||
>20 belong >4095
|
||||
>>0 byte&0x80 0x80 dynamically linked executable
|
||||
>>0 byte&0x80 0x00 executable
|
||||
>16 belong >0 not stripped
|
||||
|
||||
0 belong&0377777777 041400410 BSD/i386 pure
|
||||
>20 belong <4096
|
||||
>>0 byte&0xC0 &0x80 shared library
|
||||
>>0 byte&0xC0 0x40 PIC object
|
||||
>>0 byte&0xC0 0x00 object
|
||||
>20 belong >4095
|
||||
>>0 byte&0x80 0x80 dynamically linked executable
|
||||
>>0 byte&0x80 0x00 executable
|
||||
>16 belong >0 not stripped
|
||||
|
||||
0 belong&0377777777 041400413 BSD/i386 demand paged
|
||||
>20 belong <4096
|
||||
>>0 byte&0xC0 &0x80 shared library
|
||||
>>0 byte&0xC0 0x40 PIC object
|
||||
>>0 byte&0xC0 0x00 object
|
||||
>20 belong >4095
|
||||
>>0 byte&0x80 0x80 dynamically linked executable
|
||||
>>0 byte&0x80 0x00 executable
|
||||
>16 belong >0 not stripped
|
||||
|
||||
0 belong&0377777777 041400314 BSD/i386 compact demand paged
|
||||
>20 belong <4096
|
||||
>>0 byte&0xC0 &0x80 shared library
|
||||
>>0 byte&0xC0 0x40 PIC object
|
||||
>>0 byte&0xC0 0x00 object
|
||||
>20 belong >4095
|
||||
>>0 byte&0x80 0x80 dynamically linked executable
|
||||
>>0 byte&0x80 0x00 executable
|
||||
>16 belong >0 not stripped
|
||||
|
||||
# XXX gross hack to identify core files
|
||||
# cores start with a struct tss; we take advantage of the following:
|
||||
# byte 7: highest byte of the kernel stack pointer, always 0xfe
|
||||
@ -88,8 +121,8 @@
|
||||
# 28: low order byte of the current PTD entry, always 0 since the
|
||||
# PTD is page-aligned
|
||||
#
|
||||
7 string \357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 i386 a.out core file
|
||||
>1039 string >\0 from "%s"
|
||||
7 string \357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 FreeBSD/i386 a.out core file
|
||||
>1039 string >\0 from '%s'
|
||||
|
||||
# /var/run/ld.so.hints
|
||||
# What are you laughing about?
|
||||
|
@ -1,4 +1,9 @@
|
||||
#------------------------------------------------------------------------------
|
||||
#------------------------------------------------------------
|
||||
# Java ByteCode
|
||||
# From Larry Schwimmer (schwim@cs.stanford.edu)
|
||||
0 belong 0xcafebabe
|
||||
>4 belong 0x0003002d Java bytecode
|
||||
#
|
||||
# java: file(1) magic for java compiled classes
|
||||
#
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
0 beshort 0x9900 PGP key public ring
|
||||
0 beshort 0x9501 PGP key security ring
|
||||
0 beshort 0x9500 PGP key security ring
|
||||
0 beshort 0xa600 PGP encrypted data
|
||||
0 string -----BEGIN\040PGP PGP armored data
|
||||
>15 string PUBLIC\040KEY\040BLOCK- public key block
|
||||
>15 string MESSAGE- message
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Makefile for file(1) cmd.
|
||||
# Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
|
||||
# @(#)$Id$
|
||||
# @(#)$Id: Makefile,v 1.9 1997/02/22 19:29:07 peter 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.
|
||||
@ -29,11 +29,11 @@ MAGICOWN= bin
|
||||
MAGICGRP= bin
|
||||
MAGICMODE= 444
|
||||
|
||||
CFLAGS+= -DMAGIC='"$(MAGICDIR)/magic"'
|
||||
CFLAGS+= -DMAGIC='"$(MAGICDIR)/magic"' -DBUILTIN_ELF
|
||||
|
||||
PROG= file
|
||||
SRCS= file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \
|
||||
compress.c is_tar.c print.c international.c
|
||||
compress.c is_tar.c readelf.c internat.c print.c
|
||||
|
||||
MAN1= file.1
|
||||
MAN5= magic.5
|
||||
|
@ -1,11 +1,9 @@
|
||||
** README for file(1) Command **
|
||||
@(#) $Id$
|
||||
@(#) $Id: README,v 1.1.1.2 1997/03/18 17:58:39 mpp Exp $
|
||||
|
||||
This is Release 3.x of Ian Darwin's (copyright but distributable)
|
||||
file(1) command. Release 3.x is scheduled for inclusion in the
|
||||
4.4 BSD (Berkeley Software Distribution) of UNIX-like
|
||||
software, and is the standard "file" command for Linux, 386bsd,
|
||||
and other systems. (See "patchlevel.h" for the exact release number).
|
||||
file(1) command. This version is the standard "file" command for Linux,
|
||||
*BSD, and other systems. (See "patchlevel.h" for the exact release number).
|
||||
|
||||
UNIX is a trademark of UNIX System Laboratories.
|
||||
|
||||
@ -58,15 +56,29 @@ magic.4 - man page for the magic file, courtesy Guy Harris.
|
||||
file.c - main program
|
||||
file.h - header file
|
||||
fsmagic.c - first set of tests the program runs, based on filesystem info
|
||||
is_tar.c - knows about tarchives (courtesy John Gilmore).
|
||||
is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).
|
||||
magdir - directory of /etc/magic pieces
|
||||
magdir/Makefile - ADJUST THIS FOR YOUR CONFIGURATION
|
||||
names.h - header file for ascmagic.c
|
||||
softmagic.c - 2nd set of tests, based on /etc/magic
|
||||
strtok.c, getopt.c - in case you them (courtesy of Henry Spencer).
|
||||
strtol.c, strchr.c - in case you need them - public domain.
|
||||
tst - simple test suite, built from tst/Makefile
|
||||
readelf.[ch] - Standalone elf parsing code.
|
||||
compress.c - on-the-fly decompression.
|
||||
internat.c - recognize international `text' files.
|
||||
print.c - print results, errors, warnings.
|
||||
|
||||
If your gzip sometimes fails to decompress things complaining about a short
|
||||
file, apply this patch [which is going to be in the next version of gzip]:
|
||||
*** - Tue Oct 29 02:06:35 1996
|
||||
--- util.c Sun Jul 21 21:51:38 1996
|
||||
*** 106,111 ****
|
||||
--- 108,114 ----
|
||||
|
||||
if (insize == 0) {
|
||||
if (eof_ok) return EOF;
|
||||
+ flush_window();
|
||||
read_error();
|
||||
}
|
||||
bytes_in += (ulg)insize;
|
||||
|
||||
E-mail: christos@deshaw.com, moraes@deshaw.com
|
||||
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include "file.h"
|
||||
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
static char *moduleid =
|
||||
"@(#)$Id: apprentice.c,v 1.1.1.3 1997/03/18 17:58:42 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
#define EATAB {while (isascii((unsigned char) *l) && \
|
||||
@ -133,10 +133,10 @@ int check; /* non-zero? checking-only run. */
|
||||
/*
|
||||
* extend the sign bit if the comparison is to be signed
|
||||
*/
|
||||
unsigned long
|
||||
uint32
|
||||
signextend(m, v)
|
||||
struct magic *m;
|
||||
unsigned long v;
|
||||
uint32 v;
|
||||
{
|
||||
if (!(m->flag & UNSIGNED))
|
||||
switch(m->type) {
|
||||
@ -159,7 +159,7 @@ unsigned long v;
|
||||
case LONG:
|
||||
case BELONG:
|
||||
case LELONG:
|
||||
v = (long) v;
|
||||
v = (int32) v;
|
||||
break;
|
||||
case STRING:
|
||||
break;
|
||||
@ -210,6 +210,10 @@ int *ndx, check;
|
||||
++l; /* step over */
|
||||
m->flag |= INDIR;
|
||||
}
|
||||
if (m->cont_level != 0 && *l == '&') {
|
||||
++l; /* step over */
|
||||
m->flag |= ADD;
|
||||
}
|
||||
|
||||
/* get offset, then skip over it */
|
||||
m->offset = (int) strtoul(l,&t,0);
|
||||
@ -491,21 +495,16 @@ int plen, *slen;
|
||||
*p++ = (char)val;
|
||||
break;
|
||||
|
||||
/* \x and up to 3 hex digits */
|
||||
/* \x and up to 2 hex digits */
|
||||
case 'x':
|
||||
val = 'x'; /* Default if no digits */
|
||||
c = hextoint(*s++); /* Get next char */
|
||||
if (c >= 0) {
|
||||
val = c;
|
||||
c = hextoint(*s++);
|
||||
if (c >= 0) {
|
||||
if (c >= 0)
|
||||
val = (val << 4) + c;
|
||||
c = hextoint(*s++);
|
||||
if (c >= 0) {
|
||||
val = (val << 4) + c;
|
||||
} else
|
||||
--s;
|
||||
} else
|
||||
else
|
||||
--s;
|
||||
} else
|
||||
--s;
|
||||
|
@ -35,8 +35,8 @@
|
||||
#include "names.h"
|
||||
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
static char *moduleid =
|
||||
"@(#)$Id: ascmagic.c,v 1.1.1.3 1997/03/18 17:58:46 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
/* an optimisation over plain strcmp() */
|
||||
@ -89,6 +89,7 @@ int nbytes; /* size actually read */
|
||||
}
|
||||
|
||||
|
||||
/* Make sure we are dealing with ascii text before looking for tokens */
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
if (!isascii(buf[i]))
|
||||
return 0; /* not all ASCII */
|
||||
|
@ -1,5 +1,5 @@
|
||||
.TH FILE 1 "Copyright but distributable"
|
||||
.\# $Id$
|
||||
.\" $Id: file.1,v 1.1.1.4 1997/03/18 17:58:59 mpp Exp $
|
||||
.SH NAME
|
||||
file \- determine file type
|
||||
.SH SYNOPSIS
|
||||
@ -15,7 +15,10 @@ namefile ]
|
||||
magicfiles ]
|
||||
file ...
|
||||
.SH DESCRIPTION
|
||||
.I File
|
||||
This manual page documents version 3.22 of the
|
||||
.B file
|
||||
command.
|
||||
.B File
|
||||
tests each argument in an attempt to classify it.
|
||||
There are three sets of tests, performed in this order:
|
||||
filesystem tests, magic number tests, and language tests.
|
||||
@ -25,8 +28,11 @@ test that succeeds causes the file type to be printed.
|
||||
.PP
|
||||
The type printed will usually contain one of the words
|
||||
.B text
|
||||
(the file contains only ASCII characters and is
|
||||
probably safe to read on an ASCII terminal),
|
||||
(the file contains only
|
||||
.SM ASCII
|
||||
characters and is probably safe to read on an
|
||||
.SM ASCII
|
||||
terminal),
|
||||
.B executable
|
||||
(the file contains the result of compiling a program
|
||||
in a form understandable to some \s-1UNIX\s0 kernel or another),
|
||||
@ -45,7 +51,7 @@ Don't do as Berkeley did \- change ``shell commands text''
|
||||
to ``shell script''.
|
||||
.PP
|
||||
The filesystem tests are based on examining the return from a
|
||||
.IR stat (2)
|
||||
.BR stat (2)
|
||||
system call.
|
||||
The program checks to see if the file is empty,
|
||||
or if it's some sort of special file.
|
||||
@ -54,16 +60,16 @@ Any known file types appropriate to the system you are running on
|
||||
implement them)
|
||||
are intuited if they are defined in
|
||||
the system header file
|
||||
.BR sys/stat.h .
|
||||
.IR sys/stat.h .
|
||||
.PP
|
||||
The magic number tests are used to check for files with data in
|
||||
particular fixed formats.
|
||||
The canonical example of this is a binary executable (compiled program)
|
||||
.B a.out
|
||||
.I a.out
|
||||
file, whose format is defined in
|
||||
.B a.out.h
|
||||
.I a.out.h
|
||||
and possibly
|
||||
.B exec.h
|
||||
.I exec.h
|
||||
in the standard include directory.
|
||||
These files have a `magic number' stored in a particular place
|
||||
near the beginning of the file that tells the \s-1UNIX\s0 operating system
|
||||
@ -77,21 +83,23 @@ The information in these files is read from the magic file
|
||||
If an argument appears to be an
|
||||
.SM ASCII
|
||||
file,
|
||||
.I file
|
||||
.B file
|
||||
attempts to guess its language.
|
||||
The language tests look for particular strings (cf \fInames.h\fP)
|
||||
The language tests look for particular strings (cf
|
||||
.IR names.h )
|
||||
that can appear anywhere in the first few blocks of a file.
|
||||
For example, the keyword
|
||||
.B .br
|
||||
indicates that the file is most likely a troff input file,
|
||||
just as the keyword
|
||||
indicates that the file is most likely a
|
||||
.BR troff (1)
|
||||
input file, just as the keyword
|
||||
.B struct
|
||||
indicates a C program.
|
||||
These tests are less reliable than the previous
|
||||
two groups, so they are performed last.
|
||||
The language test routines also test for some miscellany
|
||||
(such as
|
||||
.I tar
|
||||
.BR tar (1)
|
||||
archives) and determine whether an unknown file should be
|
||||
labelled as `ascii text' or `data'.
|
||||
.SH OPTIONS
|
||||
@ -124,7 +132,7 @@ to test the standard input, use ``-'' as a filename argument.
|
||||
.TP 8
|
||||
.B \-L
|
||||
option causes symlinks to be followed, as the like-named option in
|
||||
.IR ls (1).
|
||||
.BR ls (1).
|
||||
(on systems that support symbolic links).
|
||||
.SH FILES
|
||||
.I /etc/magic
|
||||
@ -134,10 +142,10 @@ The environment variable
|
||||
.B MAGIC
|
||||
can be used to set the default magic number files.
|
||||
.SH SEE ALSO
|
||||
.IR magic (5)
|
||||
.BR magic (5)
|
||||
\- description of magic file format.
|
||||
.br
|
||||
.IR strings (1), " od" (1)
|
||||
.BR strings (1), " od" (1)
|
||||
\- tools for examining non-textfiles.
|
||||
.SH STANDARDS CONFORMANCE
|
||||
This program is believed to exceed the System V Interface Definition
|
||||
@ -170,7 +178,7 @@ in an existing magic file would have to be changed to
|
||||
.br
|
||||
.PP
|
||||
SunOS releases 3.2 and later from Sun Microsystems include a
|
||||
.IR file (1)
|
||||
.BR file (1)
|
||||
command derived from the System V one, but with some extensions.
|
||||
My version differs from Sun's only in minor ways.
|
||||
It includes the extension of the `&' operator, used as,
|
||||
@ -189,15 +197,15 @@ The order of entries in the magic file is significant.
|
||||
Depending on what system you are using, the order that
|
||||
they are put together may be incorrect.
|
||||
If your old
|
||||
.I file
|
||||
.B file
|
||||
command uses a magic file,
|
||||
keep the old magic file around for comparison purposes
|
||||
(rename it to
|
||||
.IR /etc/magic.orig ).
|
||||
.SH HISTORY
|
||||
There has been a
|
||||
.I file
|
||||
command in every UNIX since at least Research Version 6
|
||||
.B file
|
||||
command in every \s-1UNIX\s0 since at least Research Version 6
|
||||
(man page dated January, 1975).
|
||||
The System V version introduced one significant major change:
|
||||
the external list of magic number types.
|
||||
@ -226,7 +234,7 @@ put the ``old-style'' `&'
|
||||
operator back the way it was, because 1) Rob McMahon's change broke the
|
||||
previous style of usage, 2) the SunOS ``new-style'' `&' operator,
|
||||
which this version of
|
||||
.I file
|
||||
.B file
|
||||
supports, also handles `x&y op z', and 3) Rob's change wasn't documented
|
||||
in any case;
|
||||
.PP
|
||||
@ -235,11 +243,11 @@ put in multiple levels of `>';
|
||||
put in ``beshort'', ``leshort'', etc. keywords to look at numbers in the
|
||||
file in a specific byte order, rather than in the native byte order of
|
||||
the process running
|
||||
.IR file .
|
||||
.BR file .
|
||||
.RE
|
||||
.PP
|
||||
Changes by Ian Darwin and various authors including
|
||||
Christos Zoulas (christos@ee.cornell.edu), 1990-1992.
|
||||
Christos Zoulas (christos@deshaw.com), 1990-1992.
|
||||
.SH LEGAL NOTICE
|
||||
Copyright (c) Ian F. Darwin, Toronto, Canada,
|
||||
1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993.
|
||||
@ -283,33 +291,42 @@ The files
|
||||
and
|
||||
.I is_tar.c
|
||||
were written by John Gilmore from his public-domain
|
||||
.I tar
|
||||
.B tar
|
||||
program, and are not covered by the above restrictions.
|
||||
.SH BUGS
|
||||
There must be a better way to automate the construction of the Magic
|
||||
file from all the glop in Magdir. What is it?
|
||||
Better yet, the magic file should be compiled into binary (say,
|
||||
.IR ndbm (3)
|
||||
or, better yet, fixed-length ASCII strings
|
||||
for use in heterogenous network environments) for faster startup.
|
||||
.BR ndbm (3)
|
||||
or, better yet, fixed-length
|
||||
.SM ASCII
|
||||
strings for use in heterogenous network environments) for faster startup.
|
||||
Then the program would run as fast as the Version 7 program of the same name,
|
||||
with the flexibility of the System V version.
|
||||
.PP
|
||||
.I File
|
||||
.B File
|
||||
uses several algorithms that favor speed over accuracy,
|
||||
thus it can be misled about the contents of ASCII files.
|
||||
thus it can be misled about the contents of
|
||||
.SM ASCII
|
||||
files.
|
||||
.PP
|
||||
The support for ASCII files (primarily for programming languages)
|
||||
The support for
|
||||
.SM ASCII
|
||||
files (primarily for programming languages)
|
||||
is simplistic, inefficient and requires recompilation to update.
|
||||
.PP
|
||||
There should be an ``else'' clause to follow a series of continuation lines.
|
||||
.PP
|
||||
The magic file and keywords should have regular expression support.
|
||||
Their use of ASCII TAB as a field delimiter is ugly and makes
|
||||
Their use of
|
||||
.SM "ASCII TAB"
|
||||
as a field delimiter is ugly and makes
|
||||
it hard to edit the files, but is entrenched.
|
||||
.PP
|
||||
It might be advisable to allow upper-case letters in keywords
|
||||
for e.g., troff commands vs man page macros.
|
||||
for e.g.,
|
||||
.BR troff (1)
|
||||
commands vs man page macros.
|
||||
Regular expression support would make this easy.
|
||||
.PP
|
||||
The program doesn't grok \s-2FORTRAN\s0.
|
||||
@ -342,6 +359,6 @@ This manual page, and particularly this section, is too long.
|
||||
.SH AVAILABILITY
|
||||
You can obtain the original author's latest version by anonymous FTP
|
||||
on
|
||||
.B tesla.ee.cornell.edu
|
||||
.B ftp.deshaw.com
|
||||
in the directory
|
||||
.BR /pub/file-X.YY.tar.gz
|
||||
.I /pub/file/file-X.YY.tar.gz
|
||||
|
@ -25,8 +25,8 @@
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
static char *moduleid =
|
||||
"@(#)$Id: file.c,v 1.1.1.3 1997/03/18 17:58:41 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
#include <stdio.h>
|
||||
@ -37,15 +37,17 @@ static char *moduleid =
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h> /* for open() */
|
||||
#if (__COHERENT__ >= 0x420)
|
||||
#include <sys/utime.h>
|
||||
# include <sys/utime.h>
|
||||
#else
|
||||
#include <utime.h>
|
||||
# ifdef USE_UTIMES
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <utime.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <unistd.h> /* for read() */
|
||||
|
||||
#ifdef __ELF__
|
||||
#include <elf.h>
|
||||
#endif
|
||||
#include <netinet/in.h> /* for byte swapping */
|
||||
|
||||
#include "patchlevel.h"
|
||||
#include "file.h"
|
||||
@ -76,7 +78,11 @@ char *progname; /* used throughout */
|
||||
int lineno; /* line number in the magic file */
|
||||
|
||||
|
||||
static void unwrap __P((char *fn));
|
||||
static void unwrap __P((char *fn));
|
||||
#if 0
|
||||
static int byteconv4 __P((int, int, int));
|
||||
static short byteconv2 __P((int, int, int));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* main - parse arguments and handle options
|
||||
@ -180,18 +186,23 @@ char *fn;
|
||||
FILE *f;
|
||||
int wid = 0, cwid;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL) {
|
||||
error("Cannot open `%s' (%s).\n", fn, strerror(errno));
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
if (strcmp("-", fn) == 0) {
|
||||
f = stdin;
|
||||
wid = 1;
|
||||
} else {
|
||||
if ((f = fopen(fn, "r")) == NULL) {
|
||||
error("Cannot open `%s' (%s).\n", fn, strerror(errno));
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
while (fgets(buf, MAXPATHLEN, f) != NULL) {
|
||||
cwid = strlen(buf) - 1;
|
||||
if (cwid > wid)
|
||||
wid = cwid;
|
||||
}
|
||||
while (fgets(buf, MAXPATHLEN, f) != NULL) {
|
||||
cwid = strlen(buf) - 1;
|
||||
if (cwid > wid)
|
||||
wid = cwid;
|
||||
}
|
||||
|
||||
rewind(f);
|
||||
rewind(f);
|
||||
}
|
||||
|
||||
while (fgets(buf, MAXPATHLEN, f) != NULL) {
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
@ -202,6 +213,71 @@ char *fn;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* byteconv4
|
||||
* Input:
|
||||
* from 4 byte quantity to convert
|
||||
* same whether to perform byte swapping
|
||||
* big_endian whether we are a big endian host
|
||||
*/
|
||||
static int
|
||||
byteconv4(from, same, big_endian)
|
||||
int from;
|
||||
int same;
|
||||
int big_endian;
|
||||
{
|
||||
if (same)
|
||||
return from;
|
||||
else if (big_endian) /* lsb -> msb conversion on msb */
|
||||
{
|
||||
union {
|
||||
int i;
|
||||
char c[4];
|
||||
} retval, tmpval;
|
||||
|
||||
tmpval.i = from;
|
||||
retval.c[0] = tmpval.c[3];
|
||||
retval.c[1] = tmpval.c[2];
|
||||
retval.c[2] = tmpval.c[1];
|
||||
retval.c[3] = tmpval.c[0];
|
||||
|
||||
return retval.i;
|
||||
}
|
||||
else
|
||||
return ntohl(from); /* msb -> lsb conversion on lsb */
|
||||
}
|
||||
|
||||
/*
|
||||
* byteconv2
|
||||
* Same as byteconv4, but for shorts
|
||||
*/
|
||||
static short
|
||||
byteconv2(from, same, big_endian)
|
||||
int from;
|
||||
int same;
|
||||
int big_endian;
|
||||
{
|
||||
if (same)
|
||||
return from;
|
||||
else if (big_endian) /* lsb -> msb conversion on msb */
|
||||
{
|
||||
union {
|
||||
short s;
|
||||
char c[2];
|
||||
} retval, tmpval;
|
||||
|
||||
tmpval.s = (short) from;
|
||||
retval.c[0] = tmpval.c[1];
|
||||
retval.c[1] = tmpval.c[0];
|
||||
|
||||
return retval.s;
|
||||
}
|
||||
else
|
||||
return ntohs(from); /* msb -> lsb conversion on lsb */
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* process - process input file
|
||||
*/
|
||||
@ -213,7 +289,6 @@ int wid;
|
||||
int fd = 0;
|
||||
static const char stdname[] = "standard input";
|
||||
unsigned char buf[HOWMANY+1]; /* one extra for terminating '\0' */
|
||||
struct utimbuf utbuf;
|
||||
struct stat sb;
|
||||
int nbytes = 0; /* number of bytes read from a datafile */
|
||||
char match = '\0';
|
||||
@ -265,61 +340,31 @@ int wid;
|
||||
buf[nbytes++] = '\0'; /* null-terminate it */
|
||||
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");
|
||||
}
|
||||
}
|
||||
#ifdef BUILTIN_ELF
|
||||
if (match == 's' && nbytes > 5)
|
||||
tryelf(fd, buf, nbytes);
|
||||
#endif
|
||||
|
||||
if (inname != stdname) {
|
||||
#ifdef RESTORE_TIME
|
||||
/*
|
||||
* Try to restore access, modification times if read it.
|
||||
*/
|
||||
# ifdef USE_UTIMES
|
||||
struct timeval utsbuf[2];
|
||||
utsbuf[0].tv_sec = sb.st_atime;
|
||||
utsbuf[1].tv_sec = sb.st_mtime;
|
||||
|
||||
(void) utimes(inname, utsbuf); /* don't care if loses */
|
||||
# else
|
||||
struct utimbuf utbuf;
|
||||
|
||||
utbuf.actime = sb.st_atime;
|
||||
utbuf.modtime = sb.st_mtime;
|
||||
(void) utime(inname, &utbuf); /* don't care if loses */
|
||||
# endif
|
||||
#endif
|
||||
(void) close(fd);
|
||||
}
|
||||
(void) putchar('\n');
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* file.h - definitions for file(1) program
|
||||
* @(#)$Id$
|
||||
* @(#)$Id: file.h,v 1.1.1.3 1997/03/18 17:58:51 mpp Exp $
|
||||
*
|
||||
* Copyright (c) Ian F. Darwin, 1987.
|
||||
* Written by Ian F. Darwin.
|
||||
@ -26,6 +26,12 @@
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#ifndef __file_h__
|
||||
#define __file_h__
|
||||
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
#ifndef HOWMANY
|
||||
# define HOWMANY 8192 /* how much of the file to look at */
|
||||
#endif
|
||||
@ -37,12 +43,13 @@ struct magic {
|
||||
short flag;
|
||||
#define INDIR 1 /* if '>(...)' appears, */
|
||||
#define UNSIGNED 2 /* comparison is unsigned */
|
||||
#define ADD 4 /* if '>&' appears, */
|
||||
short cont_level; /* level of ">" */
|
||||
struct {
|
||||
char type; /* byte short long */
|
||||
long offset; /* offset from indirection */
|
||||
int32 offset; /* offset from indirection */
|
||||
} in;
|
||||
long offset; /* offset to magic number */
|
||||
int32 offset; /* offset to magic number */
|
||||
unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
|
||||
char type; /* int, short, long or string. */
|
||||
char vallen; /* length of string value, if any */
|
||||
@ -60,12 +67,12 @@ struct magic {
|
||||
union VALUETYPE {
|
||||
unsigned char b;
|
||||
unsigned short h;
|
||||
unsigned long l;
|
||||
uint32 l;
|
||||
char s[MAXstring];
|
||||
unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
|
||||
unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
|
||||
} value; /* either number or string */
|
||||
unsigned long mask; /* mask before comparison with value */
|
||||
uint32 mask; /* mask before comparison with value */
|
||||
char nospflag; /* supress space character */
|
||||
char desc[MAXDESC]; /* description */
|
||||
};
|
||||
@ -98,8 +105,9 @@ extern int softmagic __P((unsigned char *, 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));
|
||||
|
||||
extern uint32 signextend __P((struct magic *, unsigned int32));
|
||||
extern int internatmagic __P((unsigned char *, int));
|
||||
extern void tryelf __P((int, char *, int));
|
||||
|
||||
|
||||
extern int errno; /* Some unixes don't define this.. */
|
||||
@ -119,7 +127,16 @@ extern int lflag; /* follow symbolic links? */
|
||||
extern int optind; /* From getopt(3) */
|
||||
extern char *optarg;
|
||||
|
||||
#if !defined(__STDC__) || defined(sun) || defined(__sun__) || defined(__convex__)
|
||||
#if defined(sun) || defined(__sun__) || defined (__sun)
|
||||
# if defined(__svr4) || defined (__SVR4) || defined(__svr4__)
|
||||
# define SOLARIS
|
||||
# else
|
||||
# define SUNOS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(__STDC__) || defined(SUNOS) || defined(__convex__)
|
||||
extern int sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
#define strerror(e) \
|
||||
@ -130,3 +147,5 @@ extern char *sys_errlist[];
|
||||
#ifndef MAXPATHLEN
|
||||
#define MAXPATHLEN 512
|
||||
#endif
|
||||
|
||||
#endif /* __file_h__ */
|
||||
|
@ -31,6 +31,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#ifndef major
|
||||
# if defined(__SVR4) || defined(_SVR4_SOURCE)
|
||||
# include <sys/mkdev.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifndef major /* if `major' not defined in types.h, */
|
||||
#include <sys/sysmacros.h> /* try this one. */
|
||||
#endif
|
||||
@ -45,8 +50,8 @@
|
||||
#include "file.h"
|
||||
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
static char *moduleid =
|
||||
"@(#)$Id: fsmagic.c,v 1.1.1.3 1997/03/18 17:58:44 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
int
|
||||
@ -84,12 +89,12 @@ struct stat *sb;
|
||||
ckfputs("directory", stdout);
|
||||
return 1;
|
||||
case S_IFCHR:
|
||||
(void) printf("character special (%d/%d)",
|
||||
major(sb->st_rdev), minor(sb->st_rdev));
|
||||
(void) printf("character special (%ld/%ld)",
|
||||
(long) major(sb->st_rdev), (long) minor(sb->st_rdev));
|
||||
return 1;
|
||||
case S_IFBLK:
|
||||
(void) printf("block special (%d/%d)",
|
||||
major(sb->st_rdev), minor(sb->st_rdev));
|
||||
(void) printf("block special (%ld/%ld)",
|
||||
(long) major(sb->st_rdev), (long) minor(sb->st_rdev));
|
||||
return 1;
|
||||
/* TODO add code to handle V7 MUX and Blit MUX files */
|
||||
#ifdef S_IFIFO
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Pubic Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
|
||||
*
|
||||
* @(#)list.c 1.18 9/23/86 Public Domain - gnu
|
||||
* $Id$
|
||||
* $Id: is_tar.c,v 1.1.1.2 1997/03/18 17:58:48 mpp Exp $
|
||||
*
|
||||
* Comments changed and some code/comments reformatted
|
||||
* for file command by Ian Darwin.
|
||||
@ -19,9 +19,9 @@
|
||||
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
static long from_oct(int, char*); /* Decode octal number */
|
||||
static int from_oct(int, char*); /* Decode octal number */
|
||||
#else
|
||||
static long from_oct();
|
||||
static int from_oct();
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -37,7 +37,7 @@ int nbytes;
|
||||
{
|
||||
register union record *header = (union record *)buf;
|
||||
register int i;
|
||||
register long sum, recsum;
|
||||
register int sum, recsum;
|
||||
register char *p;
|
||||
|
||||
if (nbytes < sizeof(union record))
|
||||
@ -75,12 +75,12 @@ int nbytes;
|
||||
*
|
||||
* Result is -1 if the field is invalid (all blank, or nonoctal).
|
||||
*/
|
||||
static long
|
||||
static int
|
||||
from_oct(digs, where)
|
||||
register int digs;
|
||||
register char *where;
|
||||
{
|
||||
register long value;
|
||||
register int value;
|
||||
|
||||
while (isspace(*where)) { /* Skip spaces */
|
||||
where++;
|
||||
|
@ -3,14 +3,17 @@
|
||||
.SH NAME
|
||||
magic \- file command's magic number file
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.IR file (1)
|
||||
This manual page documents the format of the magic file as
|
||||
used by the
|
||||
.BR file (1)
|
||||
command, version 3.22. The
|
||||
.B file
|
||||
command identifies the type of a file using,
|
||||
among other tests,
|
||||
a test for whether the file begins with a certain
|
||||
.IR "magic number" .
|
||||
The file
|
||||
.B /etc/magic
|
||||
.I /etc/magic
|
||||
specifies what magic numbers are to be tested for,
|
||||
what message to print if a particular magic number is found,
|
||||
and additional information to extract from the file.
|
||||
@ -113,7 +116,7 @@ then presumably print that string, by doing
|
||||
.IP message
|
||||
The message to be printed if the comparison succeeds. If the string
|
||||
contains a
|
||||
.IR printf (3S)
|
||||
.BR printf (3S)
|
||||
format specification, the value from the file (with any specified masking
|
||||
performed) is printed using the message as the format string.
|
||||
.PP
|
||||
@ -156,6 +159,15 @@ type specifier. To that number the value of
|
||||
.I y
|
||||
is added and the result is used as an offset in the file. The default type
|
||||
if one is not specified is long.
|
||||
.PP
|
||||
Sometimes you do not know the exact offset as this depends on the length of
|
||||
preceding fields. You can specify an offset relative to the end of the
|
||||
last uplevel field (of course this may only be done for sublevel tests, i.e.
|
||||
test beginning with
|
||||
.B >
|
||||
). Such a relative offset is specified using
|
||||
.B &
|
||||
as a prefix to the offset.
|
||||
.SH BUGS
|
||||
The formats
|
||||
.IR long ,
|
||||
@ -176,7 +188,7 @@ a system on which the lengths are invariant.
|
||||
There is (currently) no support for specified-endian data to be used in
|
||||
indirect offsets.
|
||||
.SH SEE ALSO
|
||||
.IR file (1)
|
||||
.BR file (1)
|
||||
\- the command that reads this file.
|
||||
.\"
|
||||
.\" From: guy@sun.uucp (Guy Harris)
|
||||
@ -191,4 +203,4 @@ indirect offsets.
|
||||
.\" the changes I posted to the S5R2 version.
|
||||
.\"
|
||||
.\" Modified for Ian Darwin's version of the file command.
|
||||
.\" @(#)$Id$
|
||||
.\" @(#)$Id: magic.5,v 1.1.1.3 1997/03/18 17:58:57 mpp Exp $
|
||||
|
@ -10,22 +10,24 @@
|
||||
*
|
||||
* See LEGAL.NOTICE
|
||||
*
|
||||
* $Id$
|
||||
* $Id: names.h,v 1.1.1.3 1997/03/18 17:58:52 mpp Exp $
|
||||
*/
|
||||
|
||||
/* these types are used to index the table 'types': keep em in sync! */
|
||||
#define L_C 0 /* first and foremost on UNIX */
|
||||
#define L_FORT 1 /* the oldest one */
|
||||
#define L_MAKE 2 /* Makefiles */
|
||||
#define L_PLI 3 /* PL/1 */
|
||||
#define L_MACH 4 /* some kinda assembler */
|
||||
#define L_ENG 5 /* English */
|
||||
#define L_PAS 6 /* Pascal */
|
||||
#define L_MAIL 7 /* Electronic mail */
|
||||
#define L_NEWS 8 /* Usenet Netnews */
|
||||
#define L_CC 1 /* Bjarne's postincrement */
|
||||
#define L_FORT 2 /* the oldest one */
|
||||
#define L_MAKE 3 /* Makefiles */
|
||||
#define L_PLI 4 /* PL/1 */
|
||||
#define L_MACH 5 /* some kinda assembler */
|
||||
#define L_ENG 6 /* English */
|
||||
#define L_PAS 7 /* Pascal */
|
||||
#define L_MAIL 8 /* Electronic mail */
|
||||
#define L_NEWS 9 /* Usenet Netnews */
|
||||
|
||||
static char *types[] = {
|
||||
"C program text",
|
||||
"C++ program text",
|
||||
"FORTRAN program text",
|
||||
"make commands text" ,
|
||||
"PL/1 program text",
|
||||
@ -43,6 +45,12 @@ static struct names {
|
||||
} names[] = {
|
||||
/* These must be sorted by eye for optimal hit rate */
|
||||
/* Add to this list only after substantial meditation */
|
||||
{"//", L_CC},
|
||||
{"template", L_CC},
|
||||
{"virtual", L_CC},
|
||||
{"class", L_CC},
|
||||
{"public:", L_CC},
|
||||
{"private:", L_CC},
|
||||
{"/*", L_C}, /* must precede "The", "the", etc. */
|
||||
{"#include", L_C},
|
||||
{"char", L_C},
|
||||
|
@ -1,16 +1,19 @@
|
||||
#define FILE_VERSION_MAJOR 3
|
||||
#define patchlevel 19
|
||||
#define patchlevel 22
|
||||
|
||||
/*
|
||||
* Patchlevel file for Ian Darwin's MAGIC command.
|
||||
* $Id: patchlevel.h,v 1.5 1997/02/22 19:29:15 peter Exp $
|
||||
* $Id: patchlevel.h,v 1.1.1.3 1997/03/18 17:58:54 mpp Exp $
|
||||
*
|
||||
* $Log: patchlevel.h,v $
|
||||
* Revision 1.6 1997/02/22 19:54:59 peter
|
||||
* Revert $FreeBSD$ to $Id$
|
||||
*
|
||||
* Revision 1.5 1997/02/22 19:29:15 peter
|
||||
* Revert $Id$ to $Id$
|
||||
* Revert $Id: patchlevel.h,v 1.6 1997/02/22 19:54:59 peter Exp $ to $Id: patchlevel.h,v 1.6 1997/02/22 19:54:59 peter Exp $
|
||||
*
|
||||
* Revision 1.4 1997/01/14 06:59:48 jkh
|
||||
* Make the long-awaited change from $Id: patchlevel.h,v 1.5 1997/02/22 19:29:15 peter Exp $ to $Id: patchlevel.h,v 1.5 1997/02/22 19:29:15 peter Exp $
|
||||
* Make the long-awaited change from $Id: patchlevel.h,v 1.6 1997/02/22 19:54:59 peter Exp $ to $Id: patchlevel.h,v 1.6 1997/02/22 19:54:59 peter Exp $
|
||||
*
|
||||
* This will make a number of things easier in the future, as well as (finally!)
|
||||
* avoiding the Id-smashing problem which has plagued developers for so long.
|
||||
@ -37,6 +40,33 @@
|
||||
* The following file was removed:
|
||||
* - Magdir/Makefile
|
||||
*
|
||||
* Revision 1.1.1.3 1997/03/18 17:58:54 mpp
|
||||
* Upgrade to file version 3.22.
|
||||
*
|
||||
* Obtained from: ftp://ftp.deshaw.com/pub/file/file-3.22.tar.gz
|
||||
*
|
||||
* Revision 1.22 1997/01/15 17:23:24 christos
|
||||
* - add support for elf core files: find the program name under SVR4 [Ken Pizzini]
|
||||
* - print strings only up to the first carriage return [various]
|
||||
* - freebsd international ascii support [J Wunsch]
|
||||
* - magic fixes and additions [Guy Harris]
|
||||
* - 64 bit fixes [Larry Schwimmer]
|
||||
* - support for both utime and utimes, but don't restore file access times
|
||||
* by default [various]
|
||||
* - \xXX only takes 2 hex digits, not 3.
|
||||
* - re-implement support for core files [Guy Harris]
|
||||
*
|
||||
* Revision 1.21 1996/10/05 18:15:29 christos
|
||||
* Segregate elf stuff and conditionally enable it with -DBUILTIN_ELF
|
||||
* More magic fixes
|
||||
*
|
||||
* Revision 1.20 1996/06/22 22:15:52 christos
|
||||
* - support relative offsets of the form >&
|
||||
* - fix bug with truncating magic strings that contain \n
|
||||
* - file -f - did not read from stdin as documented
|
||||
* - support elf file parsing using our own elf support.
|
||||
* - as always magdir fixes and additions.
|
||||
*
|
||||
* Revision 1.19 1995/10/27 23:14:46 christos
|
||||
* Ability to parse colon separated list of magic files
|
||||
* New LEGAL.NOTICE
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
"@(#)$Id: print.c,v 1.1.1.3 1997/03/18 17:58:49 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
#define SZOF(a) (sizeof(a) / sizeof(a[0]))
|
||||
@ -58,7 +58,7 @@ struct magic *m;
|
||||
m->offset);
|
||||
|
||||
if (m->flag & INDIR)
|
||||
(void) fprintf(stderr, "(%s,%ld),",
|
||||
(void) fprintf(stderr, "(%s,%d),",
|
||||
(m->in.type >= 0 && m->in.type < SZOF(typ)) ?
|
||||
typ[(unsigned char) m->in.type] :
|
||||
"*bad*",
|
||||
@ -69,7 +69,7 @@ struct magic *m;
|
||||
typ[(unsigned char) m->type] :
|
||||
"*bad*");
|
||||
if (m->mask != ~0L)
|
||||
(void) fprintf(stderr, " & %.8lx", m->mask);
|
||||
(void) fprintf(stderr, " & %.8x", m->mask);
|
||||
|
||||
(void) fprintf(stderr, ",%c", m->reln);
|
||||
|
||||
@ -82,7 +82,7 @@ struct magic *m;
|
||||
case LELONG:
|
||||
case BESHORT:
|
||||
case BELONG:
|
||||
(void) fprintf(stderr, "%ld", m->value.l);
|
||||
(void) fprintf(stderr, "%d", m->value.l);
|
||||
break;
|
||||
case STRING:
|
||||
showstr(stderr, m->value.s, -1);
|
||||
|
@ -27,22 +27,23 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "file.h"
|
||||
|
||||
#ifndef lint
|
||||
static char *moduleid =
|
||||
"@(#)$Id$";
|
||||
static char *moduleid =
|
||||
"@(#)$Id: softmagic.c,v 1.1.1.3 1997/03/18 17:58:45 mpp Exp $";
|
||||
#endif /* lint */
|
||||
|
||||
static int match __P((unsigned char *, int));
|
||||
static int mget __P((union VALUETYPE *,
|
||||
unsigned char *, struct magic *, int));
|
||||
static int mcheck __P((union VALUETYPE *, struct magic *));
|
||||
static void mprint __P((union VALUETYPE *, struct magic *));
|
||||
static void mdebug __P((long, char *, int));
|
||||
static int32 mprint __P((union VALUETYPE *, struct magic *));
|
||||
static void mdebug __P((int32, char *, int));
|
||||
static int mconvert __P((union VALUETYPE *, struct magic *));
|
||||
|
||||
/*
|
||||
@ -98,6 +99,13 @@ int nbytes;
|
||||
int cont_level = 0;
|
||||
int need_separator = 0;
|
||||
union VALUETYPE p;
|
||||
static int32 *tmpoff = NULL;
|
||||
static size_t tmplen = 0;
|
||||
int32 oldoff = 0;
|
||||
|
||||
if (tmpoff == NULL)
|
||||
if ((tmpoff = (int32 *) malloc(tmplen = 20)) == NULL)
|
||||
error("out of memory\n");
|
||||
|
||||
for (magindex = 0; magindex < nmagic; magindex++) {
|
||||
/* if main entry matches, print it... */
|
||||
@ -113,7 +121,7 @@ int nbytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
mprint(&p, &magic[magindex]);
|
||||
tmpoff[cont_level] = mprint(&p, &magic[magindex]);
|
||||
/*
|
||||
* If we printed something, we'll need to print
|
||||
* a blank before we print something else.
|
||||
@ -121,8 +129,11 @@ int nbytes;
|
||||
if (magic[magindex].desc[0])
|
||||
need_separator = 1;
|
||||
/* and any continuations that match */
|
||||
cont_level++;
|
||||
while (magic[magindex+1].cont_level != 0 &&
|
||||
if (++cont_level >= tmplen)
|
||||
if ((tmpoff = (int32 *) realloc(tmpoff,
|
||||
tmplen += 20)) == NULL)
|
||||
error("out of memory\n");
|
||||
while (magic[magindex+1].cont_level != 0 &&
|
||||
++magindex < nmagic) {
|
||||
if (cont_level >= magic[magindex].cont_level) {
|
||||
if (cont_level > magic[magindex].cont_level) {
|
||||
@ -132,6 +143,10 @@ int nbytes;
|
||||
*/
|
||||
cont_level = magic[magindex].cont_level;
|
||||
}
|
||||
if (magic[magindex].flag & ADD) {
|
||||
oldoff=magic[magindex].offset;
|
||||
magic[magindex].offset += tmpoff[cont_level-1];
|
||||
}
|
||||
if (mget(&p, s, &magic[magindex], nbytes) &&
|
||||
mcheck(&p, &magic[magindex])) {
|
||||
/*
|
||||
@ -149,7 +164,7 @@ int nbytes;
|
||||
(void) putchar(' ');
|
||||
need_separator = 0;
|
||||
}
|
||||
mprint(&p, &magic[magindex]);
|
||||
tmpoff[cont_level] = mprint(&p, &magic[magindex]);
|
||||
if (magic[magindex].desc[0])
|
||||
need_separator = 1;
|
||||
|
||||
@ -158,7 +173,14 @@ int nbytes;
|
||||
* at a higher level,
|
||||
* process them.
|
||||
*/
|
||||
cont_level++;
|
||||
if (++cont_level >= tmplen)
|
||||
if ((tmpoff =
|
||||
(int32 *) realloc(tmpoff,
|
||||
tmplen += 20)) == NULL)
|
||||
error("out of memory\n");
|
||||
}
|
||||
if (magic[magindex].flag & ADD) {
|
||||
magic[magindex].offset = oldoff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,13 +189,14 @@ int nbytes;
|
||||
return 0; /* no match at all */
|
||||
}
|
||||
|
||||
static void
|
||||
static int32
|
||||
mprint(p, m)
|
||||
union VALUETYPE *p;
|
||||
struct magic *m;
|
||||
{
|
||||
char *pp, *rt;
|
||||
unsigned long v;
|
||||
uint32 v;
|
||||
int32 t=0 ;
|
||||
|
||||
|
||||
switch (m->type) {
|
||||
@ -181,6 +204,7 @@ struct magic *m;
|
||||
v = p->b;
|
||||
v = signextend(m, v) & m->mask;
|
||||
(void) printf(m->desc, (unsigned char) v);
|
||||
t = m->offset + sizeof(char);
|
||||
break;
|
||||
|
||||
case SHORT:
|
||||
@ -189,6 +213,7 @@ struct magic *m;
|
||||
v = p->h;
|
||||
v = signextend(m, v) & m->mask;
|
||||
(void) printf(m->desc, (unsigned short) v);
|
||||
t = m->offset + sizeof(short);
|
||||
break;
|
||||
|
||||
case LONG:
|
||||
@ -196,17 +221,25 @@ struct magic *m;
|
||||
case LELONG:
|
||||
v = p->l;
|
||||
v = signextend(m, v) & m->mask;
|
||||
(void) printf(m->desc, (unsigned long) v);
|
||||
(void) printf(m->desc, (uint32) v);
|
||||
t = m->offset + sizeof(int32);
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
if (m->reln == '=') {
|
||||
(void) printf(m->desc, m->value.s);
|
||||
t = m->offset + strlen(m->value.s);
|
||||
}
|
||||
else {
|
||||
if (*m->value.s == '\0') {
|
||||
char *cp = strchr(p->s,'\n');
|
||||
if (cp)
|
||||
*cp = '\0';
|
||||
}
|
||||
(void) printf(m->desc, p->s);
|
||||
t = m->offset + strlen(p->s);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
|
||||
case DATE:
|
||||
case BEDATE:
|
||||
@ -215,11 +248,14 @@ struct magic *m;
|
||||
if ((rt = strchr(pp, '\n')) != NULL)
|
||||
*rt = '\0';
|
||||
(void) printf(m->desc, pp);
|
||||
return;
|
||||
t = m->offset + sizeof(time_t);
|
||||
break;
|
||||
|
||||
default:
|
||||
error("invalid m->type (%d) in mprint().\n", m->type);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -230,8 +266,6 @@ mconvert(p, m)
|
||||
union VALUETYPE *p;
|
||||
struct magic *m;
|
||||
{
|
||||
char *rt;
|
||||
|
||||
switch (m->type) {
|
||||
case BYTE:
|
||||
case SHORT:
|
||||
@ -239,17 +273,21 @@ struct magic *m;
|
||||
case DATE:
|
||||
return 1;
|
||||
case STRING:
|
||||
/* Null terminate and eat the return */
|
||||
p->s[sizeof(p->s) - 1] = '\0';
|
||||
if ((rt = strchr(p->s, '\n')) != NULL)
|
||||
*rt = '\0';
|
||||
return 1;
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
/* Null terminate and eat the return */
|
||||
p->s[sizeof(p->s) - 1] = '\0';
|
||||
if ((ptr = strchr(p->s, '\n')) != NULL)
|
||||
*ptr = '\0';
|
||||
return 1;
|
||||
}
|
||||
case BESHORT:
|
||||
p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
|
||||
return 1;
|
||||
case BELONG:
|
||||
case BEDATE:
|
||||
p->l = (long)
|
||||
p->l = (int32)
|
||||
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
|
||||
return 1;
|
||||
case LESHORT:
|
||||
@ -257,7 +295,7 @@ struct magic *m;
|
||||
return 1;
|
||||
case LELONG:
|
||||
case LEDATE:
|
||||
p->l = (long)
|
||||
p->l = (int32)
|
||||
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
|
||||
return 1;
|
||||
default:
|
||||
@ -269,11 +307,11 @@ struct magic *m;
|
||||
|
||||
static void
|
||||
mdebug(offset, str, len)
|
||||
long offset;
|
||||
int32 offset;
|
||||
char *str;
|
||||
int len;
|
||||
{
|
||||
(void) fprintf(stderr, "mget @%ld: ", offset);
|
||||
(void) fprintf(stderr, "mget @%d: ", offset);
|
||||
showstr(stderr, (char *) str, len);
|
||||
(void) fputc('\n', stderr);
|
||||
(void) fputc('\n', stderr);
|
||||
@ -286,7 +324,7 @@ unsigned char *s;
|
||||
struct magic *m;
|
||||
int nbytes;
|
||||
{
|
||||
long offset = m->offset;
|
||||
int32 offset = m->offset;
|
||||
|
||||
if (offset + sizeof(union VALUETYPE) <= nbytes)
|
||||
memcpy(p, s + offset, sizeof(union VALUETYPE));
|
||||
@ -295,7 +333,7 @@ int nbytes;
|
||||
* the usefulness of padding with zeroes eludes me, it
|
||||
* might even cause problems
|
||||
*/
|
||||
long have = nbytes - offset;
|
||||
int32 have = nbytes - offset;
|
||||
memset(p, 0, sizeof(union VALUETYPE));
|
||||
if (have > 0)
|
||||
memcpy(p, s + offset, have);
|
||||
@ -345,8 +383,8 @@ mcheck(p, m)
|
||||
union VALUETYPE* p;
|
||||
struct magic *m;
|
||||
{
|
||||
register unsigned long l = m->value.l;
|
||||
register unsigned long v;
|
||||
register uint32 l = m->value.l;
|
||||
register uint32 v;
|
||||
int matched;
|
||||
|
||||
if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
|
||||
@ -389,7 +427,7 @@ struct magic *m;
|
||||
register int len = m->vallen;
|
||||
|
||||
while (--len >= 0)
|
||||
if ((v = *b++ - *a++) != 0)
|
||||
if ((v = *b++ - *a++) != '\0')
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -403,21 +441,21 @@ struct magic *m;
|
||||
switch (m->reln) {
|
||||
case 'x':
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%lu == *any* = 1\n", v);
|
||||
(void) fprintf(stderr, "%u == *any* = 1\n", v);
|
||||
matched = 1;
|
||||
break;
|
||||
|
||||
case '!':
|
||||
matched = v != l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%lu != %lu = %d\n",
|
||||
(void) fprintf(stderr, "%u != %u = %d\n",
|
||||
v, l, matched);
|
||||
break;
|
||||
|
||||
case '=':
|
||||
matched = v == l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%lu == %lu = %d\n",
|
||||
(void) fprintf(stderr, "%u == %u = %d\n",
|
||||
v, l, matched);
|
||||
break;
|
||||
|
||||
@ -425,13 +463,13 @@ struct magic *m;
|
||||
if (m->flag & UNSIGNED) {
|
||||
matched = v > l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%lu > %lu = %d\n",
|
||||
(void) fprintf(stderr, "%u > %u = %d\n",
|
||||
v, l, matched);
|
||||
}
|
||||
else {
|
||||
matched = (long) v > (long) l;
|
||||
matched = (int32) v > (int32) l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%ld > %ld = %d\n",
|
||||
(void) fprintf(stderr, "%d > %d = %d\n",
|
||||
v, l, matched);
|
||||
}
|
||||
break;
|
||||
@ -440,13 +478,13 @@ struct magic *m;
|
||||
if (m->flag & UNSIGNED) {
|
||||
matched = v < l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%lu < %lu = %d\n",
|
||||
(void) fprintf(stderr, "%u < %u = %d\n",
|
||||
v, l, matched);
|
||||
}
|
||||
else {
|
||||
matched = (long) v < (long) l;
|
||||
matched = (int32) v < (int32) l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "%ld < %ld = %d\n",
|
||||
(void) fprintf(stderr, "%d < %d = %d\n",
|
||||
v, l, matched);
|
||||
}
|
||||
break;
|
||||
@ -454,14 +492,14 @@ struct magic *m;
|
||||
case '&':
|
||||
matched = (v & l) == l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "((%lx & %lx) == %lx) = %d\n",
|
||||
(void) fprintf(stderr, "((%x & %x) == %x) = %d\n",
|
||||
v, l, l, matched);
|
||||
break;
|
||||
|
||||
case '^':
|
||||
matched = (v & l) != l;
|
||||
if (debug)
|
||||
(void) fprintf(stderr, "((%lx & %lx) != %lx) = %d\n",
|
||||
(void) fprintf(stderr, "((%x & %x) != %x) = %d\n",
|
||||
v, l, l, matched);
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user