00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __file_h__
00030 #define __file_h__
00031
00032
00033
00034 #ifndef HOWMANY
00035 # define HOWMANY 65536
00036 #endif
00037 #define MAXMAGIS 4096
00038 #define MAXDESC 50
00039 #define MAXstring 32
00040
00041 #define MAGICNO 0xF11E041C
00042 #define VERSIONNO 1
00043
00044 #define CHECK 1
00045 #define COMPILE 2
00046
00047 struct magic {
00048 uint16_t cont_level;
00049 uint8_t nospflag;
00050 uint8_t flag;
00051 #define INDIR 1
00052 #define UNSIGNED 2
00053 #define OFFADD 4
00054 uint8_t reln;
00055 uint8_t vallen;
00056 uint8_t type;
00057 uint8_t in_type;
00058 #define BYTE 1
00059 #define SHORT 2
00060 #define LONG 4
00061 #define STRING 5
00062 #define DATE 6
00063 #define BESHORT 7
00064 #define BELONG 8
00065 #define BEDATE 9
00066 #define LESHORT 10
00067 #define LELONG 11
00068 #define LEDATE 12
00069 #define PSTRING 13
00070 #define LDATE 14
00071 #define BELDATE 15
00072 #define LELDATE 16
00073 #define REGEX 17
00074 uint8_t in_op;
00075 uint8_t mask_op;
00076 #define OPAND 1
00077 #define OPOR 2
00078 #define OPXOR 3
00079 #define OPADD 4
00080 #define OPMINUS 5
00081 #define OPMULTIPLY 6
00082 #define OPDIVIDE 7
00083 #define OPMODULO 8
00084 #define OPINVERSE 0x80
00085 int32_t offset;
00086 int32_t in_offset;
00087 union VALUETYPE {
00088 uint8_t b;
00089 uint16_t h;
00090 uint32_t l;
00091 char s[MAXstring];
00092 const char * buf;
00093 uint8_t hs[2];
00094 uint8_t hl[4];
00095 } value;
00096 uint32_t mask;
00097 char desc[MAXDESC];
00098 } __attribute__((__packed__));
00099
00100 #define BIT(A) (1 << (A))
00101 #define STRING_IGNORE_LOWERCASE BIT(0)
00102 #define STRING_COMPACT_BLANK BIT(1)
00103 #define STRING_COMPACT_OPTIONAL_BLANK BIT(2)
00104 #define CHAR_IGNORE_LOWERCASE 'c'
00105 #define CHAR_COMPACT_BLANK 'B'
00106 #define CHAR_COMPACT_OPTIONAL_BLANK 'b'
00107
00108
00109
00110 struct mlist {
00111 struct magic *magic;
00112 uint32_t nmagic;
00113
00114 struct mlist *next;
00115
00116 struct mlist *prev;
00117 };
00118
00119 enum fmagicFlags_e {
00120
00121 FMAGIC_FLAGS_NONE = 0,
00122
00123 FMAGIC_FLAGS_DEBUG = (1 << 0),
00124 FMAGIC_FLAGS_BRIEF = (1 << 1),
00125 FMAGIC_FLAGS_MIME = (1 << 2),
00126 FMAGIC_FLAGS_CONTINUE = (1 << 3),
00127 FMAGIC_FLAGS_FOLLOW = (1 << 4),
00128 FMAGIC_FLAGS_SPECIAL = (1 << 5),
00129 FMAGIC_FLAGS_UNCOMPRESS = (1 << 6)
00130 };
00131
00132 struct fmagic_s {
00133 int flags;
00134
00135 const char *magicfile;
00136 int lineno;
00137
00138 struct mlist * mlist;
00139
00140 struct mlist * ml;
00141
00142 const char * fn;
00143 int fd;
00144 struct stat sb;
00145
00146 unsigned char * buf;
00147 int nb;
00148 union VALUETYPE val;
00149 int cls;
00150 int swap;
00151
00152 char * obp;
00153 size_t nob;
00154 char obuf[512];
00155 };
00156
00157 typedef struct fmagic_s * fmagic;
00158
00159
00160 extern fmagic global_fmagic;
00161
00162
00163 extern const char * default_magicfile;
00164
00165 #ifdef __cplusplus
00166 extern "C" {
00167 #endif
00168
00169
00170 extern int fmagicSetup(fmagic fm, const char *fn, int action)
00171
00172 ;
00173 extern int fmagicProcess(fmagic fm, const char *fn, int wid)
00174
00175 ;
00176
00177 extern int fmagicA(fmagic fm)
00178 ;
00179 extern int fmagicD(fmagic fm)
00180
00181 ;
00182 extern void fmagicE(fmagic fm)
00183
00184 ;
00185 extern int fmagicF(fmagic fm, int zfl)
00186
00187 ;
00188 extern int fmagicS(fmagic fm)
00189
00190 ;
00191 extern int fmagicZ(fmagic fm)
00192
00193 ;
00194
00195 extern void fmagicPrintf(const fmagic fm, const char *f, ...)
00196 ;
00197
00198
00199 extern char *fmttime(long v, int local)
00200 ;
00201
00202 extern void magwarn(const char *f, ...)
00203
00204 ;
00205 extern void mdump(struct magic *m)
00206
00207 ;
00208 extern void showstr(FILE *fp, const char *s, int len)
00209
00210 ;
00211
00212 extern uint32_t signextend(struct magic *m, uint32_t v)
00213
00214 ;
00215 extern int pipe2file(int fd, void *startbuf, size_t nbytes)
00216
00217 ;
00218
00219 #ifdef __cplusplus
00220 }
00221 #endif
00222
00223
00224 #endif