#include <stdio.h>#include <errno.h>#include <fcntl.h>#include <stdint.h>#include <inttypes.h>#include <sys/stat.h>Go to the source code of this file.
Data Structures | |
| struct | magic |
| union | magic::VALUETYPE |
| struct | mlist |
| struct | magic_set |
| struct | magic_set::cont |
| struct | magic_set::out |
Defines | |
| #define | MAGIC "/etc/magic" |
| #define | PATHSEP ':' |
| #define | private static |
| #define | public |
| #define | HOWMANY (256 * 1024) |
| #define | MAXMAGIS 8192 |
| #define | MAXDESC 64 |
| #define | MAXstring 32 |
| #define | MAGICNO 0xF11E041C |
| #define | VERSIONNO 2 |
| #define | FILE_MAGICSIZE (32 * 4) |
| #define | FILE_LOAD 0 |
| #define | FILE_CHECK 1 |
| #define | FILE_COMPILE 2 |
| #define | INDIR 1 |
| #define | UNSIGNED 2 |
| #define | OFFADD 4 |
| #define | INDIROFFADD 8 |
| #define | FILE_BYTE 1 |
| #define | FILE_SHORT 2 |
| #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 |
| #define | FILE_BESTRING16 18 |
| #define | FILE_LESTRING16 19 |
| #define | FILE_SEARCH 20 |
| #define | FILE_FORMAT_NAME |
| #define | FILE_FMT_NUM "cduxXi" |
| #define | FILE_FMT_STR "s" |
| #define | FILE_FORMAT_STRING |
| #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 |
| #define | FILE_OPINVERSE 0x40 |
| #define | FILE_OPINDIRECT 0x80 |
| #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' |
| #define | O_BINARY 0 |
| #define | FILE_RCSID(id) |
Functions | |
| protected const char * | file_fmttime (uint32_t, int) |
| protected int | file_buffer (struct magic_set *ms, int, const void *, size_t) |
| protected int | file_fsmagic (struct magic_set *ms, const char *fn, struct stat *sb) |
| protected int | file_pipe2file (struct magic_set *ms, int fd, const void *startbuf, size_t nbytes) |
| protected int | file_printf (struct magic_set *ms, const char *,...) |
| protected int | file_reset (struct magic_set *ms) |
| protected int | file_tryelf (struct magic_set *ms, int, const unsigned char *, size_t) |
| protected int | file_zmagic (struct magic_set *ms, int, const unsigned char *, size_t) |
| protected int | file_ascmagic (struct magic_set *ms, const unsigned char *, size_t) |
| protected int | file_is_tar (struct magic_set *ms, const unsigned char *, size_t) |
| protected int | file_softmagic (struct magic_set *ms, const unsigned char *, size_t) |
| protected struct mlist * | file_apprentice (struct magic_set *ms, const char *, int) |
| protected uint32_t | file_signextend (struct magic_set *ms, struct magic *, uint32_t) |
| protected void | file_delmagic (struct magic *p, int type, size_t entries) |
| protected void | file_badread (struct magic_set *ms) |
| protected void | file_badseek (struct magic_set *ms) |
| protected void | file_oomem (struct magic_set *ms) |
| protected void | file_error (struct magic_set *ms, int, const char *,...) |
| protected void | file_magwarn (struct magic_set *ms, const char *,...) |
| protected void | file_mdump (struct magic *m) |
| protected void | file_showstr (FILE *fp, const char *, size_t) |
| protected size_t | file_mbswidth (const char *) |
| protected const char * | file_getbuffer (struct magic_set *ms) |
| #define CHAR_COMPACT_BLANK 'B' |
Definition at line 215 of file file.h.
Referenced by file_mdump(), and parse().
| #define CHAR_COMPACT_OPTIONAL_BLANK 'b' |
Definition at line 216 of file file.h.
Referenced by file_mdump(), and parse().
| #define CHAR_IGNORE_LOWERCASE 'c' |
Definition at line 214 of file file.h.
Referenced by file_mdump(), and parse().
| #define FILE_BEDATE 9 |
Definition at line 104 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_BELDATE 15 |
Definition at line 110 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_BELONG 8 |
Definition at line 103 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_BESHORT 7 |
Definition at line 102 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_BESTRING16 18 |
Definition at line 113 of file file.h.
Referenced by file_signextend(), getvalue(), mconvert(), mcopy(), mprint(), mymcheck(), and parse().
| #define FILE_BYTE 1 |
Definition at line 97 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_CHECK 1 |
Definition at line 80 of file file.h.
Referenced by apprentice_file(), main(), and parse().
| #define FILE_COMPILE 2 |
Definition at line 81 of file file.h.
Referenced by apprentice_1(), and main().
| #define FILE_DATE 6 |
Definition at line 101 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_FORMAT_NAME |
/* 0 */ "invalid 0", \ /* 1 */ "byte", \ /* 2 */ "short", \ /* 3 */ "invalid 3", \ /* 4 */ "long", \ /* 5 */ "string", \ /* 6 */ "date", \ /* 7 */ "beshort", \ /* 8 */ "belong", \ /* 9 */ "bedate", \ /* 10 */ "leshort", \ /* 11 */ "lelong", \ /* 12 */ "ledate", \ /* 13 */ "pstring", \ /* 14 */ "ldate", \ /* 15 */ "beldate", \ /* 16 */ "leldate", \ /* 17 */ "regex", \ /* 18 */ "bestring16", \ /* 19 */ "lestring16", \ /* 20 */ "search",
Definition at line 117 of file file.h.
Referenced by check_format().
| #define FILE_FORMAT_STRING |
/* 0 */ NULL, \ /* 1 */ FILE_FMT_NUM, \ /* 2 */ FILE_FMT_NUM, \ /* 3 */ NULL, \ /* 4 */ FILE_FMT_NUM, \ /* 5 */ FILE_FMT_STR, \ /* 6 */ FILE_FMT_STR, \ /* 7 */ FILE_FMT_NUM, \ /* 8 */ FILE_FMT_NUM, \ /* 9 */ FILE_FMT_STR, \ /* 10 */ FILE_FMT_NUM, \ /* 11 */ FILE_FMT_NUM, \ /* 12 */ FILE_FMT_STR, \ /* 13 */ FILE_FMT_STR, \ /* 14 */ FILE_FMT_STR, \ /* 15 */ FILE_FMT_STR, \ /* 16 */ FILE_FMT_STR, \ /* 17 */ FILE_FMT_STR, \ /* 18 */ FILE_FMT_STR, \ /* 19 */ FILE_FMT_STR, \ /* 20 */ FILE_FMT_STR,
Definition at line 143 of file file.h.
Referenced by check_format().
| #define FILE_LDATE 14 |
Definition at line 109 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_LEDATE 12 |
Definition at line 107 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_LELDATE 16 |
Definition at line 111 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_LELONG 11 |
Definition at line 106 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_LESHORT 10 |
Definition at line 105 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_LESTRING16 19 |
Definition at line 114 of file file.h.
Referenced by file_signextend(), getvalue(), mconvert(), mcopy(), mprint(), mymcheck(), and parse().
| #define FILE_LONG 4 |
Definition at line 99 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_MAGICSIZE (32 * 4) |
Definition at line 77 of file file.h.
Referenced by apprentice_1().
| #define FILE_OPADD 3 |
Definition at line 175 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPAND 0 |
Definition at line 172 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPDIVIDE 6 |
Definition at line 178 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPINDIRECT 0x80 |
| #define FILE_OPINVERSE 0x40 |
Definition at line 180 of file file.h.
Referenced by file_mdump(), mconvert(), mget(), and parse().
| #define FILE_OPMINUS 4 |
Definition at line 176 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPMODULO 7 |
Definition at line 179 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPMULTIPLY 5 |
Definition at line 177 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPOR 1 |
Definition at line 173 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_OPXOR 2 |
Definition at line 174 of file file.h.
Referenced by mconvert(), mget(), and parse().
| #define FILE_PSTRING 13 |
Definition at line 108 of file file.h.
Referenced by file_mdump(), file_signextend(), getvalue(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_RCSID | ( | id | ) |
| #define FILE_REGEX 17 |
Definition at line 112 of file file.h.
Referenced by file_mdump(), file_signextend(), getvalue(), mconvert(), mcopy(), mprint(), mymcheck(), and parse().
| #define FILE_SEARCH 20 |
Definition at line 115 of file file.h.
Referenced by file_signextend(), getvalue(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_SHORT 2 |
Definition at line 98 of file file.h.
Referenced by file_mdump(), file_signextend(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define FILE_STRING 5 |
Definition at line 100 of file file.h.
Referenced by file_mdump(), file_signextend(), getvalue(), mconvert(), mget(), mprint(), mymcheck(), and parse().
| #define HOWMANY (256 * 1024) |
Definition at line 69 of file file.h.
Referenced by file_ascmagic(), and uncompressbuf().
| #define INDIR 1 |
Definition at line 88 of file file.h.
Referenced by file_mdump(), mget(), and parse().
| #define MAGIC "/etc/magic" |
Definition at line 53 of file file.h.
Referenced by file_apprentice().
| #define MAGICNO 0xF11E041C |
Definition at line 75 of file file.h.
Referenced by apprentice_map().
| #define MAXMAGIS 8192 |
Definition at line 71 of file file.h.
Referenced by apprentice_file().
| #define PATHSEP ':' |
Definition at line 59 of file file.h.
Referenced by file_apprentice().
| #define STRING_COMPACT_BLANK BIT(1) |
Definition at line 212 of file file.h.
Referenced by file_mdump(), mymcheck(), and parse().
| #define STRING_COMPACT_OPTIONAL_BLANK BIT(2) |
Definition at line 213 of file file.h.
Referenced by file_mdump(), mymcheck(), and parse().
| #define STRING_IGNORE_LOWERCASE BIT(0) |
Definition at line 211 of file file.h.
Referenced by file_mdump(), mymcheck(), and parse().
| #define UNSIGNED 2 |
Definition at line 89 of file file.h.
Referenced by file_mdump(), file_signextend(), mymcheck(), and parse().
| #define VERSIONNO 2 |
Definition at line 76 of file file.h.
Referenced by apprentice_map().
Definition at line 254 of file apprentice.c.
References apprentice_1(), file_error(), file_oomem(), magic_set::flags, getenv, MAGIC, mlist::next, PATHSEP, and mlist::prev.
| protected int file_ascmagic | ( | struct magic_set * | ms, | |
| const unsigned char * | , | |||
| size_t | ||||
| ) |
Definition at line 78 of file ascmagic.c.
References ascmatch(), file_printf(), magic_set::flags, from_ebcdic(), HOWMANY, ISSPC, looks_ascii(), looks_extended(), looks_latin1(), looks_unicode(), looks_utf8(), MAXLINELEN, names::name, NNAMES, names::type, and types.
| protected void file_badread | ( | struct magic_set * | ms | ) |
Referenced by apprentice_map().
| protected void file_badseek | ( | struct magic_set * | ms | ) |
Referenced by file_pipe2file().
| protected int file_buffer | ( | struct magic_set * | ms, | |
| int | , | |||
| const void * | , | |||
| size_t | ||||
| ) |
Referenced by file_zmagic().
| protected void file_delmagic | ( | struct magic * | p, | |
| int | type, | |||
| size_t | entries | |||
| ) |
Definition at line 231 of file apprentice.c.
Referenced by apprentice_1().
| protected void file_error | ( | struct magic_set * | ms, | |
| int | , | |||
| const char * | , | |||
| ... | ||||
| ) |
Referenced by apprentice_1(), apprentice_compile(), apprentice_file(), apprentice_map(), file_apprentice(), file_fsmagic(), file_pipe2file(), getstr(), mconvert(), mget(), mprint(), mymcheck(), and uncompressbuf().
| protected const char* file_fmttime | ( | uint32_t | , | |
| int | ||||
| ) |
Definition at line 157 of file print.c.
Referenced by file_mdump(), and mprint().
| protected int file_fsmagic | ( | struct magic_set * | ms, | |
| const char * | fn, | |||
| struct stat * | sb | |||
| ) |
Definition at line 64 of file fsmagic.c.
References errno, file_error(), file_printf(), magic_set::flags, magic_set::haderr, major, and minor.
| protected const char* file_getbuffer | ( | struct magic_set * | ms | ) |
| protected int file_is_tar | ( | struct magic_set * | ms, | |
| const unsigned char * | , | |||
| size_t | ||||
| ) |
| protected void file_magwarn | ( | struct magic_set * | ms, | |
| const char * | , | |||
| ... | ||||
| ) |
Definition at line 141 of file print.c.
References magic_set::file, and magic_set::line.
Referenced by apprentice_1(), check_format(), file_signextend(), getvalue(), and parse().
| protected size_t file_mbswidth | ( | const char * | ) |
| protected void file_mdump | ( | struct magic * | m | ) |
Definition at line 51 of file print.c.
References CHAR_COMPACT_BLANK, CHAR_COMPACT_OPTIONAL_BLANK, CHAR_IGNORE_LOWERCASE, magic::cont_level, magic::desc, FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BESHORT, FILE_BYTE, FILE_DATE, file_fmttime(), FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LESHORT, FILE_LONG, FILE_OPINVERSE, FILE_PSTRING, FILE_REGEX, FILE_SHORT, file_showstr(), FILE_STRING, magic::flag, magic::in_offset, magic::in_op, magic::in_type, INDIR, magic::VALUETYPE::l, magic::mask, magic::mask_op, magic::offset, magic::reln, magic::VALUETYPE::s, STRING_COMPACT_BLANK, STRING_COMPACT_OPTIONAL_BLANK, STRING_IGNORE_LOWERCASE, SZOF, magic::type, UNSIGNED, and magic::value.
| protected void file_oomem | ( | struct magic_set * | ms | ) |
Referenced by apprentice_1(), apprentice_file(), apprentice_map(), check_mem(), file_apprentice(), mcopy(), and parse().
| protected int file_pipe2file | ( | struct magic_set * | ms, | |
| int | fd, | |||
| const void * | startbuf, | |||
| size_t | nbytes | |||
| ) |
Definition at line 190 of file compress.c.
References errno, file_badseek(), file_error(), SEEK_SET, sread(), and swrite().
| protected int file_printf | ( | struct magic_set * | ms, | |
| const char * | , | |||
| ... | ||||
| ) |
Referenced by file_ascmagic(), file_fsmagic(), file_zmagic(), match(), and mprint().
| protected int file_reset | ( | struct magic_set * | ms | ) |
| protected void file_showstr | ( | FILE * | fp, | |
| const char * | , | |||
| size_t | ||||
| ) |
Definition at line 997 of file apprentice.c.
Referenced by file_mdump(), and mdebug().
Definition at line 374 of file apprentice.c.
References FILE_BEDATE, FILE_BELDATE, FILE_BELONG, FILE_BESHORT, FILE_BESTRING16, FILE_BYTE, FILE_DATE, FILE_LDATE, FILE_LEDATE, FILE_LELDATE, FILE_LELONG, FILE_LESHORT, FILE_LESTRING16, FILE_LONG, file_magwarn(), FILE_PSTRING, FILE_REGEX, FILE_SEARCH, FILE_SHORT, FILE_STRING, magic::flag, magic_set::flags, magic::type, and UNSIGNED.
Referenced by getvalue(), mprint(), mymcheck(), and parse().
| protected int file_softmagic | ( | struct magic_set * | ms, | |
| const unsigned char * | , | |||
| size_t | ||||
| ) |
Definition at line 82 of file softmagic.c.
References mlist::magic, match(), magic_set::mlist, mlist::next, and mlist::nmagic.
| protected int file_tryelf | ( | struct magic_set * | ms, | |
| int | , | |||
| const unsigned char * | , | |||
| size_t | ||||
| ) |
| protected int file_zmagic | ( | struct magic_set * | ms, | |
| int | , | |||
| const unsigned char * | , | |||
| size_t | ||||
| ) |
Definition at line 101 of file compress.c.
References compr, file_buffer(), file_printf(), magic_set::flags, and uncompressbuf().
1.6.1