2002-07-10 20:15:52 +04:00
|
|
|
/* $NetBSD: file.h,v 1.29 2002/07/10 16:15:54 pooka Exp $ */
|
1997-01-09 23:18:21 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* file.h - definitions for file(1) program
|
2002-07-09 18:59:52 +04:00
|
|
|
* @(#)Id: file.h,v 1.43 2002/07/03 18:57:52 christos Exp
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Copyright (c) Ian F. Darwin, 1987.
|
|
|
|
* Written by Ian F. Darwin.
|
|
|
|
*
|
|
|
|
* This software is not subject to any license of the American Telephone
|
|
|
|
* and Telegraph Company or of the Regents of the University of California.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose on
|
|
|
|
* any computer system, and to alter it and redistribute it freely, subject
|
|
|
|
* to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The author is not responsible for the consequences of use of this
|
|
|
|
* software, no matter how awful, even if they arise from flaws in it.
|
|
|
|
*
|
|
|
|
* 2. The origin of this software must not be misrepresented, either by
|
|
|
|
* explicit claim or by omission. Since few users ever read sources,
|
|
|
|
* credits must appear in the documentation.
|
|
|
|
*
|
|
|
|
* 3. Altered versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software. Since few users
|
|
|
|
* ever read sources, credits must appear in the documentation.
|
|
|
|
*
|
|
|
|
* 4. This notice may not be removed or altered.
|
|
|
|
*/
|
|
|
|
|
1997-01-28 03:49:36 +03:00
|
|
|
#ifndef __file_h__
|
|
|
|
#define __file_h__
|
|
|
|
|
2002-07-09 18:59:52 +04:00
|
|
|
#ifndef __linux__
|
|
|
|
#define _LARGEFILE_SOURCE
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#endif
|
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-07-09 18:59:52 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
/* Do this here and now, because struct stat gets re-defined on solaris */
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1995-04-28 23:23:38 +04:00
|
|
|
#ifndef HOWMANY
|
2002-07-09 18:59:52 +04:00
|
|
|
# define HOWMANY 65536 /* how much of the file to look at */
|
1995-04-28 23:23:38 +04:00
|
|
|
#endif
|
1999-12-31 16:09:20 +03:00
|
|
|
#define MAXMAGIS 4096 /* max entries in /etc/magic */
|
1993-03-21 12:45:37 +03:00
|
|
|
#define MAXDESC 50 /* max leng of text description */
|
|
|
|
#define MAXstring 32 /* max leng of "string" types */
|
|
|
|
|
2001-03-17 14:21:51 +03:00
|
|
|
#define MAGICNO 0xF11E041C
|
|
|
|
#define VERSIONNO 1
|
|
|
|
|
|
|
|
#define CHECK 1
|
|
|
|
#define COMPILE 2
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
struct magic {
|
2002-06-05 16:52:57 +04:00
|
|
|
uint16_t cont_level; /* level of ">" */
|
|
|
|
uint8_t nospflag; /* supress space character */
|
|
|
|
uint8_t flag;
|
1993-06-10 04:37:55 +04:00
|
|
|
#define INDIR 1 /* if '>(...)' appears, */
|
1993-11-03 07:04:19 +03:00
|
|
|
#define UNSIGNED 2 /* comparison is unsigned */
|
2001-07-23 02:53:00 +04:00
|
|
|
#define OFFADD 4 /* if '>&' appears, */
|
2002-06-05 16:52:57 +04:00
|
|
|
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
|
|
|
|
uint8_t vallen; /* length of string value, if any */
|
|
|
|
uint8_t type; /* int, short, long or string. */
|
|
|
|
uint8_t in_type; /* type of indirrection */
|
1993-03-21 12:45:37 +03:00
|
|
|
#define BYTE 1
|
|
|
|
#define SHORT 2
|
|
|
|
#define LONG 4
|
|
|
|
#define STRING 5
|
1993-06-10 04:37:55 +04:00
|
|
|
#define DATE 6
|
|
|
|
#define BESHORT 7
|
|
|
|
#define BELONG 8
|
|
|
|
#define BEDATE 9
|
|
|
|
#define LESHORT 10
|
|
|
|
#define LELONG 11
|
|
|
|
#define LEDATE 12
|
2001-07-23 02:53:00 +04:00
|
|
|
#define PSTRING 13
|
|
|
|
#define LDATE 14
|
|
|
|
#define BELDATE 15
|
|
|
|
#define LELDATE 16
|
2002-05-18 11:00:44 +04:00
|
|
|
#define REGEX 17
|
2002-06-05 16:52:57 +04:00
|
|
|
uint8_t in_op; /* operator for indirection */
|
|
|
|
uint8_t mask_op; /* operator for mask */
|
2001-07-23 02:53:00 +04:00
|
|
|
#define OPAND 1
|
|
|
|
#define OPOR 2
|
|
|
|
#define OPXOR 3
|
|
|
|
#define OPADD 4
|
|
|
|
#define OPMINUS 5
|
|
|
|
#define OPMULTIPLY 6
|
|
|
|
#define OPDIVIDE 7
|
|
|
|
#define OPMODULO 8
|
|
|
|
#define OPINVERSE 0x80
|
2002-06-05 16:52:57 +04:00
|
|
|
int32_t offset; /* offset to magic number */
|
|
|
|
int32_t in_offset; /* offset from indirection */
|
1993-03-21 12:45:37 +03:00
|
|
|
union VALUETYPE {
|
2002-06-05 16:52:57 +04:00
|
|
|
uint8_t b;
|
|
|
|
uint16_t h;
|
|
|
|
uint32_t l;
|
1993-03-21 12:45:37 +03:00
|
|
|
char s[MAXstring];
|
2002-05-18 11:00:44 +04:00
|
|
|
char *buf;
|
2002-06-05 16:52:57 +04:00
|
|
|
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
|
|
|
|
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
|
1993-03-21 12:45:37 +03:00
|
|
|
} value; /* either number or string */
|
2002-06-05 16:52:57 +04:00
|
|
|
uint32_t mask; /* mask before comparison with value */
|
1993-03-21 12:45:37 +03:00
|
|
|
char desc[MAXDESC]; /* description */
|
2002-06-05 16:52:57 +04:00
|
|
|
} __attribute__((__packed__));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-05-15 02:53:37 +04:00
|
|
|
#define BIT(A) (1 << (A))
|
|
|
|
#define STRING_IGNORE_LOWERCASE BIT(0)
|
|
|
|
#define STRING_COMPACT_BLANK BIT(1)
|
|
|
|
#define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
|
|
|
|
#define CHAR_IGNORE_LOWERCASE 'c'
|
|
|
|
#define CHAR_COMPACT_BLANK 'B'
|
|
|
|
#define CHAR_COMPACT_OPTIONAL_BLANK 'b'
|
|
|
|
|
|
|
|
|
2001-03-17 14:21:51 +03:00
|
|
|
/* list of magic entries */
|
|
|
|
struct mlist {
|
|
|
|
struct magic *magic; /* array of magic entries */
|
2002-06-05 16:52:57 +04:00
|
|
|
uint32_t nmagic; /* number of entries in array */
|
2001-03-17 14:21:51 +03:00
|
|
|
struct mlist *next, *prev;
|
|
|
|
};
|
|
|
|
|
2002-06-14 23:05:18 +04:00
|
|
|
extern int apprentice(const char *, int);
|
|
|
|
extern int ascmagic(unsigned char *, int);
|
|
|
|
extern void error(const char *, ...);
|
|
|
|
extern void ckfputs(const char *, FILE *);
|
1993-06-10 04:37:55 +04:00
|
|
|
struct stat;
|
2002-06-14 23:05:18 +04:00
|
|
|
extern int fsmagic(const char *, struct stat *);
|
|
|
|
extern char *fmttime(long, int);
|
|
|
|
extern int is_compress(const unsigned char *, int *);
|
|
|
|
extern int is_tar(unsigned char *, int);
|
|
|
|
extern void magwarn(const char *, ...);
|
|
|
|
extern void mdump(struct magic *);
|
|
|
|
extern void process(const char *, int);
|
|
|
|
extern void showstr(FILE *, const char *, int);
|
|
|
|
extern int softmagic(unsigned char *, int);
|
|
|
|
extern int tryit(const char *, unsigned char *, int, int);
|
|
|
|
extern int zmagic(const char *, unsigned char *, int);
|
|
|
|
extern void ckfprintf(FILE *, const char *, ...);
|
|
|
|
extern uint32_t signextend(struct magic *, unsigned int32);
|
|
|
|
extern void tryelf(int, unsigned char *, int);
|
|
|
|
extern int pipe2file(int, void *, size_t);
|
2002-05-18 11:00:44 +04:00
|
|
|
|
1993-06-10 04:37:55 +04:00
|
|
|
|
|
|
|
extern char *progname; /* the program name */
|
1998-09-20 19:27:15 +04:00
|
|
|
extern const char *magicfile; /* name of the magic file */
|
1993-06-10 04:37:55 +04:00
|
|
|
extern int lineno; /* current line number in magic file */
|
|
|
|
|
2001-03-17 14:21:51 +03:00
|
|
|
extern struct mlist mlist; /* list of arrays of magic entries */
|
1993-06-10 04:37:55 +04:00
|
|
|
|
|
|
|
extern int debug; /* enable debugging? */
|
|
|
|
extern int zflag; /* process compressed files? */
|
|
|
|
extern int lflag; /* follow symbolic links? */
|
1999-11-01 20:39:26 +03:00
|
|
|
extern int sflag; /* read/analyze block special files? */
|
2000-05-15 02:53:37 +04:00
|
|
|
extern int iflag; /* Output types as mime-types */
|
1993-06-10 04:37:55 +04:00
|
|
|
|
2001-02-05 04:51:52 +03:00
|
|
|
#ifdef NEED_GETOPT
|
1993-06-10 04:37:55 +04:00
|
|
|
extern int optind; /* From getopt(3) */
|
|
|
|
extern char *optarg;
|
2001-02-05 04:51:52 +03:00
|
|
|
#endif
|
1993-06-10 04:37:55 +04:00
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
#ifndef HAVE_STRERROR
|
1993-06-10 04:37:55 +04:00
|
|
|
extern int sys_nerr;
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
#define strerror(e) \
|
|
|
|
(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
|
|
|
|
#endif
|
|
|
|
|
1999-11-01 20:39:26 +03:00
|
|
|
#ifndef HAVE_STRTOUL
|
|
|
|
#define strtoul(a, b, c) strtol(a, b, c)
|
1993-06-10 04:37:55 +04:00
|
|
|
#endif
|
1997-01-28 03:49:36 +03:00
|
|
|
|
2001-07-23 02:53:00 +04:00
|
|
|
#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
|
|
|
|
#define QUICK
|
|
|
|
#endif
|
|
|
|
|
1998-09-20 19:27:15 +04:00
|
|
|
#define FILE_RCSID(id) \
|
|
|
|
static const char *rcsid(const char *p) { \
|
|
|
|
return rcsid(p = id); \
|
|
|
|
}
|
|
|
|
|
1997-01-28 03:49:36 +03:00
|
|
|
#endif /* __file_h__ */
|