2004-08-09 08:45:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Ian F. Darwin 1986-1995.
|
|
|
|
* Software written by Ian F. Darwin and others;
|
|
|
|
* maintained 1995-present by Christos Zoulas and others.
|
2009-05-02 06:25:51 +00:00
|
|
|
*
|
2004-08-09 08:45:41 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* this list of conditions, and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-05-02 06:25:51 +00:00
|
|
|
*
|
2004-08-09 08:45:41 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1994-09-03 19:16:28 +00:00
|
|
|
/*
|
|
|
|
* file.h - definitions for file(1) program
|
2012-04-13 23:30:38 +00:00
|
|
|
* @(#)$File: file.h,v 1.135 2011/09/20 15:30:14 christos Exp $
|
1994-09-03 19:16:28 +00:00
|
|
|
*/
|
|
|
|
|
1997-03-18 18:00:03 +00:00
|
|
|
#ifndef __file_h__
|
|
|
|
#define __file_h__
|
|
|
|
|
2000-11-05 08:33:55 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-06 06:01:12 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#ifdef _WIN64
|
|
|
|
#define SIZE_T_FORMAT "I64"
|
|
|
|
#else
|
|
|
|
#define SIZE_T_FORMAT ""
|
|
|
|
#endif
|
|
|
|
#define INT64_T_FORMAT "I64"
|
|
|
|
#else
|
|
|
|
#define SIZE_T_FORMAT "z"
|
|
|
|
#define INT64_T_FORMAT "ll"
|
|
|
|
#endif
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
#include <stdio.h> /* Include that here, to make sure __P gets defined */
|
2002-09-16 05:54:26 +00:00
|
|
|
#include <errno.h>
|
2006-06-19 07:52:15 +00:00
|
|
|
#include <fcntl.h> /* For open and flags */
|
2002-09-16 05:54:26 +00:00
|
|
|
#ifdef HAVE_STDINT_H
|
2011-10-06 06:01:12 +00:00
|
|
|
#ifndef __STDC_LIMIT_MACROS
|
|
|
|
#define __STDC_LIMIT_MACROS
|
|
|
|
#endif
|
2002-09-16 05:54:26 +00:00
|
|
|
#include <stdint.h>
|
2004-08-09 08:45:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_INTTYPES_H
|
2003-02-15 18:53:17 +00:00
|
|
|
#include <inttypes.h>
|
2002-09-16 05:54:26 +00:00
|
|
|
#endif
|
2007-05-24 21:59:38 +00:00
|
|
|
#include <regex.h>
|
2007-05-24 16:12:23 +00:00
|
|
|
#include <sys/types.h>
|
2009-05-02 06:25:51 +00:00
|
|
|
#include <sys/param.h>
|
2002-09-16 05:54:26 +00:00
|
|
|
/* Do this here and now, because struct stat gets re-defined on solaris */
|
|
|
|
#include <sys/stat.h>
|
2009-01-02 02:57:16 +00:00
|
|
|
#include <stdarg.h>
|
1997-03-18 18:00:03 +00:00
|
|
|
|
2007-05-24 21:59:38 +00:00
|
|
|
#define ENABLE_CONDITIONALS
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
#ifndef MAGIC
|
|
|
|
#define MAGIC "/etc/magic"
|
|
|
|
#endif
|
|
|
|
|
2011-10-06 06:01:12 +00:00
|
|
|
#if defined(__EMX__) || defined (WIN32)
|
2004-08-09 08:45:41 +00:00
|
|
|
#define PATHSEP ';'
|
|
|
|
#else
|
|
|
|
#define PATHSEP ':'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define private static
|
|
|
|
#ifndef protected
|
|
|
|
#define protected
|
|
|
|
#endif
|
|
|
|
#define public
|
|
|
|
|
2011-10-06 06:01:12 +00:00
|
|
|
#ifndef __arraycount
|
|
|
|
#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
|
|
|
|
#endif
|
|
|
|
|
2007-05-24 21:59:38 +00:00
|
|
|
#ifndef __GNUC_PREREQ__
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __GNUC_PREREQ__(x, y) \
|
|
|
|
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
|
|
|
|
(__GNUC__ > (x)))
|
|
|
|
#else
|
|
|
|
#define __GNUC_PREREQ__(x, y) 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
#ifndef __GNUC__
|
|
|
|
#ifndef __attribute__
|
|
|
|
#define __attribute__(a)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-05-24 21:59:38 +00:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
1996-01-23 12:29:07 +00:00
|
|
|
#ifndef HOWMANY
|
2006-06-19 07:52:15 +00:00
|
|
|
# define HOWMANY (256 * 1024) /* how much of the file to look at */
|
1996-01-23 12:29:07 +00:00
|
|
|
#endif
|
2009-01-02 02:57:16 +00:00
|
|
|
#define MAXMAGIS 8192 /* max entries in any one magic file
|
|
|
|
or directory */
|
|
|
|
#define MAXDESC 64 /* max leng of text description/MIME type */
|
2011-10-06 06:01:12 +00:00
|
|
|
#define MAXstring 64 /* max leng of "string" types */
|
1994-09-03 19:16:28 +00:00
|
|
|
|
2001-03-25 18:37:04 +00:00
|
|
|
#define MAGICNO 0xF11E041C
|
2011-10-06 06:01:12 +00:00
|
|
|
#define VERSIONNO 8
|
|
|
|
#define FILE_MAGICSIZE 232
|
2001-03-25 18:37:04 +00:00
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
#define FILE_LOAD 0
|
|
|
|
#define FILE_CHECK 1
|
|
|
|
#define FILE_COMPILE 2
|
2011-10-06 06:01:12 +00:00
|
|
|
#define FILE_LIST 3
|
2003-02-15 18:53:17 +00:00
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
union VALUETYPE {
|
|
|
|
uint8_t b;
|
|
|
|
uint16_t h;
|
|
|
|
uint32_t l;
|
|
|
|
uint64_t q;
|
|
|
|
uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */
|
|
|
|
uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */
|
|
|
|
uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */
|
|
|
|
char s[MAXstring]; /* the search string or regex pattern */
|
|
|
|
unsigned char us[MAXstring];
|
|
|
|
float f;
|
|
|
|
double d;
|
2009-05-02 06:25:51 +00:00
|
|
|
};
|
2009-01-02 02:57:16 +00:00
|
|
|
|
1994-09-03 19:16:28 +00:00
|
|
|
struct magic {
|
2004-08-09 08:45:41 +00:00
|
|
|
/* Word 1 */
|
2002-09-16 05:54:26 +00:00
|
|
|
uint16_t cont_level; /* level of ">" */
|
|
|
|
uint8_t flag;
|
2009-01-02 02:57:16 +00:00
|
|
|
#define INDIR 0x01 /* if '(...)' appears */
|
|
|
|
#define OFFADD 0x02 /* if '>&' or '>...(&' appears */
|
|
|
|
#define INDIROFFADD 0x04 /* if '>&(' appears */
|
|
|
|
#define UNSIGNED 0x08 /* comparison is unsigned */
|
|
|
|
#define NOSPACE 0x10 /* suppress space character before output */
|
|
|
|
#define BINTEST 0x20 /* test is for a binary type (set only
|
2009-05-02 06:25:51 +00:00
|
|
|
for top-level tests) */
|
2011-10-06 06:01:12 +00:00
|
|
|
#define TEXTTEST 0x40 /* for passing to file_softmagic */
|
2009-01-02 02:57:16 +00:00
|
|
|
|
|
|
|
uint8_t factor;
|
2007-05-24 21:59:38 +00:00
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
/* Word 2 */
|
2002-09-16 05:54:26 +00:00
|
|
|
uint8_t reln; /* relation (0=eq, '>'=gt, etc) */
|
|
|
|
uint8_t vallen; /* length of string value, if any */
|
2009-01-02 02:57:16 +00:00
|
|
|
uint8_t type; /* comparison type (FILE_*) */
|
|
|
|
uint8_t in_type; /* type of indirection */
|
2007-05-24 21:59:38 +00:00
|
|
|
#define FILE_INVALID 0
|
2004-08-09 08:45:41 +00:00
|
|
|
#define FILE_BYTE 1
|
|
|
|
#define FILE_SHORT 2
|
2007-05-24 21:59:38 +00:00
|
|
|
#define FILE_DEFAULT 3
|
2004-08-09 08:45:41 +00:00
|
|
|
#define FILE_LONG 4
|
|
|
|
#define FILE_STRING 5
|
|
|
|
#define FILE_DATE 6
|
|
|
|
#define FILE_BESHORT 7
|
|
|
|
#define FILE_BELONG 8
|
|
|
|
#define FILE_BEDATE 9
|
|
|
|
#define FILE_LESHORT 10
|
|
|
|
#define FILE_LELONG 11
|
|
|
|
#define FILE_LEDATE 12
|
|
|
|
#define FILE_PSTRING 13
|
|
|
|
#define FILE_LDATE 14
|
|
|
|
#define FILE_BELDATE 15
|
|
|
|
#define FILE_LELDATE 16
|
|
|
|
#define FILE_REGEX 17
|
2004-12-28 04:31:47 +00:00
|
|
|
#define FILE_BESTRING16 18
|
|
|
|
#define FILE_LESTRING16 19
|
2006-06-19 07:52:15 +00:00
|
|
|
#define FILE_SEARCH 20
|
|
|
|
#define FILE_MEDATE 21
|
|
|
|
#define FILE_MELDATE 22
|
|
|
|
#define FILE_MELONG 23
|
2007-05-24 16:12:23 +00:00
|
|
|
#define FILE_QUAD 24
|
|
|
|
#define FILE_LEQUAD 25
|
|
|
|
#define FILE_BEQUAD 26
|
|
|
|
#define FILE_QDATE 27
|
|
|
|
#define FILE_LEQDATE 28
|
|
|
|
#define FILE_BEQDATE 29
|
|
|
|
#define FILE_QLDATE 30
|
|
|
|
#define FILE_LEQLDATE 31
|
|
|
|
#define FILE_BEQLDATE 32
|
2008-01-13 20:35:16 +00:00
|
|
|
#define FILE_FLOAT 33
|
|
|
|
#define FILE_BEFLOAT 34
|
|
|
|
#define FILE_LEFLOAT 35
|
|
|
|
#define FILE_DOUBLE 36
|
|
|
|
#define FILE_BEDOUBLE 37
|
|
|
|
#define FILE_LEDOUBLE 38
|
2009-05-02 06:25:51 +00:00
|
|
|
#define FILE_BEID3 39
|
|
|
|
#define FILE_LEID3 40
|
|
|
|
#define FILE_INDIRECT 41
|
|
|
|
#define FILE_NAMES_SIZE 42/* size of array to contain all names */
|
2004-08-09 08:45:41 +00:00
|
|
|
|
2007-05-24 21:59:38 +00:00
|
|
|
#define IS_STRING(t) \
|
|
|
|
((t) == FILE_STRING || \
|
|
|
|
(t) == FILE_PSTRING || \
|
|
|
|
(t) == FILE_BESTRING16 || \
|
|
|
|
(t) == FILE_LESTRING16 || \
|
|
|
|
(t) == FILE_REGEX || \
|
|
|
|
(t) == FILE_SEARCH || \
|
|
|
|
(t) == FILE_DEFAULT)
|
2007-05-24 16:12:23 +00:00
|
|
|
|
|
|
|
#define FILE_FMT_NONE 0
|
|
|
|
#define FILE_FMT_NUM 1 /* "cduxXi" */
|
|
|
|
#define FILE_FMT_STR 2 /* "s" */
|
|
|
|
#define FILE_FMT_QUAD 3 /* "ll" */
|
2008-01-13 20:35:16 +00:00
|
|
|
#define FILE_FMT_FLOAT 4 /* "eEfFgG" */
|
|
|
|
#define FILE_FMT_DOUBLE 5 /* "eEfFgG" */
|
2004-08-09 08:45:41 +00:00
|
|
|
|
|
|
|
/* Word 3 */
|
2002-09-16 05:54:26 +00:00
|
|
|
uint8_t in_op; /* operator for indirection */
|
|
|
|
uint8_t mask_op; /* operator for mask */
|
2007-05-24 21:59:38 +00:00
|
|
|
#ifdef ENABLE_CONDITIONALS
|
|
|
|
uint8_t cond; /* conditional type */
|
|
|
|
#else
|
2009-01-02 02:57:16 +00:00
|
|
|
uint8_t dummy;
|
2007-05-24 21:59:38 +00:00
|
|
|
#endif
|
2009-05-02 06:25:51 +00:00
|
|
|
uint8_t factor_op;
|
2009-01-02 02:57:16 +00:00
|
|
|
#define FILE_FACTOR_OP_PLUS '+'
|
|
|
|
#define FILE_FACTOR_OP_MINUS '-'
|
|
|
|
#define FILE_FACTOR_OP_TIMES '*'
|
|
|
|
#define FILE_FACTOR_OP_DIV '/'
|
|
|
|
#define FILE_FACTOR_OP_NONE '\0'
|
2007-05-24 21:59:38 +00:00
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
#define FILE_OPS "&|^+-*/%"
|
|
|
|
#define FILE_OPAND 0
|
|
|
|
#define FILE_OPOR 1
|
|
|
|
#define FILE_OPXOR 2
|
|
|
|
#define FILE_OPADD 3
|
|
|
|
#define FILE_OPMINUS 4
|
|
|
|
#define FILE_OPMULTIPLY 5
|
|
|
|
#define FILE_OPDIVIDE 6
|
|
|
|
#define FILE_OPMODULO 7
|
2007-05-24 21:59:38 +00:00
|
|
|
#define FILE_OPS_MASK 0x07 /* mask for above ops */
|
|
|
|
#define FILE_UNUSED_1 0x08
|
|
|
|
#define FILE_UNUSED_2 0x10
|
|
|
|
#define FILE_UNUSED_3 0x20
|
2006-06-19 07:52:15 +00:00
|
|
|
#define FILE_OPINVERSE 0x40
|
|
|
|
#define FILE_OPINDIRECT 0x80
|
2007-05-24 21:59:38 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_CONDITIONALS
|
|
|
|
#define COND_NONE 0
|
|
|
|
#define COND_IF 1
|
|
|
|
#define COND_ELIF 2
|
|
|
|
#define COND_ELSE 3
|
|
|
|
#endif /* ENABLE_CONDITIONALS */
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
/* Word 4 */
|
|
|
|
uint32_t offset; /* offset to magic number */
|
|
|
|
/* Word 5 */
|
2006-06-19 07:52:15 +00:00
|
|
|
int32_t in_offset; /* offset from indirection */
|
2004-08-09 08:45:41 +00:00
|
|
|
/* Word 6 */
|
2007-05-24 16:12:23 +00:00
|
|
|
uint32_t lineno; /* line number in magic file */
|
|
|
|
/* Word 7,8 */
|
2007-05-24 21:59:38 +00:00
|
|
|
union {
|
|
|
|
uint64_t _mask; /* for use with numeric and date types */
|
|
|
|
struct {
|
|
|
|
uint32_t _count; /* repeat/line count */
|
|
|
|
uint32_t _flags; /* modifier flags */
|
|
|
|
} _s; /* for use with string types */
|
|
|
|
} _u;
|
|
|
|
#define num_mask _u._mask
|
2009-01-02 02:57:16 +00:00
|
|
|
#define str_range _u._s._count
|
2007-05-24 21:59:38 +00:00
|
|
|
#define str_flags _u._s._flags
|
2004-08-09 08:45:41 +00:00
|
|
|
/* Words 9-16 */
|
2009-05-02 06:25:51 +00:00
|
|
|
union VALUETYPE value; /* either number or string */
|
2011-10-06 06:01:12 +00:00
|
|
|
/* Words 17-32 */
|
1994-09-03 19:16:28 +00:00
|
|
|
char desc[MAXDESC]; /* description */
|
2011-10-06 06:01:12 +00:00
|
|
|
/* Words 33-48 */
|
2009-01-02 02:57:16 +00:00
|
|
|
char mimetype[MAXDESC]; /* MIME type */
|
2011-10-06 06:01:12 +00:00
|
|
|
/* Words 49-50 */
|
2009-05-02 06:25:51 +00:00
|
|
|
char apple[8];
|
2004-08-09 08:45:41 +00:00
|
|
|
};
|
1994-09-03 19:16:28 +00:00
|
|
|
|
2000-11-05 08:33:55 +00:00
|
|
|
#define BIT(A) (1 << (A))
|
2011-10-06 06:01:12 +00:00
|
|
|
#define STRING_COMPACT_WHITESPACE BIT(0)
|
|
|
|
#define STRING_COMPACT_OPTIONAL_WHITESPACE BIT(1)
|
|
|
|
#define STRING_IGNORE_LOWERCASE BIT(2)
|
|
|
|
#define STRING_IGNORE_UPPERCASE BIT(3)
|
|
|
|
#define REGEX_OFFSET_START BIT(4)
|
|
|
|
#define STRING_TEXTTEST BIT(5)
|
|
|
|
#define STRING_BINTEST BIT(6)
|
|
|
|
#define PSTRING_1_BE BIT(7)
|
|
|
|
#define PSTRING_1_LE BIT(7)
|
|
|
|
#define PSTRING_2_BE BIT(8)
|
|
|
|
#define PSTRING_2_LE BIT(9)
|
|
|
|
#define PSTRING_4_BE BIT(10)
|
|
|
|
#define PSTRING_4_LE BIT(11)
|
|
|
|
#define PSTRING_LEN \
|
|
|
|
(PSTRING_1_BE|PSTRING_2_LE|PSTRING_2_BE|PSTRING_4_LE|PSTRING_4_BE)
|
|
|
|
#define PSTRING_LENGTH_INCLUDES_ITSELF BIT(12)
|
|
|
|
#define CHAR_COMPACT_WHITESPACE 'W'
|
|
|
|
#define CHAR_COMPACT_OPTIONAL_WHITESPACE 'w'
|
|
|
|
#define CHAR_IGNORE_LOWERCASE 'c'
|
|
|
|
#define CHAR_IGNORE_UPPERCASE 'C'
|
|
|
|
#define CHAR_REGEX_OFFSET_START 's'
|
|
|
|
#define CHAR_TEXTTEST 't'
|
|
|
|
#define CHAR_BINTEST 'b'
|
|
|
|
#define CHAR_PSTRING_1_BE 'B'
|
|
|
|
#define CHAR_PSTRING_1_LE 'B'
|
|
|
|
#define CHAR_PSTRING_2_BE 'H'
|
|
|
|
#define CHAR_PSTRING_2_LE 'h'
|
|
|
|
#define CHAR_PSTRING_4_BE 'L'
|
|
|
|
#define CHAR_PSTRING_4_LE 'l'
|
|
|
|
#define CHAR_PSTRING_LENGTH_INCLUDES_ITSELF 'J'
|
2007-05-24 21:59:38 +00:00
|
|
|
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
|
2009-01-02 02:57:16 +00:00
|
|
|
#define STRING_DEFAULT_RANGE 100
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
|
2001-03-25 18:37:04 +00:00
|
|
|
/* list of magic entries */
|
|
|
|
struct mlist {
|
|
|
|
struct magic *magic; /* array of magic entries */
|
2004-08-09 08:45:41 +00:00
|
|
|
uint32_t nmagic; /* number of entries in array */
|
|
|
|
int mapped; /* allocation type: 0 => apprentice_file
|
|
|
|
* 1 => apprentice_map + malloc
|
|
|
|
* 2 => apprentice_map + mmap */
|
2001-03-25 18:37:04 +00:00
|
|
|
struct mlist *next, *prev;
|
|
|
|
};
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define CAST(T, b) static_cast<T>(b)
|
2011-10-06 06:01:12 +00:00
|
|
|
#define RCAST(T, b) reinterpret_cast<T>(b)
|
2009-01-02 02:57:16 +00:00
|
|
|
#else
|
2011-10-06 06:01:12 +00:00
|
|
|
#define CAST(T, b) (T)(b)
|
|
|
|
#define RCAST(T, b) (T)(b)
|
2009-01-02 02:57:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct level_info {
|
|
|
|
int32_t off;
|
|
|
|
int got_match;
|
|
|
|
#ifdef ENABLE_CONDITIONALS
|
|
|
|
int last_match;
|
|
|
|
int last_cond; /* used for error checking by parse() */
|
|
|
|
#endif
|
2009-05-02 06:25:51 +00:00
|
|
|
};
|
2004-08-09 08:45:41 +00:00
|
|
|
struct magic_set {
|
2007-05-24 21:59:38 +00:00
|
|
|
struct mlist *mlist;
|
|
|
|
struct cont {
|
|
|
|
size_t len;
|
2009-01-02 02:57:16 +00:00
|
|
|
struct level_info *li;
|
2007-05-24 21:59:38 +00:00
|
|
|
} c;
|
|
|
|
struct out {
|
2009-01-02 02:57:16 +00:00
|
|
|
char *buf; /* Accumulation buffer */
|
|
|
|
char *pbuf; /* Printable buffer */
|
2007-05-24 21:59:38 +00:00
|
|
|
} o;
|
|
|
|
uint32_t offset;
|
|
|
|
int error;
|
2009-05-02 06:25:51 +00:00
|
|
|
int flags; /* Control magic tests. */
|
|
|
|
int event_flags; /* Note things that happened. */
|
|
|
|
#define EVENT_HAD_ERR 0x01
|
2007-05-24 21:59:38 +00:00
|
|
|
const char *file;
|
|
|
|
size_t line; /* current magic line number */
|
|
|
|
|
|
|
|
/* data for searches */
|
|
|
|
struct {
|
|
|
|
const char *s; /* start of search in original source */
|
|
|
|
size_t s_len; /* length of search region */
|
|
|
|
size_t offset; /* starting offset in source: XXX - should this be off_t? */
|
|
|
|
size_t rm_len; /* match length */
|
|
|
|
} search;
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* FIXME: Make the string dynamically allocated so that e.g.
|
|
|
|
strings matched in files can be longer than MAXstring */
|
2007-05-24 21:59:38 +00:00
|
|
|
union VALUETYPE ms_value; /* either number or string */
|
2004-08-09 08:45:41 +00:00
|
|
|
};
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* Type for Unicode characters */
|
|
|
|
typedef unsigned long unichar;
|
|
|
|
|
1994-09-03 19:16:28 +00:00
|
|
|
struct stat;
|
2006-06-19 07:52:15 +00:00
|
|
|
protected const char *file_fmttime(uint32_t, int);
|
2007-05-24 21:59:38 +00:00
|
|
|
protected int file_buffer(struct magic_set *, int, const char *, const void *,
|
|
|
|
size_t);
|
2004-08-09 08:45:41 +00:00
|
|
|
protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
|
|
|
|
protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
|
2009-01-02 02:57:16 +00:00
|
|
|
protected int file_vprintf(struct magic_set *, const char *, va_list);
|
2011-10-06 06:01:12 +00:00
|
|
|
protected size_t file_printedlen(const struct magic_set *);
|
|
|
|
protected int file_replace(struct magic_set *, const char *, const char *);
|
2009-01-02 02:57:16 +00:00
|
|
|
protected int file_printf(struct magic_set *, const char *, ...)
|
|
|
|
__attribute__((__format__(__printf__, 2, 3)));
|
2004-08-09 08:45:41 +00:00
|
|
|
protected int file_reset(struct magic_set *);
|
2007-05-24 21:59:38 +00:00
|
|
|
protected int file_tryelf(struct magic_set *, int, const unsigned char *,
|
|
|
|
size_t);
|
2009-05-02 06:25:51 +00:00
|
|
|
protected int file_trycdf(struct magic_set *, int, const unsigned char *,
|
|
|
|
size_t);
|
2011-10-06 06:01:12 +00:00
|
|
|
#if HAVE_FORK
|
2007-05-24 21:59:38 +00:00
|
|
|
protected int file_zmagic(struct magic_set *, int, const char *,
|
|
|
|
const unsigned char *, size_t);
|
2011-10-06 06:01:12 +00:00
|
|
|
#endif
|
2012-04-13 23:30:38 +00:00
|
|
|
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t,
|
|
|
|
int);
|
2009-05-02 06:25:51 +00:00
|
|
|
protected int file_ascmagic_with_encoding(struct magic_set *,
|
|
|
|
const unsigned char *, size_t, unichar *, size_t, const char *,
|
2012-04-13 23:30:38 +00:00
|
|
|
const char *, int);
|
2009-05-02 06:25:51 +00:00
|
|
|
protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
|
|
|
|
unichar **, size_t *, const char **, const char **, const char **);
|
2004-08-09 08:45:41 +00:00
|
|
|
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
|
2009-05-02 06:25:51 +00:00
|
|
|
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
|
2012-04-13 23:30:38 +00:00
|
|
|
int, int);
|
2004-08-09 08:45:41 +00:00
|
|
|
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
|
2007-05-24 21:59:38 +00:00
|
|
|
protected uint64_t file_signextend(struct magic_set *, struct magic *,
|
|
|
|
uint64_t);
|
2004-08-09 08:45:41 +00:00
|
|
|
protected void file_delmagic(struct magic *, int type, size_t entries);
|
|
|
|
protected void file_badread(struct magic_set *);
|
|
|
|
protected void file_badseek(struct magic_set *);
|
2007-05-24 16:12:23 +00:00
|
|
|
protected void file_oomem(struct magic_set *, size_t);
|
2009-01-02 02:57:16 +00:00
|
|
|
protected void file_error(struct magic_set *, int, const char *, ...)
|
|
|
|
__attribute__((__format__(__printf__, 3, 4)));
|
|
|
|
protected void file_magerror(struct magic_set *, const char *, ...)
|
|
|
|
__attribute__((__format__(__printf__, 2, 3)));
|
|
|
|
protected void file_magwarn(struct magic_set *, const char *, ...)
|
|
|
|
__attribute__((__format__(__printf__, 2, 3)));
|
2004-08-09 08:45:41 +00:00
|
|
|
protected void file_mdump(struct magic *);
|
|
|
|
protected void file_showstr(FILE *, const char *, size_t);
|
|
|
|
protected size_t file_mbswidth(const char *);
|
|
|
|
protected const char *file_getbuffer(struct magic_set *);
|
2007-05-24 21:59:38 +00:00
|
|
|
protected ssize_t sread(int, void *, size_t, int);
|
|
|
|
protected int file_check_mem(struct magic_set *, unsigned int);
|
2009-05-18 22:27:42 +00:00
|
|
|
protected int file_looks_utf8(const unsigned char *, size_t, unichar *,
|
|
|
|
size_t *);
|
2011-10-06 06:01:12 +00:00
|
|
|
protected size_t file_pstring_length_size(const struct magic *);
|
|
|
|
protected size_t file_pstring_get_length(const struct magic *, const char *);
|
2009-05-18 22:27:42 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
|
|
|
|
size_t);
|
|
|
|
#endif /* __EMX__ */
|
|
|
|
|
2007-05-24 16:12:23 +00:00
|
|
|
|
|
|
|
#ifndef COMPILE_ONLY
|
|
|
|
extern const char *file_names[];
|
|
|
|
extern const size_t file_nnames;
|
|
|
|
#endif
|
1994-09-03 19:16:28 +00:00
|
|
|
|
2000-11-05 08:33:55 +00:00
|
|
|
#ifndef HAVE_STRERROR
|
1994-09-03 19:16:28 +00:00
|
|
|
extern int sys_nerr;
|
|
|
|
extern char *sys_errlist[];
|
|
|
|
#define strerror(e) \
|
|
|
|
(((e) >= 0 && (e) < sys_nerr) ? sys_errlist[(e)] : "Unknown error")
|
2000-11-05 08:33:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRTOUL
|
1996-01-23 12:29:07 +00:00
|
|
|
#define strtoul(a, b, c) strtol(a, b, c)
|
1994-09-03 19:16:28 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
#ifndef HAVE_VASPRINTF
|
|
|
|
int vasprintf(char **, const char *, va_list);
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_ASPRINTF
|
|
|
|
int asprintf(char **ptr, const char *format_string, ...);
|
2006-06-19 07:52:15 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
#ifndef HAVE_STRLCPY
|
|
|
|
size_t strlcpy(char *dst, const char *src, size_t siz);
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_STRLCAT
|
|
|
|
size_t strlcat(char *dst, const char *src, size_t siz);
|
|
|
|
#endif
|
2011-10-06 06:01:12 +00:00
|
|
|
#ifndef HAVE_GETLINE
|
|
|
|
ssize_t getline(char **dst, size_t *len, FILE *fp);
|
|
|
|
ssize_t getdelim(char **dst, size_t *len, int delimiter, FILE *fp);
|
|
|
|
#endif
|
2009-05-02 06:25:51 +00:00
|
|
|
|
2001-07-30 03:09:46 +00:00
|
|
|
#if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK)
|
|
|
|
#define QUICK
|
|
|
|
#endif
|
|
|
|
|
2006-06-19 07:52:15 +00:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
#ifndef __cplusplus
|
2011-10-06 06:01:12 +00:00
|
|
|
#if defined(__GNUC__) && (__GNUC__ >= 3)
|
2009-05-02 06:25:51 +00:00
|
|
|
#define FILE_RCSID(id) \
|
|
|
|
static const char rcsid[] __attribute__((__used__)) = id;
|
|
|
|
#else
|
2000-11-05 08:33:55 +00:00
|
|
|
#define FILE_RCSID(id) \
|
|
|
|
static const char *rcsid(const char *p) { \
|
|
|
|
return rcsid(p = id); \
|
|
|
|
}
|
2009-05-02 06:25:51 +00:00
|
|
|
#endif
|
2009-01-02 02:57:16 +00:00
|
|
|
#else
|
|
|
|
#define FILE_RCSID(id)
|
|
|
|
#endif
|
1997-03-18 18:00:03 +00:00
|
|
|
|
|
|
|
#endif /* __file_h__ */
|