diff --git a/ext/fileinfo/generate_patch.sh b/ext/fileinfo/generate_patch.sh index 0ebc3b2c0f7..b7d6dc8aae5 100755 --- a/ext/fileinfo/generate_patch.sh +++ b/ext/fileinfo/generate_patch.sh @@ -1,4 +1,4 @@ -VERSION=5.40 +VERSION=5.43 if [[ ! -d libmagic.orig ]]; then mkdir libmagic.orig wget -O - ftp://ftp.astron.com/pub/file/file-$VERSION.tar.gz \ diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch index 85170a92d42..57abb074c99 100644 --- a/ext/fileinfo/libmagic.patch +++ b/ext/fileinfo/libmagic.patch @@ -1,6 +1,6 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c ---- libmagic.orig/apprentice.c 2021-02-22 17:51:11.000000000 -0700 -+++ libmagic/apprentice.c 2022-06-06 00:36:46.758464267 -0600 +--- libmagic.orig/apprentice.c 2022-05-31 20:54:25.000000000 +0200 ++++ libmagic/apprentice.c 2022-09-12 14:46:49.582740235 +0200 @@ -29,6 +29,8 @@ * apprentice - make one pass through /etc/magic, learning its secrets. */ @@ -10,7 +10,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c #include "file.h" #ifndef lint -@@ -37,19 +39,33 @@ +@@ -37,6 +39,19 @@ #include "magic.h" #include @@ -30,26 +30,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c #ifdef HAVE_UNISTD_H #include #endif --#include -+#endif - #include - #include - #include - #include --#ifdef QUICK --#include -+ -+#ifndef SSIZE_MAX -+#define MAXMAGIC_SIZE ((ssize_t)0x7fffffff) -+#else -+#define MAXMAGIC_SIZE SSIZE_MAX - #endif --#include --#include - - - #define EATAB {while (isascii(CAST(unsigned char, *l)) && \ -@@ -66,6 +82,10 @@ +@@ -72,6 +87,10 @@ #endif #endif @@ -60,18 +41,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c #ifndef MAP_FAILED #define MAP_FAILED (void *) -1 #endif -@@ -128,10 +148,7 @@ - private uint32_t swap4(uint32_t); - private uint64_t swap8(uint64_t); - private char *mkdbname(struct magic_set *, const char *, int); --private struct magic_map *apprentice_buf(struct magic_set *, struct magic *, -- size_t); - private struct magic_map *apprentice_map(struct magic_set *, const char *); --private int check_buffer(struct magic_set *, struct magic_map *, const char *); - private void apprentice_unmap(struct magic_map *); - private int apprentice_compile(struct magic_set *, struct magic_map *, - const char *); -@@ -167,38 +184,7 @@ +@@ -186,38 +205,7 @@ { NULL, 0, NULL } }; @@ -111,7 +81,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c struct type_tbl_s { const char name[16]; -@@ -417,7 +403,7 @@ +@@ -444,7 +432,7 @@ struct mlist *ml; mlp->map = NULL; @@ -120,14 +90,25 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c return -1; ml->map = idx == 0 ? map : NULL; -@@ -502,10 +488,16 @@ +@@ -452,9 +440,9 @@ + ml->nmagic = map->nmagic[idx]; + if (ml->nmagic) { + ml->magic_rxcomp = CAST(file_regex_t **, +- calloc(ml->nmagic, sizeof(*ml->magic_rxcomp))); ++ ecalloc(ml->nmagic, sizeof(*ml->magic_rxcomp))); + if (ml->magic_rxcomp == NULL) { +- free(ml); ++ efree(ml); + return -1; + } + } else +@@ -537,13 +525,19 @@ return; for (i = 0; i < MAGIC_SETS; i++) mlist_free(ms->mlist[i]); - free(ms->o.pbuf); - free(ms->o.buf); - free(ms->c.li); -- free(ms); + if (ms->o.pbuf) { + efree(ms->o.pbuf); + } @@ -137,11 +118,15 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c + if (ms->c.li) { + efree(ms->c.li); + } + #ifdef USE_C_LOCALE + freelocale(ms->c_lc_ctype); + #endif +- free(ms); + efree(ms); } protected struct magic_set * -@@ -514,7 +506,7 @@ +@@ -552,7 +546,7 @@ struct magic_set *ms; size_t i, len; @@ -150,7 +135,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c sizeof(struct magic_set)))) == NULL) return NULL; -@@ -527,7 +519,7 @@ +@@ -565,7 +559,7 @@ ms->o.blen = 0; len = (ms->c.len = 10) * sizeof(*ms->c.li); @@ -159,19 +144,8 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c goto free; ms->event_flags = 0; -@@ -546,48 +538,35 @@ - ms->encoding_max = FILE_ENCODING_MAX; - return ms; - free: -- free(ms); -+ efree(ms); - return NULL; - } - - private void - apprentice_unmap(struct magic_map *map) - { -- size_t i; +@@ -599,38 +593,26 @@ + char *p; if (map == NULL) return; - @@ -179,13 +153,12 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c - case MAP_TYPE_USER: - break; - case MAP_TYPE_MALLOC: +- p = CAST(char *, map->p); - for (i = 0; i < MAGIC_SETS; i++) { -- void *b = map->magic[i]; -- void *p = map->p; -- if (CAST(char *, b) >= CAST(char *, p) && -- CAST(char *, b) <= CAST(char *, p) + map->len) +- char *b = RCAST(char *, map->magic[i]); +- if (p != NULL && b >= p && b <= p + map->len) - continue; -- free(map->magic[i]); +- free(b); + if (map->p != php_magic_database) { + if (map->p == NULL) { + int j; @@ -197,7 +170,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c + } else { + efree(map->p); } -- free(map->p); +- free(p); - break; -#ifdef QUICK - case MAP_TYPE_MMAP: @@ -206,6 +179,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c - break; -#endif - default: +- fprintf(stderr, "Bad map type %d", map->type); - abort(); } - free(map); @@ -221,68 +195,30 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c return NULL; } mlist->next = mlist->prev = mlist; -@@ -610,7 +589,7 @@ +@@ -651,21 +633,9 @@ + private void + mlist_free_one(struct mlist *ml) { +- size_t i; +- if (ml->map) apprentice_unmap(CAST(struct magic_map *, ml->map)); +- +- for (i = 0; i < ml->nmagic; ++i) { +- if (ml->magic_rxcomp[i]) { +- file_regfree(ml->magic_rxcomp[i]); +- free(ml->magic_rxcomp[i]); +- ml->magic_rxcomp[i] = NULL; +- } +- } +- free(ml->magic_rxcomp); +- ml->magic_rxcomp = NULL; - free(ml); + efree(ml); } private void -@@ -629,51 +608,6 @@ - mlist_free_one(mlist); - } - --#ifndef COMPILE_ONLY --/* void **bufs: an array of compiled magic files */ --protected int --buffer_apprentice(struct magic_set *ms, struct magic **bufs, -- size_t *sizes, size_t nbufs) --{ -- size_t i, j; -- struct mlist *ml; -- struct magic_map *map; -- -- if (nbufs == 0) -- return -1; -- -- (void)file_reset(ms, 0); -- -- init_file_tables(); -- -- for (i = 0; i < MAGIC_SETS; i++) { -- mlist_free(ms->mlist[i]); -- if ((ms->mlist[i] = mlist_alloc()) == NULL) { -- file_oomem(ms, sizeof(*ms->mlist[i])); -- goto fail; -- } -- } -- -- for (i = 0; i < nbufs; i++) { -- map = apprentice_buf(ms, bufs[i], sizes[i]); -- if (map == NULL) -- goto fail; -- -- for (j = 0; j < MAGIC_SETS; j++) { -- if (add_mlist(ms->mlist[j], map, j) == -1) { -- file_oomem(ms, sizeof(*ml)); -- goto fail; -- } -- } -- } -- -- return 0; --fail: -- mlist_free_all(ms); -- return -1; --} --#endif -- - /* const char *fn: list of magic files and directories */ - protected int - file_apprentice(struct magic_set *ms, const char *fn, int action) -@@ -684,12 +618,28 @@ +@@ -739,12 +709,28 @@ (void)file_reset(ms, 0); @@ -312,7 +248,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c file_oomem(ms, strlen(fn)); return -1; } -@@ -702,7 +652,7 @@ +@@ -757,7 +743,7 @@ mlist_free(ms->mlist[j]); ms->mlist[j] = NULL; } @@ -321,7 +257,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c return -1; } } -@@ -719,7 +669,7 @@ +@@ -774,7 +760,7 @@ fn = p; } @@ -330,16 +266,16 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c if (errs == -1) { for (i = 0; i < MAGIC_SETS; i++) { -@@ -1159,7 +1109,7 @@ +@@ -1284,7 +1270,7 @@ - mset[i].max += ALLOC_INCR; + size_t incr = mset[i].max + ALLOC_INCR; if ((mp = CAST(struct magic_entry *, -- realloc(mset[i].me, sizeof(*mp) * mset[i].max))) == -+ erealloc(mset[i].me, sizeof(*mp) * mset[i].max))) == +- realloc(mset[i].me, sizeof(*mp) * incr))) == ++ erealloc(mset[i].me, sizeof(*mp) * incr))) == NULL) { - file_oomem(ms, sizeof(*mp) * mset[i].max); + file_oomem(ms, sizeof(*mp) * incr); return -1; -@@ -1180,13 +1130,19 @@ +@@ -1306,13 +1292,19 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs, struct magic_entry_set *mset) { @@ -363,7 +299,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c if (errno != ENOENT) file_error(ms, errno, "cannot read magic file `%s'", fn); -@@ -1196,8 +1152,7 @@ +@@ -1322,8 +1314,7 @@ memset(&me, 0, sizeof(me)); /* read and parse this file */ @@ -373,7 +309,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c if (len == 0) /* null line, garbage, etc */ continue; if (line[len - 1] == '\n') { -@@ -1232,7 +1187,7 @@ +@@ -1358,7 +1349,7 @@ continue; } if ((*bang[i].fun)(ms, &me, @@ -382,7 +318,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c len - bang[i].len - 2) != 0) { (*errs)++; continue; -@@ -1256,8 +1211,8 @@ +@@ -1382,8 +1373,8 @@ } if (me.mp) (void)addentry(ms, &me, mset); @@ -393,8 +329,8 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } /* -@@ -1336,7 +1291,7 @@ - mentrycount += me[i].cont_count; +@@ -1468,7 +1459,7 @@ + } slen = sizeof(**ma) * mentrycount; - if ((*ma = CAST(struct magic *, malloc(slen))) == NULL) { @@ -402,7 +338,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c file_oomem(ms, slen); return -1; } -@@ -1358,8 +1313,8 @@ +@@ -1490,8 +1481,8 @@ if (me == NULL) return; for (i = 0; i < nme; i++) @@ -413,7 +349,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } private struct magic_map * -@@ -1368,18 +1323,19 @@ +@@ -1500,18 +1491,19 @@ int errs = 0; uint32_t i, j; size_t files = 0, maxfiles = 0; @@ -438,7 +374,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c { file_oomem(ms, sizeof(*map)); return NULL; -@@ -1391,52 +1347,50 @@ +@@ -1523,52 +1515,50 @@ (void)fprintf(stderr, "%s\n", usg_hdr); /* load directory or file */ @@ -510,16 +446,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } } else load_1(ms, action, fn, &errs, mset); -@@ -1465,7 +1419,7 @@ - /* coalesce per file arrays into a single one, if needed */ - if (mset[j].count == 0) - continue; -- -+ - if (coalesce_entries(ms, mset[j].me, mset[j].count, - &map->magic[j], &map->nmagic[j]) == -1) { - errs++; -@@ -1474,7 +1428,6 @@ +@@ -1606,7 +1596,6 @@ } out: @@ -527,7 +454,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c for (j = 0; j < MAGIC_SETS; j++) magic_entry_free(mset[j].me, mset[j].count); -@@ -1910,7 +1863,7 @@ +@@ -2053,7 +2042,7 @@ if (me->cont_count == me->max_count) { struct magic *nm; size_t cnt = me->max_count + ALLOC_CHUNK; @@ -536,7 +463,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c sizeof(*nm) * cnt))) == NULL) { file_oomem(ms, sizeof(*nm) * cnt); return -1; -@@ -1925,7 +1878,7 @@ +@@ -2068,7 +2057,7 @@ static const size_t len = sizeof(*m) * ALLOC_CHUNK; if (me->mp != NULL) return 1; @@ -545,7 +472,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c file_oomem(ms, len); return -1; } -@@ -2148,7 +2101,7 @@ +@@ -2291,7 +2280,7 @@ m->mask_op = 0; if (*l == '~') { @@ -554,7 +481,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c m->mask_op |= FILE_OPINVERSE; else if (ms->flags & MAGIC_CHECK) file_magwarn(ms, "'~' invalid for string types"); -@@ -2157,7 +2110,7 @@ +@@ -2300,7 +2289,7 @@ m->str_range = 0; m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; if ((op = get_op(*l)) != -1) { @@ -563,16 +490,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c int r; if (op != FILE_OPDIVIDE) { -@@ -2277,7 +2230,7 @@ - */ - private int - parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line, -- size_t len __attribute__((__unused__))) -+ size_t len) - { - const char *l = line; - char *el; -@@ -2339,8 +2292,7 @@ +@@ -2482,8 +2471,7 @@ private int parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, @@ -582,15 +500,15 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c { size_t i; const char *l = line; -@@ -2705,14 +2657,19 @@ +@@ -2840,13 +2828,19 @@ return -1; } if (m->type == FILE_REGEX) { - file_regex_t rx; -- int rc = file_regcomp(&rx, m->value.s, REG_EXTENDED); -- if (rc) { -- if (ms->flags & MAGIC_CHECK) -- file_regerror(&rx, rc, ms); +- int rc = file_regcomp(ms, &rx, m->value.s, +- REG_EXTENDED); +- if (rc == 0) { +- file_regfree(&rx); + zend_string *pattern; + int options = 0; + pcre_cache_entry *pce; @@ -601,7 +519,6 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c + zend_string_release(pattern); + return -1; } -- file_regfree(&rx); - return rc ? -1 : 0; + zend_string_release(pattern); + @@ -609,35 +526,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } return 0; default: -@@ -3068,120 +3025,83 @@ - } - - /* -- * handle a buffer containing a compiled file. -- */ --private struct magic_map * --apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) --{ -- struct magic_map *map; -- -- if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { -- file_oomem(ms, sizeof(*map)); -- return NULL; -- } -- map->len = len; -- map->p = buf; -- map->type = MAP_TYPE_USER; -- if (check_buffer(ms, map, "buffer") != 0) { -- apprentice_unmap(map); -- return NULL; -- } -- return map; --} -- --/* - * handle a compiled file. - */ - +@@ -3246,92 +3240,77 @@ private struct magic_map * apprentice_map(struct magic_set *ms, const char *fn) { @@ -652,22 +541,22 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c + size_t i; + php_stream *stream = NULL; + php_stream_statbuf st; -+ -+ - fd = -1; - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { ++ ++ + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { file_oomem(ms, sizeof(*map)); - goto error; + return NULL; - } -- map->type = MAP_TYPE_USER; /* unspecified */ ++ } + + if (fn == NULL) { + map->p = (void *)&php_magic_database; + goto internal_loaded; -+ } + } +- map->type = MAP_TYPE_USER; /* unspecified */ + +#ifdef PHP_WIN32 + /* Don't bother on windows with php_stream_open_wrapper, @@ -773,7 +662,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } needsbyteswap = 1; } else -@@ -3191,17 +3111,29 @@ +@@ -3341,17 +3320,29 @@ else version = ptr[1]; if (version != VERSIONNO) { @@ -812,7 +701,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } map->magic[0] = CAST(struct magic *, map->p) + 1; nentries = 0; -@@ -3214,15 +3146,29 @@ +@@ -3364,15 +3355,29 @@ map->magic[i + 1] = map->magic[i] + map->nmagic[i]; nentries += map->nmagic[i]; } @@ -845,7 +734,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c } /* -@@ -3233,7 +3179,6 @@ +@@ -3383,7 +3388,6 @@ { static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS; static const size_t m = sizeof(**map->magic); @@ -853,7 +742,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c size_t len; char *dbname; int rv = -1; -@@ -3242,14 +3187,17 @@ +@@ -3392,14 +3396,17 @@ struct magic m; uint32_t h[2 + MAGIC_SETS]; } hdr; @@ -873,7 +762,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c file_error(ms, errno, "cannot open `%s'", dbname); goto out; } -@@ -3258,26 +3206,25 @@ +@@ -3408,26 +3415,25 @@ hdr.h[1] = VERSIONNO; memcpy(hdr.h + 2, map->nmagic, nm); @@ -908,7 +797,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c return rv; } -@@ -3311,17 +3258,18 @@ +@@ -3461,17 +3467,18 @@ q++; /* Compatibility with old code that looked in .mime */ if (ms->flags & MAGIC_MIME) { @@ -934,7 +823,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c /* Compatibility with old code that looked in .mime */ if (strstr(fn, ".mime") != NULL) -@@ -3411,7 +3359,7 @@ +@@ -3593,7 +3600,7 @@ m->offset = swap4(CAST(uint32_t, m->offset)); m->in_offset = swap4(CAST(uint32_t, m->in_offset)); m->lineno = swap4(CAST(uint32_t, m->lineno)); @@ -944,8 +833,8 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c m->str_flags = swap4(m->str_flags); } diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c ---- libmagic.orig/ascmagic.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/ascmagic.c 2021-10-24 17:03:48.529884451 -0600 +--- libmagic.orig/ascmagic.c 2021-12-06 17:25:22.000000000 +0100 ++++ libmagic/ascmagic.c 2022-09-12 14:46:49.582740235 +0200 @@ -96,7 +96,7 @@ rv = file_ascmagic_with_encoding(ms, &bb, ubuf, ulen, code, type, text); @@ -975,8 +864,8 @@ diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c return rv; } diff -u libmagic.orig/buffer.c libmagic/buffer.c ---- libmagic.orig/buffer.c 2021-02-22 17:49:26.000000000 -0700 -+++ libmagic/buffer.c 2021-10-24 17:03:45.681791493 -0600 +--- libmagic.orig/buffer.c 2020-02-16 16:52:49.000000000 +0100 ++++ libmagic/buffer.c 2022-09-12 14:46:49.582740235 +0200 @@ -31,19 +31,23 @@ #endif /* lint */ @@ -1031,8 +920,8 @@ diff -u libmagic.orig/buffer.c libmagic/buffer.c goto out; } diff -u libmagic.orig/cdf.c libmagic/cdf.c ---- libmagic.orig/cdf.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/cdf.c 2021-10-24 17:03:45.681791493 -0600 +--- libmagic.orig/cdf.c 2021-10-20 15:56:15.000000000 +0200 ++++ libmagic/cdf.c 2022-09-12 14:46:49.582740235 +0200 @@ -43,7 +43,17 @@ #include #endif @@ -1051,51 +940,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c #include #include #include -@@ -85,40 +95,9 @@ - CDF_TOLE8(CAST(uint64_t, x)))) - #define CDF_GETUINT32(x, y) cdf_getuint32(x, y) - --#define CDF_MALLOC(n) cdf_malloc(__FILE__, __LINE__, (n)) --#define CDF_REALLOC(p, n) cdf_realloc(__FILE__, __LINE__, (p), (n)) --#define CDF_CALLOC(n, u) cdf_calloc(__FILE__, __LINE__, (n), (u)) -- -- --/*ARGSUSED*/ --static void * --cdf_malloc(const char *file __attribute__((__unused__)), -- size_t line __attribute__((__unused__)), size_t n) --{ -- DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n", -- file, line, __func__, n)); -- return malloc(n); --} -- --/*ARGSUSED*/ --static void * --cdf_realloc(const char *file __attribute__((__unused__)), -- size_t line __attribute__((__unused__)), void *p, size_t n) --{ -- DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n", -- file, line, __func__, n)); -- return realloc(p, n); --} -- --/*ARGSUSED*/ --static void * --cdf_calloc(const char *file __attribute__((__unused__)), -- size_t line __attribute__((__unused__)), size_t n, size_t u) --{ -- DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u %" -- SIZE_T_FORMAT "u\n", file, line, __func__, n, u)); -- return calloc(n, u); --} -+#define CDF_MALLOC(n) emalloc(n) -+#define CDF_REALLOC(p, n) erealloc(p, n) -+#define CDF_CALLOC(n, u) ecalloc(n, u) - - /* - * swap a short -@@ -314,7 +293,7 @@ +@@ -334,7 +344,7 @@ scn->sst_len = 0; scn->sst_dirlen = 0; scn->sst_ss = 0; @@ -1104,7 +949,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c scn->sst_tab = NULL; return -1; } -@@ -322,9 +301,11 @@ +@@ -342,9 +352,11 @@ static size_t cdf_check_stream(const cdf_stream_t *sst, const cdf_header_t *h) { @@ -1116,7 +961,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return sst->sst_ss; } -@@ -347,11 +328,11 @@ +@@ -367,11 +379,11 @@ } static ssize_t @@ -1130,7 +975,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c goto out; if (info->i_buf != NULL && info->i_len >= siz) { -@@ -362,7 +343,10 @@ +@@ -382,7 +394,10 @@ if (info->i_fd == -1) goto out; @@ -1142,7 +987,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return -1; return CAST(ssize_t, len); -@@ -377,7 +361,7 @@ +@@ -397,7 +412,7 @@ char buf[512]; (void)memcpy(cdf_bo.s, "\01\02\03\04", 4); @@ -1151,7 +996,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return -1; cdf_unpack_header(h, buf); cdf_swap_header(h); -@@ -524,14 +508,14 @@ +@@ -544,14 +559,14 @@ } out: sat->sat_len = i; @@ -1169,7 +1014,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return -1; } -@@ -699,7 +683,7 @@ +@@ -719,7 +734,7 @@ return -1; if ((buf = CAST(char *, CDF_MALLOC(ss))) == NULL) { @@ -1178,7 +1023,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return -1; } -@@ -722,11 +706,11 @@ +@@ -742,11 +757,11 @@ if (NEED_SWAP) for (i = 0; i < dir->dir_len; i++) cdf_swap_dir(&dir->dir_tab[i]); @@ -1193,7 +1038,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c errno = EFTYPE; return -1; } -@@ -771,7 +755,7 @@ +@@ -791,7 +806,7 @@ out: errno = EFTYPE; out1: @@ -1202,7 +1047,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c return -1; } -@@ -933,7 +917,7 @@ +@@ -953,7 +968,7 @@ *maxcount = newcount; return inp; out: @@ -1211,7 +1056,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c *maxcount = 0; *info = NULL; return NULL; -@@ -1115,7 +1099,7 @@ +@@ -1136,7 +1151,7 @@ } return 0; out: @@ -1220,7 +1065,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c *info = NULL; *count = 0; *maxcount = 0; -@@ -1407,7 +1391,7 @@ +@@ -1428,7 +1443,7 @@ cdf_directory_t *d; char name[__arraycount(d->d_name)]; cdf_stream_t scn; @@ -1229,7 +1074,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c static const char *types[] = { "empty", "user storage", "user stream", "lockbytes", "property", "root storage" }; -@@ -1449,7 +1433,7 @@ +@@ -1470,7 +1485,7 @@ break; } cdf_dump_stream(&scn); @@ -1238,7 +1083,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c break; default: break; -@@ -1462,7 +1446,7 @@ +@@ -1483,7 +1498,7 @@ cdf_dump_property_info(const cdf_property_info_t *info, size_t count) { cdf_timestamp_t tp; @@ -1247,7 +1092,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c char buf[64]; size_t i, j; -@@ -1547,7 +1531,7 @@ +@@ -1568,7 +1583,7 @@ (void)fprintf(stderr, "Class %s\n", buf); (void)fprintf(stderr, "Count %d\n", ssi.si_count); cdf_dump_property_info(info, count); @@ -1256,7 +1101,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c } -@@ -1568,7 +1552,7 @@ +@@ -1589,7 +1604,7 @@ cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name), cdf_ctime(&ts.tv_sec, tbuf)); } @@ -1266,8 +1111,8 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c #endif diff -u libmagic.orig/cdf.h libmagic/cdf.h ---- libmagic.orig/cdf.h 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/cdf.h 2021-10-24 17:03:40.741632734 -0600 +--- libmagic.orig/cdf.h 2019-09-30 17:42:50.000000000 +0200 ++++ libmagic/cdf.h 2022-09-12 14:46:49.582740235 +0200 @@ -35,10 +35,10 @@ #ifndef _H_CDF_ #define _H_CDF_ @@ -1283,8 +1128,8 @@ diff -u libmagic.orig/cdf.h libmagic/cdf.h #ifdef __DJGPP__ #define timespec timeval diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c ---- libmagic.orig/cdf_time.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/cdf_time.c 2021-10-24 17:03:40.741632734 -0600 +--- libmagic.orig/cdf_time.c 2021-12-06 17:25:22.000000000 +0100 ++++ libmagic/cdf_time.c 2022-09-12 14:46:49.582740235 +0200 @@ -23,6 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. @@ -1310,20 +1155,11 @@ diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c + char *ptr = php_ctime_r(sec, buf); if (ptr != NULL) return buf; - (void)snprintf(buf, 26, "*Bad* %#16.16" INT64_T_FORMAT "x\n", + #ifdef WIN32 diff -u libmagic.orig/compress.c libmagic/compress.c ---- libmagic.orig/compress.c 2021-02-22 17:49:07.000000000 -0700 -+++ libmagic/compress.c 2021-10-24 17:03:48.529884451 -0600 -@@ -51,7 +51,7 @@ - #ifndef HAVE_SIG_T - typedef void (*sig_t)(int); - #endif /* HAVE_SIG_T */ --#if !defined(__MINGW32__) && !defined(WIN32) && !defined(__MINGW64__) -+#ifndef PHP_WIN32 - #include - #endif - #ifdef HAVE_SYS_WAIT_H -@@ -60,13 +60,14 @@ +--- libmagic.orig/compress.c 2022-04-11 20:15:07.000000000 +0200 ++++ libmagic/compress.c 2022-09-12 14:46:49.582740235 +0200 +@@ -63,13 +63,14 @@ #if defined(HAVE_SYS_TIME_H) #include #endif @@ -1341,7 +1177,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c #define BUILTIN_BZLIB #include #endif -@@ -118,6 +119,8 @@ +@@ -121,6 +122,8 @@ } #endif @@ -1350,17 +1186,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c static int lzmacmp(const unsigned char *buf) { -@@ -221,8 +224,7 @@ - size_t *); - #endif - --static int makeerror(unsigned char **, size_t *, const char *, ...) -- __attribute__((__format__(__printf__, 3, 4))); -+static int makeerror(unsigned char **, size_t *, const char *, ...); - private const char *methodname(size_t); - - private int -@@ -294,7 +296,7 @@ +@@ -297,7 +300,7 @@ if (urv == ERRDATA) prv = format_decompression_error(ms, i, newbuf); else @@ -1369,7 +1195,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c if (prv == -1) goto error; rv = 1; -@@ -311,17 +313,17 @@ +@@ -314,17 +317,17 @@ * XXX: If file_buffer fails here, we overwrite * the compressed text. FIXME. */ @@ -1390,7 +1216,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c } if (!mime && file_printf(ms, ")") == -1) goto error; -@@ -342,7 +344,8 @@ +@@ -345,7 +348,8 @@ if (sa_saved && sig_act.sa_handler != SIG_IGN) (void)sigaction(SIGPIPE, &sig_act, NULL); @@ -1400,16 +1226,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c ms->flags |= MAGIC_COMPRESS; DPRINTF("Zmagic returns %d\n", rv); return rv; -@@ -377,7 +380,7 @@ - * `safe' read for sockets and pipes. - */ - protected ssize_t --sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) -+sread(int fd, void *buf, size_t n, int canbepipe) - { - ssize_t rv; - #ifdef FIONREAD -@@ -425,7 +428,7 @@ +@@ -428,7 +432,7 @@ nocheck: do @@ -1418,7 +1235,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c case -1: if (errno == EINTR) continue; -@@ -504,13 +507,13 @@ +@@ -521,13 +525,13 @@ return -1; } (void)close(tfd); @@ -1434,7 +1251,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c #ifdef BUILTIN_DECOMPRESS #define FHCRC (1 << 1) -@@ -561,7 +564,7 @@ +@@ -578,7 +582,7 @@ int rc; z_stream z; @@ -1443,14 +1260,14 @@ diff -u libmagic.orig/compress.c libmagic/compress.c return makeerror(newch, n, "No buffer, %s", strerror(errno)); z.next_in = CCAST(Bytef *, old); -@@ -986,3 +989,4 @@ +@@ -1045,3 +1049,4 @@ return rv; } #endif +#endif diff -u libmagic.orig/der.c libmagic/der.c ---- libmagic.orig/der.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/der.c 2021-10-24 17:03:48.529884451 -0600 +--- libmagic.orig/der.c 2022-02-14 17:41:23.000000000 +0100 ++++ libmagic/der.c 2022-09-12 14:46:49.582740235 +0200 @@ -54,7 +54,9 @@ #include "magic.h" #include "der.h" @@ -1462,8 +1279,8 @@ diff -u libmagic.orig/der.c libmagic/der.c #include #endif diff -u libmagic.orig/elfclass.h libmagic/elfclass.h ---- libmagic.orig/elfclass.h 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/elfclass.h 2021-10-24 17:03:40.741632734 -0600 +--- libmagic.orig/elfclass.h 2019-02-20 02:30:19.000000000 +0100 ++++ libmagic/elfclass.h 2022-09-12 14:46:49.582740235 +0200 @@ -41,7 +41,7 @@ return toomany(ms, "program headers", phnum); flags |= FLAGS_IS_CORE; @@ -1492,9 +1309,9 @@ diff -u libmagic.orig/elfclass.h libmagic/elfclass.h fsize, elf_getu16(swap, elfhdr.e_machine), CAST(int, elf_getu16(swap, elfhdr.e_shstrndx)), diff -u libmagic.orig/encoding.c libmagic/encoding.c ---- libmagic.orig/encoding.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/encoding.c 2021-10-24 17:03:48.529884451 -0600 -@@ -98,14 +98,14 @@ +--- libmagic.orig/encoding.c 2022-06-10 15:40:17.000000000 +0200 ++++ libmagic/encoding.c 2022-09-12 14:46:49.582740235 +0200 +@@ -97,7 +97,7 @@ nbytes = ms->encoding_max; mlen = (nbytes + 1) * sizeof((*ubuf)[0]); @@ -1503,38 +1320,27 @@ diff -u libmagic.orig/encoding.c libmagic/encoding.c if (*ubuf == NULL) { file_oomem(ms, mlen); goto done; - } - mlen = (nbytes + 1) * sizeof(nbuf[0]); - if ((nbuf = CAST(unsigned char *, -- calloc(CAST(size_t, 1), mlen))) == NULL) { -+ ecalloc(CAST(size_t, 1), mlen))) == NULL) { - file_oomem(ms, mlen); - goto done; - } -@@ -174,9 +174,9 @@ +@@ -150,7 +150,7 @@ + unsigned char *nbuf; + + mlen = (nbytes + 1) * sizeof(nbuf[0]); +- if ((nbuf = CAST(unsigned char *, malloc(mlen))) == NULL) { ++ if ((nbuf = CAST(unsigned char *, emalloc(mlen))) == NULL) { + file_oomem(ms, mlen); + goto done; + } +@@ -170,7 +170,7 @@ + rv = 0; + *type = "binary"; + } +- free(nbuf); ++ efree(nbuf); } done: -- free(nbuf); -+ efree(nbuf); - if (ubuf == &udefbuf) -- free(udefbuf); -+ efree(udefbuf); - - return rv; - } -@@ -283,7 +283,7 @@ - u = 0; \ - for (i = 0; i < __arraycount(dist); i++) { \ - if (dist[i]) \ -- u++; \ -+ u += dist[i]; \ - } \ - if (u < 3) \ - return 0; \ diff -u libmagic.orig/file.h libmagic/file.h ---- libmagic.orig/file.h 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/file.h 2021-10-24 17:03:48.529884451 -0600 +--- libmagic.orig/file.h 2022-05-28 22:24:09.000000000 +0200 ++++ libmagic/file.h 2022-09-12 14:46:49.582740235 +0200 @@ -33,17 +33,14 @@ #ifndef __file_h__ #define __file_h__ @@ -1558,7 +1364,7 @@ diff -u libmagic.orig/file.h libmagic/file.h #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS -@@ -79,23 +76,26 @@ +@@ -79,19 +76,18 @@ #include /* Include that here, to make sure __P gets defined */ #include #include /* For open and flags */ @@ -1575,35 +1381,21 @@ diff -u libmagic.orig/file.h libmagic/file.h /* Do this here and now, because struct stat gets re-defined on solaris */ #include #include - -+#define abort() zend_error_noreturn(E_ERROR, "fatal libmagic error") +-#include +-#if defined(HAVE_XLOCALE_H) +-#include +-#endif + ++#define abort() zend_error_noreturn(E_ERROR, "fatal libmagic error") + #define ENABLE_CONDITIONALS - #ifndef MAGIC - #define MAGIC "/etc/magic" - #endif +@@ -171,14 +167,12 @@ + #define FILE_COMPILE 2 + #define FILE_LIST 3 --#if defined(__EMX__) || defined (WIN32) -+#if defined(__EMX__) || defined(PHP_WIN32) - #define PATHSEP ';' - #else - #define PATHSEP ':' -@@ -129,12 +129,6 @@ - #endif - #endif - --#ifndef __GNUC__ --#ifndef __attribute__ --#define __attribute__(a) --#endif --#endif +-typedef regex_t file_regex_t; - - #ifndef MIN - #define MIN(a,b) (((a) < (b)) ? (a) : (b)) - #endif -@@ -169,10 +163,10 @@ - struct buffer { int fd; - struct stat st; @@ -1615,17 +1407,17 @@ diff -u libmagic.orig/file.h libmagic/file.h void *ebuf; size_t elen; }; -@@ -266,7 +260,7 @@ - #define FILE_OFFSET 50 - #define FILE_NAMES_SIZE 51 /* size of array to contain all names */ +@@ -280,7 +274,7 @@ + #define FILE_BEMSDOSTIME 58 + #define FILE_NAMES_SIZE 59 /* size of array to contain all names */ -#define IS_STRING(t) \ +#define IS_LIBMAGIC_STRING(t) \ ((t) == FILE_STRING || \ (t) == FILE_PSTRING || \ (t) == FILE_BESTRING16 || \ -@@ -484,13 +478,11 @@ - protected const char *file_fmttime(char *, size_t, uint64_t, int); +@@ -512,10 +506,9 @@ + size_t); protected struct magic_set *file_ms_alloc(int); protected void file_ms_free(struct magic_set *); -protected int file_default(struct magic_set *, size_t); @@ -1636,19 +1428,9 @@ diff -u libmagic.orig/file.h libmagic/file.h + size_t); +protected int file_fsmagic(struct magic_set *, const char *, zend_stat_t *); protected int file_pipe2file(struct magic_set *, int, const void *, size_t); --protected int file_vprintf(struct magic_set *, const char *, va_list) -- __attribute__((__format__(__printf__, 2, 0))); -+protected int file_vprintf(struct magic_set *, const char *, va_list); - protected int file_separator(struct magic_set *); - protected char *file_copystr(char *, size_t, size_t, const char *); - protected int file_checkfmt(char *, size_t, const char *); -@@ -498,12 +490,11 @@ - protected int file_print_guid(char *, size_t, const uint64_t *); - protected int file_parse_guid(const char *, uint64_t *); - protected int file_replace(struct magic_set *, const char *, const char *); --protected int file_printf(struct magic_set *, const char *, ...) -- __attribute__((__format__(__printf__, 2, 3))); -+protected int file_printf(struct magic_set *, const char *, ...); + protected int file_vprintf(struct magic_set *, const char *, va_list) + __attribute__((__format__(__printf__, 2, 0))); +@@ -531,7 +524,7 @@ protected int file_reset(struct magic_set *, int); protected int file_tryelf(struct magic_set *, const struct buffer *); protected int file_trycdf(struct magic_set *, const struct buffer *); @@ -1657,23 +1439,7 @@ diff -u libmagic.orig/file.h libmagic/file.h protected int file_zmagic(struct magic_set *, const struct buffer *, const char *); #endif -@@ -527,12 +518,9 @@ - protected void file_badread(struct magic_set *); - protected void file_badseek(struct magic_set *); - protected void file_oomem(struct magic_set *, size_t); --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))); -+protected void file_error(struct magic_set *, int, const char *, ...); -+protected void file_magerror(struct magic_set *, const char *, ...); -+protected void file_magwarn(struct magic_set *, const char *, ...); - protected void file_mdump(struct magic *); - protected void file_showstr(FILE *, const char *, size_t); - protected size_t file_mbswidth(const char *); -@@ -554,34 +542,12 @@ +@@ -585,18 +578,12 @@ protected int file_clear_closexec(int); protected char *file_strtrim(char *); @@ -1683,34 +1449,18 @@ diff -u libmagic.orig/file.h libmagic/file.h protected void buffer_fini(struct buffer *); protected int buffer_fill(const struct buffer *); --#include --#if defined(HAVE_XLOCALE_H) --#include --#endif - --typedef struct { -- const char *pat; --#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE) --#define USE_C_LOCALE -- locale_t old_lc_ctype; -- locale_t c_lc_ctype; --#else -- char *old_lc_ctype; --#endif -- int rc; -- regex_t rx; --} file_regex_t; - --protected int file_regcomp(file_regex_t *, const char *, int); --protected int file_regexec(file_regex_t *, const char *, size_t, regmatch_t *, +-protected int file_regcomp(struct magic_set *, file_regex_t *, const char *, - int); +-protected int file_regexec(struct magic_set *, file_regex_t *, const char *, +- size_t, regmatch_t *, int); -protected void file_regfree(file_regex_t *); --protected void file_regerror(file_regex_t *, int, struct magic_set *); +public zend_string* convert_libmagic_pattern(const char *val, size_t len, uint32_t options); typedef struct { char *buf; -@@ -597,23 +563,10 @@ +@@ -612,23 +599,10 @@ extern const size_t file_nnames; #endif @@ -1736,7 +1486,7 @@ diff -u libmagic.orig/file.h libmagic/file.h size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRCASESTR -@@ -629,39 +582,6 @@ +@@ -644,39 +618,6 @@ #ifndef HAVE_ASCTIME_R char *asctime_r(const struct tm *, char *); #endif @@ -1776,7 +1526,7 @@ diff -u libmagic.orig/file.h libmagic/file.h #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK) #define QUICK -@@ -691,4 +611,16 @@ +@@ -706,4 +647,16 @@ #define __RCSID(a) #endif @@ -1794,8 +1544,8 @@ diff -u libmagic.orig/file.h libmagic/file.h + #endif /* __file_h__ */ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c ---- libmagic.orig/fsmagic.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/fsmagic.c 2021-10-24 17:03:45.681791493 -0600 +--- libmagic.orig/fsmagic.c 2022-04-11 20:15:07.000000000 +0200 ++++ libmagic/fsmagic.c 2022-09-12 14:46:49.582740235 +0200 @@ -66,26 +66,10 @@ # define minor(dev) ((dev) & 0xff) #endif @@ -2031,7 +1781,7 @@ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c - char *tmp; - char buf2[BUFSIZ+BUFSIZ+4]; - -- if ((tmp = strrchr(fn, '/')) == NULL) { +- if ((tmp = CCAST(char *, strrchr(fn, '/'))) == NULL) { - tmp = buf; /* in current directory anyway */ - } else { - if (tmp - fn + 1 > BUFSIZ) { @@ -2087,8 +1837,8 @@ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c #ifndef __COHERENT__ case S_IFSOCK: diff -u libmagic.orig/funcs.c libmagic/funcs.c ---- libmagic.orig/funcs.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/funcs.c 2021-10-24 17:03:48.529884451 -0600 +--- libmagic.orig/funcs.c 2022-05-28 22:24:09.000000000 +0200 ++++ libmagic/funcs.c 2022-09-12 14:46:49.582740235 +0200 @@ -51,6 +51,13 @@ #define SIZE_MAX ((size_t)~0) #endif @@ -2103,7 +1853,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c protected char * file_copystr(char *buf, size_t blen, size_t width, const char *str) { -@@ -63,7 +70,7 @@ +@@ -66,7 +73,7 @@ private void file_clearbuf(struct magic_set *ms) { @@ -2112,7 +1862,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c ms->o.buf = NULL; ms->o.blen = 0; } -@@ -128,7 +135,7 @@ +@@ -132,7 +139,7 @@ protected int file_vprintf(struct magic_set *ms, const char *fmt, va_list ap) { @@ -2121,7 +1871,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c char *buf, *newstr; char tbuf[1024]; -@@ -141,10 +148,10 @@ +@@ -145,10 +152,10 @@ return -1; } @@ -2133,9 +1883,9 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c - free(buf); + if (buf) efree(buf); file_clearbuf(ms); - file_error(ms, 0, "Output buffer space exceeded %d+%zu", len, - blen); -@@ -152,20 +159,14 @@ + file_error(ms, 0, "Output buffer space exceeded %d+%" + SIZE_T_FORMAT "u", len, blen); +@@ -156,20 +163,14 @@ } if (ms->o.buf != NULL) { @@ -2159,7 +1909,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c } protected int -@@ -184,7 +185,6 @@ +@@ -188,7 +189,6 @@ * error - print best error message possible */ /*VARARGS*/ @@ -2167,7 +1917,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c private void file_error_core(struct magic_set *ms, int error, const char *f, va_list va, size_t lineno) -@@ -316,8 +316,8 @@ +@@ -320,8 +320,8 @@ */ /*ARGSUSED*/ protected int @@ -2178,7 +1928,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c const void *buf, size_t nb) { int m = 0, rv = 0, looks_text = 0; -@@ -327,6 +327,19 @@ +@@ -331,6 +331,19 @@ const char *ftype = NULL; char *rbuf = NULL; struct buffer b; @@ -2198,7 +1948,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c buffer_init(&b, fd, st, buf, nb); ms->mode = b.st.st_mode; -@@ -359,7 +372,8 @@ +@@ -363,7 +376,8 @@ } } #endif @@ -2208,7 +1958,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c /* try compression stuff */ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) { m = file_zmagic(ms, &b, inname); -@@ -484,10 +498,10 @@ +@@ -488,10 +502,10 @@ if (file_printf(ms, "%s", code_mime) == -1) rv = -1; } @@ -2221,7 +1971,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c buffer_fini(&b); if (rv) return rv; -@@ -505,7 +519,7 @@ +@@ -509,7 +523,7 @@ } file_clearbuf(ms); if (ms->o.pbuf) { @@ -2230,7 +1980,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c ms->o.pbuf = NULL; } ms->event_flags &= ~EVENT_HAD_ERR; -@@ -543,7 +557,7 @@ +@@ -547,7 +561,7 @@ return NULL; } psize = len * 4 + 1; @@ -2239,7 +1989,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c file_oomem(ms, psize); return NULL; } -@@ -607,8 +621,8 @@ +@@ -611,8 +625,8 @@ if (level >= ms->c.len) { len = (ms->c.len = 20 + level) * sizeof(*ms->c.li); ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ? @@ -2250,20 +2000,18 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c if (ms->c.li == NULL) { file_oomem(ms, len); return -1; -@@ -631,82 +645,38 @@ +@@ -635,86 +649,38 @@ protected int file_replace(struct magic_set *ms, const char *pat, const char *rep) { - file_regex_t rx; - int rc, rv = -1; - -- rc = file_regcomp(&rx, pat, REG_EXTENDED); -- if (rc) { -- file_regerror(&rx, rc, ms); -- } else { +- rc = file_regcomp(ms, &rx, pat, REG_EXTENDED); +- if (rc == 0) { - regmatch_t rm; - int nm = 0; -- while (file_regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) { +- while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) { - ms->o.buf[rm.rm_so] = '\0'; - if (file_printf(ms, "%s%s", rep, - rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1) @@ -2301,67 +2049,73 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c -} -protected int --file_regcomp(file_regex_t *rx, const char *pat, int flags) +-file_regcomp(struct magic_set *ms file_locale_used, file_regex_t *rx, +- const char *pat, int flags) -{ -#ifdef USE_C_LOCALE -- rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0); -- assert(rx->c_lc_ctype != NULL); -- rx->old_lc_ctype = uselocale(rx->c_lc_ctype); -- assert(rx->old_lc_ctype != NULL); +- locale_t old = uselocale(ms->c_lc_ctype); +- assert(old != NULL); -#else -- rx->old_lc_ctype = setlocale(LC_CTYPE, NULL); -- assert(rx->old_lc_ctype != NULL); -- rx->old_lc_ctype = strdup(rx->old_lc_ctype); -- assert(rx->old_lc_ctype != NULL); +- char old[1024]; +- strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old)); - (void)setlocale(LC_CTYPE, "C"); -#endif -- rx->pat = pat; +- int rc; +- rc = regcomp(rx, pat, flags); - -- return rx->rc = regcomp(&rx->rx, pat, flags); --} -- --protected int --file_regexec(file_regex_t *rx, const char *str, size_t nmatch, -- regmatch_t* pmatch, int eflags) --{ -- assert(rx->rc == 0); -- /* XXX: force initialization because glibc does not always do this */ -- if (nmatch != 0) -- memset(pmatch, 0, nmatch * sizeof(*pmatch)); -- return regexec(&rx->rx, str, nmatch, pmatch, eflags); --} -- --protected void --file_regfree(file_regex_t *rx) --{ -- if (rx->rc == 0) -- regfree(&rx->rx); -#ifdef USE_C_LOCALE -- (void)uselocale(rx->old_lc_ctype); -- freelocale(rx->c_lc_ctype); +- uselocale(old); -#else -- (void)setlocale(LC_CTYPE, rx->old_lc_ctype); -- free(rx->old_lc_ctype); +- (void)setlocale(LC_CTYPE, old); -#endif --} +- if (rc > 0 && (ms->flags & MAGIC_CHECK)) { +- char errmsg[512]; + strncpy(ms->o.buf, ZSTR_VAL(res), ZSTR_LEN(res)); + ms->o.buf[ZSTR_LEN(res)] = '\0'; --protected void --file_regerror(file_regex_t *rx, int rc, struct magic_set *ms) +- (void)regerror(rc, rx, errmsg, sizeof(errmsg)); +- file_magerror(ms, "regex error %d for `%s', (%s)", rc, pat, +- errmsg); +- } +- return rc; +-} +- +-protected int +-file_regexec(struct magic_set *ms file_locale_used, file_regex_t *rx, +- const char *str, size_t nmatch, regmatch_t* pmatch, int eflags) -{ -- char errmsg[512]; +-#ifdef USE_C_LOCALE +- locale_t old = uselocale(ms->c_lc_ctype); +- assert(old != NULL); +-#else +- char old[1024]; +- strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old)); +- (void)setlocale(LC_CTYPE, "C"); +-#endif +- int rc; +- /* XXX: force initialization because glibc does not always do this */ +- if (nmatch != 0) +- memset(pmatch, 0, nmatch * sizeof(*pmatch)); +- rc = regexec(rx, str, nmatch, pmatch, eflags); +-#ifdef USE_C_LOCALE +- uselocale(old); +-#else +- (void)setlocale(LC_CTYPE, old); +-#endif +- return rc; +-} + zend_string_release_ex(res, 0); -- (void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg)); -- file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat, -- errmsg); +-protected void +-file_regfree(file_regex_t *rx) +-{ +- regfree(rx); +out: + return rep_cnt; } protected file_pushbuf_t * -@@ -717,7 +687,7 @@ +@@ -725,7 +691,7 @@ if (ms->event_flags & EVENT_HAD_ERR) return NULL; @@ -2370,7 +2124,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c return NULL; pb->buf = ms->o.buf; -@@ -737,8 +707,8 @@ +@@ -745,8 +711,8 @@ char *rbuf; if (ms->event_flags & EVENT_HAD_ERR) { @@ -2381,7 +2135,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c return NULL; } -@@ -748,7 +718,7 @@ +@@ -756,7 +722,7 @@ ms->o.blen = pb->blen; ms->offset = pb->offset; @@ -2390,25 +2144,25 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c return rbuf; } -@@ -809,6 +779,7 @@ - g->data4[6], g->data4[7]); +@@ -840,6 +806,7 @@ + #endif } +#if 0 protected int file_pipe_closexec(int *fds) { -@@ -827,6 +798,7 @@ - file_clear_closexec(int fd) { - return fcntl(fd, F_SETFD, 0); +@@ -855,6 +822,7 @@ + return 0; + #endif } +#endif - protected char * - file_strtrim(char *str) + protected int + file_clear_closexec(int fd) { diff -u libmagic.orig/magic.c libmagic/magic.c ---- libmagic.orig/magic.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/magic.c 2022-06-06 00:36:46.758464267 -0600 +--- libmagic.orig/magic.c 2021-12-06 17:25:22.000000000 +0100 ++++ libmagic/magic.c 2022-09-12 14:46:49.582740235 +0200 @@ -25,11 +25,6 @@ * SUCH DAMAGE. */ @@ -2440,7 +2194,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c #endif #include /* for PIPE_BUF */ -@@ -69,194 +70,18 @@ +@@ -69,200 +70,18 @@ #endif #endif @@ -2537,6 +2291,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c - free(dllpath); -} - +-#ifndef BUILD_AS_WINDOWS_STATIC_LIBARAY -/* Placate GCC by offering a sacrificial previous prototype */ -BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); - @@ -2549,6 +2304,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c - return 1; -} -#endif +-#endif - -private const char * -get_default_magic(void) @@ -2600,6 +2356,10 @@ diff -u libmagic.orig/magic.c libmagic/magic.c - default_magic = NULL; - } - +- /* Before anything else, try to get a magic file from user HOME */ +- if ((home = getenv("HOME")) != NULL) +- _w32_append_path(&hmagicpath, "%s%s", home, hmagic); +- - /* First, try to get a magic file from user-application data */ - if ((home = getenv("LOCALAPPDATA")) != NULL) - _w32_append_path(&hmagicpath, "%s%s", home, hmagic); @@ -2641,7 +2401,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c public struct magic_set * magic_open(int flags) { -@@ -302,21 +127,6 @@ +@@ -321,21 +140,6 @@ return file_apprentice(ms, magicfile, FILE_LOAD); } @@ -2663,7 +2423,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c public int magic_compile(struct magic_set *ms, const char *magicfile) { -@@ -341,39 +151,6 @@ +@@ -360,39 +164,6 @@ return file_apprentice(ms, magicfile, FILE_LIST); } @@ -2703,7 +2463,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c #ifndef COMPILE_ONLY /* -@@ -384,7 +161,7 @@ +@@ -403,7 +174,7 @@ { if (ms == NULL) return NULL; @@ -2712,7 +2472,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c } /* -@@ -395,19 +172,25 @@ +@@ -414,19 +185,25 @@ { if (ms == NULL) return NULL; @@ -2744,7 +2504,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c if (file_reset(ms, 1) == -1) goto out; -@@ -417,7 +200,7 @@ +@@ -436,7 +213,7 @@ * some overlapping space for matches near EOF */ #define SLOP (1 + sizeof(union VALUETYPE)) @@ -2753,7 +2513,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c return NULL; switch (file_fsmagic(ms, inname, &sb)) { -@@ -430,98 +213,46 @@ +@@ -449,96 +226,46 @@ goto done; } @@ -2767,8 +2527,6 @@ diff -u libmagic.orig/magic.c libmagic/magic.c - errno = 0; - if ((fd = open(inname, flags)) < 0) { - okstat = stat(inname, &sb) == 0; -- if (okstat && S_ISFIFO(sb.st_mode)) -- ispipe = 1; -#ifdef WIN32 - /* - * Can't stat, can't open. It may have been opened in @@ -2795,7 +2553,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c + rv = -1; goto done; } --#if O_CLOEXEC == 0 +-#if O_CLOEXEC == 0 && defined(F_SETFD) - (void)fcntl(fd, F_SETFD, FD_CLOEXEC); -#endif } @@ -2841,7 +2599,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c - } else if (fd != -1) { - /* Windows refuses to read from a big console buffer. */ - size_t howmany = --#if defined(WIN32) +-#ifdef WIN32 - _isatty(fd) ? 8 * 1024 : -#endif - ms->bytes_max; @@ -2876,7 +2634,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c } out: return rv == 0 ? file_getbuffer(ms) : NULL; -@@ -539,7 +270,7 @@ +@@ -556,7 +283,7 @@ * The main work is done here! * We have the file name and/or the data buffer to be identified. */ @@ -2886,8 +2644,8 @@ diff -u libmagic.orig/magic.c libmagic/magic.c } return file_getbuffer(ms); diff -u libmagic.orig/magic.h libmagic/magic.h ---- libmagic.orig/magic.h 2022-07-05 00:56:31.213294537 -0600 -+++ libmagic/magic.h 2021-10-24 17:03:48.529884451 -0600 +--- libmagic.orig/magic.h 2022-09-14 00:16:09.361229251 +0200 ++++ libmagic/magic.h 2022-09-12 14:46:49.142737580 +0200 @@ -126,6 +126,7 @@ const char *magic_getpath(const char *, int); @@ -2897,8 +2655,8 @@ diff -u libmagic.orig/magic.h libmagic/magic.h const char *magic_buffer(magic_t, const void *, size_t); diff -u libmagic.orig/print.c libmagic/print.c ---- libmagic.orig/print.c 2021-02-22 17:49:07.000000000 -0700 -+++ libmagic/print.c 2021-10-24 17:03:45.681791493 -0600 +--- libmagic.orig/print.c 2021-12-06 17:25:22.000000000 +0100 ++++ libmagic/print.c 2022-09-12 14:46:49.582740235 +0200 @@ -28,6 +28,7 @@ /* * print.c - debugging printout routines @@ -2916,7 +2674,7 @@ diff -u libmagic.orig/print.c libmagic/print.c if (m->str_flags) { (void) fputc('/', stderr); if (m->str_flags & STRING_COMPACT_WHITESPACE) -@@ -225,18 +226,18 @@ +@@ -242,18 +243,18 @@ file_magwarn(struct magic_set *ms, const char *f, ...) { va_list va; @@ -2944,7 +2702,7 @@ diff -u libmagic.orig/print.c libmagic/print.c } protected const char * -@@ -257,13 +258,13 @@ +@@ -281,13 +282,13 @@ } if (flags & FILE_T_LOCAL) { @@ -2962,8 +2720,8 @@ diff -u libmagic.orig/print.c libmagic/print.c if (pp == NULL) goto out; diff -u libmagic.orig/readcdf.c libmagic/readcdf.c ---- libmagic.orig/readcdf.c 2021-02-22 17:49:08.000000000 -0700 -+++ libmagic/readcdf.c 2021-10-24 17:03:45.681791493 -0600 +--- libmagic.orig/readcdf.c 2022-02-14 17:41:23.000000000 +0100 ++++ libmagic/readcdf.c 2022-09-12 14:46:49.582740235 +0200 @@ -31,7 +31,11 @@ #include @@ -3086,8 +2844,8 @@ diff -u libmagic.orig/readcdf.c libmagic/readcdf.c /* If we handled it already, return */ if (i != -1) diff -u libmagic.orig/softmagic.c libmagic/softmagic.c ---- libmagic.orig/softmagic.c 2021-02-22 17:49:06.000000000 -0700 -+++ libmagic/softmagic.c 2022-07-05 00:49:26.658974406 -0600 +--- libmagic.orig/softmagic.c 2022-05-28 22:13:23.000000000 +0200 ++++ libmagic/softmagic.c 2022-09-12 14:46:49.582740235 +0200 @@ -43,6 +43,10 @@ #include #include "der.h" @@ -3096,7 +2854,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c +# define PREG_OFFSET_CAPTURE (1<<8) +#endif + - private int match(struct magic_set *, struct magic *, uint32_t, + private int match(struct magic_set *, struct magic *, file_regex_t **, uint32_t, const struct buffer *, size_t, int, int, int, uint16_t *, uint16_t *, int *, int *, int *, int *); @@ -139,8 +143,8 @@ @@ -3126,8 +2884,8 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c /* * Go through the whole list, stopping if you find a match. Process all * the continuations of that match before returning. -@@ -222,7 +230,7 @@ - struct magic *m = &magic[magindex]; +@@ -223,7 +231,7 @@ + file_regex_t **m_rxcomp = &magic_rxcomp[magindex]; if (m->type != FILE_NAME) - if ((IS_STRING(m->type) && @@ -3135,7 +2893,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c #define FLT (STRING_BINTEST | STRING_TEXTTEST) ((text && (m->str_flags & FLT) == STRING_BINTEST) || (!text && (m->str_flags & FLT) == STRING_TEXTTEST))) || -@@ -277,9 +285,11 @@ +@@ -278,9 +286,11 @@ goto flush; } @@ -3148,95 +2906,13 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c *need_separator = 1; *printed_something = 1; *returnval = 1; -@@ -290,17 +300,14 @@ - * If we are going to print something, we'll need to print - * a blank before we print something else. - */ -- if (*m->desc) { -- *found_match = 1; -+ if (print && *m->desc) { -+ *need_separator = 1; -+ *printed_something = 1; - *returnval = 1; -- if (print) { -- *need_separator = 1; -- *printed_something = 1; -- if (print_sep(ms, firstline) == -1) -- return -1; -- if (mprint(ms, m) == -1) -- return -1; -- } -+ if (print_sep(ms, firstline) == -1) -+ return -1; -+ if (mprint(ms, m) == -1) -+ return -1; - } - - switch (moffset(ms, m, &bb, &ms->c.li[cont_level].off)) { -@@ -391,18 +398,16 @@ - } else - ms->c.li[cont_level].got_match = 1; - -+ if (*m->desc) -+ *found_match = 1; -+ - if ((e = handle_annotation(ms, m, firstline)) - != 0) { -- *found_match = 1; - *need_separator = 1; - *printed_something = 1; - *returnval = 1; - return e; - } -- if (*m->desc) { -- *found_match = 1; -- *returnval = 1; -- } - if (print && *m->desc) { - /* - * This continuation matched. Print -@@ -427,6 +432,7 @@ - if (file_printf(ms, " ") == -1) - return -1; - } -+ *returnval = 1; - *need_separator = 0; - if (mprint(ms, m) == -1) - return -1; -@@ -458,43 +464,39 @@ - firstline = 0; - } - if (*found_match) { -- if ((ms->flags & MAGIC_CONTINUE) == 0) -- goto out; -- // So that we print a separator -- *printed_something = 0; -- firstline = 0; -+ if ((ms->flags & MAGIC_CONTINUE) == 0) -+ return *returnval; /* don't keep searching */ -+ // So that we print a separator -+ *printed_something = 0; -+ firstline = 0; - } - cont_level = 0; - } --out: -- /* -- * If we are not printing (we are doing mime etc.) -- * and we did not find a mime entry, and we are at 0 level -- * we want to return 0 so that the default mime printer -- * takes over and prints "application/octet-stream" -- */ -- if (! print && ! *printed_something && ! *name_count) -- return 0; - return *returnval; /* This is hit if -k is set or there is no match */ - } - +@@ -472,19 +482,25 @@ private int check_fmt(struct magic_set *ms, const char *fmt) { - file_regex_t rx; - int rc, rv = -1; +- const char* pat = "%[-0-9\\.]*s"; + pcre_cache_entry *pce; + int rv = -1; + zend_string *pattern; @@ -3244,15 +2920,14 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c if (strchr(fmt, '%') == NULL) return 0; -- rc = file_regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB); -- if (rc) { -- file_regerror(&rx, rc, ms); +- rc = file_regcomp(ms, &rx, pat, REG_EXTENDED|REG_NOSUB); +- if (rc == 0) { +- rc = file_regexec(ms, &rx, fmt, 0, 0, 0); +- rv = !rc; + pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0); + if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) { + rv = -1; - } else { -- rc = file_regexec(&rx, fmt, 0, 0, 0); -- rv = !rc; ++ } else { + pcre2_code *re = php_pcre_pce_re(pce); + pcre2_match_data *match_data = php_pcre_create_match_data(0, re); + if (match_data) { @@ -3265,20 +2940,25 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c return rv; } -@@ -1531,11 +1533,7 @@ +@@ -502,7 +518,7 @@ + + for (len = 0; len < n && str[len]; len++) + continue; +- if ((copy = CAST(char *, malloc(len + 1))) == NULL) ++ if ((copy = CAST(char *, emalloc(len + 1))) == NULL) + return NULL; + (void)memcpy(copy, str, len); + copy[len] = '\0'; +@@ -1525,7 +1541,7 @@ size_t len; *c = ms->c; len = c->len * sizeof(*c->li); - ms->c.li = CAST(struct level_info *, malloc(len)); -- if (ms->c.li == NULL) { -- ms->c = *c; -- return -1; -- } + ms->c.li = CAST(struct level_info *, emalloc(len)); - memcpy(ms->c.li, c->li, len); - return 0; - } -@@ -1543,7 +1541,7 @@ + if (ms->c.li == NULL) { + ms->c = *c; + return -1; +@@ -1537,7 +1553,7 @@ private void restore_cont(struct magic_set *ms, struct cont *c) { @@ -3287,7 +2967,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c ms->c = *c; } -@@ -1845,15 +1843,15 @@ +@@ -1847,15 +1863,15 @@ if ((ms->flags & MAGIC_NODESC) == 0 && file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) { @@ -3306,23 +2986,8 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c return rv; case FILE_USE: -@@ -1958,10 +1956,13 @@ - } - else if ((flags & STRING_COMPACT_WHITESPACE) && - isspace(*a)) { -+ /* XXX Dirty. The data and the pattern is what is causing this. -+ Revert _i for the next port and see if it still matters. */ -+ uint32_t _i = 0; - a++; - if (isspace(*b++)) { - if (!isspace(*a)) -- while (b < eb && isspace(*b)) -+ while (EXPECTED(_i++ < 2048) && b < eb && isspace(*b)) - b++; - } - else { -@@ -1997,6 +1998,60 @@ - return file_strncmp(a, b, len, maxlen, flags); +@@ -2026,6 +2042,60 @@ + return NULL; } +public zend_string* convert_libmagic_pattern(const char *val, size_t len, uint32_t options) @@ -3380,40 +3045,26 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c +} + private int - magiccheck(struct magic_set *ms, struct magic *m) + magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache) { -@@ -2144,14 +2199,13 @@ - slen = MIN(m->vallen, sizeof(m->value.s)); - l = 0; - v = 0; --#ifdef HAVE_MEMMEM - if (slen > 0 && m->str_flags == 0) { - const char *found; - idx = m->str_range + slen; - if (m->str_range == 0 || ms->search.s_len < idx) - idx = ms->search.s_len; -- found = CAST(const char *, memmem(ms->search.s, idx, -- m->value.s, slen)); -+ found = CAST(const char *, php_memnstr(ms->search.s, -+ m->value.s, slen, ms->search.s + idx)); - if (!found) - return 0; - idx = found - ms->search.s; -@@ -2159,7 +2213,6 @@ +@@ -2197,7 +2267,6 @@ ms->search.rm_len = ms->search.s_len - idx; break; } -#endif for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { - if (slen + idx > ms->search.s_len) -@@ -2176,65 +2229,77 @@ + if (slen + idx > ms->search.s_len) { +@@ -2216,56 +2285,76 @@ break; } case FILE_REGEX: { - int rc; -- file_regex_t rx; +- file_regex_t *rx = *m_cache; - const char *search; +- regmatch_t pmatch; +- size_t slen = ms->search.s_len; +- char *copy; + zend_string *pattern; + uint32_t options = 0; + pcre_cache_entry *pce; @@ -3422,34 +3073,53 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c - return 0; + options |= PCRE2_MULTILINE; +- if (rx == NULL) { +- rx = *m_cache = alloc_regex(ms, m); +- if (rx == NULL) +- return -1; +- } - l = 0; -- rc = file_regcomp(&rx, m->value.s, -- REG_EXTENDED|REG_NEWLINE| -- ((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0)); -- if (rc) { -- file_regerror(&rx, rc, ms); -- v = CAST(uint64_t, -1); +- if (slen != 0) { +- copy = CAST(char *, malloc(slen)); +- if (copy == NULL) { +- file_error(ms, errno, +- "can't allocate %" SIZE_T_FORMAT "u bytes", +- slen); +- return -1; +- } +- memcpy(copy, ms->search.s, slen); +- copy[--slen] = '\0'; +- search = copy; +- } else { +- search = CCAST(char *, ""); +- copy = NULL; + if (m->str_flags & STRING_IGNORE_CASE) { + options |= PCRE2_CASELESS; -+ } -+ + } +- rc = file_regexec(ms, rx, RCAST(const char *, search), +- 1, &pmatch, 0); +- free(copy); +- switch (rc) { +- case 0: +- ms->search.s += CAST(int, pmatch.rm_so); +- ms->search.offset += CAST(size_t, pmatch.rm_so); +- ms->search.rm_len = CAST(size_t, +- pmatch.rm_eo - pmatch.rm_so); +- v = 0; +- break; + +- case REG_NOMATCH: +- v = 1; +- break; + pattern = convert_libmagic_pattern((char *)m->value.s, m->vallen, options); -+ + +- default: + l = v = 0; + if ((pce = pcre_get_compiled_regex_cache(pattern)) == NULL) { + zend_string_release(pattern); -+ return -1; - } else { -- regmatch_t pmatch; -- size_t slen = ms->search.s_len; -- char *copy; -- if (slen != 0) { -- copy = CAST(char *, malloc(slen)); -- if (copy == NULL) { -- file_regfree(&rx); -- file_error(ms, errno, -- "can't allocate %" SIZE_T_FORMAT "u bytes", -- slen); + return -1; +- break; ++ } else { + /* pce now contains the compiled regex */ + zval retval; + zval subpats; @@ -3469,11 +3139,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c + if (Z_LVAL(retval) < 0) { + zval_ptr_dtor(&subpats); + zend_string_release(pattern); - return -1; -- } -- memcpy(copy, ms->search.s, slen); -- copy[--slen] = '\0'; -- search = copy; ++ return -1; + } else if ((Z_LVAL(retval) > 0) && (Z_TYPE(subpats) == IS_ARRAY)) { + /* Need to fetch global match which equals pmatch[0] */ + zval *pzval; @@ -3502,43 +3168,17 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c + zend_string_release(pattern); + return -1; + } - } else { -- search = CCAST(char *, ""); -- copy = NULL; -- } -- rc = file_regexec(&rx, RCAST(const char *, search), -- 1, &pmatch, 0); -- free(copy); -- switch (rc) { -- case 0: -- ms->search.s += CAST(int, pmatch.rm_so); -- ms->search.offset += CAST(size_t, pmatch.rm_so); -- ms->search.rm_len = CAST(size_t, -- pmatch.rm_eo - pmatch.rm_so); -- v = 0; -- break; -- -- case REG_NOMATCH: - v = 1; -- break; -- -- default: -- file_regerror(&rx, rc, ms); -- v = CAST(uint64_t, -1); -- break; - } ++ } else { ++ v = 1; ++ } + zval_ptr_dtor(&subpats); + zend_string_release(pattern); } -- file_regfree(&rx); -- if (v == CAST(uint64_t, -1)) -- return -1; break; } - case FILE_USE: diff -u libmagic.orig/strcasestr.c libmagic/strcasestr.c ---- libmagic.orig/strcasestr.c 2021-02-22 17:49:12.000000000 -0700 -+++ libmagic/strcasestr.c 2022-06-06 00:36:46.758464267 -0600 +--- libmagic.orig/strcasestr.c 2014-09-11 17:05:33.000000000 +0200 ++++ libmagic/strcasestr.c 2022-09-12 14:46:49.582740235 +0200 @@ -39,6 +39,8 @@ #include "file.h" diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c index 56dd053cb54..c8062c06182 100644 --- a/ext/fileinfo/libmagic/apprentice.c +++ b/ext/fileinfo/libmagic/apprentice.c @@ -29,6 +29,8 @@ * apprentice - make one pass through /etc/magic, learning its secrets. */ +#include "php.h" + #include "file.h" #ifndef lint @@ -37,6 +39,19 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $") #include "magic.h" #include + +#if defined(__hpux) && !defined(HAVE_STRTOULL) +#if SIZEOF_LONG == 8 +# define strtoull strtoul +#else +# define strtoull __strtoull +#endif +#endif + +#ifdef PHP_WIN32 +#include "win32/unistd.h" +#define strtoull _strtoui64 +#else #ifdef HAVE_UNISTD_H #include #endif @@ -72,6 +87,10 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $") #endif #endif +#ifndef offsetof +#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) +#endif + #ifndef MAP_FAILED #define MAP_FAILED (void *) -1 #endif @@ -186,38 +205,7 @@ private struct { { NULL, 0, NULL } }; -#ifdef COMPILE_ONLY - -int main(int, char *[]); - -int -main(int argc, char *argv[]) -{ - int ret; - struct magic_set *ms; - char *progname; - - if ((progname = strrchr(argv[0], '/')) != NULL) - progname++; - else - progname = argv[0]; - - if (argc != 2) { - (void)fprintf(stderr, "Usage: %s file\n", progname); - return 1; - } - - if ((ms = magic_open(MAGIC_CHECK)) == NULL) { - (void)fprintf(stderr, "%s: %s\n", progname, strerror(errno)); - return 1; - } - ret = magic_compile(ms, argv[1]) == -1 ? 1 : 0; - if (ret == 1) - (void)fprintf(stderr, "%s: %s\n", progname, magic_error(ms)); - magic_close(ms); - return ret; -} -#endif /* COMPILE_ONLY */ +#include "../data_file.c" struct type_tbl_s { const char name[16]; @@ -446,7 +434,7 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx) struct mlist *ml; mlp->map = NULL; - if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL) + if ((ml = CAST(struct mlist *, emalloc(sizeof(*ml)))) == NULL) return -1; ml->map = idx == 0 ? map : NULL; @@ -454,9 +442,9 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx) ml->nmagic = map->nmagic[idx]; if (ml->nmagic) { ml->magic_rxcomp = CAST(file_regex_t **, - calloc(ml->nmagic, sizeof(*ml->magic_rxcomp))); + ecalloc(ml->nmagic, sizeof(*ml->magic_rxcomp))); if (ml->magic_rxcomp == NULL) { - free(ml); + efree(ml); return -1; } } else @@ -539,13 +527,19 @@ file_ms_free(struct magic_set *ms) return; for (i = 0; i < MAGIC_SETS; i++) mlist_free(ms->mlist[i]); - free(ms->o.pbuf); - free(ms->o.buf); - free(ms->c.li); + if (ms->o.pbuf) { + efree(ms->o.pbuf); + } + if (ms->o.buf) { + efree(ms->o.buf); + } + if (ms->c.li) { + efree(ms->c.li); + } #ifdef USE_C_LOCALE freelocale(ms->c_lc_ctype); #endif - free(ms); + efree(ms); } protected struct magic_set * @@ -554,7 +548,7 @@ file_ms_alloc(int flags) struct magic_set *ms; size_t i, len; - if ((ms = CAST(struct magic_set *, calloc(CAST(size_t, 1u), + if ((ms = CAST(struct magic_set *, ecalloc(CAST(size_t, 1u), sizeof(struct magic_set)))) == NULL) return NULL; @@ -567,7 +561,7 @@ file_ms_alloc(int flags) ms->o.blen = 0; len = (ms->c.len = 10) * sizeof(*ms->c.li); - if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL) + if ((ms->c.li = CAST(struct level_info *, emalloc(len))) == NULL) goto free; ms->event_flags = 0; @@ -601,38 +595,26 @@ apprentice_unmap(struct magic_map *map) char *p; if (map == NULL) return; - - switch (map->type) { - case MAP_TYPE_USER: - break; - case MAP_TYPE_MALLOC: - p = CAST(char *, map->p); - for (i = 0; i < MAGIC_SETS; i++) { - char *b = RCAST(char *, map->magic[i]); - if (p != NULL && b >= p && b <= p + map->len) - continue; - free(b); + if (map->p != php_magic_database) { + if (map->p == NULL) { + int j; + for (j = 0; j < MAGIC_SETS; j++) { + if (map->magic[j]) { + efree(map->magic[j]); + } + } + } else { + efree(map->p); } - free(p); - break; -#ifdef QUICK - case MAP_TYPE_MMAP: - if (map->p && map->p != MAP_FAILED) - (void)munmap(map->p, map->len); - break; -#endif - default: - fprintf(stderr, "Bad map type %d", map->type); - abort(); } - free(map); + efree(map); } private struct mlist * mlist_alloc(void) { struct mlist *mlist; - if ((mlist = CAST(struct mlist *, calloc(1, sizeof(*mlist)))) == NULL) { + if ((mlist = CAST(struct mlist *, ecalloc(1, sizeof(*mlist)))) == NULL) { return NULL; } mlist->next = mlist->prev = mlist; @@ -653,21 +635,9 @@ mlist_free_all(struct magic_set *ms) private void mlist_free_one(struct mlist *ml) { - size_t i; - if (ml->map) apprentice_unmap(CAST(struct magic_map *, ml->map)); - - for (i = 0; i < ml->nmagic; ++i) { - if (ml->magic_rxcomp[i]) { - file_regfree(ml->magic_rxcomp[i]); - free(ml->magic_rxcomp[i]); - ml->magic_rxcomp[i] = NULL; - } - } - free(ml->magic_rxcomp); - ml->magic_rxcomp = NULL; - free(ml); + efree(ml); } private void @@ -741,12 +711,28 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) (void)file_reset(ms, 0); +/* XXX disabling default magic loading so the compiled in data is used */ +#if 0 if ((fn = magic_getpath(fn, action)) == NULL) return -1; +#endif init_file_tables(); - if ((mfn = strdup(fn)) == NULL) { + if (fn == NULL) + fn = getenv("MAGIC"); + if (fn == NULL) { + for (i = 0; i < MAGIC_SETS; i++) { + mlist_free(ms->mlist[i]); + if ((ms->mlist[i] = mlist_alloc()) == NULL) { + file_oomem(ms, sizeof(*ms->mlist[i])); + return -1; + } + } + return apprentice_1(ms, fn, action); + } + + if ((mfn = estrdup(fn)) == NULL) { file_oomem(ms, strlen(fn)); return -1; } @@ -759,7 +745,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) mlist_free(ms->mlist[j]); ms->mlist[j] = NULL; } - free(mfn); + efree(mfn); return -1; } } @@ -776,7 +762,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) fn = p; } - free(mfn); + efree(mfn); if (errs == -1) { for (i = 0; i < MAGIC_SETS; i++) { @@ -1289,7 +1275,7 @@ addentry(struct magic_set *ms, struct magic_entry *me, size_t incr = mset[i].max + ALLOC_INCR; if ((mp = CAST(struct magic_entry *, - realloc(mset[i].me, sizeof(*mp) * incr))) == + erealloc(mset[i].me, sizeof(*mp) * incr))) == NULL) { file_oomem(ms, sizeof(*mp) * incr); return -1; @@ -1312,13 +1298,19 @@ private void load_1(struct magic_set *ms, int action, const char *fn, int *errs, struct magic_entry_set *mset) { - size_t lineno = 0, llen = 0; + char buffer[BUFSIZ + 1]; char *line = NULL; - ssize_t len; + size_t len; + size_t lineno = 0; struct magic_entry me; - FILE *f = fopen(ms->file = fn, "r"); - if (f == NULL) { + php_stream *stream; + + + ms->file = fn; + stream = php_stream_open_wrapper((char *)fn, "rb", REPORT_ERRORS, NULL); + + if (stream == NULL) { if (errno != ENOENT) file_error(ms, errno, "cannot read magic file `%s'", fn); @@ -1328,8 +1320,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs, memset(&me, 0, sizeof(me)); /* read and parse this file */ - for (ms->line = 1; (len = getline(&line, &llen, f)) != -1; - ms->line++) { + for (ms->line = 1; (line = php_stream_get_line(stream, buffer , BUFSIZ, &len)) != NULL; ms->line++) { if (len == 0) /* null line, garbage, etc */ continue; if (line[len - 1] == '\n') { @@ -1364,7 +1355,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs, continue; } if ((*bang[i].fun)(ms, &me, - line + bang[i].len + 2, + line + bang[i].len + 2, len - bang[i].len - 2) != 0) { (*errs)++; continue; @@ -1388,8 +1379,8 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs, } if (me.mp) (void)addentry(ms, &me, mset); - free(line); - (void)fclose(f); + efree(line); + php_stream_close(stream); } /* @@ -1474,7 +1465,7 @@ coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme, } slen = sizeof(**ma) * mentrycount; - if ((*ma = CAST(struct magic *, malloc(slen))) == NULL) { + if ((*ma = CAST(struct magic *, emalloc(slen))) == NULL) { file_oomem(ms, slen); return -1; } @@ -1496,8 +1487,8 @@ magic_entry_free(struct magic_entry *me, uint32_t nme) if (me == NULL) return; for (i = 0; i < nme; i++) - free(me[i].mp); - free(me); + efree(me[i].mp); + efree(me); } private struct magic_map * @@ -1506,18 +1497,19 @@ apprentice_load(struct magic_set *ms, const char *fn, int action) int errs = 0; uint32_t i, j; size_t files = 0, maxfiles = 0; - char **filearr = NULL, *mfn; - struct stat st; + char **filearr = NULL; + zend_stat_t st = {0}; struct magic_map *map; struct magic_entry_set mset[MAGIC_SETS]; - DIR *dir; - struct dirent *d; + php_stream *dir; + php_stream_dirent d; + memset(mset, 0, sizeof(mset)); ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { file_oomem(ms, sizeof(*map)); return NULL; @@ -1529,52 +1521,50 @@ apprentice_load(struct magic_set *ms, const char *fn, int action) (void)fprintf(stderr, "%s\n", usg_hdr); /* load directory or file */ - if (stat(fn, &st) == 0 && S_ISDIR(st.st_mode)) { - dir = opendir(fn); + /* FIXME: Read file names and sort them to prevent + non-determinism. See Debian bug #488562. */ + if (php_sys_stat(fn, &st) == 0 && S_ISDIR(st.st_mode)) { + int mflen; + char mfn[MAXPATHLEN]; + + dir = php_stream_opendir((char *)fn, REPORT_ERRORS, NULL); if (!dir) { errs++; goto out; } - while ((d = readdir(dir)) != NULL) { - if (d->d_name[0] == '.') - continue; - if (asprintf(&mfn, "%s/%s", fn, d->d_name) < 0) { + while (php_stream_readdir(dir, &d)) { + if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, d.d_name)) < 0) { file_oomem(ms, - strlen(fn) + strlen(d->d_name) + 2); + strlen(fn) + strlen(d.d_name) + 2); errs++; - closedir(dir); + php_stream_closedir(dir); goto out; } - if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) { - free(mfn); + if (zend_stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) { continue; } if (files >= maxfiles) { size_t mlen; - char **nfilearr; maxfiles = (maxfiles + 1) * 2; mlen = maxfiles * sizeof(*filearr); - if ((nfilearr = CAST(char **, - realloc(filearr, mlen))) == NULL) { + if ((filearr = CAST(char **, + erealloc(filearr, mlen))) == NULL) { file_oomem(ms, mlen); - free(mfn); - closedir(dir); + php_stream_closedir(dir); errs++; goto out; } - filearr = nfilearr; } - filearr[files++] = mfn; + filearr[files++] = estrndup(mfn, (mflen > sizeof(mfn) - 1)? sizeof(mfn) - 1: mflen); } - closedir(dir); + php_stream_closedir(dir); if (filearr) { qsort(filearr, files, sizeof(*filearr), cmpstrp); for (i = 0; i < files; i++) { load_1(ms, action, filearr[i], &errs, mset); - free(filearr[i]); + efree(filearr[i]); } - free(filearr); - filearr = NULL; + efree(filearr); } } else load_1(ms, action, fn, &errs, mset); @@ -1612,7 +1602,6 @@ apprentice_load(struct magic_set *ms, const char *fn, int action) } out: - free(filearr); for (j = 0; j < MAGIC_SETS; j++) magic_entry_free(mset[j].me, mset[j].count); @@ -2060,7 +2049,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, if (me->cont_count == me->max_count) { struct magic *nm; size_t cnt = me->max_count + ALLOC_CHUNK; - if ((nm = CAST(struct magic *, realloc(me->mp, + if ((nm = CAST(struct magic *, erealloc(me->mp, sizeof(*nm) * cnt))) == NULL) { file_oomem(ms, sizeof(*nm) * cnt); return -1; @@ -2075,7 +2064,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, static const size_t len = sizeof(*m) * ALLOC_CHUNK; if (me->mp != NULL) return 1; - if ((m = CAST(struct magic *, malloc(len))) == NULL) { + if ((m = CAST(struct magic *, emalloc(len))) == NULL) { file_oomem(ms, len); return -1; } @@ -2301,7 +2290,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, m->mask_op = 0; if (*l == '~') { - if (!IS_STRING(m->type)) + if (!IS_LIBMAGIC_STRING(m->type)) m->mask_op |= FILE_OPINVERSE; else if (ms->flags & MAGIC_CHECK) file_magwarn(ms, "'~' invalid for string types"); @@ -2310,7 +2299,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line, m->str_range = 0; m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0; if ((op = get_op(*l)) != -1) { - if (IS_STRING(m->type)) { + if (IS_LIBMAGIC_STRING(m->type)) { int r; if (op != FILE_OPDIVIDE) { @@ -2493,8 +2482,7 @@ goodchar(unsigned char x, const char *extra) private int parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line, - size_t llen, off_t off, size_t len, const char *name, const char *extra, - int nt) + size_t llen, zend_off_t off, size_t len, const char *name, const char *extra, int nt) { size_t i; const char *l = line; @@ -2852,13 +2840,19 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action) return -1; } if (m->type == FILE_REGEX) { - file_regex_t rx; - int rc = file_regcomp(ms, &rx, m->value.s, - REG_EXTENDED); - if (rc == 0) { - file_regfree(&rx); + zend_string *pattern; + int options = 0; + pcre_cache_entry *pce; + + pattern = convert_libmagic_pattern(m->value.s, strlen(m->value.s), options); + + if ((pce = pcre_get_compiled_regex_cache(pattern)) == NULL) { + zend_string_release(pattern); + return -1; } - return rc ? -1 : 0; + zend_string_release(pattern); + + return 0; } return 0; default: @@ -3258,92 +3252,77 @@ apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len) private struct magic_map * apprentice_map(struct magic_set *ms, const char *fn) { - int fd; - struct stat st; + uint32_t *ptr; + uint32_t version, entries = 0, nentries; + int needsbyteswap; char *dbname = NULL; struct magic_map *map; - struct magic_map *rv = NULL; + size_t i; + php_stream *stream = NULL; + php_stream_statbuf st; - fd = -1; - if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) { + + + if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { file_oomem(ms, sizeof(*map)); - goto error; + return NULL; } - map->type = MAP_TYPE_USER; /* unspecified */ + + if (fn == NULL) { + map->p = (void *)&php_magic_database; + goto internal_loaded; + } + +#ifdef PHP_WIN32 + /* Don't bother on windows with php_stream_open_wrapper, + return to give apprentice_load() a chance. */ + if (php_stream_stat_path_ex((char *)fn, 0, &st, NULL) == SUCCESS) { + if (st.sb.st_mode & S_IFDIR) { + goto error; + } + } +#endif dbname = mkdbname(ms, fn, 0); if (dbname == NULL) goto error; - if ((fd = open(dbname, O_RDONLY|O_BINARY)) == -1) - goto error; + stream = php_stream_open_wrapper((char *)fn, "rb", REPORT_ERRORS, NULL); - if (fstat(fd, &st) == -1) { + if (!stream) { + goto error; + } + +#ifndef PHP_WIN32 + if (php_stream_stat(stream, &st) < 0) { file_error(ms, errno, "cannot stat `%s'", dbname); goto error; } - if (st.st_size < 8 || st.st_size > maxoff_t()) { +#endif + if (st.sb.st_size < 8 || st.sb.st_size > maxoff_t()) { file_error(ms, 0, "file `%s' is too %s", dbname, - st.st_size < 8 ? "small" : "large"); + st.sb.st_size < 8 ? "small" : "large"); goto error; } - map->len = CAST(size_t, st.st_size); -#ifdef QUICK - map->type = MAP_TYPE_MMAP; - if ((map->p = mmap(0, CAST(size_t, st.st_size), PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_FILE, fd, CAST(off_t, 0))) == MAP_FAILED) { - file_error(ms, errno, "cannot map `%s'", dbname); - goto error; - } -#else map->type = MAP_TYPE_MALLOC; - if ((map->p = CAST(void *, malloc(map->len))) == NULL) { - file_oomem(ms, map->len); - goto error; - } - if (read(fd, map->p, map->len) != (ssize_t)map->len) { + map->len = CAST(size_t, st.sb.st_size); + map->p = CAST(void *, emalloc(map->len)); + + if (php_stream_read(stream, map->p, (size_t)st.sb.st_size) != (size_t)st.sb.st_size) { file_badread(ms); goto error; } -#endif - (void)close(fd); - fd = -1; - if (check_buffer(ms, map, dbname) != 0) { - goto error; - } -#ifdef QUICK - if (mprotect(map->p, CAST(size_t, st.st_size), PROT_READ) == -1) { - file_error(ms, errno, "cannot mprotect `%s'", dbname); - goto error; - } -#endif + php_stream_close(stream); + stream = NULL; - free(dbname); - return map; - -error: - if (fd != -1) - (void)close(fd); - apprentice_unmap(map); - free(dbname); - return rv; -} - -private int -check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) -{ - uint32_t *ptr; - uint32_t entries, nentries; - uint32_t version; - int i, needsbyteswap; - - ptr = CAST(uint32_t *, map->p); +internal_loaded: + ptr = (uint32_t *)(void *)map->p; if (*ptr != MAGICNO) { if (swap4(*ptr) != MAGICNO) { file_error(ms, 0, "bad magic in `%s'", dbname); - return -1; + goto error; } needsbyteswap = 1; } else @@ -3353,17 +3332,29 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) else version = ptr[1]; if (version != VERSIONNO) { - file_error(ms, 0, "File %s supports only version %d magic " - "files. `%s' is version %d", VERSION, + file_error(ms, 0, "File %d supports only version %d magic " + "files. `%s' is version %d", MAGIC_VERSION, VERSIONNO, dbname, version); - return -1; + goto error; } - entries = CAST(uint32_t, map->len / sizeof(struct magic)); - if ((entries * sizeof(struct magic)) != map->len) { - file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not " - "a multiple of %" SIZE_T_FORMAT "u", - dbname, map->len, sizeof(struct magic)); - return -1; + + /* php_magic_database is a const, performing writes will segfault. This is for big-endian + machines only, PPC and Sparc specifically. Consider static variable or MINIT in + future. */ + if (needsbyteswap && fn == NULL) { + map->p = emalloc(sizeof(php_magic_database)); + map->p = memcpy(map->p, php_magic_database, sizeof(php_magic_database)); + } + + if (NULL != fn) { + nentries = (uint32_t)(st.sb.st_size / sizeof(struct magic)); + entries = (uint32_t)(st.sb.st_size / sizeof(struct magic)); + if ((zend_off_t)(entries * sizeof(struct magic)) != st.sb.st_size) { + file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu", + dbname, (unsigned long long)st.sb.st_size, + sizeof(struct magic)); + goto error; + } } map->magic[0] = CAST(struct magic *, map->p) + 1; nentries = 0; @@ -3376,15 +3367,29 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname) map->magic[i + 1] = map->magic[i] + map->nmagic[i]; nentries += map->nmagic[i]; } - if (entries != nentries + 1) { + if (NULL != fn && entries != nentries + 1) { file_error(ms, 0, "Inconsistent entries in `%s' %u != %u", dbname, entries, nentries + 1); - return -1; + goto error; } if (needsbyteswap) for (i = 0; i < MAGIC_SETS; i++) byteswap(map->magic[i], map->nmagic[i]); - return 0; + + if (dbname) { + efree(dbname); + } + return map; + +error: + if (stream) { + php_stream_close(stream); + } + apprentice_unmap(map); + if (dbname) { + efree(dbname); + } + return NULL; } /* @@ -3395,7 +3400,6 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) { static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS; static const size_t m = sizeof(**map->magic); - int fd = -1; size_t len; char *dbname; int rv = -1; @@ -3404,14 +3408,17 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) struct magic m; uint32_t h[2 + MAGIC_SETS]; } hdr; + php_stream *stream; dbname = mkdbname(ms, fn, 1); if (dbname == NULL) goto out; - if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) - { + /* wb+ == O_WRONLY|O_CREAT|O_TRUNC|O_BINARY */ + stream = php_stream_open_wrapper((char *)fn, "wb+", REPORT_ERRORS, NULL); + + if (!stream) { file_error(ms, errno, "cannot open `%s'", dbname); goto out; } @@ -3420,26 +3427,25 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn) hdr.h[1] = VERSIONNO; memcpy(hdr.h + 2, map->nmagic, nm); - if (write(fd, &hdr, sizeof(hdr)) != CAST(ssize_t, sizeof(hdr))) { + if (php_stream_write(stream,(const char *)&hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr)) { file_error(ms, errno, "error writing `%s'", dbname); - goto out2; + goto out; } for (i = 0; i < MAGIC_SETS; i++) { len = m * map->nmagic[i]; - if (write(fd, map->magic[i], len) != CAST(ssize_t, len)) { + if (php_stream_write(stream, (const char *)map->magic[i], len) != (ssize_t)len) { file_error(ms, errno, "error writing `%s'", dbname); - goto out2; + goto out; } } + if (stream) { + php_stream_close(stream); + } rv = 0; -out2: - if (fd != -1) - (void)close(fd); out: - apprentice_unmap(map); - free(dbname); + efree(dbname); return rv; } @@ -3473,17 +3479,18 @@ mkdbname(struct magic_set *ms, const char *fn, int strip) q++; /* Compatibility with old code that looked in .mime */ if (ms->flags & MAGIC_MIME) { - if (asprintf(&buf, "%.*s.mime%s", CAST(int, q - fn), fn, ext) - < 0) - return NULL; - if (access(buf, R_OK) != -1) { + spprintf(&buf, MAXPATHLEN, "%.*s.mime%s", CAST(int, q - fn), fn, ext); +#ifdef PHP_WIN32 + if (VCWD_ACCESS(buf, R_OK) == 0) { +#else + if (VCWD_ACCESS(buf, R_OK) != -1) { +#endif ms->flags &= MAGIC_MIME_TYPE; return buf; } - free(buf); + efree(buf); } - if (asprintf(&buf, "%.*s%s", CAST(int, q - fn), fn, ext) < 0) - return NULL; + spprintf(&buf, MAXPATHLEN, "%.*s%s", CAST(int, q - fn), fn, ext); /* Compatibility with old code that looked in .mime */ if (strstr(fn, ".mime") != NULL) @@ -3605,7 +3612,7 @@ bs1(struct magic *m) m->offset = swap4(CAST(uint32_t, m->offset)); m->in_offset = swap4(CAST(uint32_t, m->in_offset)); m->lineno = swap4(CAST(uint32_t, m->lineno)); - if (IS_STRING(m->type)) { + if (IS_LIBMAGIC_STRING(m->type)) { m->str_range = swap4(m->str_range); m->str_flags = swap4(m->str_flags); } diff --git a/ext/fileinfo/libmagic/ascmagic.c b/ext/fileinfo/libmagic/ascmagic.c index c9a2f348ef0..bc0e5aee653 100644 --- a/ext/fileinfo/libmagic/ascmagic.c +++ b/ext/fileinfo/libmagic/ascmagic.c @@ -96,7 +96,7 @@ file_ascmagic(struct magic_set *ms, const struct buffer *b, int text) rv = file_ascmagic_with_encoding(ms, &bb, ubuf, ulen, code, type, text); - free(ubuf); + efree(ubuf); return rv; } @@ -143,7 +143,7 @@ file_ascmagic_with_encoding(struct magic_set *ms, const struct buffer *b, /* malloc size is a conservative overestimate; could be improved, or at least realloced after conversion. */ mlen = ulen * 6; - if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) { + if ((utf8_buf = CAST(unsigned char *, emalloc(mlen))) == NULL) { file_oomem(ms, mlen); goto done; } @@ -330,7 +330,8 @@ file_ascmagic_with_encoding(struct magic_set *ms, const struct buffer *b, } rv = 1; done: - free(utf8_buf); + if (utf8_buf) + efree(utf8_buf); return rv; } diff --git a/ext/fileinfo/libmagic/buffer.c b/ext/fileinfo/libmagic/buffer.c index 227015ae3e5..3a02308220e 100644 --- a/ext/fileinfo/libmagic/buffer.c +++ b/ext/fileinfo/libmagic/buffer.c @@ -31,19 +31,23 @@ FILE_RCSID("@(#)$File: buffer.c,v 1.8 2020/02/16 15:52:49 christos Exp $") #endif /* lint */ #include "magic.h" +#ifdef PHP_WIN32 +#include "win32/unistd.h" +#else #include +#endif #include #include #include void -buffer_init(struct buffer *b, int fd, const struct stat *st, const void *data, +buffer_init(struct buffer *b, int fd, const zend_stat_t *st, const void *data, size_t len) { b->fd = fd; if (st) memcpy(&b->st, st, sizeof(b->st)); - else if (b->fd == -1 || fstat(b->fd, &b->st) == -1) + else if (b->fd == -1 || zend_fstat(b->fd, &b->st) == -1) memset(&b->st, 0, sizeof(b->st)); b->fbuf = data; b->flen = len; @@ -55,7 +59,7 @@ buffer_init(struct buffer *b, int fd, const struct stat *st, const void *data, void buffer_fini(struct buffer *b) { - free(b->ebuf); + efree(b->ebuf); } int @@ -71,12 +75,14 @@ buffer_fill(const struct buffer *bb) b->elen = CAST(size_t, b->st.st_size) < b->flen ? CAST(size_t, b->st.st_size) : b->flen; - if ((b->ebuf = malloc(b->elen)) == NULL) + if ((b->ebuf = emalloc(b->elen)) == NULL) goto out; b->eoff = b->st.st_size - b->elen; - if (pread(b->fd, b->ebuf, b->elen, b->eoff) == -1) { - free(b->ebuf); + if (FINFO_LSEEK_FUNC(b->fd, b->eoff, SEEK_SET) == (zend_off_t)-1 || + FINFO_READ_FUNC(b->fd, b->ebuf, b->elen) != (ssize_t)b->elen) + { + efree(b->ebuf); b->ebuf = NULL; goto out; } diff --git a/ext/fileinfo/libmagic/cdf.c b/ext/fileinfo/libmagic/cdf.c index 874a6ed3303..6313db7ded7 100644 --- a/ext/fileinfo/libmagic/cdf.c +++ b/ext/fileinfo/libmagic/cdf.c @@ -43,7 +43,17 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.121 2021/10/20 13:56:15 christos Exp $") #include #endif #include + +#ifdef PHP_WIN32 +#include "win32/unistd.h" +#else #include +#endif + +#ifndef UINT32_MAX +# define UINT32_MAX (0xffffffff) +#endif + #include #include #include @@ -334,7 +344,7 @@ cdf_zero_stream(cdf_stream_t *scn) scn->sst_len = 0; scn->sst_dirlen = 0; scn->sst_ss = 0; - free(scn->sst_tab); + efree(scn->sst_tab); scn->sst_tab = NULL; return -1; } @@ -342,9 +352,11 @@ cdf_zero_stream(cdf_stream_t *scn) static size_t cdf_check_stream(const cdf_stream_t *sst, const cdf_header_t *h) { +#ifndef NDEBUG size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ? CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h); assert(ss == sst->sst_ss); +#endif return sst->sst_ss; } @@ -367,11 +379,11 @@ cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h, } static ssize_t -cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len) +cdf_read(const cdf_info_t *info, zend_off_t off, void *buf, size_t len) { size_t siz = CAST(size_t, off + len); - if (CAST(off_t, off + len) != CAST(off_t, siz)) + if (CAST(zend_off_t, off + len) != CAST(zend_off_t, siz)) goto out; if (info->i_buf != NULL && info->i_len >= siz) { @@ -382,7 +394,10 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len) if (info->i_fd == -1) goto out; - if (pread(info->i_fd, buf, len, off) != CAST(ssize_t, len)) + if (FINFO_LSEEK_FUNC(info->i_fd, off, SEEK_SET) == (zend_off_t)-1) + return -1; + + if (FINFO_READ_FUNC(info->i_fd, buf, len) != (ssize_t)len) return -1; return CAST(ssize_t, len); @@ -397,7 +412,7 @@ cdf_read_header(const cdf_info_t *info, cdf_header_t *h) char buf[512]; (void)memcpy(cdf_bo.s, "\01\02\03\04", 4); - if (cdf_read(info, CAST(off_t, 0), buf, sizeof(buf)) == -1) + if (cdf_read(info, CAST(zend_off_t, 0), buf, sizeof(buf)) == -1) return -1; cdf_unpack_header(h, buf); cdf_swap_header(h); @@ -544,14 +559,14 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat) } out: sat->sat_len = i; - free(msa); + efree(msa); return 0; out3: errno = EFTYPE; out2: - free(msa); + efree(msa); out1: - free(sat->sat_tab); + efree(sat->sat_tab); return -1; } @@ -719,7 +734,7 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h, return -1; if ((buf = CAST(char *, CDF_MALLOC(ss))) == NULL) { - free(dir->dir_tab); + efree(dir->dir_tab); return -1; } @@ -742,11 +757,11 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h, if (NEED_SWAP) for (i = 0; i < dir->dir_len; i++) cdf_swap_dir(&dir->dir_tab[i]); - free(buf); + efree(buf); return 0; out: - free(dir->dir_tab); - free(buf); + efree(dir->dir_tab); + efree(buf); errno = EFTYPE; return -1; } @@ -791,7 +806,7 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h, out: errno = EFTYPE; out1: - free(ssat->sat_tab); + efree(ssat->sat_tab); return -1; } @@ -953,7 +968,7 @@ cdf_grow_info(cdf_property_info_t **info, size_t *maxcount, size_t incr) *maxcount = newcount; return inp; out: - free(*info); + efree(*info); *maxcount = 0; *info = NULL; return NULL; @@ -1136,7 +1151,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h, } return 0; out: - free(*info); + efree(*info); *info = NULL; *count = 0; *maxcount = 0; @@ -1428,7 +1443,7 @@ cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h, cdf_directory_t *d; char name[__arraycount(d->d_name)]; cdf_stream_t scn; - struct timespec ts; + struct timeval ts; static const char *types[] = { "empty", "user storage", "user stream", "lockbytes", "property", "root storage" }; @@ -1470,7 +1485,7 @@ cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h, break; } cdf_dump_stream(&scn); - free(scn.sst_tab); + efree(scn.sst_tab); break; default: break; @@ -1483,7 +1498,7 @@ void cdf_dump_property_info(const cdf_property_info_t *info, size_t count) { cdf_timestamp_t tp; - struct timespec ts; + struct timeval ts; char buf[64]; size_t i, j; @@ -1568,7 +1583,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst) (void)fprintf(stderr, "Class %s\n", buf); (void)fprintf(stderr, "Count %d\n", ssi.si_count); cdf_dump_property_info(info, count); - free(info); + efree(info); } @@ -1589,7 +1604,7 @@ cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst) cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name), cdf_ctime(&ts.tv_sec, tbuf)); } - free(cat); + efree(cat); } #endif diff --git a/ext/fileinfo/libmagic/cdf.h b/ext/fileinfo/libmagic/cdf.h index 05056668fb2..07f1dd8c157 100644 --- a/ext/fileinfo/libmagic/cdf.h +++ b/ext/fileinfo/libmagic/cdf.h @@ -35,10 +35,10 @@ #ifndef _H_CDF_ #define _H_CDF_ -#ifdef WIN32 +#ifdef PHP_WIN32 #include -#define timespec timeval -#define tv_nsec tv_usec +#define asctime_r php_asctime_r +#define ctime_r php_ctime_r #endif #ifdef __DJGPP__ #define timespec timeval diff --git a/ext/fileinfo/libmagic/cdf_time.c b/ext/fileinfo/libmagic/cdf_time.c index 68388f11412..ca80300cd4d 100644 --- a/ext/fileinfo/libmagic/cdf_time.c +++ b/ext/fileinfo/libmagic/cdf_time.c @@ -23,6 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include "php.h" #include "file.h" @@ -152,7 +153,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts) #endif #ifdef notyet struct tm tm; - if (gmtime_r(&ts->ts_sec, &tm) == NULL) { + if (php_gmtime_r(&ts->ts_sec, &tm) == NULL) { errno = EINVAL; return -1; } @@ -168,7 +169,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts) char * cdf_ctime(const time_t *sec, char *buf) { - char *ptr = ctime_r(sec, buf); + char *ptr = php_ctime_r(sec, buf); if (ptr != NULL) return buf; #ifdef WIN32 diff --git a/ext/fileinfo/libmagic/compress.c b/ext/fileinfo/libmagic/compress.c index b456626f8f8..233f670ead1 100644 --- a/ext/fileinfo/libmagic/compress.c +++ b/ext/fileinfo/libmagic/compress.c @@ -63,13 +63,14 @@ typedef void (*sig_t)(int); #if defined(HAVE_SYS_TIME_H) #include #endif - -#if defined(HAVE_ZLIB_H) && defined(ZLIBSUPPORT) +#if defined(HAVE_ZLIB_H) && defined(PHP_FILEINFO_UNCOMPRESS) #define BUILTIN_DECOMPRESS #include #endif -#if defined(HAVE_BZLIB_H) && defined(BZLIBSUPPORT) +#undef FIONREAD + +#if defined(PHP_FILEINFO_UNCOMPRESS) #define BUILTIN_BZLIB #include #endif @@ -121,6 +122,8 @@ zlibcmp(const unsigned char *buf) } #endif +#ifdef PHP_FILEINFO_UNCOMPRESS + static int lzmacmp(const unsigned char *buf) { @@ -297,7 +300,7 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name) if (urv == ERRDATA) prv = format_decompression_error(ms, i, newbuf); else - prv = file_buffer(ms, -1, NULL, name, newbuf, nsz); + prv = file_buffer(ms, NULL, NULL, name, newbuf, nsz); if (prv == -1) goto error; rv = 1; @@ -314,17 +317,17 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name) * XXX: If file_buffer fails here, we overwrite * the compressed text. FIXME. */ - if (file_buffer(ms, -1, NULL, NULL, buf, nbytes) == -1) { + if (file_buffer(ms, NULL, NULL, NULL, buf, nbytes) == -1) { if (file_pop_buffer(ms, pb) != NULL) abort(); goto error; } if ((rbuf = file_pop_buffer(ms, pb)) != NULL) { if (file_printf(ms, "%s", rbuf) == -1) { - free(rbuf); + efree(rbuf); goto error; } - free(rbuf); + efree(rbuf); } if (!mime && file_printf(ms, ")") == -1) goto error; @@ -345,7 +348,8 @@ out: if (sa_saved && sig_act.sa_handler != SIG_IGN) (void)sigaction(SIGPIPE, &sig_act, NULL); - free(newbuf); + if (newbuf) + efree(newbuf); ms->flags |= MAGIC_COMPRESS; DPRINTF("Zmagic returns %d\n", rv); return rv; @@ -428,7 +432,7 @@ sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__))) nocheck: do - switch ((rv = read(fd, buf, n))) { + switch ((rv = FINFO_READ_FUNC(fd, buf, n))) { case -1: if (errno == EINTR) continue; @@ -521,13 +525,13 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf, return -1; } (void)close(tfd); - if (lseek(fd, CAST(off_t, 0), SEEK_SET) == CAST(off_t, -1)) { + if (FINFO_LSEEK_FUNC(fd, (zend_off_t)0, SEEK_SET) == (zend_off_t)-1) { file_badseek(ms); return -1; } return fd; } -#if HAVE_FORK +#ifdef PHP_FILEINFO_UNCOMPRESS #ifdef BUILTIN_DECOMPRESS #define FHCRC (1 << 1) @@ -578,7 +582,7 @@ uncompresszlib(const unsigned char *old, unsigned char **newch, int rc; z_stream z; - if ((*newch = CAST(unsigned char *, malloc(bytes_max + 1))) == NULL) + if ((*newch = CAST(unsigned char *, emalloc(bytes_max + 1))) == NULL) return makeerror(newch, n, "No buffer, %s", strerror(errno)); z.next_in = CCAST(Bytef *, old); @@ -1048,3 +1052,4 @@ wait_err: return rv; } #endif +#endif diff --git a/ext/fileinfo/libmagic/config.h b/ext/fileinfo/libmagic/config.h new file mode 100644 index 00000000000..22ce7f63974 --- /dev/null +++ b/ext/fileinfo/libmagic/config.h @@ -0,0 +1 @@ +#include "php.h" diff --git a/ext/fileinfo/libmagic/der.c b/ext/fileinfo/libmagic/der.c index cb44b9ece9e..617d73e599a 100644 --- a/ext/fileinfo/libmagic/der.c +++ b/ext/fileinfo/libmagic/der.c @@ -54,7 +54,9 @@ FILE_RCSID("@(#)$File: der.c,v 1.24 2022/07/30 18:08:36 christos Exp $") #include "magic.h" #include "der.h" #else +#ifndef PHP_WIN32 #include +#endif #include #include #endif diff --git a/ext/fileinfo/libmagic/elfclass.h b/ext/fileinfo/libmagic/elfclass.h index 936d8dc912e..29a65f42abb 100644 --- a/ext/fileinfo/libmagic/elfclass.h +++ b/ext/fileinfo/libmagic/elfclass.h @@ -41,7 +41,7 @@ return toomany(ms, "program headers", phnum); flags |= FLAGS_IS_CORE; if (dophn_core(ms, clazz, swap, fd, - CAST(off_t, elf_getu(swap, elfhdr.e_phoff)), phnum, + CAST(zend_off_t, elf_getu(swap, elfhdr.e_phoff)), phnum, CAST(size_t, elf_getu16(swap, elfhdr.e_phentsize)), fsize, &flags, ¬ecount) == -1) return -1; @@ -56,7 +56,7 @@ if (shnum > ms->elf_shnum_max) return toomany(ms, "section", shnum); if (dophn_exec(ms, clazz, swap, fd, - CAST(off_t, elf_getu(swap, elfhdr.e_phoff)), phnum, + CAST(zend_off_t, elf_getu(swap, elfhdr.e_phoff)), phnum, CAST(size_t, elf_getu16(swap, elfhdr.e_phentsize)), fsize, shnum, &flags, ¬ecount) == -1) return -1; @@ -66,7 +66,7 @@ if (shnum > ms->elf_shnum_max) return toomany(ms, "section headers", shnum); if (doshn(ms, clazz, swap, fd, - CAST(off_t, elf_getu(swap, elfhdr.e_shoff)), shnum, + CAST(zend_off_t, elf_getu(swap, elfhdr.e_shoff)), shnum, CAST(size_t, elf_getu16(swap, elfhdr.e_shentsize)), fsize, elf_getu16(swap, elfhdr.e_machine), CAST(int, elf_getu16(swap, elfhdr.e_shstrndx)), diff --git a/ext/fileinfo/libmagic/encoding.c b/ext/fileinfo/libmagic/encoding.c index 4481a897d08..32415eaaf50 100644 --- a/ext/fileinfo/libmagic/encoding.c +++ b/ext/fileinfo/libmagic/encoding.c @@ -97,7 +97,7 @@ file_encoding(struct magic_set *ms, const struct buffer *b, nbytes = ms->encoding_max; mlen = (nbytes + 1) * sizeof((*ubuf)[0]); - *ubuf = CAST(file_unichar_t *, calloc(CAST(size_t, 1), mlen)); + *ubuf = CAST(file_unichar_t *, ecalloc(CAST(size_t, 1), mlen)); if (*ubuf == NULL) { file_oomem(ms, mlen); goto done; @@ -150,7 +150,7 @@ file_encoding(struct magic_set *ms, const struct buffer *b, unsigned char *nbuf; mlen = (nbytes + 1) * sizeof(nbuf[0]); - if ((nbuf = CAST(unsigned char *, malloc(mlen))) == NULL) { + if ((nbuf = CAST(unsigned char *, emalloc(mlen))) == NULL) { file_oomem(ms, mlen); goto done; } @@ -170,7 +170,7 @@ file_encoding(struct magic_set *ms, const struct buffer *b, rv = 0; *type = "binary"; } - free(nbuf); + efree(nbuf); } done: diff --git a/ext/fileinfo/libmagic/file.h b/ext/fileinfo/libmagic/file.h index 85675dff3f9..44e4924b720 100644 --- a/ext/fileinfo/libmagic/file.h +++ b/ext/fileinfo/libmagic/file.h @@ -33,17 +33,14 @@ #ifndef __file_h__ #define __file_h__ -#ifdef HAVE_CONFIG_H -#include -#endif +#include "config.h" + +#include "php.h" +#include "ext/standard/php_string.h" +#include "ext/pcre/php_pcre.h" -#ifdef HAVE_STDINT_H #include -#endif - -#ifdef HAVE_INTTYPES_H #include -#endif #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS @@ -79,19 +76,18 @@ #include /* Include that here, to make sure __P gets defined */ #include #include /* For open and flags */ -#include -#include + #include -#ifndef WIN32 +#ifdef PHP_WIN32 +#include "win32/param.h" +#else #include #endif /* Do this here and now, because struct stat gets re-defined on solaris */ #include #include -#include -#if defined(HAVE_XLOCALE_H) -#include -#endif + +#define abort() zend_error_noreturn(E_ERROR, "fatal libmagic error") #define ENABLE_CONDITIONALS @@ -171,14 +167,12 @@ #define FILE_COMPILE 2 #define FILE_LIST 3 -typedef regex_t file_regex_t; - struct buffer { int fd; - struct stat st; + zend_stat_t st; const void *fbuf; size_t flen; - off_t eoff; + zend_off_t eoff; void *ebuf; size_t elen; }; @@ -281,7 +275,7 @@ struct magic { #define FILE_OCTAL 59 #define FILE_NAMES_SIZE 60 /* size of array to contain all names */ -#define IS_STRING(t) \ +#define IS_LIBMAGIC_STRING(t) \ ((t) == FILE_STRING || \ (t) == FILE_PSTRING || \ (t) == FILE_BESTRING16 || \ @@ -515,10 +509,9 @@ protected const char *file_fmtvarint(char *, size_t, const unsigned char *, protected const char *file_fmtnum(char *, size_t, const char *, int); protected struct magic_set *file_ms_alloc(int); protected void file_ms_free(struct magic_set *); -protected int file_default(struct magic_set *, size_t); -protected int file_buffer(struct magic_set *, int, struct stat *, const char *, - const void *, size_t); -protected int file_fsmagic(struct magic_set *, const char *, struct stat *); +protected int file_buffer(struct magic_set *, php_stream *, zend_stat_t *, const char *, const void *, + size_t); +protected int file_fsmagic(struct magic_set *, const char *, zend_stat_t *); protected int file_pipe2file(struct magic_set *, int, const void *, size_t); protected int file_vprintf(struct magic_set *, const char *, va_list) __attribute__((__format__(__printf__, 2, 0))); @@ -534,7 +527,7 @@ protected int file_printf(struct magic_set *, const char *, ...) protected int file_reset(struct magic_set *, int); protected int file_tryelf(struct magic_set *, const struct buffer *); protected int file_trycdf(struct magic_set *, const struct buffer *); -#if HAVE_FORK +#ifdef PHP_FILEINFO_UNCOMPRESS protected int file_zmagic(struct magic_set *, const struct buffer *, const char *); #endif @@ -588,18 +581,12 @@ protected int file_pipe_closexec(int *); protected int file_clear_closexec(int); protected char *file_strtrim(char *); -protected void buffer_init(struct buffer *, int, const struct stat *, +protected void buffer_init(struct buffer *, int, const zend_stat_t *, const void *, size_t); protected void buffer_fini(struct buffer *); protected int buffer_fill(const struct buffer *); - - -protected int file_regcomp(struct magic_set *, file_regex_t *, const char *, - int); -protected int file_regexec(struct magic_set *, file_regex_t *, const char *, - size_t, regmatch_t *, int); -protected void file_regfree(file_regex_t *); +public zend_string* convert_libmagic_pattern(const char *val, size_t len, uint32_t options); typedef struct { char *buf; @@ -615,23 +602,10 @@ extern const char *file_names[]; extern const size_t file_nnames; #endif -#ifndef HAVE_PREAD -ssize_t pread(int, void *, size_t, off_t); -#endif -#ifndef HAVE_VASPRINTF -int vasprintf(char **, const char *, va_list); -#endif -#ifndef HAVE_ASPRINTF -int asprintf(char **, const char *, ...); -#endif -#ifndef HAVE_DPRINTF -int dprintf(int, const char *, ...); -#endif - -#ifndef HAVE_STRLCPY +#ifndef strlcpy size_t strlcpy(char *, const char *, size_t); #endif -#ifndef HAVE_STRLCAT +#ifndef strlcat size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRCASESTR @@ -647,39 +621,6 @@ char *ctime_r(const time_t *, char *); #ifndef HAVE_ASCTIME_R char *asctime_r(const struct tm *, char *); #endif -#ifndef HAVE_GMTIME_R -struct tm *gmtime_r(const time_t *, struct tm *); -#endif -#ifndef HAVE_LOCALTIME_R -struct tm *localtime_r(const time_t *, struct tm *); -#endif -#ifndef HAVE_FMTCHECK -const char *fmtcheck(const char *, const char *) - __attribute__((__format_arg__(2))); -#endif - -#ifdef HAVE_LIBSECCOMP -// basic filter -// this mode should not interfere with normal operations -// only some dangerous syscalls are blacklisted -int enable_sandbox_basic(void); - -// enhanced filter -// this mode allows only the necessary syscalls used during normal operation -// extensive testing required !!! -int enable_sandbox_full(void); -#endif - -protected const char *file_getprogname(void); -protected void file_setprogname(const char *); -protected void file_err(int, const char *, ...) - __attribute__((__format__(__printf__, 2, 3), __noreturn__)); -protected void file_errx(int, const char *, ...) - __attribute__((__format__(__printf__, 2, 3), __noreturn__)); -protected void file_warn(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -protected void file_warnx(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); #if defined(HAVE_MMAP) && defined(HAVE_SYS_MMAN_H) && !defined(QUICK) #define QUICK @@ -709,4 +650,16 @@ static const char *rcsid(const char *p) { \ #define __RCSID(a) #endif +#ifdef PHP_WIN32 +#ifdef _WIN64 +#define FINFO_LSEEK_FUNC _lseeki64 +#else +#define FINFO_LSEEK_FUNC _lseek +#endif +#define FINFO_READ_FUNC _read +#else +#define FINFO_LSEEK_FUNC lseek +#define FINFO_READ_FUNC read +#endif + #endif /* __file_h__ */ diff --git a/ext/fileinfo/libmagic/fsmagic.c b/ext/fileinfo/libmagic/fsmagic.c index f01d374f183..fb37fa7cc4c 100644 --- a/ext/fileinfo/libmagic/fsmagic.c +++ b/ext/fileinfo/libmagic/fsmagic.c @@ -66,26 +66,10 @@ FILE_RCSID("@(#)$File: fsmagic.c,v 1.82 2022/04/11 18:14:41 christos Exp $") # define minor(dev) ((dev) & 0xff) #endif #undef HAVE_MAJOR -#ifdef S_IFLNK -private int -bad_link(struct magic_set *ms, int err, char *buf) -{ - int mime = ms->flags & MAGIC_MIME; - if ((mime & MAGIC_MIME_TYPE) && - file_printf(ms, "inode/symlink") - == -1) - return -1; - else if (!mime) { - if (ms->flags & MAGIC_ERROR) { - file_error(ms, err, - "broken symbolic link to %s", buf); - return -1; - } - if (file_printf(ms, "broken symbolic link to %s", buf) == -1) - return -1; - } - return 1; -} + +#ifdef PHP_WIN32 + +# undef S_IFIFO #endif private int handle_mime(struct magic_set *ms, int mime, const char *str) @@ -103,60 +87,17 @@ handle_mime(struct magic_set *ms, int mime, const char *str) } protected int -file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) +file_fsmagic(struct magic_set *ms, const char *fn, zend_stat_t *sb) { int ret, did = 0; int mime = ms->flags & MAGIC_MIME; int silent = ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION); -#ifdef S_IFLNK - char buf[BUFSIZ+4]; - ssize_t nch; - struct stat tstatbuf; -#endif if (fn == NULL) return 0; #define COMMA (did++ ? ", " : "") - /* - * Fstat is cheaper but fails for files you don't have read perms on. - * On 4.2BSD and similar systems, use lstat() to identify symlinks. - */ -#ifdef S_IFLNK - if ((ms->flags & MAGIC_SYMLINK) == 0) - ret = lstat(fn, sb); - else -#endif - ret = stat(fn, sb); /* don't merge into if; see "ret =" above */ - -#ifdef WIN32 - { - HANDLE hFile = CreateFile((LPCSTR)fn, 0, FILE_SHARE_DELETE | - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, - NULL); - if (hFile != INVALID_HANDLE_VALUE) { - /* - * Stat failed, but we can still open it - assume it's - * a block device, if nothing else. - */ - if (ret) { - sb->st_mode = S_IFBLK; - ret = 0; - } - switch (GetFileType(hFile)) { - case FILE_TYPE_CHAR: - sb->st_mode |= S_IFCHR; - sb->st_mode &= ~S_IFREG; - break; - case FILE_TYPE_PIPE: - sb->st_mode |= S_IFIFO; - sb->st_mode &= ~S_IFREG; - break; - } - CloseHandle(hFile); - } - } -#endif + ret = php_sys_stat(fn, sb); if (ret) { if (ms->flags & MAGIC_ERROR) { @@ -189,32 +130,24 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) } switch (sb->st_mode & S_IFMT) { - case S_IFDIR: - if (mime) { - if (handle_mime(ms, mime, "directory") == -1) - return -1; - } else if (silent) { - } else if (file_printf(ms, "%sdirectory", COMMA) == -1) - return -1; - break; -#ifdef S_IFCHR - case S_IFCHR: - /* - * If -s has been specified, treat character special files - * like ordinary files. Otherwise, just report that they - * are block special files and go on to the next file. - */ - if ((ms->flags & MAGIC_DEVICES) != 0) { - ret = 0; - break; - } - if (mime) { - if (handle_mime(ms, mime, "chardevice") == -1) - return -1; - } else if (silent) { - } else { -#ifdef HAVE_STRUCT_STAT_ST_RDEV -# ifdef dv_unit +#ifndef PHP_WIN32 +# ifdef S_IFCHR + case S_IFCHR: + /* + * If -s has been specified, treat character special files + * like ordinary files. Otherwise, just report that they + * are block special files and go on to the next file. + */ + if ((ms->flags & MAGIC_DEVICES) != 0) { + ret = 0; + break; + } + if (mime) { + if (handle_mime(ms, mime, "chardevice") == -1) + return -1; + } else { +# ifdef HAVE_STAT_ST_RDEV +# ifdef dv_unit if (file_printf(ms, "%scharacter special (%d/%d/%d)", COMMA, major(sb->st_rdev), dv_unit(sb->st_rdev), dv_subunit(sb->st_rdev)) == -1) @@ -229,45 +162,11 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) if (file_printf(ms, "%scharacter special", COMMA) == -1) return -1; #endif - } - break; -#endif -#ifdef S_IFBLK - case S_IFBLK: - /* - * If -s has been specified, treat block special files - * like ordinary files. Otherwise, just report that they - * are block special files and go on to the next file. - */ - if ((ms->flags & MAGIC_DEVICES) != 0) { - ret = 0; - break; - } - if (mime) { - if (handle_mime(ms, mime, "blockdevice") == -1) - return -1; - } else if (silent) { - } else { -#ifdef HAVE_STRUCT_STAT_ST_RDEV -# ifdef dv_unit - if (file_printf(ms, "%sblock special (%d/%d/%d)", - COMMA, major(sb->st_rdev), dv_unit(sb->st_rdev), - dv_subunit(sb->st_rdev)) == -1) - return -1; -# else - if (file_printf(ms, "%sblock special (%ld/%ld)", - COMMA, (long)major(sb->st_rdev), - (long)minor(sb->st_rdev)) == -1) - return -1; + } + return 1; # endif -#else - if (file_printf(ms, "%sblock special", COMMA) == -1) - return -1; #endif - } - break; -#endif - /* TODO add code to handle V7 MUX and Blit MUX files */ + #ifdef S_IFIFO case S_IFIFO: if((ms->flags & MAGIC_DEVICES) != 0) @@ -292,92 +191,14 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb) #endif #ifdef S_IFLNK case S_IFLNK: - if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) { + /* stat is used, if it made here then the link is broken */ if (ms->flags & MAGIC_ERROR) { - file_error(ms, errno, "unreadable symlink `%s'", - fn); + file_error(ms, errno, "unreadable symlink `%s'", fn); return -1; } - if (mime) { - if (handle_mime(ms, mime, "symlink") == -1) - return -1; - } else if (silent) { - } else if (file_printf(ms, - "%sunreadable symlink `%s' (%s)", COMMA, fn, - strerror(errno)) == -1) - return -1; - break; - } - buf[nch] = '\0'; /* readlink(2) does not do this */ - - /* If broken symlink, say so and quit early. */ -#ifdef __linux__ - /* - * linux procfs/devfs makes symlinks like pipe:[3515864880] - * that we can't stat their readlink output, so stat the - * original filename instead. - */ - if (stat(fn, &tstatbuf) < 0) - return bad_link(ms, errno, buf); -#else - if (*buf == '/') { - if (stat(buf, &tstatbuf) < 0) - return bad_link(ms, errno, buf); - } else { - char *tmp; - char buf2[BUFSIZ+BUFSIZ+4]; - - if ((tmp = CCAST(char *, strrchr(fn, '/'))) == NULL) { - tmp = buf; /* in current directory anyway */ - } else { - if (tmp - fn + 1 > BUFSIZ) { - if (ms->flags & MAGIC_ERROR) { - file_error(ms, 0, - "path too long: `%s'", buf); - return -1; - } - if (mime) { - if (handle_mime(ms, mime, - "x-path-too-long") == -1) - return -1; - } else if (silent) { - } else if (file_printf(ms, - "%spath too long: `%s'", COMMA, - fn) == -1) - return -1; - break; - } - /* take dir part */ - (void)strlcpy(buf2, fn, sizeof buf2); - buf2[tmp - fn + 1] = '\0'; - /* plus (rel) link */ - (void)strlcat(buf2, buf, sizeof buf2); - tmp = buf2; - } - if (stat(tmp, &tstatbuf) < 0) - return bad_link(ms, errno, buf); - } + return 1; #endif - /* Otherwise, handle it. */ - if ((ms->flags & MAGIC_SYMLINK) != 0) { - const char *p; - ms->flags &= MAGIC_SYMLINK; - p = magic_file(ms, buf); - ms->flags |= MAGIC_SYMLINK; - if (p == NULL) - return -1; - } else { /* just print what it points to */ - if (mime) { - if (handle_mime(ms, mime, "symlink") == -1) - return -1; - } else if (silent) { - } else if (file_printf(ms, "%ssymbolic link to %s", - COMMA, buf) == -1) - return -1; - } - break; -#endif #ifdef S_IFSOCK #ifndef __COHERENT__ case S_IFSOCK: diff --git a/ext/fileinfo/libmagic/funcs.c b/ext/fileinfo/libmagic/funcs.c index 41c4106c59e..ed6f4b43ec3 100644 --- a/ext/fileinfo/libmagic/funcs.c +++ b/ext/fileinfo/libmagic/funcs.c @@ -51,6 +51,13 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.131 2022/09/13 18:46:07 christos Exp $") #define SIZE_MAX ((size_t)~0) #endif +#include "php.h" +#include "main/php_network.h" + +#ifndef PREG_OFFSET_CAPTURE +# define PREG_OFFSET_CAPTURE (1<<8) +#endif + protected char * file_copystr(char *buf, size_t blen, size_t width, const char *str) { @@ -66,7 +73,7 @@ file_copystr(char *buf, size_t blen, size_t width, const char *str) private void file_clearbuf(struct magic_set *ms) { - free(ms->o.buf); + efree(ms->o.buf); ms->o.buf = NULL; ms->o.blen = 0; } @@ -132,7 +139,7 @@ file_checkfmt(char *msg, size_t mlen, const char *fmt) protected int file_vprintf(struct magic_set *ms, const char *fmt, va_list ap) { - int len; + size_t len; char *buf, *newstr; char tbuf[1024]; @@ -145,10 +152,10 @@ file_vprintf(struct magic_set *ms, const char *fmt, va_list ap) return -1; } - len = vasprintf(&buf, fmt, ap); - if (len < 0 || (size_t)len > 1024 || len + ms->o.blen > 1024 * 1024) { + len = vspprintf(&buf, 0, fmt, ap); + if (len > 1024 || len + ms->o.blen > 1024 * 1024) { size_t blen = ms->o.blen; - free(buf); + if (buf) efree(buf); file_clearbuf(ms); file_error(ms, 0, "Output buffer space exceeded %d+%" SIZE_T_FORMAT "u", len, blen); @@ -156,20 +163,14 @@ file_vprintf(struct magic_set *ms, const char *fmt, va_list ap) } if (ms->o.buf != NULL) { - len = asprintf(&newstr, "%s%s", ms->o.buf, buf); - free(buf); - if (len < 0) - goto out; - free(ms->o.buf); + len = spprintf(&newstr, 0, "%s%s", ms->o.buf, buf); + efree(buf); + efree(ms->o.buf); buf = newstr; } ms->o.buf = buf; ms->o.blen = len; return 0; -out: - file_clearbuf(ms); - file_error(ms, errno, "vasprintf failed"); - return -1; } protected int @@ -320,8 +321,8 @@ file_default(struct magic_set *ms, size_t nb) */ /*ARGSUSED*/ protected int -file_buffer(struct magic_set *ms, int fd, struct stat *st, - const char *inname __attribute__ ((__unused__)), +file_buffer(struct magic_set *ms, php_stream *stream, zend_stat_t *st, + const char *inname, const void *buf, size_t nb) { int m = 0, rv = 0, looks_text = 0; @@ -331,6 +332,19 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st, const char *ftype = NULL; char *rbuf = NULL; struct buffer b; + int fd = -1; + + if (stream) { +#ifdef _WIN64 + php_socket_t _fd = fd; +#else + int _fd; +#endif + int _ret = php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&_fd, 0); + if (SUCCESS == _ret) { + fd = (int)_fd; + } + } buffer_init(&b, fd, st, buf, nb); ms->mode = b.st.st_mode; @@ -363,7 +377,8 @@ file_buffer(struct magic_set *ms, int fd, struct stat *st, } } #endif -#if HAVE_FORK + +#if PHP_FILEINFO_UNCOMPRESS /* try compression stuff */ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) { m = file_zmagic(ms, &b, inname); @@ -488,10 +503,10 @@ simple: if (file_printf(ms, "%s", code_mime) == -1) rv = -1; } -#if HAVE_FORK +#if PHP_FILEINFO_UNCOMPRESS done_encoding: #endif - free(rbuf); + efree(rbuf); buffer_fini(&b); if (rv) return rv; @@ -509,7 +524,7 @@ file_reset(struct magic_set *ms, int checkloaded) } file_clearbuf(ms); if (ms->o.pbuf) { - free(ms->o.pbuf); + efree(ms->o.pbuf); ms->o.pbuf = NULL; } ms->event_flags &= ~EVENT_HAD_ERR; @@ -547,7 +562,7 @@ file_getbuffer(struct magic_set *ms) return NULL; } psize = len * 4 + 1; - if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) { + if ((pbuf = CAST(char *, erealloc(ms->o.pbuf, psize))) == NULL) { file_oomem(ms, psize); return NULL; } @@ -611,8 +626,8 @@ file_check_mem(struct magic_set *ms, unsigned int level) if (level >= ms->c.len) { len = (ms->c.len = 20 + level) * sizeof(*ms->c.li); ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ? - malloc(len) : - realloc(ms->c.li, len)); + emalloc(len) : + erealloc(ms->c.li, len)); if (ms->c.li == NULL) { file_oomem(ms, len); return -1; @@ -635,87 +650,38 @@ file_printedlen(const struct magic_set *ms) protected int file_replace(struct magic_set *ms, const char *pat, const char *rep) { - file_regex_t rx; - int rc, rv = -1; + zend_string *pattern; + uint32_t opts = 0; + pcre_cache_entry *pce; + zend_string *res; + zend_string *repl; + size_t rep_cnt = 0; - rc = file_regcomp(ms, &rx, pat, REG_EXTENDED); - if (rc == 0) { - regmatch_t rm; - int nm = 0; - while (file_regexec(ms, &rx, ms->o.buf, 1, &rm, 0) == 0) { - ms->o.buf[rm.rm_so] = '\0'; - if (file_printf(ms, "%s%s", rep, - rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1) - goto out; - nm++; - } - rv = nm; + opts |= PCRE2_MULTILINE; + pattern = convert_libmagic_pattern((char*)pat, strlen(pat), opts); + if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) { + zend_string_release(pattern); + rep_cnt = -1; + goto out; } + zend_string_release(pattern); + + repl = zend_string_init(rep, strlen(rep), 0); + res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), repl, -1, &rep_cnt); + + zend_string_release_ex(repl, 0); + if (NULL == res) { + rep_cnt = -1; + goto out; + } + + strncpy(ms->o.buf, ZSTR_VAL(res), ZSTR_LEN(res)); + ms->o.buf[ZSTR_LEN(res)] = '\0'; + + zend_string_release_ex(res, 0); + out: - file_regfree(&rx); - return rv; -} - -protected int -file_regcomp(struct magic_set *ms file_locale_used, file_regex_t *rx, - const char *pat, int flags) -{ -#ifdef USE_C_LOCALE - locale_t old = uselocale(ms->c_lc_ctype); - assert(old != NULL); -#else - char old[1024]; - strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old)); - (void)setlocale(LC_CTYPE, "C"); -#endif - int rc; - rc = regcomp(rx, pat, flags); - -#ifdef USE_C_LOCALE - uselocale(old); -#else - (void)setlocale(LC_CTYPE, old); -#endif - if (rc > 0 && (ms->flags & MAGIC_CHECK)) { - char errmsg[512]; - - (void)regerror(rc, rx, errmsg, sizeof(errmsg)); - file_magerror(ms, "regex error %d for `%s', (%s)", rc, pat, - errmsg); - } - return rc; -} - -/*ARGSUSED*/ -protected int -file_regexec(struct magic_set *ms file_locale_used, file_regex_t *rx, - const char *str, size_t nmatch, regmatch_t* pmatch, int eflags) -{ -#ifdef USE_C_LOCALE - locale_t old = uselocale(ms->c_lc_ctype); - assert(old != NULL); -#else - char old[1024]; - strlcpy(old, setlocale(LC_CTYPE, NULL), sizeof(old)); - (void)setlocale(LC_CTYPE, "C"); -#endif - int rc; - /* XXX: force initialization because glibc does not always do this */ - if (nmatch != 0) - memset(pmatch, 0, nmatch * sizeof(*pmatch)); - rc = regexec(rx, str, nmatch, pmatch, eflags); -#ifdef USE_C_LOCALE - uselocale(old); -#else - (void)setlocale(LC_CTYPE, old); -#endif - return rc; -} - -protected void -file_regfree(file_regex_t *rx) -{ - regfree(rx); + return rep_cnt; } protected file_pushbuf_t * @@ -726,7 +692,7 @@ file_push_buffer(struct magic_set *ms) if (ms->event_flags & EVENT_HAD_ERR) return NULL; - if ((pb = (CAST(file_pushbuf_t *, malloc(sizeof(*pb))))) == NULL) + if ((pb = (CAST(file_pushbuf_t *, emalloc(sizeof(*pb))))) == NULL) return NULL; pb->buf = ms->o.buf; @@ -746,8 +712,8 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) char *rbuf; if (ms->event_flags & EVENT_HAD_ERR) { - free(pb->buf); - free(pb); + efree(pb->buf); + efree(pb); return NULL; } @@ -757,7 +723,7 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb) ms->o.blen = pb->blen; ms->offset = pb->offset; - free(pb); + efree(pb); return rbuf; } @@ -841,6 +807,7 @@ file_print_guid(char *str, size_t len, const uint64_t *guid) #endif } +#if 0 protected int file_pipe_closexec(int *fds) { @@ -856,6 +823,7 @@ file_pipe_closexec(int *fds) return 0; #endif } +#endif protected int file_clear_closexec(int fd) { diff --git a/ext/fileinfo/libmagic/magic.c b/ext/fileinfo/libmagic/magic.c index 7768497ae07..72d824ac04c 100644 --- a/ext/fileinfo/libmagic/magic.c +++ b/ext/fileinfo/libmagic/magic.c @@ -25,11 +25,6 @@ * SUCH DAMAGE. */ -#ifdef WIN32 -#include -#include -#endif - #include "file.h" #ifndef lint @@ -39,10 +34,16 @@ FILE_RCSID("@(#)$File: magic.c,v 1.117 2021/12/06 15:33:00 christos Exp $") #include "magic.h" #include +#ifdef PHP_WIN32 +#include "win32/unistd.h" +#else #include +#endif #include -#ifdef QUICK -#include +#include "config.h" + +#ifdef PHP_WIN32 +#include #endif #include /* for PIPE_BUF */ @@ -69,200 +70,18 @@ FILE_RCSID("@(#)$File: magic.c,v 1.117 2021/12/06 15:33:00 christos Exp $") #endif #endif -private void close_and_restore(const struct magic_set *, const char *, int, - const struct stat *); -private int unreadable_info(struct magic_set *, mode_t, const char *); -private const char* get_default_magic(void); -#ifndef COMPILE_ONLY -private const char *file_or_fd(struct magic_set *, const char *, int); +#ifdef PHP_WIN32 +# undef S_IFLNK +# undef S_IFIFO #endif +private int unreadable_info(struct magic_set *, mode_t, const char *); +private const char *file_or_stream(struct magic_set *, const char *, php_stream *); + #ifndef STDIN_FILENO #define STDIN_FILENO 0 #endif -#ifdef WIN32 -/* HINSTANCE of this shared library. Needed for get_default_magic() */ -static HINSTANCE _w32_dll_instance = NULL; - -static void -_w32_append_path(char **hmagicpath, const char *fmt, ...) -{ - char *tmppath; - char *newpath; - va_list ap; - - va_start(ap, fmt); - if (vasprintf(&tmppath, fmt, ap) < 0) { - va_end(ap); - return; - } - va_end(ap); - - if (access(tmppath, R_OK) == -1) - goto out; - - if (*hmagicpath == NULL) { - *hmagicpath = tmppath; - return; - } - - if (asprintf(&newpath, "%s%c%s", *hmagicpath, PATHSEP, tmppath) < 0) - goto out; - - free(*hmagicpath); - free(tmppath); - *hmagicpath = newpath; - return; -out: - free(tmppath); -} - -static void -_w32_get_magic_relative_to(char **hmagicpath, HINSTANCE module) -{ - static const char *trypaths[] = { - "%s/share/misc/magic.mgc", - "%s/magic.mgc", - }; - LPSTR dllpath; - size_t sp; - - dllpath = calloc(MAX_PATH + 1, sizeof(*dllpath)); - - if (!GetModuleFileNameA(module, dllpath, MAX_PATH)) - goto out; - - PathRemoveFileSpecA(dllpath); - - if (module) { - char exepath[MAX_PATH]; - GetModuleFileNameA(NULL, exepath, MAX_PATH); - PathRemoveFileSpecA(exepath); - if (stricmp(exepath, dllpath) == 0) - goto out; - } - - sp = strlen(dllpath); - if (sp > 3 && stricmp(&dllpath[sp - 3], "bin") == 0) { - _w32_append_path(hmagicpath, - "%s/../share/misc/magic.mgc", dllpath); - goto out; - } - - for (sp = 0; sp < __arraycount(trypaths); sp++) - _w32_append_path(hmagicpath, trypaths[sp], dllpath); -out: - free(dllpath); -} - -#ifndef BUILD_AS_WINDOWS_STATIC_LIBARAY -/* Placate GCC by offering a sacrificial previous prototype */ -BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID); - -BOOL WINAPI -DllMain(HINSTANCE hinstDLL, DWORD fdwReason, - LPVOID lpvReserved __attribute__((__unused__))) -{ - if (fdwReason == DLL_PROCESS_ATTACH) - _w32_dll_instance = hinstDLL; - return 1; -} -#endif -#endif - -private const char * -get_default_magic(void) -{ - static const char hmagic[] = "/.magic/magic.mgc"; - static char *default_magic; - char *home, *hmagicpath; - -#ifndef WIN32 - struct stat st; - - if (default_magic) { - free(default_magic); - default_magic = NULL; - } - if ((home = getenv("HOME")) == NULL) - return MAGIC; - - if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0) - return MAGIC; - if (stat(hmagicpath, &st) == -1) { - free(hmagicpath); - if (asprintf(&hmagicpath, "%s/.magic", home) < 0) - return MAGIC; - if (stat(hmagicpath, &st) == -1) - goto out; - if (S_ISDIR(st.st_mode)) { - free(hmagicpath); - if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0) - return MAGIC; - if (access(hmagicpath, R_OK) == -1) - goto out; - } - } - - if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0) - goto out; - free(hmagicpath); - return default_magic; -out: - default_magic = NULL; - free(hmagicpath); - return MAGIC; -#else - hmagicpath = NULL; - - if (default_magic) { - free(default_magic); - default_magic = NULL; - } - - /* Before anything else, try to get a magic file from user HOME */ - if ((home = getenv("HOME")) != NULL) - _w32_append_path(&hmagicpath, "%s%s", home, hmagic); - - /* First, try to get a magic file from user-application data */ - if ((home = getenv("LOCALAPPDATA")) != NULL) - _w32_append_path(&hmagicpath, "%s%s", home, hmagic); - - /* Second, try to get a magic file from the user profile data */ - if ((home = getenv("USERPROFILE")) != NULL) - _w32_append_path(&hmagicpath, - "%s/Local Settings/Application Data%s", home, hmagic); - - /* Third, try to get a magic file from Common Files */ - if ((home = getenv("COMMONPROGRAMFILES")) != NULL) - _w32_append_path(&hmagicpath, "%s%s", home, hmagic); - - /* Fourth, try to get magic file relative to exe location */ - _w32_get_magic_relative_to(&hmagicpath, NULL); - - /* Fifth, try to get magic file relative to dll location */ - _w32_get_magic_relative_to(&hmagicpath, _w32_dll_instance); - - /* Avoid MAGIC constant - it likely points to a file within MSys tree */ - default_magic = hmagicpath; - return default_magic; -#endif -} - -public const char * -magic_getpath(const char *magicfile, int action) -{ - if (magicfile != NULL) - return magicfile; - - magicfile = getenv("MAGIC"); - if (magicfile != NULL) - return magicfile; - - return action == FILE_LOAD ? get_default_magic() : MAGIC; -} - public struct magic_set * magic_open(int flags) { @@ -321,21 +140,6 @@ magic_load(struct magic_set *ms, const char *magicfile) return file_apprentice(ms, magicfile, FILE_LOAD); } -#ifndef COMPILE_ONLY -/* - * Install a set of compiled magic buffers. - */ -public int -magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes, - size_t nbufs) -{ - if (ms == NULL) - return -1; - return buffer_apprentice(ms, RCAST(struct magic **, bufs), - sizes, nbufs); -} -#endif - public int magic_compile(struct magic_set *ms, const char *magicfile) { @@ -360,39 +164,6 @@ magic_list(struct magic_set *ms, const char *magicfile) return file_apprentice(ms, magicfile, FILE_LIST); } -private void -close_and_restore(const struct magic_set *ms, const char *name, int fd, - const struct stat *sb) -{ - if (fd == STDIN_FILENO || name == NULL) - return; - (void) close(fd); - - if ((ms->flags & MAGIC_PRESERVE_ATIME) != 0) { - /* - * Try to restore access, modification times if read it. - * This is really *bad* because it will modify the status - * time of the file... And of course this will affect - * backup programs - */ -#ifdef HAVE_UTIMES - struct timeval utsbuf[2]; - (void)memset(utsbuf, 0, sizeof(utsbuf)); - utsbuf[0].tv_sec = sb->st_atime; - utsbuf[1].tv_sec = sb->st_mtime; - - (void) utimes(name, utsbuf); /* don't care if loses */ -#elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H) - struct utimbuf utbuf; - - (void)memset(&utbuf, 0, sizeof(utbuf)); - utbuf.actime = sb->st_atime; - utbuf.modtime = sb->st_mtime; - (void) utime(name, &utbuf); /* don't care if loses */ -#endif - } -} - #ifndef COMPILE_ONLY /* @@ -403,7 +174,7 @@ magic_descriptor(struct magic_set *ms, int fd) { if (ms == NULL) return NULL; - return file_or_fd(ms, NULL, fd); + return file_or_stream(ms, NULL, NULL); } /* @@ -414,19 +185,25 @@ magic_file(struct magic_set *ms, const char *inname) { if (ms == NULL) return NULL; - return file_or_fd(ms, inname, STDIN_FILENO); + return file_or_stream(ms, inname, NULL); +} + +public const char * +magic_stream(struct magic_set *ms, php_stream *stream) +{ + if (ms == NULL) + return NULL; + return file_or_stream(ms, NULL, stream); } private const char * -file_or_fd(struct magic_set *ms, const char *inname, int fd) +file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream) { int rv = -1; unsigned char *buf; - struct stat sb; + zend_stat_t sb = {0}; ssize_t nbytes = 0; /* number of bytes read from a datafile */ - int ispipe = 0; - int okstat = 0; - off_t pos = CAST(off_t, -1); + int no_in_stream = 0; if (file_reset(ms, 1) == -1) goto out; @@ -436,7 +213,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) * some overlapping space for matches near EOF */ #define SLOP (1 + sizeof(union VALUETYPE)) - if ((buf = CAST(unsigned char *, malloc(ms->bytes_max + SLOP))) == NULL) + if ((buf = CAST(unsigned char *, emalloc(ms->bytes_max + SLOP))) == NULL) return NULL; switch (file_fsmagic(ms, inname, &sb)) { @@ -449,96 +226,46 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) goto done; } -#ifdef WIN32 - /* Place stdin in binary mode, so EOF (Ctrl+Z) doesn't stop early. */ - if (fd == STDIN_FILENO) - _setmode(STDIN_FILENO, O_BINARY); -#endif - if (inname != NULL) { - int flags = O_RDONLY|O_BINARY|O_NONBLOCK|O_CLOEXEC; - errno = 0; - if ((fd = open(inname, flags)) < 0) { - okstat = stat(inname, &sb) == 0; -#ifdef WIN32 - /* - * Can't stat, can't open. It may have been opened in - * fsmagic, so if the user doesn't have read permission, - * allow it to say so; otherwise an error was probably - * displayed in fsmagic. - */ - if (!okstat && errno == EACCES) { - sb.st_mode = S_IFBLK; - okstat = 1; - } -#endif - if (okstat && - unreadable_info(ms, sb.st_mode, inname) == -1) + errno = 0; + + if (inname && !stream) { + no_in_stream = 1; + stream = php_stream_open_wrapper((char *)inname, "rb", REPORT_ERRORS, NULL); + if (!stream) { + if (unreadable_info(ms, sb.st_mode, inname) == -1) goto done; - rv = 0; + rv = -1; goto done; } -#if O_CLOEXEC == 0 && defined(F_SETFD) - (void)fcntl(fd, F_SETFD, FD_CLOEXEC); -#endif } - if (fd != -1) { - okstat = fstat(fd, &sb) == 0; - if (okstat && S_ISFIFO(sb.st_mode)) - ispipe = 1; - if (inname == NULL) - pos = lseek(fd, CAST(off_t, 0), SEEK_CUR); + php_stream_statbuf ssb; + if (php_stream_stat(stream, &ssb) < 0) { + if (ms->flags & MAGIC_ERROR) { + file_error(ms, errno, "cannot stat `%s'", inname); + rv = -1; + goto done; + } } + memcpy(&sb, &ssb.sb, sizeof(zend_stat_t)); /* * try looking at the first ms->bytes_max bytes */ - if (ispipe) { - if (fd != -1) { - ssize_t r = 0; - - while ((r = sread(fd, RCAST(void *, &buf[nbytes]), - CAST(size_t, ms->bytes_max - nbytes), 1)) > 0) { - nbytes += r; - if (r < PIPE_BUF) break; - } - } - - if (nbytes == 0 && inname) { - /* We can not read it, but we were able to stat it. */ - if (unreadable_info(ms, sb.st_mode, inname) == -1) - goto done; - rv = 0; - goto done; - } - - } else if (fd != -1) { - /* Windows refuses to read from a big console buffer. */ - size_t howmany = -#ifdef WIN32 - _isatty(fd) ? 8 * 1024 : -#endif - ms->bytes_max; - if ((nbytes = read(fd, RCAST(void *, buf), howmany)) == -1) { - if (inname == NULL && fd != STDIN_FILENO) - file_error(ms, errno, "cannot read fd %d", fd); - else - file_error(ms, errno, "cannot read `%s'", - inname == NULL ? "/dev/stdin" : inname); - goto done; - } + if ((nbytes = php_stream_read(stream, (char *)buf, ms->bytes_max - nbytes)) < 0) { + file_error(ms, errno, "cannot read `%s'", inname); + goto done; } (void)memset(buf + nbytes, 0, SLOP); /* NUL terminate */ - if (file_buffer(ms, fd, okstat ? &sb : NULL, inname, buf, CAST(size_t, nbytes)) == -1) + if (file_buffer(ms, stream, &sb, inname, buf, CAST(size_t, nbytes)) == -1) goto done; rv = 0; done: - free(buf); - if (fd != -1) { - if (pos != CAST(off_t, -1)) - (void)lseek(fd, pos, SEEK_SET); - close_and_restore(ms, inname, fd, &sb); + efree(buf); + + if (no_in_stream && stream) { + php_stream_close(stream); } out: return rv == 0 ? file_getbuffer(ms) : NULL; @@ -556,7 +283,7 @@ magic_buffer(struct magic_set *ms, const void *buf, size_t nb) * The main work is done here! * We have the file name and/or the data buffer to be identified. */ - if (file_buffer(ms, -1, NULL, NULL, buf, nb) == -1) { + if (file_buffer(ms, NULL, NULL, NULL, buf, nb) == -1) { return NULL; } return file_getbuffer(ms); diff --git a/ext/fileinfo/libmagic/print.c b/ext/fileinfo/libmagic/print.c index 019f98e669e..482d123266a 100644 --- a/ext/fileinfo/libmagic/print.c +++ b/ext/fileinfo/libmagic/print.c @@ -28,6 +28,7 @@ /* * print.c - debugging printout routines */ +#include "php.h" #include "file.h" @@ -73,7 +74,7 @@ file_mdump(struct magic *m) if (m->mask_op & FILE_OPINVERSE) (void) fputc('~', stderr); - if (IS_STRING(m->type)) { + if (IS_LIBMAGIC_STRING(m->type)) { if (m->str_flags) { (void) fputc('/', stderr); if (m->str_flags & STRING_COMPACT_WHITESPACE) @@ -246,18 +247,18 @@ protected void file_magwarn(struct magic_set *ms, const char *f, ...) { va_list va; + char *expanded_format = NULL; + int expanded_len; - /* cuz we use stdout for most, stderr here */ - (void) fflush(stdout); - - if (ms->file) - (void) fprintf(stderr, "%s, %lu: ", ms->file, - CAST(unsigned long, ms->line)); - (void) fprintf(stderr, "Warning: "); va_start(va, f); - (void) vfprintf(stderr, f, va); + expanded_len = vasprintf(&expanded_format, f, va); va_end(va); - (void) fputc('\n', stderr); + + if (expanded_len >= 0 && expanded_format) { + php_error_docref(NULL, E_WARNING, "%s", expanded_format); + + free(expanded_format); + } } protected const char * @@ -285,13 +286,13 @@ file_fmtdatetime(char *buf, size_t bsize, uint64_t v, int flags) } if (flags & FILE_T_LOCAL) { - tm = localtime_r(&t, &tmz); + tm = php_localtime_r(&t, &tmz); } else { - tm = gmtime_r(&t, &tmz); + tm = php_gmtime_r(&t, &tmz); } if (tm == NULL) goto out; - pp = asctime_r(tm, buf); + pp = php_asctime_r(tm, buf); if (pp == NULL) goto out; diff --git a/ext/fileinfo/libmagic/readcdf.c b/ext/fileinfo/libmagic/readcdf.c index 0b06b421eb9..ad106830093 100644 --- a/ext/fileinfo/libmagic/readcdf.c +++ b/ext/fileinfo/libmagic/readcdf.c @@ -31,7 +31,11 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.76 2022/01/17 16:59:01 christos Exp $") #include #include +#ifdef PHP_WIN32 +#include "win32/unistd.h" +#else #include +#endif #include #include #include @@ -100,10 +104,6 @@ cdf_clsid_to_mime(const uint64_t clsid[2], const struct cv *cv) if (clsid[0] == cv[i].clsid[0] && clsid[1] == cv[i].clsid[1]) return cv[i].mime; } -#ifdef CDF_DEBUG - fprintf(stderr, "unknown mime %" PRIx64 ", %" PRIx64 "\n", clsid[0], - clsid[1]); -#endif return NULL; } @@ -112,35 +112,24 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv) { size_t i; const char *rv = NULL; -#ifdef USE_C_LOCALE - locale_t old_lc_ctype, c_lc_ctype; + char *vbuf_lower; - c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0); - assert(c_lc_ctype != NULL); - old_lc_ctype = uselocale(c_lc_ctype); - assert(old_lc_ctype != NULL); -#else - char *old_lc_ctype = setlocale(LC_CTYPE, NULL); - assert(old_lc_ctype != NULL); - old_lc_ctype = strdup(old_lc_ctype); - assert(old_lc_ctype != NULL); - (void)setlocale(LC_CTYPE, "C"); -#endif - for (i = 0; nv[i].pattern != NULL; i++) - if (strcasestr(vbuf, nv[i].pattern) != NULL) { + vbuf_lower = zend_str_tolower_dup(vbuf, strlen(vbuf)); + for (i = 0; nv[i].pattern != NULL; i++) { + char *pattern_lower; + int found; + + pattern_lower = zend_str_tolower_dup(nv[i].pattern, strlen(nv[i].pattern)); + found = (strstr(vbuf_lower, pattern_lower) != NULL); + efree(pattern_lower); + + if (found) { rv = nv[i].mime; break; } -#ifdef CDF_DEBUG - fprintf(stderr, "unknown app %s\n", vbuf); -#endif -#ifdef USE_C_LOCALE - (void)uselocale(old_lc_ctype); - freelocale(c_lc_ctype); -#else - (void)setlocale(LC_CTYPE, old_lc_ctype); - free(old_lc_ctype); -#endif + } + + efree(vbuf_lower); return rv; } @@ -156,7 +145,9 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, const char *s, *e; int len; - if (!NOTMIME(ms) && root_storage) + memset(&ts, 0, sizeof(ts)); + + if (!NOTMIME(ms) && root_storage) str = cdf_clsid_to_mime(root_storage->d_storage_uuid, clsid2mime); @@ -282,10 +273,10 @@ cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h, if (file_printf(ms, "%s%s", cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name), i == cat->cat_num - 1 ? "]" : ", ") == -1) { - free(cat); + efree(cat); return -1; } - free(cat); + efree(cat); } else if (ms->flags & MAGIC_MIME_TYPE) { if (file_printf(ms, "application/CDFV2") == -1) return -1; @@ -346,7 +337,7 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h, } m = cdf_file_property_info(ms, info, count, root_storage); - free(info); + efree(info); return m == -1 ? -2 : m; } @@ -656,11 +647,11 @@ out5: cdf_zero_stream(&scn); cdf_zero_stream(&sst); out3: - free(dir.dir_tab); + efree(dir.dir_tab); out2: - free(ssat.sat_tab); + efree(ssat.sat_tab); out1: - free(sat.sat_tab); + efree(sat.sat_tab); out0: /* If we handled it already, return */ if (i != -1) diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c index d95f7f27de8..cf8e313d872 100644 --- a/ext/fileinfo/libmagic/softmagic.c +++ b/ext/fileinfo/libmagic/softmagic.c @@ -43,6 +43,10 @@ FILE_RCSID("@(#)$File: softmagic.c,v 1.328 2022/09/13 18:46:07 christos Exp $") #include #include "der.h" +#ifndef PREG_OFFSET_CAPTURE +# define PREG_OFFSET_CAPTURE (1<<8) +#endif + private int match(struct magic_set *, struct magic *, file_regex_t **, size_t, const struct buffer *, size_t, int, int, int, uint16_t *, uint16_t *, int *, int *, int *, int *); @@ -150,8 +154,8 @@ file_softmagic(struct magic_set *ms, const struct buffer *b, return rv; } -#define FILE_FMTDEBUG -#ifdef FILE_FMTDEBUG + +#if defined(FILE_FMTDEBUG) && defined(HAVE_FMTCHECK) #define F(a, b, c) file_fmtcheck((a), (b), (c), __FILE__, __LINE__) private const char * __attribute__((__format_arg__(3))) @@ -170,10 +174,14 @@ file_fmtcheck(struct magic_set *ms, const char *desc, const char *def, " with `%s'", file, line, desc, def); return ptr; } -#else +#elif defined(HAVE_FMTCHECK) #define F(a, b, c) fmtcheck((b), (c)) +#else +#define F(a, b, c) ((b)) #endif +/* NOTE this function has been kept an the state of 5.39 for BC. Observe + * further as the upgrade to 5.41 or above goes. */ /* * Go through the whole list, stopping if you find a match. Process all * the continuations of that match before returning. @@ -235,7 +243,7 @@ match(struct magic_set *ms, struct magic *magic, file_regex_t **magic_rxcomp, file_regex_t **m_rxcomp = &magic_rxcomp[magindex]; if (m->type != FILE_NAME) - if ((IS_STRING(m->type) && + if ((IS_LIBMAGIC_STRING(m->type) && #define FLT (STRING_BINTEST | STRING_TEXTTEST) ((text && (m->str_flags & FLT) == STRING_BINTEST) || (!text && (m->str_flags & FLT) == STRING_TEXTTEST))) || @@ -484,19 +492,25 @@ flush: private int check_fmt(struct magic_set *ms, const char *fmt) { - file_regex_t rx; - int rc, rv = -1; - const char* pat = "%[-0-9\\.]*s"; + pcre_cache_entry *pce; + int rv = -1; + zend_string *pattern; if (strchr(fmt, '%') == NULL) return 0; - rc = file_regcomp(ms, &rx, pat, REG_EXTENDED|REG_NOSUB); - if (rc == 0) { - rc = file_regexec(ms, &rx, fmt, 0, 0, 0); - rv = !rc; + pattern = zend_string_init("~%[-0-9\\.]*s~", sizeof("~%[-0-9\\.]*s~") - 1, 0); + if ((pce = pcre_get_compiled_regex_cache_ex(pattern, 0)) == NULL) { + rv = -1; + } else { + pcre2_code *re = php_pcre_pce_re(pce); + pcre2_match_data *match_data = php_pcre_create_match_data(0, re); + if (match_data) { + rv = pcre2_match(re, (PCRE2_SPTR)fmt, strlen(fmt), 0, 0, match_data, php_pcre_mctx()) > 0; + php_pcre_free_match_data(match_data); + } } - file_regfree(&rx); + zend_string_release(pattern); return rv; } @@ -514,7 +528,7 @@ strndup(const char *str, size_t n) for (len = 0; len < n && str[len]; len++) continue; - if ((copy = CAST(char *, malloc(len + 1))) == NULL) + if ((copy = CAST(char *, emalloc(len + 1))) == NULL) return NULL; (void)memcpy(copy, str, len); copy[len] = '\0'; @@ -1544,7 +1558,7 @@ save_cont(struct magic_set *ms, struct cont *c) size_t len; *c = ms->c; len = c->len * sizeof(*c->li); - ms->c.li = CAST(struct level_info *, malloc(len)); + ms->c.li = CAST(struct level_info *, emalloc(len)); if (ms->c.li == NULL) { ms->c = *c; return -1; @@ -1556,7 +1570,7 @@ save_cont(struct magic_set *ms, struct cont *c) private void restore_cont(struct magic_set *ms, struct cont *c) { - free(ms->c.li); + efree(ms->c.li); ms->c = *c; } @@ -1878,15 +1892,15 @@ mget(struct magic_set *ms, struct magic *m, const struct buffer *b, if ((ms->flags & MAGIC_NODESC) == 0 && file_printf(ms, F(ms, m->desc, "%u"), offset) == -1) { - free(rbuf); + if (rbuf) efree(rbuf); return -1; } if (file_printf(ms, "%s", rbuf) == -1) { - free(rbuf); + if (rbuf) efree(rbuf); return -1; } } - free(rbuf); + if (rbuf) efree(rbuf); return rv; case FILE_USE: @@ -2057,6 +2071,60 @@ alloc_regex(struct magic_set *ms, struct magic *m) return NULL; } +public zend_string* convert_libmagic_pattern(const char *val, size_t len, uint32_t options) +{ + int i, j; + zend_string *t; + + for (i = j = 0; i < len; i++) { + switch (val[i]) { + case '~': + j += 2; + break; + case '\0': + j += 4; + break; + default: + j++; + break; + } + } + t = zend_string_alloc(j + 4, 0); + + j = 0; + ZSTR_VAL(t)[j++] = '~'; + + for (i = 0; i < len; i++, j++) { + switch (val[i]) { + case '~': + ZSTR_VAL(t)[j++] = '\\'; + ZSTR_VAL(t)[j] = '~'; + break; + case '\0': + ZSTR_VAL(t)[j++] = '\\'; + ZSTR_VAL(t)[j++] = 'x'; + ZSTR_VAL(t)[j++] = '0'; + ZSTR_VAL(t)[j] = '0'; + break; + default: + ZSTR_VAL(t)[j] = val[i]; + break; + } + } + ZSTR_VAL(t)[j++] = '~'; + + if (options & PCRE2_CASELESS) + ZSTR_VAL(t)[j++] = 'i'; + + if (options & PCRE2_MULTILINE) + ZSTR_VAL(t)[j++] = 'm'; + + ZSTR_VAL(t)[j]='\0'; + ZSTR_LEN(t) = j; + + return t; +} + private int magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache) { @@ -2218,8 +2286,8 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache) idx = m->str_range + slen; if (m->str_range == 0 || ms->search.s_len < idx) idx = ms->search.s_len; - found = CAST(const char *, memmem(ms->search.s, idx, - m->value.s, slen)); + found = CAST(const char *, php_memnstr(ms->search.s, + m->value.s, slen, ms->search.s + idx)); if (!found) { v = 1; break; @@ -2229,7 +2297,6 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache) ms->search.rm_len = ms->search.s_len - idx; break; } -#endif for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) { if (slen + idx > ms->search.s_len) { @@ -2248,55 +2315,80 @@ magiccheck(struct magic_set *ms, struct magic *m, file_regex_t **m_cache) break; } case FILE_REGEX: { - int rc; - file_regex_t *rx = *m_cache; - const char *search; - regmatch_t pmatch; - size_t slen = ms->search.s_len; - char *copy; + zend_string *pattern; + uint32_t options = 0; + pcre_cache_entry *pce; - if (ms->search.s == NULL) - return 0; + options |= PCRE2_MULTILINE; - if (rx == NULL) { - rx = *m_cache = alloc_regex(ms, m); - if (rx == NULL) - return -1; + if (m->str_flags & STRING_IGNORE_CASE) { + options |= PCRE2_CASELESS; } - l = 0; - if (slen != 0) { - copy = CAST(char *, malloc(slen)); - if (copy == NULL) { - file_error(ms, errno, - "can't allocate %" SIZE_T_FORMAT "u bytes", - slen); + + pattern = convert_libmagic_pattern((char *)m->value.s, m->vallen, options); + + l = v = 0; + if ((pce = pcre_get_compiled_regex_cache(pattern)) == NULL) { + zend_string_release(pattern); return -1; } memcpy(copy, ms->search.s, slen); copy[--slen] = '\0'; search = copy; } else { - search = CCAST(char *, ""); - copy = NULL; - } - rc = file_regexec(ms, rx, RCAST(const char *, search), - 1, &pmatch, 0); - free(copy); - switch (rc) { - case 0: - ms->search.s += CAST(int, pmatch.rm_so); - ms->search.offset += CAST(size_t, pmatch.rm_so); - ms->search.rm_len = CAST(size_t, - pmatch.rm_eo - pmatch.rm_so); - v = 0; - break; + /* pce now contains the compiled regex */ + zval retval; + zval subpats; + zend_string *haystack; - case REG_NOMATCH: - v = 1; - break; + ZVAL_NULL(&retval); + ZVAL_NULL(&subpats); - default: - return -1; + /* Cut the search len from haystack, equals to REG_STARTEND */ + haystack = zend_string_init(ms->search.s, ms->search.s_len, 0); + + /* match v = 0, no match v = 1 */ + php_pcre_match_impl(pce, haystack, &retval, &subpats, 0, 1, PREG_OFFSET_CAPTURE, 0); + /* Free haystack */ + zend_string_release(haystack); + + if (Z_LVAL(retval) < 0) { + zval_ptr_dtor(&subpats); + zend_string_release(pattern); + return -1; + } else if ((Z_LVAL(retval) > 0) && (Z_TYPE(subpats) == IS_ARRAY)) { + /* Need to fetch global match which equals pmatch[0] */ + zval *pzval; + HashTable *ht = Z_ARRVAL(subpats); + if ((pzval = zend_hash_index_find(ht, 0)) != NULL && Z_TYPE_P(pzval) == IS_ARRAY) { + /* If everything goes according to the master plan + tmpcopy now contains two elements: + 0 = the match + 1 = starting position of the match */ + zval *match, *offset; + if ((match = zend_hash_index_find(Z_ARRVAL_P(pzval), 0)) && + (offset = zend_hash_index_find(Z_ARRVAL_P(pzval), 1))) { + if (Z_TYPE_P(match) != IS_STRING && Z_TYPE_P(offset) != IS_LONG) { + goto error_out; + } + ms->search.s += Z_LVAL_P(offset); /* this is where the match starts */ + ms->search.offset += Z_LVAL_P(offset); /* this is where the match starts as size_t */ + ms->search.rm_len = Z_STRLEN_P(match) /* This is the length of the matched pattern */; + v = 0; + } else { + goto error_out; + } + } else { +error_out: + zval_ptr_dtor(&subpats); + zend_string_release(pattern); + return -1; + } + } else { + v = 1; + } + zval_ptr_dtor(&subpats); + zend_string_release(pattern); } break; } diff --git a/ext/fileinfo/libmagic/strcasestr.c b/ext/fileinfo/libmagic/strcasestr.c index 3db407f3d8b..4d62787c70d 100644 --- a/ext/fileinfo/libmagic/strcasestr.c +++ b/ext/fileinfo/libmagic/strcasestr.c @@ -39,6 +39,8 @@ __RCSID("$NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $"); #include "file.h" +#include +#include #include #include #include diff --git a/ext/fileinfo/tests/magic b/ext/fileinfo/tests/magic index fb5e08e42d5..4503d1d3c12 100644 --- a/ext/fileinfo/tests/magic +++ b/ext/fileinfo/tests/magic @@ -785,7 +785,7 @@ >16 lelong >0 verifier deps size: %d #------------------------------------------------------------------------------ -# $File: animation,v 1.88 2022/05/14 22:06:04 christos Exp $ +# $File: animation,v 1.90 2022/08/16 11:16:39 christos Exp $ # animation: file(1) magic for animation/movie formats # # animation formats @@ -815,8 +815,6 @@ #!:mime image/x-quicktime 4 string pckg Apple QuickTime compressed archive !:mime application/x-quicktime-player -4 string/W jP JPEG 2000 image -!:mime image/jp2 #### MP4 #### # https://www.ftyps.com/ with local additions @@ -953,6 +951,7 @@ # ?/enc-isoff-generic >8 string iso \b, MP4 Base Media !:mime video/mp4 +!:ext mp4 >>11 string m v1 [ISO 14496-12:2003] >>11 string 2 v2 [ISO 14496-12:2005] >>11 string 4 v4 @@ -1722,6 +1721,7 @@ 0 belong&0xFF5FFF10 0x47400010 >188 byte 0x47 MPEG transport stream data !:mime video/MP2T +!:ext ts # DIF digital video file format 0 belong&0xffffff00 0x1f070000 DIF @@ -2660,7 +2660,7 @@ >>5 ubyte x \b.%u, little-endian >>0 use \^apt-cache-be #------------------------------------------------------------------------------ -# $File: archive,v 1.162 2022/05/27 21:27:59 christos Exp $ +# $File: archive,v 1.169 2022/09/12 13:13:28 christos Exp $ # archive: file(1) magic for archive formats (see also "msdos" for self- # extracting compressed archives) # @@ -2686,7 +2686,16 @@ >>>>>>155 ubyte&0xDF =0 # space or ascii digit 0 at start of check sum >>>>>>>148 ubyte&0xEF =0x20 ->>>>>>>>0 use tar-file +# FOR DEBUGGING: +#>>>>>>>>0 regex \^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp) NAME "%s" +# check for 1st image main name with digits used for sorting +# and for name extension case insensitive like: PNG JPG JPEG TIF TIFF GIF BMP +>>>>>>>>0 regex \^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp) +#foo +>>>>>>>>>0 use tar-cbt +# if 1st member name without digits and without used image suffix then it is a TAR archive +>>>>>>>>0 default x +>>>>>>>>>0 use tar-file # minimal check and then display tar archive information which can also be # embedded inside others like Android Backup, Clam AntiVirus database 0 name tar-file @@ -2807,6 +2816,19 @@ >>508 default x # padding[255] in old tar sometimes comment field >>>257 string >\0 \b, comment: %-.40s +# Summary: Comic Book Archive *.CBT with TAR format +# URL: https://en.wikipedia.org/wiki/Comic_book_archive +# http://fileformats.archiveteam.org/wiki/Comic_Book_Archive +# Note: there exist also RAR, ZIP, ACE and 7Z packed variants +0 name tar-cbt +>0 string x Comic Book archive, tar archive +#!:mime application/x-tar +!:mime application/vnd.comicbook +#!:mime application/vnd.comicbook+tar +!:ext cbt +# name[100] probably like: 19.jpg 0001.png 0002.png +# or maybe like ComicInfo.xml +>0 string >\0 \b, 1st image %-.60s # Incremental snapshot gnu-tar format from: # https://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html @@ -4385,13 +4407,17 @@ # Felix von Leitner 0 string d8:announce BitTorrent file !:mime application/x-bittorrent +!:ext torrent # Durval Menezes, 0 string d13:announce-list BitTorrent file !:mime application/x-bittorrent +!:ext torrent 0 string d7:comment BitTorrent file !:mime application/x-bittorrent +!:ext torrent 0 string d4:info BitTorrent file !:mime application/x-bittorrent +!:ext torrent # Atari MSA archive - Teemu Hukkanen # URL: http://fileformats.archiveteam.org/wiki/MSA_(Magic_Shadow_Archiver) @@ -4743,6 +4769,9 @@ # Note: Line 1186 of paq9a.cpp gives the magic bytes 0 string pQ9\001 PAQ9A archive +# From wof (wof@stachelkaktus.net) +0 string Unison\ archive\ format Unison archive format + #------------------------------------------------------------------------------ # URL: https://de.wikipedia.org/wiki/Aria_(Software) # Reference: https://github.com/aria2/aria2/blob/master/doc/manual-src/en/technical-notes.rst @@ -5032,7 +5061,7 @@ >364 string >\0 of '%s' #------------------------------------------------------------------------------ -# $File: audio,v 1.121 2021/04/26 15:56:00 christos Exp $ +# $File: audio,v 1.124 2022/08/28 08:58:20 christos Exp $ # audio: file(1) magic for sound formats (see also "iff") # # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com), @@ -5435,10 +5464,26 @@ 0 string THX AHX version >3 byte =0 1 module data >3 byte =1 2 module data ->10 byte x TRL: %u ->11 byte x TRK: %u ->12 byte x SMP: %u ->13 byte x SS: %u +>11 ubyte x TRK: %u +>10 ubyte x TRL: %u +>12 ubyte x SMP: %u +>13 ubyte x SS: %u +>(4.H) string x Title: "%.128s" + +# header is mostly AHX format +0 string HVL +>3 byte <2 Hively Tracker Song +>3 byte =0 v1 module data +>3 byte =1 v2 module data +>11 ubyte x TRK: %u +>10 ubyte x TRL: %u +>12 ubyte x SMP: %u +>13 ubyte x SS: %u +>8 ubyte/4 =0 CHN: 4 +>8 ubyte/4 >0 CHN: 4+%u +#>-0 offset <0xffff +>(4.H) string x Title: "%.128s" + # 0 string OKTASONG Oktalyzer module data # @@ -5580,15 +5625,13 @@ # From: Alex Myczko # https://github.com/rerrahkr/BambooTracker -0 string BambooTrackerMod BambooTracker module ->22 byte x \b, version %u ->21 byte x \b.%u ->20 byte x \b.%u - -0 string BambooTrackerIst BambooTracker instrument ->22 byte x \b, version %u ->21 byte x \b.%u ->20 byte x \b.%u +0 string BambooTracker BambooTracker +>13 string Mod Module +>13 string Ist Instrument +>13 string Bnk Bank +>22 byte x \b, version %u +>21 byte x \b.%u +>20 byte x \b.%u 0 string CC2x CheeseCutter 2 song @@ -5926,11 +5969,6 @@ >0x3 byte&0x0F x \b%02d >>0x4 string >\0 title: "%s" -0 string HVL ->3 byte <2 Hively Tracker Song ->3 byte 0 1 module data ->3 byte 1 2 module data - 0 string MO3 >3 ubyte <6 MOdule with MP3 >>3 byte 0 Version 0 (With MP3 and lossless) @@ -6169,6 +6207,135 @@ >4 beshort 0xFEFF >>0 use \^nintendo-3ds-bcwav-fields +# Philips DSDIFF audio format (Direct Stream Digital Interchange File Format) +# Used for DSD audio recordings and Super Audio CD (SACD) mastering annotations +# https://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf +# From: Toni Ruottu +0 string FRM8 +12 string DSD\x20 DSDIFF audio bitstream data +!:mime audio/x-dff +!:ext dff + +# format version chunk +>&0 string FVER +# version 1 +>>&8 byte 1 + +# v1 / sampling resolution ( 1 bit PDM only ) +>>>&0 string x \b, 1 bit + +# v1 / sound property chunk +>>>&0 search/0xff PROP +>>>>&8 string SND + +# v1 / sound property chunk / channel configuration chunk +>>>>>&0 search/0xff CHNL +>>>>>>&8 ubeshort 1 \b, mono +>>>>>>&8 ubeshort 2 +>>>>>>>&0 string SLFTSRGT \b, stereo +>>>>>>>&0 default x \b, 2 channels +>>>>>>&8 ubeshort 3 +>>>>>>>&0 string SLFTSRGTLFE\x20 \b, 2.1 stereo +>>>>>>>&0 string SLFTSRGTC\x20\x20\x20 \b, 3.0 stereo +>>>>>>>&0 default x \b, 3 channels +>>>>>>&8 ubeshort 4 +>>>>>>>&0 string MLFTMRGTLS\x20\x20RS\x20\x20 \b, 4.0 surround +>>>>>>>&0 string SLFTSRGTC\x20\x20\x20LFE\x20 \b, 3.1 stereo +>>>>>>>&0 default x \b, 4 channels +>>>>>>&8 ubeshort 5 +>>>>>>>&0 string MLFTMRGTC\x20\x20\x20LS\x20\x20RS\x20\x20 \b, 5.0 surround +>>>>>>>&0 string MLFTMRGTLFE\x20LS\x20\x20RS\x20\x20 \b, 4.1 surround +>>>>>>>&0 default x \b, 5 channels +>>>>>>&8 ubeshort 6 +>>>>>>>&0 string MLFTMRGTC\x20\x20\x20LFE\x20LS\x20\x20RS\x20\x20 \b, 5.1 surround +>>>>>>>&0 default x \b, 6 channels +>>>>>>&8 ubeshort >6 \b, %u channels + +# v1 / sound property chunk / sample rate chunk +>>>>>&0 search/0xff FS\x20\x20 +>>>>>>&0 string x \b, +>>>>>>&8 ubelong%44100 0 +>>>>>>>&-4 ubelong/44100 x "DSD %u" +>>>>>>>&-4 ubelong x %u Hz + +# v1 / sound property chunk / compression type chunk +>>>>>&0 search/0xff CMPR +>>>>>>&8 string DSD\x20 \b, no compression +>>>>>>&8 string DST\x20 \b, DST compression +>>>>>>&8 default x \b, unknown compression + +# v1 / quest for metadata +>>>&0 string x + +# v1 / quest for metadata / edited master information chunk +>>>>&0 search DIIN +>>>>>&0 ubequad >0 \b, "edited master" metadata + +# v1 / quest for metadata / ID3 chunk ( defacto standard ) +>>>>&0 search ID3\x20 +>>>>>&8 string ID3 \b, ID3 version 2 +>>>>>&0 byte x \b.%u +>>>>>&1 byte x \b.%u + +# v1 / quest for metadata / failure ( possibly due to -P bytes=... being too low ) +>>>>&0 default x \b, ID3 missing (or unreachable) + +# version > 1 or 0 +>>&0 default x \b, unknown version + +# Sony DSF audio format (Direct Stream Digital Stream File) +# Used for lossless digital storage of songs produced as DSD audio +# Portable analog of a track stored on a Super Audio CD (SACD) +# https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf +# From: Toni Ruottu +0 string DSD\x20 DSF audio bitstream data +!:mime audio/x-dsf +!:ext dsf + +# format chunk +>28 string fmt\x20 +# version 1 +>>&8 ulelong 1 + +# v1 / sampling resolution ( 1 bit PDM only ) +# NOTE: the spec incorrectly uses "bits per sample" instead of "bits per byte" +>>>&0 string x \b, 1 bit + +# v1 / channel configuration +>>>>&4 ulelong 1 \b, mono +>>>>&4 ulelong 2 \b, stereo +>>>>&4 ulelong 3 \b, 3.0 stereo +>>>>&4 ulelong 4 \b, 4.0 surround +>>>>&4 ulelong 5 \b, 3.1 stereo +>>>>&4 ulelong 6 \b, 5.0 surround +>>>>&4 ulelong 7 \b, 5.1 surround +>>>>&0 default x +>>>>>&4 ulelong x \b, %u channels + +# v1 / sample rate chunk +>>>>&0 string x \b, +>>>>&12 ulelong%44100 0 +>>>>>&-4 ulelong/44100 x "DSD %u" +>>>>&12 ulelong x %u Hz + +# v1 / compression +>>>>&0 string x +>>>>>&0 ulelong 0 \b, no compression +>>>>>&0 default x \b, unknown compression + +# v1 / embedded ID3v2 metadata +>>>0 string x \b, ID3 +>>>>20 ulequad !0 +>>>>>(20.q) string ID3 version 2 +>>>>>>&0 byte x \b.%u +>>>>>>&1 byte x \b.%u +# unable to verify ID3 ( possibly due to -P bytes=... being too low ) +>>>>>&0 default x unreachable +>>>>&0 default x missing + +# version > 1 or 0 +>>&0 default x \b, unknown version + #------------------------------------------------------------------------------ # $File: avm,v 1.1 2020/08/28 20:37:58 christos Exp $ # avm: file(1) magic for avm files; this is not use @@ -6821,6 +6988,13 @@ >12 belong 1004 HCI Serial (H5) >>12 belong x type %d +#------------------------------------------------------------ +# $File: burp,v 1.1 2022/07/04 17:15:09 christos Exp $ +# Burp file, I don't know the version +#------------------------------------------------------------ +# From wof (wof@stachelkaktus.net) +0 bequad 0x6685828000000001 Burp project save file + #------------------------------------------------------------ # $File: bytecode,v 1.3 2022/03/24 15:48:58 christos Exp $ # magic for various bytecodes @@ -7457,7 +7631,7 @@ !:ext amf #------------------------------------------------------------------------------ -# $File: cafebabe,v 1.27 2021/04/26 15:56:00 christos Exp $ +# $File: cafebabe,v 1.28 2022/07/01 23:24:47 christos Exp $ # Cafe Babes unite! # # Since Java bytecode and Mach-O universal binaries have the same magic number, @@ -7501,6 +7675,12 @@ >>4 belong 0x0038 (Java SE 12) >>4 belong 0x0039 (Java SE 13) >>4 belong 0x003A (Java SE 14) +>>4 belong 0x003B (Java SE 15) +>>4 belong 0x003C (Java SE 16) +>>4 belong 0x003D (Java SE 17) +>>4 belong 0x003E (Java SE 18) +>>4 belong 0x003F (Java SE 19) +>>4 belong 0x0040 (Java SE 20) # pool count unequal zero #>>8 beshort x \b, pool count %#x # pool table @@ -8233,7 +8413,7 @@ 0 string msc Message Sequence Chart (chart) 0 string submsc Message Sequence Chart (subchart) #------------------------------------------------------------------------------ -# $File: compress,v 1.82 2021/06/30 08:11:29 christos Exp $ +# $File: compress,v 1.83 2022/08/16 11:16:39 christos Exp $ # compress: file(1) magic for pure-compression formats (no archives) # # compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc. @@ -8381,6 +8561,7 @@ # bzip2 0 string BZh bzip2 compressed data !:mime application/x-bzip2 +!:ext bz2 >3 byte >47 \b, block size = %c00k # bzip a block-sorting file compressor @@ -10103,7 +10284,7 @@ >15 long >30 $BS, block size: %i bytes #------------------------------------------------------------------------------ -# $File: database,v 1.66 2022/02/26 17:42:21 christos Exp $ +# $File: database,v 1.67 2022/07/12 18:57:42 christos Exp $ # database: file(1) magic for various databases # # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk) @@ -10511,8 +10692,10 @@ >>>>>>>>>0 ulelong <0x400000 # skip WinStore.App.exe by looking for printable 2nd character of 1st memo item >>>>>>>>>>513 ubyte >037 +# skip DOS executables CPQ0TD.DRV E30ODI.COM IBM0MONO.DRV by looking for printable 1st character of 1st memo item +>>>>>>>>>>>512 ubyte >037 # unusual dBASE III DBT like adressen.dbt ->>>>>>>>>>>0 use dbase3-memo-print +>>>>>>>>>>>>0 use dbase3-memo-print # dBASE III DBT like angest.dbt, or garbage PCX DBF >>>>>>>>8 ubelong !0 # skip PCX and some DBF by test for for reserved NULL bytes @@ -11000,7 +11183,7 @@ !:ext dbpf/package/dat/sc4 !:mime application/x-maxis-dbpf #------------------------------------------------------------------------------ -# $File: der,v 1.4 2021/03/14 17:12:04 christos Exp $ +# $File: der,v 1.5 2022/07/30 18:07:34 christos Exp $ # der: file(1) magic for DER encoded files # @@ -11111,9 +11294,9 @@ >>>>&0 der seq >>>>>&0 der obj_id9=2a864886f70d010901 >>>>>&0 der ia5_str=x \b, emailAddress=%s ->>&0 der seq ->>>&0 der utc_time=x \b, utcTime=%s ->>>&0 der utc_time=x \b, utcTime=%s +#>>&0 der seq +#>>>&0 der utc_time=x \b, utcTime=%s +#>>>&0 der utc_time=x \b, utcTime=%s >>&0 use certinfo 0 der seq @@ -11130,9 +11313,9 @@ >>>>&0 der seq >>>>>&0 der obj_id3=550403 >>>>>&0 der utf8_str=x \b, Issuer=%s ->>&0 der seq ->>>&0 der utc_time=x \b, not-valid-before=%s ->>>&0 der utc_time=x \b, not-valid-after=%s +#>>&0 der seq +#>>>&0 der utc_time=x \b, not-valid-before=%s +#>>>&0 der utc_time=x \b, not-valid-after=%s >>&0 der seq >>>&0 der set >>>>&0 der seq @@ -12182,7 +12365,7 @@ 0 string FCS3.0 Flow Cytometry Standard (FCS) data, version 3.0 #------------------------------------------------------------------------------ -# $File: filesystems,v 1.149 2022/05/21 22:50:28 christos Exp $ +# $File: filesystems,v 1.150 2022/07/04 16:40:33 christos Exp $ # filesystems: file(1) magic for different filesystems # 0 name partid @@ -14845,6 +15028,32 @@ >>0x107b byte x \b, %d devices >>0x1090 byte ^0x02 \b (unclean) +# EROFS +# https://kernel.googlesource.com/pub/scm/linux/kernel/git/xiang/erofs-utils/\ +# +/refs/heads/experimental/include/erofs_fs.h#12 +1024 lelong 0xE0F5E1E2 EROFS filesystem +#>1028 lelong x \b, checksum=%#x +>1032 lelong >0 \b, compat: +>>1032 lelong &1 SB_CHKSUM +>>1032 lelong &2 MTIME +>1036 byte x \b, blocksize=%u +>1037 byte x \b, exslots=%u +#>1038 leshort x \b, root_nid=%d +#>1040 lequad x \b, inodes=%ld +#>1048 leldate x \b, build_time=%s +#>1056 lelong x \b.%d +#>1060 lelong x \b, blocks=%d +#>1064 lelong x \b, metadata@%#x +#>1068 lelong x \b, xattr@%#x +>1072 guid x \b, uuid=%s +>1088 string >0 \b, name=%s +>1104 lelong >0 \b, incompat: +>>1104 lelong &1 LZ4_0PADDING +>>1104 lelong &2 BIG_PCLUSTER +>>1104 lelong &4 CHUNKED_FILE +>>1104 lelong &8 DEVICE_TABLE +>>1104 lelong &16 ZTAILPACKING + #------------------------------------------------------------------------------ # $File: finger,v 1.3 2019/04/19 00:42:27 christos Exp $ # fingerprint: file(1) magic for fingerprint data @@ -14960,7 +15169,7 @@ >>4 string =d \b, RGBA, interlaced #------------------------------------------------------------------------------ -# $File: fonts,v 1.50 2022/03/21 21:28:13 christos Exp $ +# $File: fonts,v 1.51 2022/08/16 11:16:39 christos Exp $ # fonts: file(1) magic for font data # 0 search/1 FONT ASCII vfont text @@ -15402,6 +15611,7 @@ # https://www.w3.org/TR/WOFF2/ 0 string wOF2 Web Open Font Format (Version 2) !:mime font/woff2 +!:ext woff2 >0 use woff #>20 belong x \b, totalCompressedSize %d >24 beshort x \b, version %d @@ -16402,6 +16612,86 @@ # From: Marek Cermak # 0 lelong 0x20010324 gconv module configuration cache data +#------------------------------------------------------------------------------ +# $File: gentoo,v 1.2 2022/09/12 13:13:28 christos Exp $ +# gentoo: file(1) magic for gentoo specific formats +# +# Summary: Gentoo ebuild Manifest files (GLEP 74) +# Reference: https://www.gentoo.org/glep/glep-0074.html +# Submitted by: Michal Gorny +# Start by doing a fast check for the most common tags. +0 string AUX +>0 use gentoo-manifest +0 string DATA +>0 use gentoo-manifest +0 string DIST +>0 use gentoo-manifest +0 string EBUILD +>0 use gentoo-manifest +0 string MANIFEST +>0 use gentoo-manifest + +# Manifest can be PGP-signed. +0 string -----BEGIN\040PGP\040SIGNED\040MESSAGE----- +>34 search/32 \n\n +>>&0 string AUX +>>>&0 use gentoo-manifest +>>&0 string DATA +>>>&0 use gentoo-manifest +>>&0 string DIST +>>>&0 use gentoo-manifest +>>&0 string EBUILD +>>>&0 use gentoo-manifest +>>&0 string MANIFEST +>>>&0 use gentoo-manifest + +# Use a more detailed regex to verify that we were correct. +# ... +# ('s already been matched prior to calling) +0 name gentoo-manifest +>&0 regex [[:space:]]+[[:print:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:alnum:]]+[[:space:]]+[[:xdigit:]]{32} Gentoo Manifest (GLEP 74) + +# Summary: Gentoo ebuild and eclass files +# Reference: https://projects.gentoo.org/pms/8/pms.html +# Submitted by: Michal Gorny +0 search/512 EAPI= +>0 regex .*\n[\040\t]*EAPI=["']? Gentoo ebuild +>>&0 regex [[:alnum:]+_.-]+ \b, EAPI %s + +0 search/512 @ECLASS:\040 Gentoo eclass +>&0 string x %s + +# Summary: Gentoo supplementary package and category metadata files +# Reference: https://www.gentoo.org/glep/glep-0068.html +# Submitted by: Michal Gorny +0 string \0 search/512 \0 search/512 \ + +# GPKG uses ustar (or ustar-compatible GNU format) that starts with +# a /gpkg-1 file +257 string ustar +>0 search/100 /gpkg-1\0 +>>0 regex [^/]+ Gentoo GLEP 78 (GPKG) binary package for "%s" +!:mime application/x-tar +!:ext tar +# the logic below requires the gpkg-1 file to be empty +>>>124 string 00000000000\0 +# determine the compression used by looking at the second member name +>>>>512 search/100 .tar. +>>>>>&0 string gz\0 using gzip compression +>>>>>&0 string bz2\0 using bzip2 compression +>>>>>&0 string lz\0 using lzip compression +>>>>>&0 string lz4\0 using lz4 compression +>>>>>&0 string lzo\0 using lzo compression +>>>>>&0 string xz\0 using xz compression +>>>>>&0 string zst\0 using zstd compression +>>>>(636.o+1024) search/611 .sig\0 \b, signed #------------------------------------------------------------------------------ # $File: geo,v 1.8 2022/03/24 15:48:58 christos Exp $ @@ -18136,7 +18426,7 @@ !:mime application/x-blorb #------------------------------------------------------------------------------ -# $File: images,v 1.223 2022/05/14 20:05:09 christos Exp $ +# $File: images,v 1.227 2022/09/11 20:58:52 christos Exp $ # images: file(1) magic for image formats (see also "iff", and "c-lang" for # XPM bitmaps) # @@ -18501,7 +18791,7 @@ >>>8 default x >>>>8 uleshort x \b(unknown %#x) >>>12 use tiff_entry ->0 uleshort 0x106 \b, PhotometricIntepretation= +>0 uleshort 0x106 \b, PhotometricInterpretation= >>8 clear x >>8 uleshort 0 \bWhiteIsZero >>8 uleshort 1 \bBlackIsZero @@ -19594,7 +19884,25 @@ >2 quad !0 # skip g3test.g3 by test for unused bits of 2nd color entry >>4 ubeshort&0xF000 0 ->>>0 use degas-bitmap +#>>>0 beshort x 1ST_VALUE=%x +>>>-0 offset x FILE_SIZE=%lld +# standard DEGAS low-res uncompressed bitmap *.pi1 with file size 32034 +>>>-0 offset =32034 VARIANT_STANDARD +#>>>>0 beshort x 1st_VALUE=%x +# like: 8ball.pi1 teddy.pi1 sonic01.pi1 +>>>>0 use degas-bitmap +# about 61 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32066 +>>>-0 offset =32066 VARIANT_ELITE +# like: spider.pi1 pinkgirl.pi1 frog3.pi1 +>>>>0 use degas-bitmap +# about 55 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32128 +>>>-0 offset =32128 VARIANT_3 +# like: mountain.pi1 bigspid.pi1 alf33.pi1 +>>>>0 use degas-bitmap +# 1 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 44834 +>>>-0 offset =44834 VARIANT_4 +# like: kenshin.pi1 +>>>>0 use degas-bitmap # DEGAS mid-res uncompressed bitmap *.pi2 (strength=50) after GEM Images like: # BEETHVEN.IMG CHURCH.IMG GAMEOVR4.IMG TURKEY.IMG clinton.img 0 beshort 0x0001 @@ -20346,10 +20654,104 @@ # height (80,90) >>0x53 uleshort x \b%d +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Imageiio/imaginfo_(Ulead) +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe3.trid.xml +# Note: called "Ulead Imageiio/Imaginfo thumbnail" by TrID +0 string IIO1$ Ulead Photo Explorer 3 +#!:mime application/octet-stream +!:mime image/x-ulead-pe3 +# IMAGEIIO.PE3 +!:ext pe3 +# look for DOS/Windows drive letter +>5 search/192/s :\\ +# directory or full name of corresponding imaginfo.pe3 like: "T:\SAMPLES\TEXTURES\SKY_SNOW\IIOE371.TMP "S:\PI3\PIMPACT3\PROGRAMS\PATTERNS\imaginfo.pe3" +>>&-1 string x "%s" +# look for DOS/Windows network path if no drive letter part +>5 default x +>>5 search/192/s \x5c\x5c +# full name of corresponding imaginfo.pe3 like: "\\Lionking\upi\SAMPLES\IMAGES\ANIMALS\imaginfo.pe3" +>>>&0 string x "%s" # Type: Ulead Photo Explorer5 (.pe5) -# URL: http://www.jisyo.com/cgibin/view.cgi?EXT=pe5 (Japanese) +# URL: http://fileformats.archiveteam.org/wiki/Imageiio/imaginfo_(Ulead) +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe4.trid.xml # From: Simon Horman -0 string IIO2H Ulead Photo Explorer5 +# Update: Joerg Jenderek +# Note: some called "Ulead Imageiio/Imaginfo thumbnail" by TrID +# and used in various Ulead applications +0 string IIO2H Ulead Photo Explorer 4 or 5 +#!:mime application/octet-stream +!:mime image/x-ulead-pe4 +# IMAGEIIO.PE4 +!:ext pe4/pe5 +# look in most samples for JPEG signature like: SAMPLES/IMAGES/SCENES/IMAGINFO.PE4 +>0x4c2 search/0xE02/s JFIF with JPEG image data +>>&-6 use jpeg +# near the end list of image names like: Img0001.pcd 1116012L.JPG NCARD4.TPL +# +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe3-imaginfo.trid.xml +11 string \001\0\0\0\0 +# check for version 3 part +>19 string \0\001\0\003\0 +>>0 use ulead-imaginfo +# From: Joerg Jenderek +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe4-imaginfo.trid.xml +11 string \001\0\0\0\0 +# check for version 4 part +>19 string \0\0\0\004\0 +>>0 use ulead-imaginfo +# display information about Ulead Imaginfo thumbnail (version, directory, image extension) +0 name ulead-imaginfo +>22 ubyte x Ulead Imaginfo thumbnail +#!:mime application/octet-stream +!:mime image/x-ulead-imaginfo +>22 ubyte =3 \b, version 3 +# IMAGINFO.PE3 +!:ext pe3 +>22 ubyte =4 \b, version 4 +# IMAGINFO.PE4 +!:ext pe4 +# MAYBE ALSO VERSION 5 ? +#>22 ubyte =5 \b, version 5 +#!:ext pe5 +>22 ubyte x +# look for DOS/Windows driver letter +>>4 search/192/s :\x5c +# skip f:\Programme\iPhoto Plus 4\Template\Business Cards\IMAGINFO.PE4 +# by looking for driver letter in range A-Z +>>>&-1 ubyte >0x40 +# directory path like: "E:\iPE\CDSample\Images\Scenes" "D:\XmasCard\Samples" "C:\TEMP\PLANTS" +>>>>&-5 pstring/l >0 \b, "%s" +# look for DOS/Windows network path if no valid drive letter part +>>>&-1 default x +>>>>4 search/192/s \x5c\x5c +# directory path like: "\\FSX\SYS\OPPS\IPE.ENG\TEMPLATE\BUSINESS" "\\Lionking\upi\SAMPLES\IMAGES\ANIMALS" +>>>>>&-4 pstring/l >0 \b, "%s" +# look for DOS/Windows network path if no drive letter part +>>4 default x +>>>4 search/192/s \x5c\x5c +# directory path like: "\\FSX\SYS\opps\ipe.eng\samples" "\\DANIEL\IPE_CD\IPE.ITA" +>>>>&-4 pstring/l >0 \b, "%s" +# look for point character inside image names +>56 search/38/s . +# image name extension like: bmp jpg pcd tpl +>>&1 string x with %-.3s images +# Summary: Ulead Pattern image (Corel Corporation) +# URL: https://en.wikipedia.org/wiki/Ulead_Systems +# https://www.file-extensions.org/pst-file-extension-ulead-pattern-image-format +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pst-ulead.trid.xml +# From: Joerg Jenderek +# Note: used also by CorelDraw Essentials 3 version 13.0.0.800 +# there seems to exist other versions +0 ubelong 0xFFFF0100 +>8 search/21 PresetInfo Ulead pattern image +#!:mime application/octet-stream +!:mime image/x-ulead-pst +!:ext pst +# string length like: 16 18 19 21 24 +#>>4 uleshort x n=%u +# like: BlendPresetInfo DropShadowPresetInfo FileNewPresetInfo VectorExtrudePresetInfo EnvelopePresetInfo ContourPresetInfo DistortionPresetInfo +>>4 pstring/h x "%s" # Type: X11 cursor # URL: http://webcvs.freedesktop.org/mime/shared-mime-info/freedesktop.org.xml.in?view=markup @@ -21951,6 +22353,17 @@ >0x24 ulelong 2 \b, embedded WebP image >0x24 ulelong 3 \b, Basis Universal +# Summary: iCEDraw graphic *.IDF +# URL: http://fileformats.archiveteam.org/wiki/ICEDraw +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/i/idf-icedraw.trid.xml +# From: Joerg Jenderek +# Note: called "iCEDraw graphic" by TrID, "iCEDraw text" by FFmpeg and "iCE Draw" by Ansilove +# verified by FFmpeg command `ffprobe ICE-9605.IDF` and `ansilove -s SQ-FORCE.IDF` +0 string \0041.4\0\0\0\0O\0 iCEDraw graphic +#!:mime application/octet-stream +!:mime image/x-idf +!:ext idf + #------------------------------------------------------------------------------ # $File: inform,v 1.5 2009/09/19 16:28:09 christos Exp $ # inform: file(1) magic for Inform interactive fiction language @@ -22413,7 +22826,7 @@ !:mime application/x-java-image #------------------------------------------------------------------------------ -# $File: javascript,v 1.3 2021/12/08 13:42:00 christos Exp $ +# $File: javascript,v 1.4 2022/09/02 08:08:17 christos Exp $ # javascript: magic for javascript and node.js scripts. # 0 string/w #!/bin/node Node.js script text executable @@ -22434,8 +22847,107 @@ 0 lequad 0x1F1903C103BC1FC6 Hermes JavaScript bytecode >8 lelong x \b, version %d +# v8 JavaScript engine bytecode +# From: Alexandre Iooss +# URL: https://v8.dev/docs/ignition +# Note: used in bytenode and NW.js protected source code +# V8 bytecode extraction was added in NodeJS v5.7.0 (V8 4.6.85.31). +# Version information is provided for some v8 versions found in NodeJS releases. +2 uleshort =0xC0DE +>0 ulelong^0xC0DE0000 >0 +# Reservation table starts at 40 +>>40 ulelong&0xFFFFFF00 =0x80000000 +# Stub keys present +>>>24 ulelong >0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0xEE4BF478 version 5.1.281.111, +>>>>4 ulelong =0xC4A0100C version 5.5.372.43, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x cpu features: %#08X, +>>>>16 ulelong x flag hash: %#08X, +>>>>20 ulelong x %u reservations, +>>>>28 ulelong x payload size: %u bytes, +>>>>32 ulelong x checksum1: %#08X, +>>>>36 ulelong x checksum2: %#08X +# No stub keys +>>>24 ulelong =0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x54F0AD81 version 6.2.414.46, +>>>>4 ulelong =0X7D1BF182 version 6.2.414.54, +>>>>4 ulelong =0x35BA122E version 6.2.414.77, +>>>>4 ulelong =0X9319F9C2 version 6.2.414.78, +>>>>4 ulelong =0xB1240060 version 6.6.346.32, +>>>>4 ulelong =0x2B757060 version 6.7.288.46, +>>>>4 ulelong =0x09D147AA version 6.7.288.49, +>>>>4 ulelong =0xF4D4F48A version 6.8.275.32, +>>>>4 ulelong =0xD3961326 version 7.0.276.38, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x cpu features: %#08X, +>>>>16 ulelong x flag hash: %#08X, +>>>>20 ulelong x %u reservations, +>>>>28 ulelong x payload size: %u bytes, +>>>>32 ulelong x checksum1: %#08X, +>>>>36 ulelong x checksum2: %#08X +# Reservation table starts at 32 +>>32 ulelong&0xFFFFFF00 =0x80000000 +# Second checksum present +>>>28 ulelong >0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x21DDF627 version 7.4.288.21, +>>>>4 ulelong =0x1FC9FE84 version 7.4.288.27, +>>>>4 ulelong =0x60A99E8B version 7.5.288.22, +>>>>4 ulelong =0x4F665E90 version 7.6.303.29, +>>>>4 ulelong =0xC7ACFCDE version 7.7.299.11, +>>>>4 ulelong =0x7F641D8F version 7.7.299.13, +>>>>4 ulelong =0xFD9A4F2E version 7.8.279.17, +>>>>4 ulelong =0x3A845324 version 7.8.279.23, +>>>>4 ulelong =0xFF52FEAF version 7.9.317.25, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x flag hash: %#08X, +>>>>16 ulelong x %u reservations, +>>>>20 ulelong x payload size: %u bytes, +>>>>24 ulelong x checksum1: %#08X, +>>>>28 ulelong x checksum2: %#08X +# No second checksum +>>>28 ulelong =0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x8725E0F8 version 8.1.307.30, +>>>>4 ulelong =0x09ED1289 version 8.1.307.31, +>>>>4 ulelong =0xA5728C87 version 8.3.110.9, +>>>>4 ulelong =0xB45C5D30 version 8.4.371.23, +>>>>4 ulelong =0xED9C278B version 8.4.371.19, +>>>>4 ulelong =0xD27BFF42 version 8.6.395.16, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x flag hash: %#08X, +>>>>16 ulelong x %u reservations, +>>>>20 ulelong x payload size: %u bytes, +>>>>24 ulelong x payload checksum: %#08X +# No reservation table and code starts at 24 +>>32 ulelong =0 +>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>4 ulelong =0x9A6F0B0F version 9.0.257.17, +>>>4 ulelong =0x271D5D1E version 9.0.257.24, +>>>4 ulelong =0x4EEA75DF version 9.0.257.25, +>>>4 ulelong =0x80809479 version 9.1.269.36, +>>>4 ulelong =0x55C46F65 version 9.1.269.38, +>>>4 ulelong =0x8A9C758A version 9.2.230.21, +>>>4 ulelong =0x9712F0E1 version 9.3.345.16, +>>>4 ulelong =0x29593715 version 9.4.146.19, +>>>4 ulelong =0xCD991825 version 9.4.146.24, +>>>4 ulelong =0xACDD64EE version 9.4.146.26, +>>>4 ulelong =0xC96B4CD5 version 9.5.172.21, +>>>4 ulelong =0xBCCE4578 version 9.5.172.25, +>>>4 ulelong =0xA2EEA077 version 9.6.180.15, +>>>4 ulelong =0xFD350011 version 10.1.124.8, +>>>4 ulelong =0xBEF4028F version 10.2.154.13, +>>>4 ulelong =0xAF632352 version 10.2.154.4, +>>>8 ulelong x source size: %u bytes, +>>>12 ulelong x flag hash: %#08X, +>>>16 ulelong x payload size: %u bytes, +>>>20 ulelong x payload checksum: %#08X + #------------------------------------------------------------------------------ -# $File: jpeg,v 1.36 2021/08/28 12:30:52 christos Exp $ +# $File: jpeg,v 1.37 2022/06/17 18:03:35 christos Exp $ # JPEG images # SunOS 5.5.1 had # @@ -22538,45 +23050,154 @@ #>>(2.S+2) use jpeg_segment # HSI is Handmade Software's proprietary JPEG encoding scheme +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/HSI_JPEG +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-hsi1.trid.xml +# Note: called by TrID "HSI JPEG bitmap" 0 string hsi1 JPEG image data, HSI proprietary +#!:mime application/octet-stream +!:mime image/x-hsi +!:ext hsi/jpg # From: David Santinoli 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 +# delete from ./animation (version 1.87) with jP (=6A50h) magic at offset 4 # From: Johan van der Knijff # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes # https://github.com/bitsgalore/jp2kMagic # # Now read value of 'Brand' field, which yields a few possibilities: +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JP2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpeg2k.trid.xml +# Note: called by TrID "JPEG 2000 bitmap" >20 string \x6a\x70\x32\x20 Part 1 (JP2) +# aliases image/jpeg2000, image/jpeg2000-image, image/x-jpeg2000-image !:mime image/jp2 +!:ext jp2 +# URL: http://fileformats.archiveteam.org/wiki/JPX +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpx.trid.xml +# Note: called by TrID "JPEG 2000 eXtended bitmap" >20 string \x6a\x70\x78\x20 Part 2 (JPX) !:mime image/jpx +!:ext jpf/jpx +# URL: http://fileformats.archiveteam.org/wiki/JPM +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpm.trid.xml +# Note: called by TrID "JPEG 2000 eXtended bitmap" >20 string \x6a\x70\x6d\x20 Part 6 (JPM) !:mime image/jpm +!:ext jpm +# URL: http://fileformats.archiveteam.org/wiki/MJ2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/v/video-mj2.trid.xml +# Note: called by TrID "Motion JPEG 2000 video" >20 string \x6d\x6a\x70\x32 Part 3 (MJ2) !:mime video/mj2 +!:ext mj2/mjp2 # Type: JPEG 2000 codesream # From: Mathieu Malaterre +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_2000_codestream +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpc.trid.xml +# Note: called by TrID "JPEG-2000 Code Stream bitmap" 0 belong 0xff4fff51 JPEG 2000 codestream -45 beshort 0xff52 +# value like: 0701h FF50h +#>45 ubeshort x \b, at 45 %#4.4x +#!:mime application/octet-stream +# https://reposcope.com/mimetype/image/x-jp2-codestream +!:mime image/x-jp2-codestream +!:ext jpc/j2c/j2k +# MAYBE also JHC like in byte_causal.jhc ? +# WHAT IS THAT? DEAD ENTRY? +#45 beshort 0xff52 # JPEG extended range +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XR +# Reference: https://www.itu.int/rec/T-REC-T.832 +# http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wmp.trid.xml +# Note: called by TrID "JPEG XR bitmap" 0 string \x49\x49\xbc +# FILE_VERSION_ID; shall be equal to 1; other values are reserved for future use >3 byte 1 +# FIRST_IFD_OFFSET; shall be an integer multiple of 2; so skip DROID fmt-590-signature-id-931.wdp >>4 lelong%2 0 JPEG-XR +#!:mime image/vnd.ms-photo !:mime image/jxr -!:ext jxr +# NO example for HDP ! +!:ext jxr/wdp/hdp +# MAYBE also WMP ? +#!:ext jxr/wdp/hdp/wmp +# moved from ./images (version 1.205 ), merged and +# partly verified by XnView `nconvert -info abydos.jxr FLOWER.wdp` +# example: https://web.archive.org/web/20160403012904/ +# http://shikino.co.jp/solution/upfile/FLOWER.wdp.zip +>90 bequad 0x574D50484F544F00 +>>98 byte&0x08 =0x08 \b, hard tiling +>>99 byte&0x80 =0x80 \b, tiling present +>>99 byte&0x40 =0x40 \b, codestream present +>>99 byte&0x38 x \b, spatial xform= +>>99 byte&0x38 0x00 \bTL +>>99 byte&0x38 0x08 \bBL +>>99 byte&0x38 0x10 \bTR +>>99 byte&0x38 0x18 \bBR +>>99 byte&0x38 0x20 \bBT +>>99 byte&0x38 0x28 \bRB +>>99 byte&0x38 0x30 \bLT +>>99 byte&0x38 0x38 \bLB +>>100 byte&0x80 =0x80 \b, short header +>>>102 beshort+1 x \b, %d +>>>104 beshort+1 x \bx%d +>>100 byte&0x80 =0x00 \b, long header +>>>102 belong+1 x \b, %x +>>>106 belong+1 x \bx%x +>>101 beshort&0xf x \b, bitdepth= +>>>101 beshort&0xf 0x0 \b1-WHITE=1 +>>>101 beshort&0xf 0x1 \b8 +>>>101 beshort&0xf 0x2 \b16 +>>>101 beshort&0xf 0x3 \b16-SIGNED +>>>101 beshort&0xf 0x4 \b16-FLOAT +>>>101 beshort&0xf 0x5 \b(reserved 5) +>>>101 beshort&0xf 0x6 \b32-SIGNED +>>>101 beshort&0xf 0x7 \b32-FLOAT +>>>101 beshort&0xf 0x8 \b5 +>>>101 beshort&0xf 0x9 \b10 +>>>101 beshort&0xf 0xa \b5-6-5 +>>>101 beshort&0xf 0xb \b(reserved %d) +>>>101 beshort&0xf 0xc \b(reserved %d) +>>>101 beshort&0xf 0xd \b(reserved %d) +>>>101 beshort&0xf 0xe \b(reserved %d) +>>>101 beshort&0xf 0xf \b1-BLACK=1 +>>101 beshort&0xf0 x \b, colorfmt= +>>>101 beshort&0xf0 0x00 \bYONLY +>>>101 beshort&0xf0 0x10 \bYUV240 +>>>101 beshort&0xf0 0x20 \bYWV422 +>>>101 beshort&0xf0 0x30 \bYWV444 +>>>101 beshort&0xf0 0x40 \bCMYK +>>>101 beshort&0xf0 0x50 \bCMYKDIRECT +>>>101 beshort&0xf0 0x60 \bNCOMPONENT +>>>101 beshort&0xf0 0x70 \bRGB +>>>101 beshort&0xf0 0x80 \bRGBE +>>>101 beshort&0xf0 >0x80 \b(reserved %#x) # JPEG XL # From: Ian Tester +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl.trid.xml +# Note: called by TrID "JPEG XL bitmap" 0 string \xff\x0a JPEG XL codestream -!:mime image/jxl +#!:mime image/jxl +!:mime image/x-jxl !:ext jxl # JPEG XL (transcoded JPEG file) +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl-iso.trid.xml +# Note: called by TrID "JPEG XL bitmap (ISOBMFF)" 0 string \x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a JPEG XL container -!:mime image/jxl +#!:mime image/jxl +!:mime image/x-jxl !:ext jxl #------------------------------------------------------------------------------ @@ -22915,7 +23536,7 @@ #------------------------------------------------------------------------------ -# $File: linux,v 1.80 2022/03/24 15:48:58 christos Exp $ +# $File: linux,v 1.82 2022/09/07 11:23:44 christos Exp $ # linux: file(1) magic for Linux files # # Values for Linux/i386 binaries, from Daniel Quinlan @@ -23279,16 +23900,6 @@ >24 lelong x %d symbols >28 lelong x %d ocons -# LUKS: Linux Unified Key Setup, On-Disk Format, http://luks.endorphin.org/spec -# Anthon van der Neut (anthon@mnt.org) -0 string LUKS\xba\xbe LUKS encrypted file, ->6 beshort x ver %d ->8 string x [%s, ->40 string x %s, ->72 string x %s] ->168 string x UUID: %s - - # Summary: Xen saved domain file # Created by: Radek Vokal 0 string LinuxGuestRecord Xen saved domain @@ -23451,6 +24062,27 @@ >>&0 string ; >>>&0 regex [A-Z0-9]+ \b, encryption %s +# From: Joerg Jenderek +# URL: https://www.gnu.org/software/grub +# Reference: https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz +# grub-2.06/include/grub/keyboard_layouts.h +# grub-2.06/grub-core/commands/keylayouts.c +# GRUB_KEYBOARD_LAYOUTS_FILEMAGIC +0 string GRUBLAYO GRUB Keyboard +!:mime application/x-grub-keyboard +!:ext gkb +# GRUB_KEYBOARD_LAYOUTS_VERSION like: 10 +>8 ulelong !10 \b, version %u +# 4 grub_uint32_t grub_keyboard_layout[160] +# for normal french keyboard this is letter a +>92 ubyte !0x71 +>>92 ubyte >0x40 \b, english q is %c +#>732 ubyte x \b, english Q is %c +# for normal german keyboard this is letter z +>124 ubyte !0x79 +>>124 ubyte >0x40 \b, english y is %c +#>764 ubyte x \b, english Y is %c + #------------------------------------------------------------------------------ # $File: lisp,v 1.27 2020/08/14 19:23:39 christos Exp $ # lisp: file(1) magic for lisp programs @@ -23594,17 +24226,130 @@ >4 byte 0x54 version 5.4 #------------------------------------------------------------------------------ -# $File: luks,v 1.4 2009/09/19 16:28:10 christos Exp $ +# $File: luks,v 1.5 2022/09/07 11:23:44 christos Exp $ # luks: file(1) magic for Linux Unified Key Setup -# URL: http://luks.endorphin.org/spec +# URL: https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup +# http://fileformats.archiveteam.org/wiki/LUKS # From: Anthon van der Neut +# Update: Joerg Jenderek +# Note: verfied by command like `cryptsetup luksDump /dev/sda3` 0 string LUKS\xba\xbe LUKS encrypted file, +# https://reposcope.com/mimetype/application/x-raw-disk-image +!:mime application/x-raw-disk-image +#!:mime application/x-luks-volume +# img is the generic extension; no suffix for partitions; luksVolumeHeaderBackUp via zuluCrypt +!:ext /luks/img/luksVolumeHeaderBackUp +# version like: 1 2 >6 beshort x ver %d +# test for version 1 variant +>6 beshort 1 +>>0 use luks-v1 +# test for version 2 variant +>6 beshort >1 +>>0 use luks-v2 +# Reference: https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/l/luks.trid.xml +# display information about LUKS version 1 +0 name luks-v1 +# cipher-name like: aes twofish >8 string x [%s, +# cipher-mode like: xts-plain64 cbc-essiv >40 string x %s, +# hash specification like: sha256 sha1 ripemd160 >72 string x %s] >168 string x UUID: %s +# NEW PART! +# payload-offset; start offset of the bulk data +>104 ubelong x \b, at %#x data +# key-bytes; number of key bytes; key-bytes*8=MK-bits +>108 ubelong x \b, %u key bytes +# mk-digest[20]; master key checksum from PBKDF2 +>112 ubequad x \b, MK digest %#16.16llx +>>120 ubequad x \b%16.16llx +>>128 ubelong x \b%8.8x +# mk-digest-salt[32]; salt parameter for master key PBKDF2 +>132 ubequad x \b, MK salt %#16.16llx +>>140 ubequad x \b%16.16llx +>>148 ubequad x \b%16.16llx +>>156 ubequad x \b%16.16llx +# mk-digest-iter; iterations parameter for master key PBKDF2 +>164 ubelong x \b, %u MK iterations +# key slot 1 +>208 ubelong =0x00AC71F3 \b; slot #0 +>>208 use luks-slot +# key slot 2 +>256 ubelong =0x00AC71F3 \b; slot #1 +>>256 use luks-slot +# key slot 3 +>304 ubelong =0x00AC71F3 \b; slot #2 +>>304 use luks-slot +# key slot 4 +>352 ubelong =0x00AC71F3 \b; slot #3 +>>352 use luks-slot +# key slot 5 +>400 ubelong =0x00AC71F3 \b; slot #4 +>>400 use luks-slot +# key slot 6 +>448 ubelong =0x00AC71F3 \b; slot #5 +>>448 use luks-slot +# key slot 7 +>496 ubelong =0x00AC71F3 \b; slot #6 +>>496 use luks-slot +# key slot 8 +>544 ubelong =0x00AC71F3 \b; slot #7 +>>544 use luks-slot +# Reference: https://gitlab.com/cryptsetup/LUKS2-docs/-/raw/master/luks2_doc_wip.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/l/luks2.trid.xml +# display information about LUKS version 2 +0 name luks-v2 +# hdr_size; size including JSON area called Metadata area by cryptsetup with value like: 16384 +>8 ubequad x \b, header size %llu +# possible check for MAGIC_2ND after header +#>(8.Q) string SKUL\xba\xbe \b, 2nd_HEADER_OK +# seqid; sequence ID, increased on update; called Epoch by cryptsetup with value like: 3 4 8 10 +>16 ubequad x \b, ID %llu +# label[48]; optional ASCII label or empty; called Label by cryptsetup with value like: "LUKS2_EXT4_ROOT" +>24 string >\0 \b, label %s +# csum_alg[32]; checksum algorithm like: sha256 sha1 sha512 wirlpool ripemd160 +>72 string x \b, algo %s +# salt[64]; salt , unique for every header +>104 ubequad x \b, salt %#llx... +# uuid[40]; UID of device as string like: 242256c6-396e-4a35-af5f-5b70cb7af9a7 +>168 string x \b, UUID: %-.40s +# subsystem[48]; optional owner subsystem label or empty +>208 string >\0 \b, sub label %-.48s +# hdr_offset; offset from device start [ bytes ] like: 0 +>256 ubequad !0 \b, offset %llx +# char _padding [184]; must be zeroed +#>264 ubequad x \b, padding %#16.16llx +#>440 ubequad x \b...%16.16llx +# csum[64]; header checksum +>448 ubequad x \b, crc %#llx... +# char _padding4096 [7*512]; Padding , must be zeroed +#>512 ubequad x \b, more padding %#16.16llx +#>4088 ubequad x \b...%16.16llx +# JSON text data terminated by the zero character; unused remainder empty and filled with zeroes like: +# {"keyslots":{"0":{"type":"luks2","key_size":64,"af":{"type":"luks1","stripes":4000,"hash":"sha256"},"area":{"type":"raw","offse" +>0x1000 string x \b, at 0x1000 %s +#>0x1000 indirect x +# display information (like active) about LUKS1 slot +0 name luks-slot +# state of keyslot; 0x00AC71F3~active 0x0000DEAD~inactive +#>0 ubelong x \b, status %#8.8x +>0 ubelong =0x00AC71F3 active +>0 ubelong =0x0000DEAD inactive +# iteration parameter for PBKDF2 +#>4 ubelong x \b, %u iterations +# salt parameter for PBKDF2 +#>8 ubequad x \b, salt %#16.16llx +#>>16 ubequad x \b%16.16llx +#>>24 ubequad x \b%16.16llx +#>>32 ubequad x \b%16.16llx +# start sector of key material like: 8 0x200 0x3f8 0x5f0 0xdd0 +>40 ubelong x \b, %#x material offset +# number of anti-forensic stripes like: 4000 +>44 ubelong !4000 \b, %u stripes #------------------------------------------------------------------------------ # $File: m4,v 1.3 2019/02/27 16:46:23 christos Exp $ # make: file(1) magic for M4 scripts @@ -24440,7 +25185,7 @@ 0 belong 0xF11E041C magic binary file for file(1) cmd >4 belong x (version %d) (big endian) #------------------------------------------------------------------------------ -# $File: mail.news,v 1.28 2021/09/11 19:20:15 christos Exp $ +# $File: mail.news,v 1.29 2022/06/17 18:02:19 christos Exp $ # mail.news: file(1) magic for mail and news # # Unfortunately, saved netnews also has From line added in some news software. @@ -24485,8 +25230,54 @@ #0 string/t Content- MIME entity text # TNEF files... -0 lelong 0x223E9F78 Transport Neutral Encapsulation Format +# URL: http://fileformats.archiveteam.org/wiki/Transport_Neutral_Encapsulation_Format +# https://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/t/tnef.trid.xml +# https://interoperability.blob.core.windows.net/files/MS-OXTNEF/%5bMS-OXTNEF%5d-210817.pdf +# Update: Joerg Jenderek +# Note: moved and merged from ./msdos (version 1.154) there just called "TNEF" +# partly verified by `tnef --list -v -f voice.tnef` and `ytnef -v triples.tnef` +# TNEF magic From "Joomy" +# TNEF_SIGNATURE +0 lelong 0x223E9F78 Transport Neutral Encapsulation Format (TNEF) !:mime application/vnd.ms-tnef +# winmail.dat or win.dat by Microsoft Outlook +!:ext tnef/dat +# https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxtnef/7fdb64ee-7f63-4d95-9af1-c672e7475c3a +# LegacyKey +#>4 uleshort x \b, key %#4.4x +# attrLevelMessage; Level where attribute applies like: 1~attrLevelMessage 2~attrLevelAttachment +>6 ubyte !1 \b, 1st level %#2.2x +# other ID (like 02900000h) or TnefVersion ID (idTnefVersion=06900800h) +>7 ubelong !0x06900800 \b, 1st id %#8.8x +>7 ubelong =0x06900800 +# TnefVersion lenght like: 4 +>>11 ulelong !4 \b, TnefVersion length %x +# TNEFVersionData; TnefVersion data like: 00010000h +>>15 ulelong !0x00010000h \b, version %#8.8x +# Checksum like: 1 +>>19 uleshort !1 \b, checksum %#4.4x +# attrLevelMessage; level of attOemCodepage like: 1 +>>21 ubyte !1 \b, level %#2.2x +# idOEMCodePage; OEMCodePage ID like: 07900600h +>>22 ubelong =0x07900600 \b, OEM codepage +# OEMCodePage length like: 8 +>>>26 ulelong =8 +# OEMCodePageData; PrimaryCodePage like: 1251 1252 +>>>>30 ulelong x %u +# OEMCodePageData; SecondaryCodePage; unused and SHOULD contain zero +>>>>34 ulelong !0 and %u +# OEMCodePageData Checksum like: E7h E8h +>>>>38 uleshort x (checksum %#x) +# attrLevelMessage of attMessageClass like: 1 +>>40 ubyte !1 \b, level %u +# idMessageClass; ID of attMessageClass like: 08800700h +>>41 ubelong =0x08800700 \b, MessageAttribute +# attMessageClass length like: 16 24 25 +#>>>45 ulelong x (length %u) +# attMessageClass data like: "IPM.Microsoft Mail.Note" "IPM.Note.Portada Newseum" +# "IPM.Appointment" "IPM.Note.Microsoft.Voicemail.UM.CA" +>>>45 pstring/l x "%s" # From: Kevin Sullivan 0 string *mbx* MBX mail folder @@ -25929,7 +26720,7 @@ #>4 use zip-dir-entry #------------------------------------------------------------------------------ -# $File: msdos,v 1.154 2022/03/21 21:25:50 christos Exp $ +# $File: msdos,v 1.158 2022/09/07 11:17:31 christos Exp $ # msdos: file(1) magic for MS-DOS files # @@ -26516,7 +27307,8 @@ # skip "GPG symmetrically encrypted data" ./gnu # skip "PGP symmetric key encrypted data" ./pgp # openpgpdefs.h: fourth byte < 14 indicate cipher algorithm type ->>>4 ubyte >13 DOS executable (COM, 0x8C-variant) +>>>4 ubyte >13 +>>>>0 use msdos-com # the remaining files should be DOS *.COM executables # dosshell.COM 8cc0 2ea35f07 e85211 e88a11 b80058 cd # hmload.COM 8cc8 8ec0 bbc02b 89dc 83c30f c1eb04 b4 @@ -26526,48 +27318,164 @@ # SHARE.COM 8cca 2e8916 d602 b430 cd21 8b 2e0200 8b # validchr.COM 8cca 2e8916 9603 b430 cd21 8b 2e028b1e # devload.COM 8cca 8916ad01 b430 cd21 8b2e0200 892e -!:mime application/x-dosexec -!:ext com - -# updated by Joerg Jenderek at Oct 2008 -0 ulelong 0xffff10eb DR-DOS executable (COM) -# byte 0xeb conflicts with "sequent" magic leshort 0xn2eb -0 ubeshort&0xeb8d >0xeb00 -# DR-DOS STACKER.COM SCREATE.SYS missed 0 name msdos-com ->0 byte x DOS executable (COM) -!:mime application/x-dosexec -!:ext com +# URL: http://fileformats.archiveteam.org/wiki/DOS_executable_(.com) +>0 byte x DOS executable ( +# DOS execuable with JuMP 16-bit instruction +>0 byte =0xE9 +# check for probably nil padding til offset 64 of Lotus driver name +>>56 quad =0 +# check for "long" alpabetical Lotus driver name like: +# Diablo "COMPAQ Text Display" "IBM Monochrome Display" "Plantronics ColorPlus" +>>>24 regex =^[A-Z][A-Za-z\040]{5,21} \bLotus driver) %s +!:mime application/x-dosexec +# like: CPQ0TD.DRV IBM0MONO.DRV (Lotus 123 10a) SDIAB4.DRV SPL0CPLS.DRV (Lotus Symphony 2) +!:ext drv +# COM with nils like MODE.COM IBMDOS.COM (pcdos 3.31 ru Compaq) RSSTUB.COM (PC-DOS 2000 de) ACCESS.COM (Lotus Symphony 1) +>>>24 default x \bCOM) +!:mime application/x-dosexec +!:ext com +# DOS excutable with JuMP 16-bit and without nil padding +>>56 quad !0 +# https://wiki.syslinux.org/wiki/index.php?title=Doc/comboot +# TODO: HOWTO distinguish COMboot from pure DOS executables? +# look for unreliable Syslinux specific api call INTerrupt 22h for 16-bit COMBOOT program +>>>1 search/0xc088 \xcd\x22 \bCOM or COMBOOT 16-bit) +!:mime application/x-dosexec +# like: sbm.cbt command.com (Windows XP) UNI2ASCI.COM (FreeDOS 1.2) +!:ext com/cbt +>>>1 default x \bCOM) +!:mime application/x-dosexec +!:ext com +# DOS executable without JuMP 16-bit instruction +>0 byte !0xE9 +# SCREATE.SYS https://en.wikipedia.org/wiki/Stac_Electronics +>>10 string =?STACVOL \bSCREATE.SYS) +!:mime application/x-dosexec +!:ext sys +# COM executable without JuMP 16-bit instruction and not SCREATE.SYS +>>10 string !?STACVOL \bCOM) +!:mime application/x-dosexec +!:ext com >6 string SFX\ of\ LHarc \b, %s >0x1FE leshort 0xAA55 \b, boot code >85 string UPX \b, UPX compressed >4 string \ $ARX \b, ARX self-extracting archive >4 string \ $LHarc \b, LHarc self-extracting archive >0x20e string SFX\ by\ LARC \b, LARC self-extracting archive +# like: E30ODI.COM MADGEODI.COM UNI2ASCI.COM RECOVER.COM (DOS 2) COMMAND.COM (DOS 2) +>1 search/0xc088 \xcd\x22 \b, maybe with interrupt 22h +>0 ubelong x \b, start instruction %#8.8x +# show more instructions but not in samples like: rem.com (DJGPP) +>4 ubelong x %8.8x # JMP 8bit 0 byte 0xeb +# byte 0xeb conflicts with magic leshort 0xn2eb of "SYMMETRY i386" handled by ./sequent # allow forward jumps only >1 byte >-1 # that offset must be accessible +# with hexadecimal values like: 0e 2e 50 8c 8d ba bc bd be e8 fb fc >>(1.b+2) byte x ->>>0 use msdos-com - +# if look like COM executable with x86 boot signature then this +# implies FAT volume with x86 real mode code already handled by ./filesystems +# +# No x86 boot signature implies often DOS executable +# check for unrealistic high number of FATs. Then it is an unusual disk image or often a DOS executable +# like: FIXBIOS.COM (50 bytes) +>>>16 ubyte >3 +# https://www.drivedroid.io/ +# skip MBR disk image drivedroid.img version 12 July 2013 by start message +>>>>2 string !DriveDroid +# ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/ +# skip unusual floppy image disk1.img of MS-DOS 1.25 (Corona Data Systems OEM) +# by check for characteristic message text near the beginning +>>>>>15 string !Non\040System\040disk +# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 4.0.rar" +# skip BeOS 4 bootfloppy.img done as "Linux kernel x86 boot executable" by ./linux +# by check for characteristic message text near the beginning +>>>>>>6 string !read\040error\015 +# https://github.com/ventoy/Ventoy/releases/download/v1.0.78/ventoy-1.0.78-windows.zip +# skip ventoy 1.0.78 boot_hybrid.img +>>>>>>>24 string !\220\220\353I$\022\017 +# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/PC-DOS 1.0 (5.25).rar" +# skip unusual floppy image PCDOS100.IMG of DOS 1.0 +# by check for characteristic message text near the beginning +>>>>>>>>9 string !7-May-81 +# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 5.0 Personal (BA).rar" +# skip BeOS 5 floppy_1.44.00.ima done as "DOS/MBR boot sector" by ./filesystems +# by check for characteristic message near the beginning +>>>>>>>>>3 string !\370sdfS\270 +# like: FIXBIOS.COM (50 bytes) +>>>>>>>>>>0 use msdos-com +# check for unrealistic low number of FATs. Then it is an unusual FAT disk image or often a DOS executable +# like: DEVICE.COM INSTALL.COM (GAG 4.10) WORD.COM (Word 1.15) +>>>16 ubyte =0 +# if low FATs with x86 boot signature it can be unusual disk image like: boot.img (Ventoy 1.0.27) geodspms.img (Syslinux) +>>>>0x1FE leshort =0xAA55 +>>>>0x1FE default x +# https://thestarman.pcministry.com/tool/hxd/dimtut.htm +# skip unusual floppy image TK-DOS11.img IBMDOS11.img of IBM DOS 1.10 +# by check for characteristic bootloader names near end of boot sector +>>>>>395 string !ibmbio\040\040com +>>>>>>0 use msdos-com +# 8-bit jump with valid number of FAT implies FAT volume already handled by ./filesystems +# like: balder.img +>>>16 default x +# skip disk images with boot signature at end of 1st sector +# like: TDSK-64b.img +>>>>(11.s-2) uleshort !0xAA55 +# skip unusual floppy image without boot signature like 360k-256.img (mtools 4.0.18) +# by check for characteristic file system type text for FAT (12 bit or 16 bit) +>>>>>54 string !FAT +# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/Microsoft MS-DOS 3.31 (Compaq OEM) (3.5).rar" +# skip unusual floppy image Disk4.img without boot signature and file system type text +# by check for characteristic OEM-ID text +>>>>>>3 string !COMPAQ\040\040 +# no such DOS COM executables found +>>>>>>>0 use msdos-com # JMP 16bit 0 byte 0xe9 +# 16-bit offset; for DEBUGGING!; can be negative like: USBDRIVE.COM +#>1 leshort x \b, OFFSET %d # forward jumps ->1 short >-1 +>1 leshort >-1 # that offset must be accessible +# with hexadecimal values like: 06 1e 0e 2e 60 8c 8d b4 ba be e8 fc >>(1.s+3) byte x ->>>0 use msdos-com +# check for unrealistic high number of FATs. Then it is not a disk image and it is a DOS executable +# like: CALLVER.COM CPUCACHE.COM K437_EUR.COM SHSUCDX.COM UMBFILL.COM (183 bytes) +>>>16 ubyte >3 +>>>>0 use msdos-com +# check for unrealistic low number of FATs. Then it is not a disk image and it is a DOS executable +# like: GAG.COM DRMOUSE.COM NDN.COM CPQ0TD.DRV +>>>16 ubyte =0 +>>>>0 use msdos-com +# maybe disc image with valid number of FATs or DOS executable +# like: IPXODI.COM PERUSE.COM TASKID.COM +>>>16 default x +# invalid low media descriptor. Then it is not a disk image and it is a DOS executable +>>>>21 ubyte <0xE5 +>>>>>0 use msdos-com +# valid media descriptor. Then it is maybe disk image or DOS executable +>>>>21 ubyte >0xE4 +# invalid sectorsize not a power of 2 from 32-32768. Then it is not a disk image and it must be DOS executable +# like: LEARN.COM (Word 1.15) +>>>>>11 uleshort&0x001f !0 +>>>>>>0 use msdos-com # negative offset, must not lead into PSP ->1 short <-259 +# like: BASICA.COM (PC dos 3.20) FORMAT.COM SMC8100.COM WORD.COM (word4) +# HIDSUPT1.COM USBDRIVE.COM USBSUPT1.COM USBUHCI.COM (FreeDOS USBDOS) +>1 leshort <-259 # that offset must be accessible +# add 10000h to jump at end of 64 KiB segment, add 1 for jump instruction and 2 for 16-bit offset >>(1,s+65539) byte x +# after jump next instruction for DEBUGGING! +#>>>&-1 ubelong x \b, NEXT instruction %#8.8x >>>0 use msdos-com -# updated by Joerg Jenderek at Oct 2008,2015 +# updated by Joerg Jenderek at Oct 2008,2015,2022 # following line is too general 0 ubyte 0xb8 # skip 2 linux kernels like memtest.bin with "\xb8\xc0\x07\x8e" in ./linux @@ -26590,19 +27498,49 @@ # syslinux version (4.x) # "COM executable (COM32R)" or "Syslinux COM32 module" by TrID >>>1 lelong 0x21CD4CFe \b, relocatable) -# Hajin Jang : -# Disable simplest COM signature to prevent false positive on some EUC-KR text files. -## remaining are DOS COM executables starting with assembler instruction MOV -## like FreeDOS BANNER*.COM FINDDISK.COM GIF2RAW.COM WINCHK.COM -## MS-DOS SYS.COM RESTART.COM -## SYSLINUX.COM (version 1.40 - 2.13) -## GFXBOOT.COM (version 3.75) -## COPYBS.COM POWEROFF.COM INT18.COM ->>1 default x COM executable for DOS -!:mime application/x-dosexec -##!:mime application/x-ms-dos-executable -##!:mime application/x-msdos-program -!:ext com +>>1 default x +# look for interrupt instruction like in rem.com (DJGPP) LOADER.COM (DR-DOS 7.x) +>>>3 search/118 \xCD +# FOR DEBUGGING; possible hexadecimal interupt number like: 10~BANNER.COM 13~bcdw_cl.com 15~poweroff.com (Syslinux) +# 1A~BERNDPCI.COM 20~SETENHKB.COM 21~mostly 22~gfxboot.com (Syslinux) 2F~SHUTDOWN.COM (GEMSYS) +#>>>>&0 ubyte x \b, INTERUPT %#x +# few examples with interrupt 0x13 instruction +>>>>&0 ubyte =0x13 +# FOR DEBUGGING! +#>>>>>3 ubequad x \b, 2nd INSTRUCTION %#16.16llx +# skip Gpt.com Mbr.com (edk2-UDK2018 bootsector) described as "DOS/MBR boot sector" by ./filesystems +# by check for assembler instructions: mov es,ax ; mov ax,07c0h ; mov ds,ax +>>>>>3 ubequad !0x8ec0b8c0078ed88d +# few COM exectables with interrupt 0x13 instruction like: Bootable CD Wizard executables bcdw_cl.com fdemuoff.com +# http://bootcd.narod.ru/bcdw150z_en.zip +>>>>>>0 use msdos-com +# few examples with interrupt 0x16 instruction like flashimg.img +>>>>&0 ubyte =0x16 +# skip Syslinux 3.71 flashimg.img done as "DOS/MBR boot sector" by ./filesystems +# by check for assembler instructions: cmp ax 0xE4E4 (magic); jnz +>>>>>8 ubelong !0x3DE4E475 +# no DOS executable with interrupt 0x16 found +>>>>>>0 use msdos-com +# most examples with interrupt instruction unequal 0x13 and 0x16 +>>>>&0 default x +#>>>>>&-1 ubyte x \b, INTERUPT %#x +# like: LOADER.COM SETENHKB.COM banner.com copybs.com gif2raw.com poweroff.com rem.com +>>>>>0 use msdos-com +# few COM executables without interupt instruction like RESTART.COM (DOS 7.10) REBOOT.COM +# or some EUC-KR text files or one Ulead Imaginfo thumbnail +>>>3 default x +# FOR DEBUGGING; 2nd instruction like 0x50 (RESTART.COM) 0x8e (REBOOT.COM) +# or random like: 0x0 (IMAGINFO.PE3 sky_snow) 0xb1 (euckr_.txt) +#>>>>3 ubyte x \b, 2nd INSTRUCTION %#x +# skip 1 Ulead Imaginfo thumbnail (IMAGINFO.PE3 sky_snow) +# inside SAMPLES/TEXTURES/SKY_SNOW +# from https://archive.org/download/PI3CANON/PI3CANON.iso +>>>>3 ubyte !0x0 +# skip some EUC-KR text files like: euckr_falsepositive.txt +# https://bugs.astron.com/view.php?id=186 +>>>>>3 ubyte !0xb1 +# like: RESTART.COM (DOS 7.10) REBOOT.COM +>>>>>>0 use msdos-com # URL: https://en.wikipedia.org/wiki/UPX # Reference: https://github.com/upx/upx/archive/v3.96.zip/upx-3.96/ @@ -27204,11 +28142,6 @@ >>>20 long >0 TIFF starts at byte %d >>>>24 long >0 length %d -# TNEF magic From "Joomy" -# Microsoft Outlook's Transport Neutral Encapsulation Format (TNEF) -0 lelong 0x223e9f78 TNEF -!:mime application/vnd.ms-tnef - # Norton Guide (.NG , .HLP) files added by Joerg Jenderek from source NG2HTML.C # of http://www.davep.org/norton-guides/ng2h-105.tgz # https://en.wikipedia.org/wiki/Norton_Guides @@ -27406,6 +28339,13 @@ >>>>>>(16.l+16) string !Panoram 7 or 8 !:ext themepack/deskthemepack >>>>>>(16.l+16) ubyte x Theme Pack +# URL: https://en.wikipedia.org/wiki/Microsoft_OneNote#File_format +# http://fileformats.archiveteam.org/wiki/OneNote +# Reference: https://mark0.net/download/triddefs_xml.7z/defs/o/onepkg.trid.xml +# 1st member name like: "Class Notes.one" "test-onenote.one" "Open Notebook.onetoc2" "Editor Öffnen.onetoc2" +>>>>>&0 string/c one \b, OneNote Package +!:mime application/msonenote +!:ext onepkg >>>>>&0 default x # look for null terminator of 1st member name >>>>>>&0 search/255 \0 @@ -27732,7 +28672,7 @@ # #------------------------------------------------------------------------------ -# $File: msooxml,v 1.17 2021/11/08 13:53:43 christos Exp $ +# $File: msooxml,v 1.18 2022/08/16 11:16:39 christos Exp $ # msooxml: file(1) magic for Microsoft Office XML # From: Ralf Brown @@ -27747,10 +28687,13 @@ 0 name msooxml >0 string word/ Microsoft Word 2007+ !:mime application/vnd.openxmlformats-officedocument.wordprocessingml.document +!:ext docx >0 string ppt/ Microsoft PowerPoint 2007+ !:mime application/vnd.openxmlformats-officedocument.presentationml.presentation +!:ext pptx >0 string xl/ Microsoft Excel 2007+ !:mime application/vnd.openxmlformats-officedocument.spreadsheetml.sheet +!:ext xlsx >0 string visio/ Microsoft Visio 2013+ !:mime application/vnd.ms-visio.drawing.main+xml >0 string AppManifest.xaml Microsoft Silverlight Application @@ -29026,7 +29969,7 @@ 0 string Octave-1-B Octave binary data (big endian) #------------------------------------------------------------------------------ -# $File: ole2compounddocs,v 1.18 2022/05/31 17:38:36 christos Exp $ +# $File: ole2compounddocs,v 1.19 2022/09/11 20:52:40 christos Exp $ # Microsoft OLE 2 Compound Documents : file(1) magic for Microsoft Structured # storage (https://en.wikipedia.org/wiki/Compound_File_Binary_Format) # Additional tests for OLE 2 Compound Documents should be under this recipe. @@ -29262,6 +30205,18 @@ !:mime application/x-corel-gal !:ext gal # +# From: Joerg Jenderek +# URL: https://archive.org/details/iPhoto-Plus-4 +# https://filext.com/file-extension/TPL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/t/tpl-ulead.trid.xml +# Note: found in Template sub directory in program directory of software iPhoto Plus version 4 +# second, third and fourth directory entry name like TplHeader TplMainImage TplPreview +>>>>128 lestring16 TplHeader : Ulead iPhoto Template +#!:mime application/x-ole-storage +!:mime image/x-ulead-tpl +# https://www.file-extensions.org/tpl-file-extension-ulead-photo-express-template +!:ext tpl +# # URL: https://en.wikipedia.org/wiki/Hangul_(word_processor) # Note: "HWP Document File" signature found in FileHeader # Second directory entry name FileHeader hint for Thinkfree Office document @@ -30339,7 +31294,7 @@ >48 byte x \b%d. >56 byte x \b%d #------------------------------------------------------------------------------ -# $File: pascal,v 1.3 2020/06/07 18:10:26 christos Exp $ +# $File: pascal,v 1.4 2022/07/30 16:53:06 christos Exp $ # pascal: file(1) magic for Pascal source # 0 search/8192 (input, Pascal source text @@ -30353,6 +31308,31 @@ 0 string PPU Pascal unit >3 string x \b, version %s +# From: Joerg Jenderek +# URL: https://en.wikipedia.org/wiki/Dan_Bricklin +0 string/b Type +# URL: https://dl.winworldpc.com/Dan%20Bricklins%20Demo%20II%20Version%202%20Manual.7z +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-v2.trid.xml +>4 string D2 Dan Bricklin's Demo 2 demo +#!:mime application/octet-stream +!:ext dbd +# URL: https://muhaz.org/turbo-pascal-download-details.html +# From: Joerg Jenderek +# Note: used by Turbo Pascal 5.5 TOUR.EXE +>4 string T2 Turbo Pascal TOUR data +#!:mime application/octet-stream +!:mime application/x-borland-cbt +!:ext cbt +# WHAT iS THAT? +#>4 string \040P Dan Bricklin's Demo 2 foo +#!:mime application/octet-stream +# _PPRINT.SG2 _PASCII.SG2 +#!:ext sg2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-gen.trid.xml +>4 default x Dan Bricklin's Demo demo (generic) +#!:mime application/octet-stream +!:ext dbd + #------------------------------------------------------------------------------ # $File: pbf,v 1.3 2019/04/19 00:42:27 christos Exp $ # file(1) magic(5) data for OpenStreetMap @@ -32175,7 +33155,7 @@ >16 long >0 not stripped #------------------------------------------------------------------------------ -# $File: python,v 1.44 2021/10/20 11:15:35 christos Exp $ +# $File: python,v 1.45 2022/07/24 23:59:37 christos Exp $ # python: file(1) magic for python # # Outlook puts """ too for urgent messages @@ -32261,6 +33241,8 @@ !:mime application/x-bytecode.python 0 belong 0x04f30d0a python 2.7 byte-compiled !:mime application/x-bytecode.python +0 belong 0x0af30d0a PyPy2.7 byte-compiled +!:mime application/x-bytecode.python 0 belong 0xb80b0d0a python 3.0 byte-compiled !:mime application/x-bytecode.python 0 belong 0xc20b0d0a python 3.0 byte-compiled @@ -32361,80 +33343,46 @@ !:mime application/x-bytecode.python 0 belong 0x3f0d0d0a python 3.7 byte-compiled !:mime application/x-bytecode.python -0 belong 0x400d0d0a python 3.7 byte-compiled + +# magic 3392+ implements PEP 552: Deterministic pycs +0 name pyc-pep552 +# the flag field determines how .pyc validity is checked +>4 ulelong&1 0 timestamp-based, +>>8 uledate x .py timestamp: %s UTC, +>>12 ulelong x .py size: %d bytes +>4 ulelong&1 !0 hash-based, check-source flag +>>4 ulelong&2 0 unset, +>>4 ulelong&2 !0 set, +>>8 ulequad x hash: 0x%llx + +# uleshort magic followed by \x0d\0xa +2 string \x0d\x0a +# extra check: only two bits of flag field are currently used +>4 ulelong <0x4 +# \x0d as part of magic should suffice till Python 3.14 (magic 3600) +>>1 ubyte 0x0d Byte-compiled Python module for !:mime application/x-bytecode.python -0 belong 0x410d0d0a python 3.7 byte-compiled +# now look at the magic number to determine the version +>>>0 uleshort <3400 CPython 3.7, +>>>0 default x +>>>>0 uleshort <3420 CPython 3.8, +>>>>0 default x +>>>>>0 uleshort <3430 CPython 3.9, +>>>>>0 default x +>>>>>>0 uleshort <3450 CPython 3.10, +>>>>>>0 default x +>>>>>>>0 uleshort <3500 CPython 3.11, +>>>>>>>0 default x CPython 3.12 or newer, +>>>0 use pyc-pep552 +>>0 uleshort 240 Byte-compiled Python module for PyPy3.7, !:mime application/x-bytecode.python -0 belong 0x420d0d0a python 3.7 byte-compiled +>>>0 use pyc-pep552 +>>0 uleshort 256 Byte-compiled Python module for PyPy3.8, !:mime application/x-bytecode.python -0 belong 0x480d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x490d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x520d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x530d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x540d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x550d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5c0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5d0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5e0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5f0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x600d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x610d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x660d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x670d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x680d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x690d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6a0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6b0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6c0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6d0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6e0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6f0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7a0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7b0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7c0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7d0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7e0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7f0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x800d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x810d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x820d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x830d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x840d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x850d0d0a python 3.11 byte-compiled +>>>0 use pyc-pep552 +>>0 uleshort 336 Byte-compiled Python module for PyPy3.9, !:mime application/x-bytecode.python +>>>0 use pyc-pep552 0 search/1/w #!\040/usr/bin/python Python script text executable !:strength + 15 @@ -32597,7 +33545,7 @@ 0 string #\ Bazaar\ merge\ directive\ format Bazaar merge directive #------------------------------------------------------------------------------ -# $File: riff,v 1.44 2022/05/14 19:42:47 christos Exp $ +# $File: riff,v 1.45 2022/07/24 23:47:49 christos Exp $ # riff: file(1) magic for RIFF format # See # @@ -32930,6 +33878,27 @@ #>>>0 use corel-des #>>>0 use corel-draw >8 string NUNDROOT \b, Steinberg CuBase +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/MIDI_Instrument_Definition_File +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/i/idf.trid.xml +# ftp://curscott.servebeer.com/Download/Apps/_Microsoft/ +# Visual%20Studio%206.0%20Professional%20MSDN/ +# SAMPLES/VC98/SDK/GRAPHICS/AUDIO/IDFEDIT/GLOBALS.H +# Note: called "MIDI Instrument Definition File" by TrID +>8 string IDF\ LIST \b, MIDI Instrument Definition File +!:mime audio/x-idf +!:ext idf +# 3rd chunk size like: 254 284 286 670 +#>>0x10 ulelong x \b, 3th SIZE %u +# for debugging purpose display next chunk like: MMAPhdr +#>>0x14 string x \b, 4th "%-8.8s" +#>>0x1C ulelong x \b, 4th SIZE 0x%x +# probably MIDI instrument name like: "Universal-MIDI-Instrument" "instrument name" "General MIDI" +>>0x30 string x "%s" +# look for inst TAG +>>0x31 search/256 inst by +# probably manufacture name like: "Unspecified Company" "NVidia Corporation" +>>>&0x24 string x "%s" # AVI == Audio Video Interleave # Reference: http://fileformats.archiveteam.org/wiki/AVI >8 string AVI\040 \b, AVI @@ -33414,6 +34383,51 @@ >>&6 leshort =2 \b, stereo >>&6 leshort >2 \b, %d channels >>&8 lelong >0 %d Hz +#------------------------------------------------------------------------------ +# $File: ringdove,v 1.1 2022/08/16 12:04:30 christos Exp $ +# ringdove: file(1) magic for RingdoveEDA data files + +# librnd and global +0 regex/128l ha:rnd-menu-v[0-9]+[\ \t\r\n]*[{] librnd menu system (lihata) +0 regex/128l ha:rnd-menu-patch-v[0-9]+[\ \t\r\n]*[{] librnd menu patch (lihata) +0 regex/128l ha:coraleda-project-v[0-9]+[\ \t\r\n]*[{] CoralEDA/Ringdove project file (lihata) +0 regex/128l ha:ringdove-project-v[0-9]+[\ \t\r\n]*[{] Ringdove project file (lihata) + +# pcb-rnd +0 regex/128l ha:pcb-rnd-board-v[0-9]+[\ \t\r\n]*[{] pcb-rnd board file (lihata) +0 regex/128l li:pcb-rnd-subcircuit-v[0-9]+[\ \t\r\n]*[{] pcb-rnd subcircuit/footprint file (lihata) +0 regex/128l ha:pcb-rnd-buffer-v[0-9]+[\ \t\r\n]*[{] pcb-rnd paste buffer content (lihata) +0 regex/128l li:pcb-rnd-conf-v[0-9]+[\ \t\r\n]*[{] pcb-rnd configuration (lihata) +0 regex/128l ha:pcb-rnd-drc-query-v[0-9]+[\ \t\r\n]*[{] pcb-rnd drc query string (lihata) +0 regex/128l li:pcb-rnd-font-v[0-9]+[\ \t\r\n]*[{] pcb-rnd vector font (lihata) +0 regex/128l ha:pcb-rnd-log-v[0-9]+[\ \t\r\n]*[{] pcb-rnd message log dump (lihata) +0 regex/128l ha:pcb-rnd-padstack-v[0-9]+[\ \t\r\n]*[{] pcb-rnd padstack (lihata) +0 regex/128l li:pcb-rnd-view-list-v[0-9]+[\ \t\r\n]*[{] pcb-rnd view list (lihata) +0 regex/128l li:view-list-v[0-9]+[\ \t\r\n]*[{] pcb-rnd view list (lihata) +0 search Netlist(Freeze) pcb-rnd or gEDA/PCB netlist forward annotation action script + +# sch-rnd (cschem data model) +0 regex/128l li:cschem-buffer-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem buffer content (lihata) +0 regex/128l li:sch-rnd-conf-v[0-9]+[\ \t\r\n]*[{] sch-rnd configuration (lihata) +0 regex/128l ha:std_devmap.v[0-9]+[\ \t\r\n]*[{] sch-rnd devmap (device mapping; lihata) +0 regex/128l li:cschem-group-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem group or symbol (lihata) +0 regex/128l ha:cschem-sheet-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem schematic sheet (lihata) + +# tEDAx (modular format) +0 regex/1l tEDAx[\ \t\r\n]v tEDAx (Trivial EDA eXchange) +>0 regex begin\ symbol\ v with schematic symbol +>0 regex begin\ board\ v with Printed Circuit Board +>0 regex begin\ route_req\ v with PCB routing request +>0 regex begin\ route_res\ v with PCB routing result +>0 regex begin\ camv_layer\ v with camv-rnd exported layer +>0 regex begin\ netlist\ v with netlist +>0 regex begin\ backann\ v with Ringdove EDA back annotation +>0 regex begin\ footprint\ v with PCB footprint +>0 regex begin\ drc\ v with PCB DRC script +>0 regex begin\ drc_query_rule\ v with pcb-rnd drc_query rules +>0 regex begin\ drc_query_def\ v with pcb-rnd drc_query value/config definitions +>0 regex begin\ etest\ v with PCB electric test + #------------------------------------------------------------------------------ # $File: rpi,v 1.3 2022/04/02 14:39:34 christos Exp $ @@ -34113,17 +35127,19 @@ 8 string DEEP Alias Maya Image File #------------------------------------------------------------------------------ -# $File: sgml,v 1.45 2022/03/21 21:36:55 christos Exp $ +# $File: sgml,v 1.46 2022/08/16 11:16:39 christos Exp $ # Type: SVG Vectorial Graphics # From: Noel Torres 0 string \14 regex ['"\ \t]*[0-9.]+['"\ \t]* >>19 search/4096 \>19 search/4096 \20 belong&0x03FFFFFF 288 (USB 2.0 >20 belong&0x03FFFFFF 289 (ATSC ALP >20 belong&0x03FFFFFF 290 (Event Tracing for Windows +>20 belong&0x03FFFFFF 291 (Hilscher netANALYZER NG pseudo-footer +>20 belong&0x03FFFFFF 292 (ZBOSS NCP protocol with pseudo-header +>20 belong&0x03FFFFFF 293 (Low-Speed USB 2.0/1.1/1.0 +>20 belong&0x03FFFFFF 294 (Full-Speed USB 2.0/1.1/1.0 +>20 belong&0x03FFFFFF 295 (High-Speed USB 2.0 # print default match >20 default x >>20 belong x (linktype#%u @@ -34997,7 +36018,7 @@ >>>7 byte 1 (alternate timings) #------------------------------------------------------------------------------ -# $File: sql,v 1.23 2021/07/30 14:53:38 christos Exp $ +# $File: sql,v 1.24 2022/07/17 15:32:48 christos Exp $ # sql: file(1) magic for SQL files # # From: "Marty Leisner" @@ -35214,6 +36235,12 @@ # H2 Database from https://www.h2database.com/ 0 string --\ H2\ 0.5/B\ --\ \n H2 Database file + +# DuckDB database file from https://duckdb.org +8 string DUCK DuckDB database file +>12 lequad x \b, version %lld +#>20 lequad x \b, flags %#llx +#>28 lequad x \b, flags %#llx # Type: OpenSSH key files # From: Nicolas Collignon @@ -35319,6 +36346,44 @@ 0 string \\\ Stata Data File >&0 regex [0-9]+ (Release %s) +#------------------------------------------------------------------------------ +# $File: subtitle,v 1.2 2022/09/07 11:29:09 christos Exp $ +# subtitle: file(1) magic for subtitles files + +# EBU-STL +# https://tech.ebu.ch/docs/tech/tech3264.pdf +3 string STL EBU-STL subtitles +>6 regex =^[0-9][0-9] \b, rate %s +>>8 string .01 \b, v1 +!:mime application/x-ebu-stl +>>>16 regex =^[^\ ]{0,32} \b, title "%s" +>>>>224 regex =^[0-9]{2} \b, created %-.2s +>>>>>&0 regex =^[0-9]{2} \b-%-.2s +>>>>>>&0 regex =^[0-9]{2} \b-%-.2s +!:ext stl + +# SubRip (srt) subtitles +0 regex/20 =^1[\r\n]+0[01]:[0-9]{2}:[0-9]{2},[0-9]{3}\040--> SubRip +!:mime application/x-subrip +!:ext srt + +# WebVTT subtitles +# https://www.w3.org/TR/webvtt1/ +0 string/t WEBVTT +>&0 regex/255 =[0-9]{2}:[0-9]{2}\\.[0-9]{3}\040--> WebVTT subtitles +!:mime text/vtt +!:ext vtt + +# XML TTML subtitles +# https://www.w3.org/TR/ttml2/ +0 string/t \20 search/400 \020xmlns= +>>&0 regex ['"]http://www.w3.org/ns/ttml TTML subtitles +!:mime application/ttml+xml +# Augment strength to beat plain XML +!:strength * 3 +!:ext ttml + #------------------------------------------------------------------------------ # $File: sun,v 1.28 2019/04/19 00:42:27 christos Exp $ # sun: file(1) magic for Sun machines @@ -37040,7 +38105,7 @@ 43 string SFDU_LABEL VICAR label file #------------------------------------------------------------------------------ -# $File: virtual,v 1.16 2022/01/18 14:08:15 christos Exp $ +# $File: virtual,v 1.17 2022/08/23 08:00:54 christos Exp $ # From: James Nobis # Microsoft hard disk images for: # Virtual Server @@ -37049,10 +38114,10 @@ # URL: http://fileformats.archiveteam.org/wiki/VHD_(Virtual_Hard_Disk) # Reference: https://download.microsoft.com/download/f/f/e/ffef50a5-07dd-4cf8-aaa3-442c0673a029/ # Virtual%20Hard%20Disk%20Format%20Spec_10_18_06.doc -0 string connectix Microsoft Disk Image, Virtual Server or Virtual PC +0 string conectix Microsoft Disk Image, Virtual Server or Virtual PC # alternative shorter names -#0 string connectix Microsoft Virtual Hard Disk image -#0 string connectix Microsoft Virtual HD image +#0 string conectix Microsoft Virtual Hard Disk image +#0 string conectix Microsoft Virtual HD image !:mime application/x-virtualbox-vhd !:ext vhd # Features is a bit field used to indicate specific feature support @@ -37638,7 +38703,7 @@ !:mime application/vnd.hdt !:ext hdt #------------------------------------------------------------------------------ -# $File: webassembly,v 1.3 2019/04/19 00:42:27 christos Exp $ +# $File: webassembly,v 1.4 2022/08/16 11:16:39 christos Exp $ # webassembly: file(1) magic for WebAssembly modules # # WebAssembly is a virtual architecture developed by a W3C Community @@ -37651,10 +38716,12 @@ 0 string \0asm WebAssembly (wasm) binary module >4 lelong =1 version %#x (MVP) +!:mime application/wasm +!:ext wasm >4 lelong >1 version %#x #------------------------------------------------------------------------------ -# $File: windows,v 1.44 2022/05/31 17:39:08 christos Exp $ +# $File: windows,v 1.46 2022/07/02 17:46:09 christos Exp $ # windows: file(1) magic for Microsoft Windows # # This file is mainly reserved for files where programs @@ -37669,14 +38736,84 @@ # Summary: Outlook Express DBX file -# Extension: .dbx # Created by: Christophe Monniez -0 string \xCF\xAD\x12\xFE MS Outlook Express DBX file ->4 byte =0xC5 \b, message database ->4 byte =0xC6 \b, folder database ->4 byte =0xC7 \b, account information ->4 byte =0x30 \b, offline database +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Outlook_Express_Database +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbx.trid.xml +# https://sourceforge.net/projects/ol2mbox/files/LibDBX/ +# v1.0.4/libdbx_1.0.4.tar.gz/FILE-FORMAT +# Note: called "Outlook Express Database" by TrID and DROID via PUID fmt/838 fmt/839 +# and partly verified by `undbx --verbosity 4 Posteingang.dbx` +0 string \xCF\xAD\x12\xFE +# skip DROID fmt-838-signature-id-1193.dbx fmt-839-signature-id-1194.dbx by check for valid file size +>0x7C ulelong >0 MS Outlook Express DBX file +#!:mime application/octet-stream +#!:mime application/vnd.ms-outlook +!:mime application/x-ms-dbx +!:ext dbx +>>4 byte =0xC5 \b, message database +>>4 byte =0xC6 \b, folder database +>>4 byte =0xC7 \b, account information +>>4 byte =0x30 \b, offline database +# version like: 5.2 5.5 (typical) +>>20 ulequad !0x0000000500000005 \b, version +# major version +>>>24 ulelong x %u +# minor version +>>>20 ulelong x \b.%u +# CLSID: 6F74FDC5-E366-11d1-9A4E-00C04FA309D4~Message 6F74FDC6-E366-11D1-9A4E-00C04FA309D4~Folder +# 26FE9D30-1A8F-11D2-AABF-006097D474C4~offline +#>>4 guid x \b, CLSID %s +# file size; total size of file; sometimes real size a little bit higher +>>0x7C ulelong x \b, ~ %u bytes +# highest Email ID; the next email will have a number one higher than this +>>0x5c ulelong x \b, highest ID %#x +# item count; number of items stored in this DBX file +>>0xC4 ulelong x \b, %u item +# plural s +>>0xC4 ulelong !1 \bs +# index pointer; file offset pointing to a page of Data Indexes +>>0xE4 ulelong >0 \b, index pointer %#x +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Nickfile +# https://www.nirsoft.net/utils/outlook_nk2_edit.html +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/n/nk2.trid.xml +# https://github.com/libyal/libnk2/blob/main/documentation +# Nickfile%20(NK2)%20format.asciidoc +# Note: called "Outlook Nickfile" by TrID & TestDisk and +# "Outlook Nickname File" by Microsoft Outlook and +# "Outlook AutoComplete File" by Nirsoft NK2Edit +# partly verfied by NK2Edit Raw Text Edit Mode +0 ubelong 0x0DF0ADBA MS Outlook Nickfile +#!:mime application/octet-stream +#!:mime application/vnd.ms-outlook +!:mime application/x-ms-nickfile +!:ext nk2/dat/bak +# nick is used by "older" Outlook; dat is used by "newer" Outlook (probably 2010 - 2016); bak is used for backup +#!:ext nick/nk2/dat/bak +# Unknown; probably a version indicator like: 0000000Ah 0000000Ch +>4 ulelong x \b, probably version %u +# Unknown2; probably a version indicator like: 1 0 +>8 ulelong x \b.%u +# number of rows (nickname or alias items) in file +>12 ulelong x \b, %u items +# number of item entries/columns/properties value like: 17h +>16 ulelong x \b, %u entries +# value type/property tag: 001Fh~4 bytes for data size of UTF-16 LE string +>20 uleshort x \b, value type %#4.4x +# entry type/property identifier: 6001h~PR_DOTSTUFF_STATE/PR_NICK_NAME_W +>22 uleshort x \b, entry type %#4.4x +# Reserved like: 0013FD90h +#>24 ulelong x \b, reserved %#8.8x +# value data array/Irrelevant Union like: 0000000004E31A80h +#>28 ulequad x \b, data %#16.16llx +# UTF-16 +>20 uleshort =0x001F +# unicode string bytes like: 2Ch +>>36 ulelong x \b, %u bytes +# unicode string value PT_UNICODE like: janesmith@contoso.org +>>40 lestring16 x "%s" # Summary: Windows crash dump # Extension: .dmp @@ -38083,9 +39220,95 @@ # Summary: Outlook Personal Folders # Created by: unknown -0 lelong 0x4E444221 Microsoft Outlook email folder ->10 leshort 0x0e (<=2002) ->10 leshort 0x17 (>=2003) +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Personal_Folder_File +# https://en.wikipedia.org/wiki/Personal_Storage_Table +# Reference: https://interoperability.blob.core.windows.net/files/MS-PST/%5bMS-PST%5d.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml +# dwMagic !BDN +0 lelong 0x4E444221 +# skip DROID x-fmt-75-signature-id-472.pab x-fmt-248-signature-id-260.pst x-fmt-249-signature-id-261.pst +# by check for existance of bPlatformCreate value +>14 ubyte x Microsoft Outlook +#!:mime application/octet-stream +# NOT official registered ! +!:mime application/vnd.ms-outlook +# dwCRCPartial; 32-bit cyclic redundancy check (CRC) value of followin 471 bytes; zero for 64-bit +#>>4 ulelong !0 \b, CRC %#x +# wMagicClient; AB (4142h) is used for PAB files; SM (534Dh) is used for PST files; SO (534Fh) is used for OST files +#>>8 leshort x \b, wMagicClient=%#x +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml +# Note: called "Microsoft Personal Address Book" by TrID and +# "Microsoft Outlook Personal Address Book" by DROID via x-fmt/75 +>>8 leshort 0x4142 Personal Address Book +#!:mime application/x-ms-pab +!:ext pab +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pst.trid.xml +# http://mark0.net/download/triddefs_xml.7z/defs/p/pst-unicode.trid.xml +# Note: called "Microsoft OutLook Personal Folder" by TrID and +# by DROID via x-fmt/248 for ANSI and via x-fmt/249 for Unicode +#>>8 leshort 0x4D53 \b, PST~ +# called "Microsoft Outlook email folder" in ./windows version 1.37 and older +>>8 leshort 0x4D53 Personal Storage +#!:mime application/x-ms-pst +!:ext pst +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/o/ost.trid.xml +# Note: called "Outlook Exchange Offline Storage" by TrID +>>8 leshort 0x4F53 Offline Storage +#!:mime application/x-ms-ost +!:ext ost +# wVer; file format version. 14 or 15 if the file is ANSI; > 21 or 23(=17h) if Unicode; 37 for written by Outlook with WIP +>>10 uleshort x ( +# probably NO intermediate versions exist +>>10 leshort <0x10 \b<=2002, ANSI, +>>10 leshort >0x14 \b>=2003, Unicode, +>>10 uleshort x version %u) +# wVerClient; client file format version like: 19 22 +#>>12 uleshort x \b, wVerClient=%u +# bPlatformCreate; This value MUST be set to 1 but also found 2 +>>14 ubyte >1 \b, bPlatformCreate=%u +# bPlatformAccess; This value MUST be set to 1 but also found 2 +>>15 ubyte >1 \b, bPlatformAccess=%u +# dwReserved1; SHOULD ignore and NOT modify this value; SHOULD initialize to zero +>>16 ulelong !0 \b, dwReserved1=%#x +# dwReserved2; SHOULD ignore and NOT modify this value; SHOULD initialize to zero +>>20 ulelong !0 \b, dwReserved2=%#x +# ANSI 32-bit variant Outlook 1997-2002 +>>10 uleshort <16 +# bidNextB; next BlockID (ANSI 4 bytes) +#>>>24 ulelong !0 \b, bidNextB=%#x +# bidNextP; Next available back BlockID pointer +#>>>28 ulelong !0 \b, bidNextP=%#x +# dwUnique; value monotonically increased when modifying PST; so CRC is changing +>>>32 ulelong !0 \b, dwUnique=%#x +# rgnid[128]; A fixed array of 32 NodeIDs, each corresponding to one of the 32 possible NID_TYPEs +#>>>36 ubequad x \b, rgnid=%#llx... +# dwReserved; Implementations SHOULD ignore this value and SHOULD NOT modify it; Initialized zero +>>>164 ulelong !0 \b, dwReserved=%#x +# ibFileEof; the size of the PST file, in bytes (ANSI 4 bytes) +>>>168 ulelong x \b, %u bytes +# ibAMapLast; offset to the last AMap page +#>>>172 ulelong x \b, ibAMapLast=%#x +# bSentinel; MUST be set to 0x80 +>>>460 ubyte !0x80 \b, bSentinel=%#x +# bCryptMethod: 0~No encryption 1~encryption with permutation 2~encryption with cyclic 16~encryption with Windows Information Protection (WIP) +>>>461 ubyte >0 \b, bCryptMethod=%u +# UNICODE 64-bit variant Outlook 2003-2007 +>>10 uleshort >20 +# bidUnused; Unused 8 bytes padding (Unicode only); sometimes like: 0x0000000100000004 +>>>24 ulequad !0x0000000100000004 \b, bidUnused=%#16.16llx +# dwUnique; value monotonically increased when modifying PST; so CRC is changing +>>>40 ulelong !0 \b, dwUnique=%#x +# rgnid[] (128 bytes): A fixed array of 32 NIDs, each corresponding to one of the 32 possible +#>>>44 ubequad x \b, rgnid=%#llx... +# ibFileEof; the size of the PST file, in bytes (Unicode 8 bytes) +>>>184 ulequad x \b, %llu bytes +# bSentinel; MUST be set to 0x80 +>>>512 ubyte !0x80 \b, bSentinel=%#x +# bCryptMethod; Encryption type like: 0 1 2 16 +>>>513 ubyte >0 \b, bCryptMethod=%u +# dwCRC; 32-bit CRC of the of the previous 516 bytes +>>>524 ulelong x \b, CRC32 %#x # Summary: Windows help cache @@ -38877,7 +40100,7 @@ >4 belong 19 (Version 1) #------------------------------------------------------------------------------ -# $File: wordprocessors,v 1.27 2021/12/06 15:05:16 christos Exp $ +# $File: wordprocessors,v 1.31 2022/08/31 08:00:53 christos Exp $ # wordprocessors: file(1) magic fo word processors. # ####### PWP file format used on Smith Corona Personal Word Processors: @@ -38905,35 +40128,170 @@ !:ext wps # Corel/WordPerfect +# URL: https://en.wikipedia.org/wiki/WordPerfect +# Reference: https://github.com/OneWingedShark/WordPerfect/blob/master/doc/SDK_Help/FileFormats/WPFF_DocumentStructure.htm +# http://mark0.net/download/triddefs_xml.7z/defs/w/wp-generic.trid.xml 0 string \xffWPC # WordPerfect >8 byte 1 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/w/wpm-macro.trid.xml +# Note: there exist other macro variants >>9 byte 1 WordPerfect macro +#!:mime application/octet-stream +!:mime application/x-wordperfect-wpm +# like: ALTD.WPM ENDFOOT.WPM FOOTEND.WPM LABELS.WPM REVEALTX.WPM +!:ext wpm +# Note: used in WordPerfect 5.1; there exist other FIL variants >>9 byte 2 WordPerfect help file +#!:mime application/octet-stream +!:mime application/x-wordperfect-help +# like: WPHELP.FIL +!:ext fil +# pointer to document area like: 10h +>>>4 ulelong !0x10 \b, at %#x document area >>9 byte 3 WordPerfect keyboard file +#!:mime application/octet-stream +!:mime application/x-wordperfect-keyboard +!:ext wpk +# no document area, so point to end of file; so this is file size like: 23381 2978 32835 3355 3775 919 +>>>4 ulelong x \b, %u bytes +>>9 byte 4 WordPerfect VAX keyboard definition +#!:mime application/octet-stream +!:mime application/x-wordperfect-keyboard +#!:ext foo +# URL: http://fileformats.archiveteam.org/wiki/WordPerfect +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/w/wpd-doc-gen.trid.xml >>9 byte 10 WordPerfect document +# https://www.iana.org/assignments/media-types/application/vnd.wordperfect +!:mime application/vnd.wordperfect +#!:apple ????WPC2 +# TODO: distinguish different suffix +!:ext wpd/wpt/wkb/icr/tut/sty/tst/crs >>9 byte 11 WordPerfect dictionary >>9 byte 12 WordPerfect thesaurus >>9 byte 13 WordPerfect block >>9 byte 14 WordPerfect rectangular block >>9 byte 15 WordPerfect column block >>9 byte 16 WordPerfect printer data +#!:mime application/octet-stream +!:mime application/x-wordperfect-prs +# like: STANDARD.PRS WORKBOOK.PRS +!:ext prs +# like: "Standard Printer" "Workbook Printer" +>>>0x64 pstring/B >A "%s" +#>>9 byte 18 WordPerfect Prefix information file +# printer resource .ALL >>9 byte 19 WordPerfect printer data +#!:mime application/octet-stream +!:mime application/x-wordperfect-all +!:ext all +# display Resource >>9 byte 20 WordPerfect driver resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-drs +# like: WPSMALL.DRS +!:ext drs +# pointer to index area with string "smalldrs" like: 46h +>>>4 uleshort !0x46 \b, at %#x index area +>>9 byte 21 WordPerfect Overlay file +#!:mime application/octet-stream +!:mime application/x-wordperfect-fil +# like: WP.FIL +!:ext fil +# URL: http://fileformats.archiveteam.org/wiki/WordPerfect_Graphics +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wpg.trid.xml +# Note: called "WordPerfect Graphics bitmap" by TrID and +# "WordPerfect Graphics Metafile" by DROID via x-fmt/395 fmt/1042 +# "WPG (Word Perfect Graphics)" by ImageMagick `identify -verbose BUTTRFLY.WPG` >>9 byte 22 WordPerfect graphic image +# TODO: skip DROID x-fmt-395-signature-id-132.wpg by check for existing document area +#>>>4 ulelong >15 WordPerfect_graphic_OK +#!:mime application/octet-stream +# http://extension.nirsoft.net/wpg +!:mime image/x-wordperfect-graphics +# https://reposcope.com/mimetype/application/x-wpg +#!:mime application/x-wpg +# like: BUTTRFLY.WPG STAR-5.WPG input.wpg WORDPFCT.WPG +!:ext wpg +# pointer to document area like: 10h 1Ah +>>>4 ulelong !0x1A \b, at %#x document area >>9 byte 23 WordPerfect hyphenation code >>9 byte 24 WordPerfect hyphenation data >>9 byte 25 WordPerfect macro resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-mrs +# like: WP.MRS +!:ext mrs >>9 byte 27 WordPerfect hyphenation lex >>9 byte 29 WordPerfect wordlist >>9 byte 30 WordPerfect equation resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-qrs +# like: WQ.QRS wpDE.qrs wpen.qrs +!:ext qrs +# jump to document area with some marker and equation +>>>(4.l) ubyte x +# equation like: "Fraction: x OVER y" +>>>>&1 string >A (...%-.19s...) +# pointer to document area like: 17C4h +>>>4 ulelong x \b, at %#x document area +#>>9 byte 31 reserved +#>>9 byte 32 WordPerfect VAX .SET >>9 byte 33 WordPerfect spell rules >>9 byte 34 WordPerfect dictionary rules +#>>9 byte 35 reserved +# video resource device driver +# Note: filetype 26 for VRS and filetype 36 for WPD apparently is wrong +>>9 byte 36 WordPerfect Video Resource +#!:mime application/octet-stream +!:mime application/x-wordperfect-vrs +# like: STANDARD.VRS +!:ext vrs +# like: "IBM CGA (& compatibles)" +>>>0x20 string >A "%.23s" >>9 byte 39 WordPerfect spell rules (Microlytics) +#>>9 byte 40 reserved +>>9 byte 41 WordPerfect Install options +#!:mime application/octet-stream +!:mime application/x-wordperfect-ins +# like: WP51.INS +!:ext ins +# probably default directory name like: "C:\WP51\" +>>>0x12 string >A "%.8s" +# maybe mouse driver for WP5.1 +>>9 byte 42 WordPerfect Resource +#!:mime application/octet-stream +!:mime application/x-wordperfect-irs +# like: STANDARD.IRS +!:ext irs +# like: "Mouse Driver (MOUSE.COM)" +>>>0x28 string >A "%.24s" >>9 byte 43 WordPerfect settings file +# maybe Macintosh WP2.0 document >>9 byte 44 WordPerfect 3.5 document +!:mime application/vnd.wordperfect +!:apple ????WPD3 +# like: WP3.wpd +!:ext wpd >>9 byte 45 WordPerfect 4.2 document +# External spell code module (WP5.1) +#>>9 byte 46 WordPerfect external spell +# external spell dictionary .LEX +#>>9 byte 47 WordPerfect external spell dictionary +# Macintosh SOFT graphics file (SOFT (Sequential Object Format) +#>>9 byte 48 WordPerfect SOFT graphics +#>>9 byte 49 reserved +#>>9 byte 50 reserved +# WPWin 5.1 Application Resource Library added for WPWin 5.1 +#>>9 byte 51 WordPerfect application resource library >>9 byte 69 WordPerfect dialog file +# From: Joerg Jenderek +# Note: found in sub directory WritingTools inside WordPerfect 2021 program directory +>>9 byte 70 WordPerfect Writing Tools +#!:mime application/octet-stream +!:mime application/x-wordperfect-cbt +# like: Wt13cbede.cbt Wt13cbeit.cbt Wt13cbefr.cbt WT21cbede.cbt Wt13cbeEN.CBD WT21cbeEN.CBD +!:ext cbd/cbt >>9 byte 76 WordPerfect button bar >>9 default x >>>9 byte x Corel WordPerfect: Unknown filetype %d @@ -39073,11 +40431,48 @@ >>9 byte 24 GroupWise admin ADS deferment data file >>9 default x >>>9 byte x GroupWise: Unknown filetype %d +# Corel Writing Tools WT*.* +# From: Joerg Jenderek +# URL: https://support.corel.com/hc/en-us/articles/215876258-Writing-Tools-Spell-Check-Dictionary-does-not-work-in-WordPerfect-X5 +# http://wordperfect.helpmax.net/en/editing-and-formatting-documents/using-the-writing-tools/working-with-user-word-lists/ +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/u/uwl-wp.trid.xml +>8 byte 32 +>>9 byte 10 Corel Writing Tools User Word List +#!:mime application/octet-stream +!:mime application/x-wordperfect-wordlist +# personal user word list UWL under user directory like: WTDE.UWL WTUS.UWL WT21DE.UWL WT21US.UWL WT13DE.UWL ... +# and "template" SAV/HWL variant under program directory like: wt13en.hwl Wt13de.sav Wt13it.sav wt13ru.sav WT21us.sav Wtcz.sav ... +!:ext uwl/hwl/sav +# jump to document area with some marker and word list +>>>(4.l) ubyte x +# look for beginning of word list starting mostly with letter a as UTF-16 like: Wt13es.sav +# but not found in russian wt13ru.sav +>>>>&0 search/91/sb a\0 +# word list starting like: "acsesory\022accessory.\001\026acomodate\026accommodate4\001" +>>>>>&0 lestring16 x (...%-.33s...) +# pointer to document area like: 200h +>>>4 ulelong !0x200 \b, at %#x document area +# file size, not including pad characters at EOF +>>>0x14 uleshort x \b, %u bytes # IntelliTAG >8 byte 33 >>9 byte 10 IntelliTAG (SGML) compiled DTD >>9 default x >>>9 byte x IntelliTAG: Unknown filetype %d +# Summary: Corel WordPerfect WritingTools advise part +# From: Joerg Jenderek +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/a/adv-wp.trid.xml +>8 byte 34 +>>9 byte 11 Corel WordPerfect dictionary advise +#!:mime application/octet-stream +!:mime application/x-wordperfect-adv +#!:mime application/vnd.wordperfect.adv +# like: WT21de.adv Wt13de.adv Wt13es.adv Wt13fr.adv wt13us.adv +!:ext adv +# advise text part often start with tag like: 580A +#>>>(16.s) ubequad x ADVISE PART %#llx +# part of advise text like: "This is too informal for most writing." +>>>(16.s+16) string x (...%-.33s...) # everything else >8 default x >>8 byte x Unknown Corel/Wordperfect product %d, @@ -39474,7 +40869,8 @@ >&0 belong 0xaa995566 Xilinx RAW bitstream (.BIN) #------------------------------------------------------------------------------ -# $File: xo65,v 1.4 2009/09/19 16:28:13 christos Exp $ +# $File: xo65,v 1.5 2022/07/17 15:36:20 christos Exp $ +# https://cc65.github.io/doc/sim65.html # xo65 object files # From: "Ullrich von Bassewitz" # @@ -39503,6 +40899,12 @@ >6 leshort&0x0003 =0x0002 alignment 4 >6 leshort&0x0003 =0x0003 alignment 256 +# sim65 executable files +0 string \x73\x69\x6d\x36\x35 sim65 executable, +>5 byte x version %d, +>6 leshort&0x0000 =0x0000 6502 +>6 leshort&0x0001 =0x0001 65C02 + #------------------------------------------------------------------------------ # $File: xwindows,v 1.13 2022/03/24 15:48:58 christos Exp $ # xwindows: file(1) magic for various X/Window system file formats. diff --git a/ext/fileinfo/tests/magicç§ã¯ã‚¬ãƒ©ã‚¹ã‚’食ã¹ã‚‰ã‚Œã¾ã™ b/ext/fileinfo/tests/magicç§ã¯ã‚¬ãƒ©ã‚¹ã‚’食ã¹ã‚‰ã‚Œã¾ã™ index fb5e08e42d5..4503d1d3c12 100644 --- a/ext/fileinfo/tests/magicç§ã¯ã‚¬ãƒ©ã‚¹ã‚’食ã¹ã‚‰ã‚Œã¾ã™ +++ b/ext/fileinfo/tests/magicç§ã¯ã‚¬ãƒ©ã‚¹ã‚’食ã¹ã‚‰ã‚Œã¾ã™ @@ -785,7 +785,7 @@ >16 lelong >0 verifier deps size: %d #------------------------------------------------------------------------------ -# $File: animation,v 1.88 2022/05/14 22:06:04 christos Exp $ +# $File: animation,v 1.90 2022/08/16 11:16:39 christos Exp $ # animation: file(1) magic for animation/movie formats # # animation formats @@ -815,8 +815,6 @@ #!:mime image/x-quicktime 4 string pckg Apple QuickTime compressed archive !:mime application/x-quicktime-player -4 string/W jP JPEG 2000 image -!:mime image/jp2 #### MP4 #### # https://www.ftyps.com/ with local additions @@ -953,6 +951,7 @@ # ?/enc-isoff-generic >8 string iso \b, MP4 Base Media !:mime video/mp4 +!:ext mp4 >>11 string m v1 [ISO 14496-12:2003] >>11 string 2 v2 [ISO 14496-12:2005] >>11 string 4 v4 @@ -1722,6 +1721,7 @@ 0 belong&0xFF5FFF10 0x47400010 >188 byte 0x47 MPEG transport stream data !:mime video/MP2T +!:ext ts # DIF digital video file format 0 belong&0xffffff00 0x1f070000 DIF @@ -2660,7 +2660,7 @@ >>5 ubyte x \b.%u, little-endian >>0 use \^apt-cache-be #------------------------------------------------------------------------------ -# $File: archive,v 1.162 2022/05/27 21:27:59 christos Exp $ +# $File: archive,v 1.169 2022/09/12 13:13:28 christos Exp $ # archive: file(1) magic for archive formats (see also "msdos" for self- # extracting compressed archives) # @@ -2686,7 +2686,16 @@ >>>>>>155 ubyte&0xDF =0 # space or ascii digit 0 at start of check sum >>>>>>>148 ubyte&0xEF =0x20 ->>>>>>>>0 use tar-file +# FOR DEBUGGING: +#>>>>>>>>0 regex \^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp) NAME "%s" +# check for 1st image main name with digits used for sorting +# and for name extension case insensitive like: PNG JPG JPEG TIF TIFF GIF BMP +>>>>>>>>0 regex \^[0-9]{2,4}[.](png|jpg|jpeg|tif|tiff|gif|bmp) +#foo +>>>>>>>>>0 use tar-cbt +# if 1st member name without digits and without used image suffix then it is a TAR archive +>>>>>>>>0 default x +>>>>>>>>>0 use tar-file # minimal check and then display tar archive information which can also be # embedded inside others like Android Backup, Clam AntiVirus database 0 name tar-file @@ -2807,6 +2816,19 @@ >>508 default x # padding[255] in old tar sometimes comment field >>>257 string >\0 \b, comment: %-.40s +# Summary: Comic Book Archive *.CBT with TAR format +# URL: https://en.wikipedia.org/wiki/Comic_book_archive +# http://fileformats.archiveteam.org/wiki/Comic_Book_Archive +# Note: there exist also RAR, ZIP, ACE and 7Z packed variants +0 name tar-cbt +>0 string x Comic Book archive, tar archive +#!:mime application/x-tar +!:mime application/vnd.comicbook +#!:mime application/vnd.comicbook+tar +!:ext cbt +# name[100] probably like: 19.jpg 0001.png 0002.png +# or maybe like ComicInfo.xml +>0 string >\0 \b, 1st image %-.60s # Incremental snapshot gnu-tar format from: # https://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html @@ -4385,13 +4407,17 @@ # Felix von Leitner 0 string d8:announce BitTorrent file !:mime application/x-bittorrent +!:ext torrent # Durval Menezes, 0 string d13:announce-list BitTorrent file !:mime application/x-bittorrent +!:ext torrent 0 string d7:comment BitTorrent file !:mime application/x-bittorrent +!:ext torrent 0 string d4:info BitTorrent file !:mime application/x-bittorrent +!:ext torrent # Atari MSA archive - Teemu Hukkanen # URL: http://fileformats.archiveteam.org/wiki/MSA_(Magic_Shadow_Archiver) @@ -4743,6 +4769,9 @@ # Note: Line 1186 of paq9a.cpp gives the magic bytes 0 string pQ9\001 PAQ9A archive +# From wof (wof@stachelkaktus.net) +0 string Unison\ archive\ format Unison archive format + #------------------------------------------------------------------------------ # URL: https://de.wikipedia.org/wiki/Aria_(Software) # Reference: https://github.com/aria2/aria2/blob/master/doc/manual-src/en/technical-notes.rst @@ -5032,7 +5061,7 @@ >364 string >\0 of '%s' #------------------------------------------------------------------------------ -# $File: audio,v 1.121 2021/04/26 15:56:00 christos Exp $ +# $File: audio,v 1.124 2022/08/28 08:58:20 christos Exp $ # audio: file(1) magic for sound formats (see also "iff") # # Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com), @@ -5435,10 +5464,26 @@ 0 string THX AHX version >3 byte =0 1 module data >3 byte =1 2 module data ->10 byte x TRL: %u ->11 byte x TRK: %u ->12 byte x SMP: %u ->13 byte x SS: %u +>11 ubyte x TRK: %u +>10 ubyte x TRL: %u +>12 ubyte x SMP: %u +>13 ubyte x SS: %u +>(4.H) string x Title: "%.128s" + +# header is mostly AHX format +0 string HVL +>3 byte <2 Hively Tracker Song +>3 byte =0 v1 module data +>3 byte =1 v2 module data +>11 ubyte x TRK: %u +>10 ubyte x TRL: %u +>12 ubyte x SMP: %u +>13 ubyte x SS: %u +>8 ubyte/4 =0 CHN: 4 +>8 ubyte/4 >0 CHN: 4+%u +#>-0 offset <0xffff +>(4.H) string x Title: "%.128s" + # 0 string OKTASONG Oktalyzer module data # @@ -5580,15 +5625,13 @@ # From: Alex Myczko # https://github.com/rerrahkr/BambooTracker -0 string BambooTrackerMod BambooTracker module ->22 byte x \b, version %u ->21 byte x \b.%u ->20 byte x \b.%u - -0 string BambooTrackerIst BambooTracker instrument ->22 byte x \b, version %u ->21 byte x \b.%u ->20 byte x \b.%u +0 string BambooTracker BambooTracker +>13 string Mod Module +>13 string Ist Instrument +>13 string Bnk Bank +>22 byte x \b, version %u +>21 byte x \b.%u +>20 byte x \b.%u 0 string CC2x CheeseCutter 2 song @@ -5926,11 +5969,6 @@ >0x3 byte&0x0F x \b%02d >>0x4 string >\0 title: "%s" -0 string HVL ->3 byte <2 Hively Tracker Song ->3 byte 0 1 module data ->3 byte 1 2 module data - 0 string MO3 >3 ubyte <6 MOdule with MP3 >>3 byte 0 Version 0 (With MP3 and lossless) @@ -6169,6 +6207,135 @@ >4 beshort 0xFEFF >>0 use \^nintendo-3ds-bcwav-fields +# Philips DSDIFF audio format (Direct Stream Digital Interchange File Format) +# Used for DSD audio recordings and Super Audio CD (SACD) mastering annotations +# https://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf +# From: Toni Ruottu +0 string FRM8 +12 string DSD\x20 DSDIFF audio bitstream data +!:mime audio/x-dff +!:ext dff + +# format version chunk +>&0 string FVER +# version 1 +>>&8 byte 1 + +# v1 / sampling resolution ( 1 bit PDM only ) +>>>&0 string x \b, 1 bit + +# v1 / sound property chunk +>>>&0 search/0xff PROP +>>>>&8 string SND + +# v1 / sound property chunk / channel configuration chunk +>>>>>&0 search/0xff CHNL +>>>>>>&8 ubeshort 1 \b, mono +>>>>>>&8 ubeshort 2 +>>>>>>>&0 string SLFTSRGT \b, stereo +>>>>>>>&0 default x \b, 2 channels +>>>>>>&8 ubeshort 3 +>>>>>>>&0 string SLFTSRGTLFE\x20 \b, 2.1 stereo +>>>>>>>&0 string SLFTSRGTC\x20\x20\x20 \b, 3.0 stereo +>>>>>>>&0 default x \b, 3 channels +>>>>>>&8 ubeshort 4 +>>>>>>>&0 string MLFTMRGTLS\x20\x20RS\x20\x20 \b, 4.0 surround +>>>>>>>&0 string SLFTSRGTC\x20\x20\x20LFE\x20 \b, 3.1 stereo +>>>>>>>&0 default x \b, 4 channels +>>>>>>&8 ubeshort 5 +>>>>>>>&0 string MLFTMRGTC\x20\x20\x20LS\x20\x20RS\x20\x20 \b, 5.0 surround +>>>>>>>&0 string MLFTMRGTLFE\x20LS\x20\x20RS\x20\x20 \b, 4.1 surround +>>>>>>>&0 default x \b, 5 channels +>>>>>>&8 ubeshort 6 +>>>>>>>&0 string MLFTMRGTC\x20\x20\x20LFE\x20LS\x20\x20RS\x20\x20 \b, 5.1 surround +>>>>>>>&0 default x \b, 6 channels +>>>>>>&8 ubeshort >6 \b, %u channels + +# v1 / sound property chunk / sample rate chunk +>>>>>&0 search/0xff FS\x20\x20 +>>>>>>&0 string x \b, +>>>>>>&8 ubelong%44100 0 +>>>>>>>&-4 ubelong/44100 x "DSD %u" +>>>>>>>&-4 ubelong x %u Hz + +# v1 / sound property chunk / compression type chunk +>>>>>&0 search/0xff CMPR +>>>>>>&8 string DSD\x20 \b, no compression +>>>>>>&8 string DST\x20 \b, DST compression +>>>>>>&8 default x \b, unknown compression + +# v1 / quest for metadata +>>>&0 string x + +# v1 / quest for metadata / edited master information chunk +>>>>&0 search DIIN +>>>>>&0 ubequad >0 \b, "edited master" metadata + +# v1 / quest for metadata / ID3 chunk ( defacto standard ) +>>>>&0 search ID3\x20 +>>>>>&8 string ID3 \b, ID3 version 2 +>>>>>&0 byte x \b.%u +>>>>>&1 byte x \b.%u + +# v1 / quest for metadata / failure ( possibly due to -P bytes=... being too low ) +>>>>&0 default x \b, ID3 missing (or unreachable) + +# version > 1 or 0 +>>&0 default x \b, unknown version + +# Sony DSF audio format (Direct Stream Digital Stream File) +# Used for lossless digital storage of songs produced as DSD audio +# Portable analog of a track stored on a Super Audio CD (SACD) +# https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf +# From: Toni Ruottu +0 string DSD\x20 DSF audio bitstream data +!:mime audio/x-dsf +!:ext dsf + +# format chunk +>28 string fmt\x20 +# version 1 +>>&8 ulelong 1 + +# v1 / sampling resolution ( 1 bit PDM only ) +# NOTE: the spec incorrectly uses "bits per sample" instead of "bits per byte" +>>>&0 string x \b, 1 bit + +# v1 / channel configuration +>>>>&4 ulelong 1 \b, mono +>>>>&4 ulelong 2 \b, stereo +>>>>&4 ulelong 3 \b, 3.0 stereo +>>>>&4 ulelong 4 \b, 4.0 surround +>>>>&4 ulelong 5 \b, 3.1 stereo +>>>>&4 ulelong 6 \b, 5.0 surround +>>>>&4 ulelong 7 \b, 5.1 surround +>>>>&0 default x +>>>>>&4 ulelong x \b, %u channels + +# v1 / sample rate chunk +>>>>&0 string x \b, +>>>>&12 ulelong%44100 0 +>>>>>&-4 ulelong/44100 x "DSD %u" +>>>>&12 ulelong x %u Hz + +# v1 / compression +>>>>&0 string x +>>>>>&0 ulelong 0 \b, no compression +>>>>>&0 default x \b, unknown compression + +# v1 / embedded ID3v2 metadata +>>>0 string x \b, ID3 +>>>>20 ulequad !0 +>>>>>(20.q) string ID3 version 2 +>>>>>>&0 byte x \b.%u +>>>>>>&1 byte x \b.%u +# unable to verify ID3 ( possibly due to -P bytes=... being too low ) +>>>>>&0 default x unreachable +>>>>&0 default x missing + +# version > 1 or 0 +>>&0 default x \b, unknown version + #------------------------------------------------------------------------------ # $File: avm,v 1.1 2020/08/28 20:37:58 christos Exp $ # avm: file(1) magic for avm files; this is not use @@ -6821,6 +6988,13 @@ >12 belong 1004 HCI Serial (H5) >>12 belong x type %d +#------------------------------------------------------------ +# $File: burp,v 1.1 2022/07/04 17:15:09 christos Exp $ +# Burp file, I don't know the version +#------------------------------------------------------------ +# From wof (wof@stachelkaktus.net) +0 bequad 0x6685828000000001 Burp project save file + #------------------------------------------------------------ # $File: bytecode,v 1.3 2022/03/24 15:48:58 christos Exp $ # magic for various bytecodes @@ -7457,7 +7631,7 @@ !:ext amf #------------------------------------------------------------------------------ -# $File: cafebabe,v 1.27 2021/04/26 15:56:00 christos Exp $ +# $File: cafebabe,v 1.28 2022/07/01 23:24:47 christos Exp $ # Cafe Babes unite! # # Since Java bytecode and Mach-O universal binaries have the same magic number, @@ -7501,6 +7675,12 @@ >>4 belong 0x0038 (Java SE 12) >>4 belong 0x0039 (Java SE 13) >>4 belong 0x003A (Java SE 14) +>>4 belong 0x003B (Java SE 15) +>>4 belong 0x003C (Java SE 16) +>>4 belong 0x003D (Java SE 17) +>>4 belong 0x003E (Java SE 18) +>>4 belong 0x003F (Java SE 19) +>>4 belong 0x0040 (Java SE 20) # pool count unequal zero #>>8 beshort x \b, pool count %#x # pool table @@ -8233,7 +8413,7 @@ 0 string msc Message Sequence Chart (chart) 0 string submsc Message Sequence Chart (subchart) #------------------------------------------------------------------------------ -# $File: compress,v 1.82 2021/06/30 08:11:29 christos Exp $ +# $File: compress,v 1.83 2022/08/16 11:16:39 christos Exp $ # compress: file(1) magic for pure-compression formats (no archives) # # compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc. @@ -8381,6 +8561,7 @@ # bzip2 0 string BZh bzip2 compressed data !:mime application/x-bzip2 +!:ext bz2 >3 byte >47 \b, block size = %c00k # bzip a block-sorting file compressor @@ -10103,7 +10284,7 @@ >15 long >30 $BS, block size: %i bytes #------------------------------------------------------------------------------ -# $File: database,v 1.66 2022/02/26 17:42:21 christos Exp $ +# $File: database,v 1.67 2022/07/12 18:57:42 christos Exp $ # database: file(1) magic for various databases # # extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk) @@ -10511,8 +10692,10 @@ >>>>>>>>>0 ulelong <0x400000 # skip WinStore.App.exe by looking for printable 2nd character of 1st memo item >>>>>>>>>>513 ubyte >037 +# skip DOS executables CPQ0TD.DRV E30ODI.COM IBM0MONO.DRV by looking for printable 1st character of 1st memo item +>>>>>>>>>>>512 ubyte >037 # unusual dBASE III DBT like adressen.dbt ->>>>>>>>>>>0 use dbase3-memo-print +>>>>>>>>>>>>0 use dbase3-memo-print # dBASE III DBT like angest.dbt, or garbage PCX DBF >>>>>>>>8 ubelong !0 # skip PCX and some DBF by test for for reserved NULL bytes @@ -11000,7 +11183,7 @@ !:ext dbpf/package/dat/sc4 !:mime application/x-maxis-dbpf #------------------------------------------------------------------------------ -# $File: der,v 1.4 2021/03/14 17:12:04 christos Exp $ +# $File: der,v 1.5 2022/07/30 18:07:34 christos Exp $ # der: file(1) magic for DER encoded files # @@ -11111,9 +11294,9 @@ >>>>&0 der seq >>>>>&0 der obj_id9=2a864886f70d010901 >>>>>&0 der ia5_str=x \b, emailAddress=%s ->>&0 der seq ->>>&0 der utc_time=x \b, utcTime=%s ->>>&0 der utc_time=x \b, utcTime=%s +#>>&0 der seq +#>>>&0 der utc_time=x \b, utcTime=%s +#>>>&0 der utc_time=x \b, utcTime=%s >>&0 use certinfo 0 der seq @@ -11130,9 +11313,9 @@ >>>>&0 der seq >>>>>&0 der obj_id3=550403 >>>>>&0 der utf8_str=x \b, Issuer=%s ->>&0 der seq ->>>&0 der utc_time=x \b, not-valid-before=%s ->>>&0 der utc_time=x \b, not-valid-after=%s +#>>&0 der seq +#>>>&0 der utc_time=x \b, not-valid-before=%s +#>>>&0 der utc_time=x \b, not-valid-after=%s >>&0 der seq >>>&0 der set >>>>&0 der seq @@ -12182,7 +12365,7 @@ 0 string FCS3.0 Flow Cytometry Standard (FCS) data, version 3.0 #------------------------------------------------------------------------------ -# $File: filesystems,v 1.149 2022/05/21 22:50:28 christos Exp $ +# $File: filesystems,v 1.150 2022/07/04 16:40:33 christos Exp $ # filesystems: file(1) magic for different filesystems # 0 name partid @@ -14845,6 +15028,32 @@ >>0x107b byte x \b, %d devices >>0x1090 byte ^0x02 \b (unclean) +# EROFS +# https://kernel.googlesource.com/pub/scm/linux/kernel/git/xiang/erofs-utils/\ +# +/refs/heads/experimental/include/erofs_fs.h#12 +1024 lelong 0xE0F5E1E2 EROFS filesystem +#>1028 lelong x \b, checksum=%#x +>1032 lelong >0 \b, compat: +>>1032 lelong &1 SB_CHKSUM +>>1032 lelong &2 MTIME +>1036 byte x \b, blocksize=%u +>1037 byte x \b, exslots=%u +#>1038 leshort x \b, root_nid=%d +#>1040 lequad x \b, inodes=%ld +#>1048 leldate x \b, build_time=%s +#>1056 lelong x \b.%d +#>1060 lelong x \b, blocks=%d +#>1064 lelong x \b, metadata@%#x +#>1068 lelong x \b, xattr@%#x +>1072 guid x \b, uuid=%s +>1088 string >0 \b, name=%s +>1104 lelong >0 \b, incompat: +>>1104 lelong &1 LZ4_0PADDING +>>1104 lelong &2 BIG_PCLUSTER +>>1104 lelong &4 CHUNKED_FILE +>>1104 lelong &8 DEVICE_TABLE +>>1104 lelong &16 ZTAILPACKING + #------------------------------------------------------------------------------ # $File: finger,v 1.3 2019/04/19 00:42:27 christos Exp $ # fingerprint: file(1) magic for fingerprint data @@ -14960,7 +15169,7 @@ >>4 string =d \b, RGBA, interlaced #------------------------------------------------------------------------------ -# $File: fonts,v 1.50 2022/03/21 21:28:13 christos Exp $ +# $File: fonts,v 1.51 2022/08/16 11:16:39 christos Exp $ # fonts: file(1) magic for font data # 0 search/1 FONT ASCII vfont text @@ -15402,6 +15611,7 @@ # https://www.w3.org/TR/WOFF2/ 0 string wOF2 Web Open Font Format (Version 2) !:mime font/woff2 +!:ext woff2 >0 use woff #>20 belong x \b, totalCompressedSize %d >24 beshort x \b, version %d @@ -16402,6 +16612,86 @@ # From: Marek Cermak # 0 lelong 0x20010324 gconv module configuration cache data +#------------------------------------------------------------------------------ +# $File: gentoo,v 1.2 2022/09/12 13:13:28 christos Exp $ +# gentoo: file(1) magic for gentoo specific formats +# +# Summary: Gentoo ebuild Manifest files (GLEP 74) +# Reference: https://www.gentoo.org/glep/glep-0074.html +# Submitted by: Michal Gorny +# Start by doing a fast check for the most common tags. +0 string AUX +>0 use gentoo-manifest +0 string DATA +>0 use gentoo-manifest +0 string DIST +>0 use gentoo-manifest +0 string EBUILD +>0 use gentoo-manifest +0 string MANIFEST +>0 use gentoo-manifest + +# Manifest can be PGP-signed. +0 string -----BEGIN\040PGP\040SIGNED\040MESSAGE----- +>34 search/32 \n\n +>>&0 string AUX +>>>&0 use gentoo-manifest +>>&0 string DATA +>>>&0 use gentoo-manifest +>>&0 string DIST +>>>&0 use gentoo-manifest +>>&0 string EBUILD +>>>&0 use gentoo-manifest +>>&0 string MANIFEST +>>>&0 use gentoo-manifest + +# Use a more detailed regex to verify that we were correct. +# ... +# ('s already been matched prior to calling) +0 name gentoo-manifest +>&0 regex [[:space:]]+[[:print:]]+[[:space:]]+[[:digit:]]+[[:space:]]+[[:alnum:]]+[[:space:]]+[[:xdigit:]]{32} Gentoo Manifest (GLEP 74) + +# Summary: Gentoo ebuild and eclass files +# Reference: https://projects.gentoo.org/pms/8/pms.html +# Submitted by: Michal Gorny +0 search/512 EAPI= +>0 regex .*\n[\040\t]*EAPI=["']? Gentoo ebuild +>>&0 regex [[:alnum:]+_.-]+ \b, EAPI %s + +0 search/512 @ECLASS:\040 Gentoo eclass +>&0 string x %s + +# Summary: Gentoo supplementary package and category metadata files +# Reference: https://www.gentoo.org/glep/glep-0068.html +# Submitted by: Michal Gorny +0 string \0 search/512 \0 search/512 \ + +# GPKG uses ustar (or ustar-compatible GNU format) that starts with +# a /gpkg-1 file +257 string ustar +>0 search/100 /gpkg-1\0 +>>0 regex [^/]+ Gentoo GLEP 78 (GPKG) binary package for "%s" +!:mime application/x-tar +!:ext tar +# the logic below requires the gpkg-1 file to be empty +>>>124 string 00000000000\0 +# determine the compression used by looking at the second member name +>>>>512 search/100 .tar. +>>>>>&0 string gz\0 using gzip compression +>>>>>&0 string bz2\0 using bzip2 compression +>>>>>&0 string lz\0 using lzip compression +>>>>>&0 string lz4\0 using lz4 compression +>>>>>&0 string lzo\0 using lzo compression +>>>>>&0 string xz\0 using xz compression +>>>>>&0 string zst\0 using zstd compression +>>>>(636.o+1024) search/611 .sig\0 \b, signed #------------------------------------------------------------------------------ # $File: geo,v 1.8 2022/03/24 15:48:58 christos Exp $ @@ -18136,7 +18426,7 @@ !:mime application/x-blorb #------------------------------------------------------------------------------ -# $File: images,v 1.223 2022/05/14 20:05:09 christos Exp $ +# $File: images,v 1.227 2022/09/11 20:58:52 christos Exp $ # images: file(1) magic for image formats (see also "iff", and "c-lang" for # XPM bitmaps) # @@ -18501,7 +18791,7 @@ >>>8 default x >>>>8 uleshort x \b(unknown %#x) >>>12 use tiff_entry ->0 uleshort 0x106 \b, PhotometricIntepretation= +>0 uleshort 0x106 \b, PhotometricInterpretation= >>8 clear x >>8 uleshort 0 \bWhiteIsZero >>8 uleshort 1 \bBlackIsZero @@ -19594,7 +19884,25 @@ >2 quad !0 # skip g3test.g3 by test for unused bits of 2nd color entry >>4 ubeshort&0xF000 0 ->>>0 use degas-bitmap +#>>>0 beshort x 1ST_VALUE=%x +>>>-0 offset x FILE_SIZE=%lld +# standard DEGAS low-res uncompressed bitmap *.pi1 with file size 32034 +>>>-0 offset =32034 VARIANT_STANDARD +#>>>>0 beshort x 1st_VALUE=%x +# like: 8ball.pi1 teddy.pi1 sonic01.pi1 +>>>>0 use degas-bitmap +# about 61 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32066 +>>>-0 offset =32066 VARIANT_ELITE +# like: spider.pi1 pinkgirl.pi1 frog3.pi1 +>>>>0 use degas-bitmap +# about 55 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 32128 +>>>-0 offset =32128 VARIANT_3 +# like: mountain.pi1 bigspid.pi1 alf33.pi1 +>>>>0 use degas-bitmap +# 1 DEGAS Elite low-res uncompressed bitmap *.pi1 with file size 44834 +>>>-0 offset =44834 VARIANT_4 +# like: kenshin.pi1 +>>>>0 use degas-bitmap # DEGAS mid-res uncompressed bitmap *.pi2 (strength=50) after GEM Images like: # BEETHVEN.IMG CHURCH.IMG GAMEOVR4.IMG TURKEY.IMG clinton.img 0 beshort 0x0001 @@ -20346,10 +20654,104 @@ # height (80,90) >>0x53 uleshort x \b%d +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Imageiio/imaginfo_(Ulead) +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe3.trid.xml +# Note: called "Ulead Imageiio/Imaginfo thumbnail" by TrID +0 string IIO1$ Ulead Photo Explorer 3 +#!:mime application/octet-stream +!:mime image/x-ulead-pe3 +# IMAGEIIO.PE3 +!:ext pe3 +# look for DOS/Windows drive letter +>5 search/192/s :\\ +# directory or full name of corresponding imaginfo.pe3 like: "T:\SAMPLES\TEXTURES\SKY_SNOW\IIOE371.TMP "S:\PI3\PIMPACT3\PROGRAMS\PATTERNS\imaginfo.pe3" +>>&-1 string x "%s" +# look for DOS/Windows network path if no drive letter part +>5 default x +>>5 search/192/s \x5c\x5c +# full name of corresponding imaginfo.pe3 like: "\\Lionking\upi\SAMPLES\IMAGES\ANIMALS\imaginfo.pe3" +>>>&0 string x "%s" # Type: Ulead Photo Explorer5 (.pe5) -# URL: http://www.jisyo.com/cgibin/view.cgi?EXT=pe5 (Japanese) +# URL: http://fileformats.archiveteam.org/wiki/Imageiio/imaginfo_(Ulead) +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe4.trid.xml # From: Simon Horman -0 string IIO2H Ulead Photo Explorer5 +# Update: Joerg Jenderek +# Note: some called "Ulead Imageiio/Imaginfo thumbnail" by TrID +# and used in various Ulead applications +0 string IIO2H Ulead Photo Explorer 4 or 5 +#!:mime application/octet-stream +!:mime image/x-ulead-pe4 +# IMAGEIIO.PE4 +!:ext pe4/pe5 +# look in most samples for JPEG signature like: SAMPLES/IMAGES/SCENES/IMAGINFO.PE4 +>0x4c2 search/0xE02/s JFIF with JPEG image data +>>&-6 use jpeg +# near the end list of image names like: Img0001.pcd 1116012L.JPG NCARD4.TPL +# +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe3-imaginfo.trid.xml +11 string \001\0\0\0\0 +# check for version 3 part +>19 string \0\001\0\003\0 +>>0 use ulead-imaginfo +# From: Joerg Jenderek +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pe4-imaginfo.trid.xml +11 string \001\0\0\0\0 +# check for version 4 part +>19 string \0\0\0\004\0 +>>0 use ulead-imaginfo +# display information about Ulead Imaginfo thumbnail (version, directory, image extension) +0 name ulead-imaginfo +>22 ubyte x Ulead Imaginfo thumbnail +#!:mime application/octet-stream +!:mime image/x-ulead-imaginfo +>22 ubyte =3 \b, version 3 +# IMAGINFO.PE3 +!:ext pe3 +>22 ubyte =4 \b, version 4 +# IMAGINFO.PE4 +!:ext pe4 +# MAYBE ALSO VERSION 5 ? +#>22 ubyte =5 \b, version 5 +#!:ext pe5 +>22 ubyte x +# look for DOS/Windows driver letter +>>4 search/192/s :\x5c +# skip f:\Programme\iPhoto Plus 4\Template\Business Cards\IMAGINFO.PE4 +# by looking for driver letter in range A-Z +>>>&-1 ubyte >0x40 +# directory path like: "E:\iPE\CDSample\Images\Scenes" "D:\XmasCard\Samples" "C:\TEMP\PLANTS" +>>>>&-5 pstring/l >0 \b, "%s" +# look for DOS/Windows network path if no valid drive letter part +>>>&-1 default x +>>>>4 search/192/s \x5c\x5c +# directory path like: "\\FSX\SYS\OPPS\IPE.ENG\TEMPLATE\BUSINESS" "\\Lionking\upi\SAMPLES\IMAGES\ANIMALS" +>>>>>&-4 pstring/l >0 \b, "%s" +# look for DOS/Windows network path if no drive letter part +>>4 default x +>>>4 search/192/s \x5c\x5c +# directory path like: "\\FSX\SYS\opps\ipe.eng\samples" "\\DANIEL\IPE_CD\IPE.ITA" +>>>>&-4 pstring/l >0 \b, "%s" +# look for point character inside image names +>56 search/38/s . +# image name extension like: bmp jpg pcd tpl +>>&1 string x with %-.3s images +# Summary: Ulead Pattern image (Corel Corporation) +# URL: https://en.wikipedia.org/wiki/Ulead_Systems +# https://www.file-extensions.org/pst-file-extension-ulead-pattern-image-format +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pst-ulead.trid.xml +# From: Joerg Jenderek +# Note: used also by CorelDraw Essentials 3 version 13.0.0.800 +# there seems to exist other versions +0 ubelong 0xFFFF0100 +>8 search/21 PresetInfo Ulead pattern image +#!:mime application/octet-stream +!:mime image/x-ulead-pst +!:ext pst +# string length like: 16 18 19 21 24 +#>>4 uleshort x n=%u +# like: BlendPresetInfo DropShadowPresetInfo FileNewPresetInfo VectorExtrudePresetInfo EnvelopePresetInfo ContourPresetInfo DistortionPresetInfo +>>4 pstring/h x "%s" # Type: X11 cursor # URL: http://webcvs.freedesktop.org/mime/shared-mime-info/freedesktop.org.xml.in?view=markup @@ -21951,6 +22353,17 @@ >0x24 ulelong 2 \b, embedded WebP image >0x24 ulelong 3 \b, Basis Universal +# Summary: iCEDraw graphic *.IDF +# URL: http://fileformats.archiveteam.org/wiki/ICEDraw +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/i/idf-icedraw.trid.xml +# From: Joerg Jenderek +# Note: called "iCEDraw graphic" by TrID, "iCEDraw text" by FFmpeg and "iCE Draw" by Ansilove +# verified by FFmpeg command `ffprobe ICE-9605.IDF` and `ansilove -s SQ-FORCE.IDF` +0 string \0041.4\0\0\0\0O\0 iCEDraw graphic +#!:mime application/octet-stream +!:mime image/x-idf +!:ext idf + #------------------------------------------------------------------------------ # $File: inform,v 1.5 2009/09/19 16:28:09 christos Exp $ # inform: file(1) magic for Inform interactive fiction language @@ -22413,7 +22826,7 @@ !:mime application/x-java-image #------------------------------------------------------------------------------ -# $File: javascript,v 1.3 2021/12/08 13:42:00 christos Exp $ +# $File: javascript,v 1.4 2022/09/02 08:08:17 christos Exp $ # javascript: magic for javascript and node.js scripts. # 0 string/w #!/bin/node Node.js script text executable @@ -22434,8 +22847,107 @@ 0 lequad 0x1F1903C103BC1FC6 Hermes JavaScript bytecode >8 lelong x \b, version %d +# v8 JavaScript engine bytecode +# From: Alexandre Iooss +# URL: https://v8.dev/docs/ignition +# Note: used in bytenode and NW.js protected source code +# V8 bytecode extraction was added in NodeJS v5.7.0 (V8 4.6.85.31). +# Version information is provided for some v8 versions found in NodeJS releases. +2 uleshort =0xC0DE +>0 ulelong^0xC0DE0000 >0 +# Reservation table starts at 40 +>>40 ulelong&0xFFFFFF00 =0x80000000 +# Stub keys present +>>>24 ulelong >0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0xEE4BF478 version 5.1.281.111, +>>>>4 ulelong =0xC4A0100C version 5.5.372.43, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x cpu features: %#08X, +>>>>16 ulelong x flag hash: %#08X, +>>>>20 ulelong x %u reservations, +>>>>28 ulelong x payload size: %u bytes, +>>>>32 ulelong x checksum1: %#08X, +>>>>36 ulelong x checksum2: %#08X +# No stub keys +>>>24 ulelong =0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x54F0AD81 version 6.2.414.46, +>>>>4 ulelong =0X7D1BF182 version 6.2.414.54, +>>>>4 ulelong =0x35BA122E version 6.2.414.77, +>>>>4 ulelong =0X9319F9C2 version 6.2.414.78, +>>>>4 ulelong =0xB1240060 version 6.6.346.32, +>>>>4 ulelong =0x2B757060 version 6.7.288.46, +>>>>4 ulelong =0x09D147AA version 6.7.288.49, +>>>>4 ulelong =0xF4D4F48A version 6.8.275.32, +>>>>4 ulelong =0xD3961326 version 7.0.276.38, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x cpu features: %#08X, +>>>>16 ulelong x flag hash: %#08X, +>>>>20 ulelong x %u reservations, +>>>>28 ulelong x payload size: %u bytes, +>>>>32 ulelong x checksum1: %#08X, +>>>>36 ulelong x checksum2: %#08X +# Reservation table starts at 32 +>>32 ulelong&0xFFFFFF00 =0x80000000 +# Second checksum present +>>>28 ulelong >0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x21DDF627 version 7.4.288.21, +>>>>4 ulelong =0x1FC9FE84 version 7.4.288.27, +>>>>4 ulelong =0x60A99E8B version 7.5.288.22, +>>>>4 ulelong =0x4F665E90 version 7.6.303.29, +>>>>4 ulelong =0xC7ACFCDE version 7.7.299.11, +>>>>4 ulelong =0x7F641D8F version 7.7.299.13, +>>>>4 ulelong =0xFD9A4F2E version 7.8.279.17, +>>>>4 ulelong =0x3A845324 version 7.8.279.23, +>>>>4 ulelong =0xFF52FEAF version 7.9.317.25, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x flag hash: %#08X, +>>>>16 ulelong x %u reservations, +>>>>20 ulelong x payload size: %u bytes, +>>>>24 ulelong x checksum1: %#08X, +>>>>28 ulelong x checksum2: %#08X +# No second checksum +>>>28 ulelong =0 +>>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>>4 ulelong =0x8725E0F8 version 8.1.307.30, +>>>>4 ulelong =0x09ED1289 version 8.1.307.31, +>>>>4 ulelong =0xA5728C87 version 8.3.110.9, +>>>>4 ulelong =0xB45C5D30 version 8.4.371.23, +>>>>4 ulelong =0xED9C278B version 8.4.371.19, +>>>>4 ulelong =0xD27BFF42 version 8.6.395.16, +>>>>8 ulelong x source size: %u bytes, +>>>>12 ulelong x flag hash: %#08X, +>>>>16 ulelong x %u reservations, +>>>>20 ulelong x payload size: %u bytes, +>>>>24 ulelong x payload checksum: %#08X +# No reservation table and code starts at 24 +>>32 ulelong =0 +>>>0 ulelong^0xC0DE0000 x v8 bytecode, external reference table size: %u bytes, +>>>4 ulelong =0x9A6F0B0F version 9.0.257.17, +>>>4 ulelong =0x271D5D1E version 9.0.257.24, +>>>4 ulelong =0x4EEA75DF version 9.0.257.25, +>>>4 ulelong =0x80809479 version 9.1.269.36, +>>>4 ulelong =0x55C46F65 version 9.1.269.38, +>>>4 ulelong =0x8A9C758A version 9.2.230.21, +>>>4 ulelong =0x9712F0E1 version 9.3.345.16, +>>>4 ulelong =0x29593715 version 9.4.146.19, +>>>4 ulelong =0xCD991825 version 9.4.146.24, +>>>4 ulelong =0xACDD64EE version 9.4.146.26, +>>>4 ulelong =0xC96B4CD5 version 9.5.172.21, +>>>4 ulelong =0xBCCE4578 version 9.5.172.25, +>>>4 ulelong =0xA2EEA077 version 9.6.180.15, +>>>4 ulelong =0xFD350011 version 10.1.124.8, +>>>4 ulelong =0xBEF4028F version 10.2.154.13, +>>>4 ulelong =0xAF632352 version 10.2.154.4, +>>>8 ulelong x source size: %u bytes, +>>>12 ulelong x flag hash: %#08X, +>>>16 ulelong x payload size: %u bytes, +>>>20 ulelong x payload checksum: %#08X + #------------------------------------------------------------------------------ -# $File: jpeg,v 1.36 2021/08/28 12:30:52 christos Exp $ +# $File: jpeg,v 1.37 2022/06/17 18:03:35 christos Exp $ # JPEG images # SunOS 5.5.1 had # @@ -22538,45 +23050,154 @@ #>>(2.S+2) use jpeg_segment # HSI is Handmade Software's proprietary JPEG encoding scheme +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/HSI_JPEG +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-hsi1.trid.xml +# Note: called by TrID "HSI JPEG bitmap" 0 string hsi1 JPEG image data, HSI proprietary +#!:mime application/octet-stream +!:mime image/x-hsi +!:ext hsi/jpg # From: David Santinoli 0 string \x00\x00\x00\x0C\x6A\x50\x20\x20\x0D\x0A\x87\x0A JPEG 2000 +# delete from ./animation (version 1.87) with jP (=6A50h) magic at offset 4 # From: Johan van der Knijff # Added sub-entries for JP2, JPX, JPM and MJ2 formats; added mimetypes # https://github.com/bitsgalore/jp2kMagic # # Now read value of 'Brand' field, which yields a few possibilities: +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JP2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpeg2k.trid.xml +# Note: called by TrID "JPEG 2000 bitmap" >20 string \x6a\x70\x32\x20 Part 1 (JP2) +# aliases image/jpeg2000, image/jpeg2000-image, image/x-jpeg2000-image !:mime image/jp2 +!:ext jp2 +# URL: http://fileformats.archiveteam.org/wiki/JPX +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpx.trid.xml +# Note: called by TrID "JPEG 2000 eXtended bitmap" >20 string \x6a\x70\x78\x20 Part 2 (JPX) !:mime image/jpx +!:ext jpf/jpx +# URL: http://fileformats.archiveteam.org/wiki/JPM +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpm.trid.xml +# Note: called by TrID "JPEG 2000 eXtended bitmap" >20 string \x6a\x70\x6d\x20 Part 6 (JPM) !:mime image/jpm +!:ext jpm +# URL: http://fileformats.archiveteam.org/wiki/MJ2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/v/video-mj2.trid.xml +# Note: called by TrID "Motion JPEG 2000 video" >20 string \x6d\x6a\x70\x32 Part 3 (MJ2) !:mime video/mj2 +!:ext mj2/mjp2 # Type: JPEG 2000 codesream # From: Mathieu Malaterre +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_2000_codestream +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jpc.trid.xml +# Note: called by TrID "JPEG-2000 Code Stream bitmap" 0 belong 0xff4fff51 JPEG 2000 codestream -45 beshort 0xff52 +# value like: 0701h FF50h +#>45 ubeshort x \b, at 45 %#4.4x +#!:mime application/octet-stream +# https://reposcope.com/mimetype/image/x-jp2-codestream +!:mime image/x-jp2-codestream +!:ext jpc/j2c/j2k +# MAYBE also JHC like in byte_causal.jhc ? +# WHAT IS THAT? DEAD ENTRY? +#45 beshort 0xff52 # JPEG extended range +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XR +# Reference: https://www.itu.int/rec/T-REC-T.832 +# http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wmp.trid.xml +# Note: called by TrID "JPEG XR bitmap" 0 string \x49\x49\xbc +# FILE_VERSION_ID; shall be equal to 1; other values are reserved for future use >3 byte 1 +# FIRST_IFD_OFFSET; shall be an integer multiple of 2; so skip DROID fmt-590-signature-id-931.wdp >>4 lelong%2 0 JPEG-XR +#!:mime image/vnd.ms-photo !:mime image/jxr -!:ext jxr +# NO example for HDP ! +!:ext jxr/wdp/hdp +# MAYBE also WMP ? +#!:ext jxr/wdp/hdp/wmp +# moved from ./images (version 1.205 ), merged and +# partly verified by XnView `nconvert -info abydos.jxr FLOWER.wdp` +# example: https://web.archive.org/web/20160403012904/ +# http://shikino.co.jp/solution/upfile/FLOWER.wdp.zip +>90 bequad 0x574D50484F544F00 +>>98 byte&0x08 =0x08 \b, hard tiling +>>99 byte&0x80 =0x80 \b, tiling present +>>99 byte&0x40 =0x40 \b, codestream present +>>99 byte&0x38 x \b, spatial xform= +>>99 byte&0x38 0x00 \bTL +>>99 byte&0x38 0x08 \bBL +>>99 byte&0x38 0x10 \bTR +>>99 byte&0x38 0x18 \bBR +>>99 byte&0x38 0x20 \bBT +>>99 byte&0x38 0x28 \bRB +>>99 byte&0x38 0x30 \bLT +>>99 byte&0x38 0x38 \bLB +>>100 byte&0x80 =0x80 \b, short header +>>>102 beshort+1 x \b, %d +>>>104 beshort+1 x \bx%d +>>100 byte&0x80 =0x00 \b, long header +>>>102 belong+1 x \b, %x +>>>106 belong+1 x \bx%x +>>101 beshort&0xf x \b, bitdepth= +>>>101 beshort&0xf 0x0 \b1-WHITE=1 +>>>101 beshort&0xf 0x1 \b8 +>>>101 beshort&0xf 0x2 \b16 +>>>101 beshort&0xf 0x3 \b16-SIGNED +>>>101 beshort&0xf 0x4 \b16-FLOAT +>>>101 beshort&0xf 0x5 \b(reserved 5) +>>>101 beshort&0xf 0x6 \b32-SIGNED +>>>101 beshort&0xf 0x7 \b32-FLOAT +>>>101 beshort&0xf 0x8 \b5 +>>>101 beshort&0xf 0x9 \b10 +>>>101 beshort&0xf 0xa \b5-6-5 +>>>101 beshort&0xf 0xb \b(reserved %d) +>>>101 beshort&0xf 0xc \b(reserved %d) +>>>101 beshort&0xf 0xd \b(reserved %d) +>>>101 beshort&0xf 0xe \b(reserved %d) +>>>101 beshort&0xf 0xf \b1-BLACK=1 +>>101 beshort&0xf0 x \b, colorfmt= +>>>101 beshort&0xf0 0x00 \bYONLY +>>>101 beshort&0xf0 0x10 \bYUV240 +>>>101 beshort&0xf0 0x20 \bYWV422 +>>>101 beshort&0xf0 0x30 \bYWV444 +>>>101 beshort&0xf0 0x40 \bCMYK +>>>101 beshort&0xf0 0x50 \bCMYKDIRECT +>>>101 beshort&0xf0 0x60 \bNCOMPONENT +>>>101 beshort&0xf0 0x70 \bRGB +>>>101 beshort&0xf0 0x80 \bRGBE +>>>101 beshort&0xf0 >0x80 \b(reserved %#x) # JPEG XL # From: Ian Tester +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl.trid.xml +# Note: called by TrID "JPEG XL bitmap" 0 string \xff\x0a JPEG XL codestream -!:mime image/jxl +#!:mime image/jxl +!:mime image/x-jxl !:ext jxl # JPEG XL (transcoded JPEG file) +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/JPEG_XL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-jxl-iso.trid.xml +# Note: called by TrID "JPEG XL bitmap (ISOBMFF)" 0 string \x00\x00\x00\x0cJXL\x20\x0d\x0a\x87\x0a JPEG XL container -!:mime image/jxl +#!:mime image/jxl +!:mime image/x-jxl !:ext jxl #------------------------------------------------------------------------------ @@ -22915,7 +23536,7 @@ #------------------------------------------------------------------------------ -# $File: linux,v 1.80 2022/03/24 15:48:58 christos Exp $ +# $File: linux,v 1.82 2022/09/07 11:23:44 christos Exp $ # linux: file(1) magic for Linux files # # Values for Linux/i386 binaries, from Daniel Quinlan @@ -23279,16 +23900,6 @@ >24 lelong x %d symbols >28 lelong x %d ocons -# LUKS: Linux Unified Key Setup, On-Disk Format, http://luks.endorphin.org/spec -# Anthon van der Neut (anthon@mnt.org) -0 string LUKS\xba\xbe LUKS encrypted file, ->6 beshort x ver %d ->8 string x [%s, ->40 string x %s, ->72 string x %s] ->168 string x UUID: %s - - # Summary: Xen saved domain file # Created by: Radek Vokal 0 string LinuxGuestRecord Xen saved domain @@ -23451,6 +24062,27 @@ >>&0 string ; >>>&0 regex [A-Z0-9]+ \b, encryption %s +# From: Joerg Jenderek +# URL: https://www.gnu.org/software/grub +# Reference: https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz +# grub-2.06/include/grub/keyboard_layouts.h +# grub-2.06/grub-core/commands/keylayouts.c +# GRUB_KEYBOARD_LAYOUTS_FILEMAGIC +0 string GRUBLAYO GRUB Keyboard +!:mime application/x-grub-keyboard +!:ext gkb +# GRUB_KEYBOARD_LAYOUTS_VERSION like: 10 +>8 ulelong !10 \b, version %u +# 4 grub_uint32_t grub_keyboard_layout[160] +# for normal french keyboard this is letter a +>92 ubyte !0x71 +>>92 ubyte >0x40 \b, english q is %c +#>732 ubyte x \b, english Q is %c +# for normal german keyboard this is letter z +>124 ubyte !0x79 +>>124 ubyte >0x40 \b, english y is %c +#>764 ubyte x \b, english Y is %c + #------------------------------------------------------------------------------ # $File: lisp,v 1.27 2020/08/14 19:23:39 christos Exp $ # lisp: file(1) magic for lisp programs @@ -23594,17 +24226,130 @@ >4 byte 0x54 version 5.4 #------------------------------------------------------------------------------ -# $File: luks,v 1.4 2009/09/19 16:28:10 christos Exp $ +# $File: luks,v 1.5 2022/09/07 11:23:44 christos Exp $ # luks: file(1) magic for Linux Unified Key Setup -# URL: http://luks.endorphin.org/spec +# URL: https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup +# http://fileformats.archiveteam.org/wiki/LUKS # From: Anthon van der Neut +# Update: Joerg Jenderek +# Note: verfied by command like `cryptsetup luksDump /dev/sda3` 0 string LUKS\xba\xbe LUKS encrypted file, +# https://reposcope.com/mimetype/application/x-raw-disk-image +!:mime application/x-raw-disk-image +#!:mime application/x-luks-volume +# img is the generic extension; no suffix for partitions; luksVolumeHeaderBackUp via zuluCrypt +!:ext /luks/img/luksVolumeHeaderBackUp +# version like: 1 2 >6 beshort x ver %d +# test for version 1 variant +>6 beshort 1 +>>0 use luks-v1 +# test for version 2 variant +>6 beshort >1 +>>0 use luks-v2 +# Reference: https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/l/luks.trid.xml +# display information about LUKS version 1 +0 name luks-v1 +# cipher-name like: aes twofish >8 string x [%s, +# cipher-mode like: xts-plain64 cbc-essiv >40 string x %s, +# hash specification like: sha256 sha1 ripemd160 >72 string x %s] >168 string x UUID: %s +# NEW PART! +# payload-offset; start offset of the bulk data +>104 ubelong x \b, at %#x data +# key-bytes; number of key bytes; key-bytes*8=MK-bits +>108 ubelong x \b, %u key bytes +# mk-digest[20]; master key checksum from PBKDF2 +>112 ubequad x \b, MK digest %#16.16llx +>>120 ubequad x \b%16.16llx +>>128 ubelong x \b%8.8x +# mk-digest-salt[32]; salt parameter for master key PBKDF2 +>132 ubequad x \b, MK salt %#16.16llx +>>140 ubequad x \b%16.16llx +>>148 ubequad x \b%16.16llx +>>156 ubequad x \b%16.16llx +# mk-digest-iter; iterations parameter for master key PBKDF2 +>164 ubelong x \b, %u MK iterations +# key slot 1 +>208 ubelong =0x00AC71F3 \b; slot #0 +>>208 use luks-slot +# key slot 2 +>256 ubelong =0x00AC71F3 \b; slot #1 +>>256 use luks-slot +# key slot 3 +>304 ubelong =0x00AC71F3 \b; slot #2 +>>304 use luks-slot +# key slot 4 +>352 ubelong =0x00AC71F3 \b; slot #3 +>>352 use luks-slot +# key slot 5 +>400 ubelong =0x00AC71F3 \b; slot #4 +>>400 use luks-slot +# key slot 6 +>448 ubelong =0x00AC71F3 \b; slot #5 +>>448 use luks-slot +# key slot 7 +>496 ubelong =0x00AC71F3 \b; slot #6 +>>496 use luks-slot +# key slot 8 +>544 ubelong =0x00AC71F3 \b; slot #7 +>>544 use luks-slot +# Reference: https://gitlab.com/cryptsetup/LUKS2-docs/-/raw/master/luks2_doc_wip.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/l/luks2.trid.xml +# display information about LUKS version 2 +0 name luks-v2 +# hdr_size; size including JSON area called Metadata area by cryptsetup with value like: 16384 +>8 ubequad x \b, header size %llu +# possible check for MAGIC_2ND after header +#>(8.Q) string SKUL\xba\xbe \b, 2nd_HEADER_OK +# seqid; sequence ID, increased on update; called Epoch by cryptsetup with value like: 3 4 8 10 +>16 ubequad x \b, ID %llu +# label[48]; optional ASCII label or empty; called Label by cryptsetup with value like: "LUKS2_EXT4_ROOT" +>24 string >\0 \b, label %s +# csum_alg[32]; checksum algorithm like: sha256 sha1 sha512 wirlpool ripemd160 +>72 string x \b, algo %s +# salt[64]; salt , unique for every header +>104 ubequad x \b, salt %#llx... +# uuid[40]; UID of device as string like: 242256c6-396e-4a35-af5f-5b70cb7af9a7 +>168 string x \b, UUID: %-.40s +# subsystem[48]; optional owner subsystem label or empty +>208 string >\0 \b, sub label %-.48s +# hdr_offset; offset from device start [ bytes ] like: 0 +>256 ubequad !0 \b, offset %llx +# char _padding [184]; must be zeroed +#>264 ubequad x \b, padding %#16.16llx +#>440 ubequad x \b...%16.16llx +# csum[64]; header checksum +>448 ubequad x \b, crc %#llx... +# char _padding4096 [7*512]; Padding , must be zeroed +#>512 ubequad x \b, more padding %#16.16llx +#>4088 ubequad x \b...%16.16llx +# JSON text data terminated by the zero character; unused remainder empty and filled with zeroes like: +# {"keyslots":{"0":{"type":"luks2","key_size":64,"af":{"type":"luks1","stripes":4000,"hash":"sha256"},"area":{"type":"raw","offse" +>0x1000 string x \b, at 0x1000 %s +#>0x1000 indirect x +# display information (like active) about LUKS1 slot +0 name luks-slot +# state of keyslot; 0x00AC71F3~active 0x0000DEAD~inactive +#>0 ubelong x \b, status %#8.8x +>0 ubelong =0x00AC71F3 active +>0 ubelong =0x0000DEAD inactive +# iteration parameter for PBKDF2 +#>4 ubelong x \b, %u iterations +# salt parameter for PBKDF2 +#>8 ubequad x \b, salt %#16.16llx +#>>16 ubequad x \b%16.16llx +#>>24 ubequad x \b%16.16llx +#>>32 ubequad x \b%16.16llx +# start sector of key material like: 8 0x200 0x3f8 0x5f0 0xdd0 +>40 ubelong x \b, %#x material offset +# number of anti-forensic stripes like: 4000 +>44 ubelong !4000 \b, %u stripes #------------------------------------------------------------------------------ # $File: m4,v 1.3 2019/02/27 16:46:23 christos Exp $ # make: file(1) magic for M4 scripts @@ -24440,7 +25185,7 @@ 0 belong 0xF11E041C magic binary file for file(1) cmd >4 belong x (version %d) (big endian) #------------------------------------------------------------------------------ -# $File: mail.news,v 1.28 2021/09/11 19:20:15 christos Exp $ +# $File: mail.news,v 1.29 2022/06/17 18:02:19 christos Exp $ # mail.news: file(1) magic for mail and news # # Unfortunately, saved netnews also has From line added in some news software. @@ -24485,8 +25230,54 @@ #0 string/t Content- MIME entity text # TNEF files... -0 lelong 0x223E9F78 Transport Neutral Encapsulation Format +# URL: http://fileformats.archiveteam.org/wiki/Transport_Neutral_Encapsulation_Format +# https://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/t/tnef.trid.xml +# https://interoperability.blob.core.windows.net/files/MS-OXTNEF/%5bMS-OXTNEF%5d-210817.pdf +# Update: Joerg Jenderek +# Note: moved and merged from ./msdos (version 1.154) there just called "TNEF" +# partly verified by `tnef --list -v -f voice.tnef` and `ytnef -v triples.tnef` +# TNEF magic From "Joomy" +# TNEF_SIGNATURE +0 lelong 0x223E9F78 Transport Neutral Encapsulation Format (TNEF) !:mime application/vnd.ms-tnef +# winmail.dat or win.dat by Microsoft Outlook +!:ext tnef/dat +# https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxtnef/7fdb64ee-7f63-4d95-9af1-c672e7475c3a +# LegacyKey +#>4 uleshort x \b, key %#4.4x +# attrLevelMessage; Level where attribute applies like: 1~attrLevelMessage 2~attrLevelAttachment +>6 ubyte !1 \b, 1st level %#2.2x +# other ID (like 02900000h) or TnefVersion ID (idTnefVersion=06900800h) +>7 ubelong !0x06900800 \b, 1st id %#8.8x +>7 ubelong =0x06900800 +# TnefVersion lenght like: 4 +>>11 ulelong !4 \b, TnefVersion length %x +# TNEFVersionData; TnefVersion data like: 00010000h +>>15 ulelong !0x00010000h \b, version %#8.8x +# Checksum like: 1 +>>19 uleshort !1 \b, checksum %#4.4x +# attrLevelMessage; level of attOemCodepage like: 1 +>>21 ubyte !1 \b, level %#2.2x +# idOEMCodePage; OEMCodePage ID like: 07900600h +>>22 ubelong =0x07900600 \b, OEM codepage +# OEMCodePage length like: 8 +>>>26 ulelong =8 +# OEMCodePageData; PrimaryCodePage like: 1251 1252 +>>>>30 ulelong x %u +# OEMCodePageData; SecondaryCodePage; unused and SHOULD contain zero +>>>>34 ulelong !0 and %u +# OEMCodePageData Checksum like: E7h E8h +>>>>38 uleshort x (checksum %#x) +# attrLevelMessage of attMessageClass like: 1 +>>40 ubyte !1 \b, level %u +# idMessageClass; ID of attMessageClass like: 08800700h +>>41 ubelong =0x08800700 \b, MessageAttribute +# attMessageClass length like: 16 24 25 +#>>>45 ulelong x (length %u) +# attMessageClass data like: "IPM.Microsoft Mail.Note" "IPM.Note.Portada Newseum" +# "IPM.Appointment" "IPM.Note.Microsoft.Voicemail.UM.CA" +>>>45 pstring/l x "%s" # From: Kevin Sullivan 0 string *mbx* MBX mail folder @@ -25929,7 +26720,7 @@ #>4 use zip-dir-entry #------------------------------------------------------------------------------ -# $File: msdos,v 1.154 2022/03/21 21:25:50 christos Exp $ +# $File: msdos,v 1.158 2022/09/07 11:17:31 christos Exp $ # msdos: file(1) magic for MS-DOS files # @@ -26516,7 +27307,8 @@ # skip "GPG symmetrically encrypted data" ./gnu # skip "PGP symmetric key encrypted data" ./pgp # openpgpdefs.h: fourth byte < 14 indicate cipher algorithm type ->>>4 ubyte >13 DOS executable (COM, 0x8C-variant) +>>>4 ubyte >13 +>>>>0 use msdos-com # the remaining files should be DOS *.COM executables # dosshell.COM 8cc0 2ea35f07 e85211 e88a11 b80058 cd # hmload.COM 8cc8 8ec0 bbc02b 89dc 83c30f c1eb04 b4 @@ -26526,48 +27318,164 @@ # SHARE.COM 8cca 2e8916 d602 b430 cd21 8b 2e0200 8b # validchr.COM 8cca 2e8916 9603 b430 cd21 8b 2e028b1e # devload.COM 8cca 8916ad01 b430 cd21 8b2e0200 892e -!:mime application/x-dosexec -!:ext com - -# updated by Joerg Jenderek at Oct 2008 -0 ulelong 0xffff10eb DR-DOS executable (COM) -# byte 0xeb conflicts with "sequent" magic leshort 0xn2eb -0 ubeshort&0xeb8d >0xeb00 -# DR-DOS STACKER.COM SCREATE.SYS missed 0 name msdos-com ->0 byte x DOS executable (COM) -!:mime application/x-dosexec -!:ext com +# URL: http://fileformats.archiveteam.org/wiki/DOS_executable_(.com) +>0 byte x DOS executable ( +# DOS execuable with JuMP 16-bit instruction +>0 byte =0xE9 +# check for probably nil padding til offset 64 of Lotus driver name +>>56 quad =0 +# check for "long" alpabetical Lotus driver name like: +# Diablo "COMPAQ Text Display" "IBM Monochrome Display" "Plantronics ColorPlus" +>>>24 regex =^[A-Z][A-Za-z\040]{5,21} \bLotus driver) %s +!:mime application/x-dosexec +# like: CPQ0TD.DRV IBM0MONO.DRV (Lotus 123 10a) SDIAB4.DRV SPL0CPLS.DRV (Lotus Symphony 2) +!:ext drv +# COM with nils like MODE.COM IBMDOS.COM (pcdos 3.31 ru Compaq) RSSTUB.COM (PC-DOS 2000 de) ACCESS.COM (Lotus Symphony 1) +>>>24 default x \bCOM) +!:mime application/x-dosexec +!:ext com +# DOS excutable with JuMP 16-bit and without nil padding +>>56 quad !0 +# https://wiki.syslinux.org/wiki/index.php?title=Doc/comboot +# TODO: HOWTO distinguish COMboot from pure DOS executables? +# look for unreliable Syslinux specific api call INTerrupt 22h for 16-bit COMBOOT program +>>>1 search/0xc088 \xcd\x22 \bCOM or COMBOOT 16-bit) +!:mime application/x-dosexec +# like: sbm.cbt command.com (Windows XP) UNI2ASCI.COM (FreeDOS 1.2) +!:ext com/cbt +>>>1 default x \bCOM) +!:mime application/x-dosexec +!:ext com +# DOS executable without JuMP 16-bit instruction +>0 byte !0xE9 +# SCREATE.SYS https://en.wikipedia.org/wiki/Stac_Electronics +>>10 string =?STACVOL \bSCREATE.SYS) +!:mime application/x-dosexec +!:ext sys +# COM executable without JuMP 16-bit instruction and not SCREATE.SYS +>>10 string !?STACVOL \bCOM) +!:mime application/x-dosexec +!:ext com >6 string SFX\ of\ LHarc \b, %s >0x1FE leshort 0xAA55 \b, boot code >85 string UPX \b, UPX compressed >4 string \ $ARX \b, ARX self-extracting archive >4 string \ $LHarc \b, LHarc self-extracting archive >0x20e string SFX\ by\ LARC \b, LARC self-extracting archive +# like: E30ODI.COM MADGEODI.COM UNI2ASCI.COM RECOVER.COM (DOS 2) COMMAND.COM (DOS 2) +>1 search/0xc088 \xcd\x22 \b, maybe with interrupt 22h +>0 ubelong x \b, start instruction %#8.8x +# show more instructions but not in samples like: rem.com (DJGPP) +>4 ubelong x %8.8x # JMP 8bit 0 byte 0xeb +# byte 0xeb conflicts with magic leshort 0xn2eb of "SYMMETRY i386" handled by ./sequent # allow forward jumps only >1 byte >-1 # that offset must be accessible +# with hexadecimal values like: 0e 2e 50 8c 8d ba bc bd be e8 fb fc >>(1.b+2) byte x ->>>0 use msdos-com - +# if look like COM executable with x86 boot signature then this +# implies FAT volume with x86 real mode code already handled by ./filesystems +# +# No x86 boot signature implies often DOS executable +# check for unrealistic high number of FATs. Then it is an unusual disk image or often a DOS executable +# like: FIXBIOS.COM (50 bytes) +>>>16 ubyte >3 +# https://www.drivedroid.io/ +# skip MBR disk image drivedroid.img version 12 July 2013 by start message +>>>>2 string !DriveDroid +# ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/ +# skip unusual floppy image disk1.img of MS-DOS 1.25 (Corona Data Systems OEM) +# by check for characteristic message text near the beginning +>>>>>15 string !Non\040System\040disk +# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 4.0.rar" +# skip BeOS 4 bootfloppy.img done as "Linux kernel x86 boot executable" by ./linux +# by check for characteristic message text near the beginning +>>>>>>6 string !read\040error\015 +# https://github.com/ventoy/Ventoy/releases/download/v1.0.78/ventoy-1.0.78-windows.zip +# skip ventoy 1.0.78 boot_hybrid.img +>>>>>>>24 string !\220\220\353I$\022\017 +# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/PC-DOS 1.0 (5.25).rar" +# skip unusual floppy image PCDOS100.IMG of DOS 1.0 +# by check for characteristic message text near the beginning +>>>>>>>>9 string !7-May-81 +# "ftp://old-dos.ru/OSCollect/OS/BeOS/BeOS 5.0 Personal (BA).rar" +# skip BeOS 5 floppy_1.44.00.ima done as "DOS/MBR boot sector" by ./filesystems +# by check for characteristic message near the beginning +>>>>>>>>>3 string !\370sdfS\270 +# like: FIXBIOS.COM (50 bytes) +>>>>>>>>>>0 use msdos-com +# check for unrealistic low number of FATs. Then it is an unusual FAT disk image or often a DOS executable +# like: DEVICE.COM INSTALL.COM (GAG 4.10) WORD.COM (Word 1.15) +>>>16 ubyte =0 +# if low FATs with x86 boot signature it can be unusual disk image like: boot.img (Ventoy 1.0.27) geodspms.img (Syslinux) +>>>>0x1FE leshort =0xAA55 +>>>>0x1FE default x +# https://thestarman.pcministry.com/tool/hxd/dimtut.htm +# skip unusual floppy image TK-DOS11.img IBMDOS11.img of IBM DOS 1.10 +# by check for characteristic bootloader names near end of boot sector +>>>>>395 string !ibmbio\040\040com +>>>>>>0 use msdos-com +# 8-bit jump with valid number of FAT implies FAT volume already handled by ./filesystems +# like: balder.img +>>>16 default x +# skip disk images with boot signature at end of 1st sector +# like: TDSK-64b.img +>>>>(11.s-2) uleshort !0xAA55 +# skip unusual floppy image without boot signature like 360k-256.img (mtools 4.0.18) +# by check for characteristic file system type text for FAT (12 bit or 16 bit) +>>>>>54 string !FAT +# "ftp://old-dos.ru/OSCollect/OS/MS-DOS/Final Releases/Microsoft MS-DOS 3.31 (Compaq OEM) (3.5).rar" +# skip unusual floppy image Disk4.img without boot signature and file system type text +# by check for characteristic OEM-ID text +>>>>>>3 string !COMPAQ\040\040 +# no such DOS COM executables found +>>>>>>>0 use msdos-com # JMP 16bit 0 byte 0xe9 +# 16-bit offset; for DEBUGGING!; can be negative like: USBDRIVE.COM +#>1 leshort x \b, OFFSET %d # forward jumps ->1 short >-1 +>1 leshort >-1 # that offset must be accessible +# with hexadecimal values like: 06 1e 0e 2e 60 8c 8d b4 ba be e8 fc >>(1.s+3) byte x ->>>0 use msdos-com +# check for unrealistic high number of FATs. Then it is not a disk image and it is a DOS executable +# like: CALLVER.COM CPUCACHE.COM K437_EUR.COM SHSUCDX.COM UMBFILL.COM (183 bytes) +>>>16 ubyte >3 +>>>>0 use msdos-com +# check for unrealistic low number of FATs. Then it is not a disk image and it is a DOS executable +# like: GAG.COM DRMOUSE.COM NDN.COM CPQ0TD.DRV +>>>16 ubyte =0 +>>>>0 use msdos-com +# maybe disc image with valid number of FATs or DOS executable +# like: IPXODI.COM PERUSE.COM TASKID.COM +>>>16 default x +# invalid low media descriptor. Then it is not a disk image and it is a DOS executable +>>>>21 ubyte <0xE5 +>>>>>0 use msdos-com +# valid media descriptor. Then it is maybe disk image or DOS executable +>>>>21 ubyte >0xE4 +# invalid sectorsize not a power of 2 from 32-32768. Then it is not a disk image and it must be DOS executable +# like: LEARN.COM (Word 1.15) +>>>>>11 uleshort&0x001f !0 +>>>>>>0 use msdos-com # negative offset, must not lead into PSP ->1 short <-259 +# like: BASICA.COM (PC dos 3.20) FORMAT.COM SMC8100.COM WORD.COM (word4) +# HIDSUPT1.COM USBDRIVE.COM USBSUPT1.COM USBUHCI.COM (FreeDOS USBDOS) +>1 leshort <-259 # that offset must be accessible +# add 10000h to jump at end of 64 KiB segment, add 1 for jump instruction and 2 for 16-bit offset >>(1,s+65539) byte x +# after jump next instruction for DEBUGGING! +#>>>&-1 ubelong x \b, NEXT instruction %#8.8x >>>0 use msdos-com -# updated by Joerg Jenderek at Oct 2008,2015 +# updated by Joerg Jenderek at Oct 2008,2015,2022 # following line is too general 0 ubyte 0xb8 # skip 2 linux kernels like memtest.bin with "\xb8\xc0\x07\x8e" in ./linux @@ -26590,19 +27498,49 @@ # syslinux version (4.x) # "COM executable (COM32R)" or "Syslinux COM32 module" by TrID >>>1 lelong 0x21CD4CFe \b, relocatable) -# Hajin Jang : -# Disable simplest COM signature to prevent false positive on some EUC-KR text files. -## remaining are DOS COM executables starting with assembler instruction MOV -## like FreeDOS BANNER*.COM FINDDISK.COM GIF2RAW.COM WINCHK.COM -## MS-DOS SYS.COM RESTART.COM -## SYSLINUX.COM (version 1.40 - 2.13) -## GFXBOOT.COM (version 3.75) -## COPYBS.COM POWEROFF.COM INT18.COM ->>1 default x COM executable for DOS -!:mime application/x-dosexec -##!:mime application/x-ms-dos-executable -##!:mime application/x-msdos-program -!:ext com +>>1 default x +# look for interrupt instruction like in rem.com (DJGPP) LOADER.COM (DR-DOS 7.x) +>>>3 search/118 \xCD +# FOR DEBUGGING; possible hexadecimal interupt number like: 10~BANNER.COM 13~bcdw_cl.com 15~poweroff.com (Syslinux) +# 1A~BERNDPCI.COM 20~SETENHKB.COM 21~mostly 22~gfxboot.com (Syslinux) 2F~SHUTDOWN.COM (GEMSYS) +#>>>>&0 ubyte x \b, INTERUPT %#x +# few examples with interrupt 0x13 instruction +>>>>&0 ubyte =0x13 +# FOR DEBUGGING! +#>>>>>3 ubequad x \b, 2nd INSTRUCTION %#16.16llx +# skip Gpt.com Mbr.com (edk2-UDK2018 bootsector) described as "DOS/MBR boot sector" by ./filesystems +# by check for assembler instructions: mov es,ax ; mov ax,07c0h ; mov ds,ax +>>>>>3 ubequad !0x8ec0b8c0078ed88d +# few COM exectables with interrupt 0x13 instruction like: Bootable CD Wizard executables bcdw_cl.com fdemuoff.com +# http://bootcd.narod.ru/bcdw150z_en.zip +>>>>>>0 use msdos-com +# few examples with interrupt 0x16 instruction like flashimg.img +>>>>&0 ubyte =0x16 +# skip Syslinux 3.71 flashimg.img done as "DOS/MBR boot sector" by ./filesystems +# by check for assembler instructions: cmp ax 0xE4E4 (magic); jnz +>>>>>8 ubelong !0x3DE4E475 +# no DOS executable with interrupt 0x16 found +>>>>>>0 use msdos-com +# most examples with interrupt instruction unequal 0x13 and 0x16 +>>>>&0 default x +#>>>>>&-1 ubyte x \b, INTERUPT %#x +# like: LOADER.COM SETENHKB.COM banner.com copybs.com gif2raw.com poweroff.com rem.com +>>>>>0 use msdos-com +# few COM executables without interupt instruction like RESTART.COM (DOS 7.10) REBOOT.COM +# or some EUC-KR text files or one Ulead Imaginfo thumbnail +>>>3 default x +# FOR DEBUGGING; 2nd instruction like 0x50 (RESTART.COM) 0x8e (REBOOT.COM) +# or random like: 0x0 (IMAGINFO.PE3 sky_snow) 0xb1 (euckr_.txt) +#>>>>3 ubyte x \b, 2nd INSTRUCTION %#x +# skip 1 Ulead Imaginfo thumbnail (IMAGINFO.PE3 sky_snow) +# inside SAMPLES/TEXTURES/SKY_SNOW +# from https://archive.org/download/PI3CANON/PI3CANON.iso +>>>>3 ubyte !0x0 +# skip some EUC-KR text files like: euckr_falsepositive.txt +# https://bugs.astron.com/view.php?id=186 +>>>>>3 ubyte !0xb1 +# like: RESTART.COM (DOS 7.10) REBOOT.COM +>>>>>>0 use msdos-com # URL: https://en.wikipedia.org/wiki/UPX # Reference: https://github.com/upx/upx/archive/v3.96.zip/upx-3.96/ @@ -27204,11 +28142,6 @@ >>>20 long >0 TIFF starts at byte %d >>>>24 long >0 length %d -# TNEF magic From "Joomy" -# Microsoft Outlook's Transport Neutral Encapsulation Format (TNEF) -0 lelong 0x223e9f78 TNEF -!:mime application/vnd.ms-tnef - # Norton Guide (.NG , .HLP) files added by Joerg Jenderek from source NG2HTML.C # of http://www.davep.org/norton-guides/ng2h-105.tgz # https://en.wikipedia.org/wiki/Norton_Guides @@ -27406,6 +28339,13 @@ >>>>>>(16.l+16) string !Panoram 7 or 8 !:ext themepack/deskthemepack >>>>>>(16.l+16) ubyte x Theme Pack +# URL: https://en.wikipedia.org/wiki/Microsoft_OneNote#File_format +# http://fileformats.archiveteam.org/wiki/OneNote +# Reference: https://mark0.net/download/triddefs_xml.7z/defs/o/onepkg.trid.xml +# 1st member name like: "Class Notes.one" "test-onenote.one" "Open Notebook.onetoc2" "Editor Öffnen.onetoc2" +>>>>>&0 string/c one \b, OneNote Package +!:mime application/msonenote +!:ext onepkg >>>>>&0 default x # look for null terminator of 1st member name >>>>>>&0 search/255 \0 @@ -27732,7 +28672,7 @@ # #------------------------------------------------------------------------------ -# $File: msooxml,v 1.17 2021/11/08 13:53:43 christos Exp $ +# $File: msooxml,v 1.18 2022/08/16 11:16:39 christos Exp $ # msooxml: file(1) magic for Microsoft Office XML # From: Ralf Brown @@ -27747,10 +28687,13 @@ 0 name msooxml >0 string word/ Microsoft Word 2007+ !:mime application/vnd.openxmlformats-officedocument.wordprocessingml.document +!:ext docx >0 string ppt/ Microsoft PowerPoint 2007+ !:mime application/vnd.openxmlformats-officedocument.presentationml.presentation +!:ext pptx >0 string xl/ Microsoft Excel 2007+ !:mime application/vnd.openxmlformats-officedocument.spreadsheetml.sheet +!:ext xlsx >0 string visio/ Microsoft Visio 2013+ !:mime application/vnd.ms-visio.drawing.main+xml >0 string AppManifest.xaml Microsoft Silverlight Application @@ -29026,7 +29969,7 @@ 0 string Octave-1-B Octave binary data (big endian) #------------------------------------------------------------------------------ -# $File: ole2compounddocs,v 1.18 2022/05/31 17:38:36 christos Exp $ +# $File: ole2compounddocs,v 1.19 2022/09/11 20:52:40 christos Exp $ # Microsoft OLE 2 Compound Documents : file(1) magic for Microsoft Structured # storage (https://en.wikipedia.org/wiki/Compound_File_Binary_Format) # Additional tests for OLE 2 Compound Documents should be under this recipe. @@ -29262,6 +30205,18 @@ !:mime application/x-corel-gal !:ext gal # +# From: Joerg Jenderek +# URL: https://archive.org/details/iPhoto-Plus-4 +# https://filext.com/file-extension/TPL +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/t/tpl-ulead.trid.xml +# Note: found in Template sub directory in program directory of software iPhoto Plus version 4 +# second, third and fourth directory entry name like TplHeader TplMainImage TplPreview +>>>>128 lestring16 TplHeader : Ulead iPhoto Template +#!:mime application/x-ole-storage +!:mime image/x-ulead-tpl +# https://www.file-extensions.org/tpl-file-extension-ulead-photo-express-template +!:ext tpl +# # URL: https://en.wikipedia.org/wiki/Hangul_(word_processor) # Note: "HWP Document File" signature found in FileHeader # Second directory entry name FileHeader hint for Thinkfree Office document @@ -30339,7 +31294,7 @@ >48 byte x \b%d. >56 byte x \b%d #------------------------------------------------------------------------------ -# $File: pascal,v 1.3 2020/06/07 18:10:26 christos Exp $ +# $File: pascal,v 1.4 2022/07/30 16:53:06 christos Exp $ # pascal: file(1) magic for Pascal source # 0 search/8192 (input, Pascal source text @@ -30353,6 +31308,31 @@ 0 string PPU Pascal unit >3 string x \b, version %s +# From: Joerg Jenderek +# URL: https://en.wikipedia.org/wiki/Dan_Bricklin +0 string/b Type +# URL: https://dl.winworldpc.com/Dan%20Bricklins%20Demo%20II%20Version%202%20Manual.7z +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-v2.trid.xml +>4 string D2 Dan Bricklin's Demo 2 demo +#!:mime application/octet-stream +!:ext dbd +# URL: https://muhaz.org/turbo-pascal-download-details.html +# From: Joerg Jenderek +# Note: used by Turbo Pascal 5.5 TOUR.EXE +>4 string T2 Turbo Pascal TOUR data +#!:mime application/octet-stream +!:mime application/x-borland-cbt +!:ext cbt +# WHAT iS THAT? +#>4 string \040P Dan Bricklin's Demo 2 foo +#!:mime application/octet-stream +# _PPRINT.SG2 _PASCII.SG2 +#!:ext sg2 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbd-gen.trid.xml +>4 default x Dan Bricklin's Demo demo (generic) +#!:mime application/octet-stream +!:ext dbd + #------------------------------------------------------------------------------ # $File: pbf,v 1.3 2019/04/19 00:42:27 christos Exp $ # file(1) magic(5) data for OpenStreetMap @@ -32175,7 +33155,7 @@ >16 long >0 not stripped #------------------------------------------------------------------------------ -# $File: python,v 1.44 2021/10/20 11:15:35 christos Exp $ +# $File: python,v 1.45 2022/07/24 23:59:37 christos Exp $ # python: file(1) magic for python # # Outlook puts """ too for urgent messages @@ -32261,6 +33241,8 @@ !:mime application/x-bytecode.python 0 belong 0x04f30d0a python 2.7 byte-compiled !:mime application/x-bytecode.python +0 belong 0x0af30d0a PyPy2.7 byte-compiled +!:mime application/x-bytecode.python 0 belong 0xb80b0d0a python 3.0 byte-compiled !:mime application/x-bytecode.python 0 belong 0xc20b0d0a python 3.0 byte-compiled @@ -32361,80 +33343,46 @@ !:mime application/x-bytecode.python 0 belong 0x3f0d0d0a python 3.7 byte-compiled !:mime application/x-bytecode.python -0 belong 0x400d0d0a python 3.7 byte-compiled + +# magic 3392+ implements PEP 552: Deterministic pycs +0 name pyc-pep552 +# the flag field determines how .pyc validity is checked +>4 ulelong&1 0 timestamp-based, +>>8 uledate x .py timestamp: %s UTC, +>>12 ulelong x .py size: %d bytes +>4 ulelong&1 !0 hash-based, check-source flag +>>4 ulelong&2 0 unset, +>>4 ulelong&2 !0 set, +>>8 ulequad x hash: 0x%llx + +# uleshort magic followed by \x0d\0xa +2 string \x0d\x0a +# extra check: only two bits of flag field are currently used +>4 ulelong <0x4 +# \x0d as part of magic should suffice till Python 3.14 (magic 3600) +>>1 ubyte 0x0d Byte-compiled Python module for !:mime application/x-bytecode.python -0 belong 0x410d0d0a python 3.7 byte-compiled +# now look at the magic number to determine the version +>>>0 uleshort <3400 CPython 3.7, +>>>0 default x +>>>>0 uleshort <3420 CPython 3.8, +>>>>0 default x +>>>>>0 uleshort <3430 CPython 3.9, +>>>>>0 default x +>>>>>>0 uleshort <3450 CPython 3.10, +>>>>>>0 default x +>>>>>>>0 uleshort <3500 CPython 3.11, +>>>>>>>0 default x CPython 3.12 or newer, +>>>0 use pyc-pep552 +>>0 uleshort 240 Byte-compiled Python module for PyPy3.7, !:mime application/x-bytecode.python -0 belong 0x420d0d0a python 3.7 byte-compiled +>>>0 use pyc-pep552 +>>0 uleshort 256 Byte-compiled Python module for PyPy3.8, !:mime application/x-bytecode.python -0 belong 0x480d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x490d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x520d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x530d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x540d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x550d0d0a python 3.8 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5c0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5d0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5e0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x5f0d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x600d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x610d0d0a python 3.9 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x660d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x670d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x680d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x690d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6a0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6b0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6c0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6d0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6e0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x6f0d0d0a python 3.10 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7a0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7b0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7c0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7d0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7e0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x7f0d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x800d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x810d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x820d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x830d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x840d0d0a python 3.11 byte-compiled -!:mime application/x-bytecode.python -0 belong 0x850d0d0a python 3.11 byte-compiled +>>>0 use pyc-pep552 +>>0 uleshort 336 Byte-compiled Python module for PyPy3.9, !:mime application/x-bytecode.python +>>>0 use pyc-pep552 0 search/1/w #!\040/usr/bin/python Python script text executable !:strength + 15 @@ -32597,7 +33545,7 @@ 0 string #\ Bazaar\ merge\ directive\ format Bazaar merge directive #------------------------------------------------------------------------------ -# $File: riff,v 1.44 2022/05/14 19:42:47 christos Exp $ +# $File: riff,v 1.45 2022/07/24 23:47:49 christos Exp $ # riff: file(1) magic for RIFF format # See # @@ -32930,6 +33878,27 @@ #>>>0 use corel-des #>>>0 use corel-draw >8 string NUNDROOT \b, Steinberg CuBase +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/MIDI_Instrument_Definition_File +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/i/idf.trid.xml +# ftp://curscott.servebeer.com/Download/Apps/_Microsoft/ +# Visual%20Studio%206.0%20Professional%20MSDN/ +# SAMPLES/VC98/SDK/GRAPHICS/AUDIO/IDFEDIT/GLOBALS.H +# Note: called "MIDI Instrument Definition File" by TrID +>8 string IDF\ LIST \b, MIDI Instrument Definition File +!:mime audio/x-idf +!:ext idf +# 3rd chunk size like: 254 284 286 670 +#>>0x10 ulelong x \b, 3th SIZE %u +# for debugging purpose display next chunk like: MMAPhdr +#>>0x14 string x \b, 4th "%-8.8s" +#>>0x1C ulelong x \b, 4th SIZE 0x%x +# probably MIDI instrument name like: "Universal-MIDI-Instrument" "instrument name" "General MIDI" +>>0x30 string x "%s" +# look for inst TAG +>>0x31 search/256 inst by +# probably manufacture name like: "Unspecified Company" "NVidia Corporation" +>>>&0x24 string x "%s" # AVI == Audio Video Interleave # Reference: http://fileformats.archiveteam.org/wiki/AVI >8 string AVI\040 \b, AVI @@ -33414,6 +34383,51 @@ >>&6 leshort =2 \b, stereo >>&6 leshort >2 \b, %d channels >>&8 lelong >0 %d Hz +#------------------------------------------------------------------------------ +# $File: ringdove,v 1.1 2022/08/16 12:04:30 christos Exp $ +# ringdove: file(1) magic for RingdoveEDA data files + +# librnd and global +0 regex/128l ha:rnd-menu-v[0-9]+[\ \t\r\n]*[{] librnd menu system (lihata) +0 regex/128l ha:rnd-menu-patch-v[0-9]+[\ \t\r\n]*[{] librnd menu patch (lihata) +0 regex/128l ha:coraleda-project-v[0-9]+[\ \t\r\n]*[{] CoralEDA/Ringdove project file (lihata) +0 regex/128l ha:ringdove-project-v[0-9]+[\ \t\r\n]*[{] Ringdove project file (lihata) + +# pcb-rnd +0 regex/128l ha:pcb-rnd-board-v[0-9]+[\ \t\r\n]*[{] pcb-rnd board file (lihata) +0 regex/128l li:pcb-rnd-subcircuit-v[0-9]+[\ \t\r\n]*[{] pcb-rnd subcircuit/footprint file (lihata) +0 regex/128l ha:pcb-rnd-buffer-v[0-9]+[\ \t\r\n]*[{] pcb-rnd paste buffer content (lihata) +0 regex/128l li:pcb-rnd-conf-v[0-9]+[\ \t\r\n]*[{] pcb-rnd configuration (lihata) +0 regex/128l ha:pcb-rnd-drc-query-v[0-9]+[\ \t\r\n]*[{] pcb-rnd drc query string (lihata) +0 regex/128l li:pcb-rnd-font-v[0-9]+[\ \t\r\n]*[{] pcb-rnd vector font (lihata) +0 regex/128l ha:pcb-rnd-log-v[0-9]+[\ \t\r\n]*[{] pcb-rnd message log dump (lihata) +0 regex/128l ha:pcb-rnd-padstack-v[0-9]+[\ \t\r\n]*[{] pcb-rnd padstack (lihata) +0 regex/128l li:pcb-rnd-view-list-v[0-9]+[\ \t\r\n]*[{] pcb-rnd view list (lihata) +0 regex/128l li:view-list-v[0-9]+[\ \t\r\n]*[{] pcb-rnd view list (lihata) +0 search Netlist(Freeze) pcb-rnd or gEDA/PCB netlist forward annotation action script + +# sch-rnd (cschem data model) +0 regex/128l li:cschem-buffer-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem buffer content (lihata) +0 regex/128l li:sch-rnd-conf-v[0-9]+[\ \t\r\n]*[{] sch-rnd configuration (lihata) +0 regex/128l ha:std_devmap.v[0-9]+[\ \t\r\n]*[{] sch-rnd devmap (device mapping; lihata) +0 regex/128l li:cschem-group-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem group or symbol (lihata) +0 regex/128l ha:cschem-sheet-v[0-9]+[\ \t\r\n]*[{] sch-rnd/cschem schematic sheet (lihata) + +# tEDAx (modular format) +0 regex/1l tEDAx[\ \t\r\n]v tEDAx (Trivial EDA eXchange) +>0 regex begin\ symbol\ v with schematic symbol +>0 regex begin\ board\ v with Printed Circuit Board +>0 regex begin\ route_req\ v with PCB routing request +>0 regex begin\ route_res\ v with PCB routing result +>0 regex begin\ camv_layer\ v with camv-rnd exported layer +>0 regex begin\ netlist\ v with netlist +>0 regex begin\ backann\ v with Ringdove EDA back annotation +>0 regex begin\ footprint\ v with PCB footprint +>0 regex begin\ drc\ v with PCB DRC script +>0 regex begin\ drc_query_rule\ v with pcb-rnd drc_query rules +>0 regex begin\ drc_query_def\ v with pcb-rnd drc_query value/config definitions +>0 regex begin\ etest\ v with PCB electric test + #------------------------------------------------------------------------------ # $File: rpi,v 1.3 2022/04/02 14:39:34 christos Exp $ @@ -34113,17 +35127,19 @@ 8 string DEEP Alias Maya Image File #------------------------------------------------------------------------------ -# $File: sgml,v 1.45 2022/03/21 21:36:55 christos Exp $ +# $File: sgml,v 1.46 2022/08/16 11:16:39 christos Exp $ # Type: SVG Vectorial Graphics # From: Noel Torres 0 string \14 regex ['"\ \t]*[0-9.]+['"\ \t]* >>19 search/4096 \>19 search/4096 \20 belong&0x03FFFFFF 288 (USB 2.0 >20 belong&0x03FFFFFF 289 (ATSC ALP >20 belong&0x03FFFFFF 290 (Event Tracing for Windows +>20 belong&0x03FFFFFF 291 (Hilscher netANALYZER NG pseudo-footer +>20 belong&0x03FFFFFF 292 (ZBOSS NCP protocol with pseudo-header +>20 belong&0x03FFFFFF 293 (Low-Speed USB 2.0/1.1/1.0 +>20 belong&0x03FFFFFF 294 (Full-Speed USB 2.0/1.1/1.0 +>20 belong&0x03FFFFFF 295 (High-Speed USB 2.0 # print default match >20 default x >>20 belong x (linktype#%u @@ -34997,7 +36018,7 @@ >>>7 byte 1 (alternate timings) #------------------------------------------------------------------------------ -# $File: sql,v 1.23 2021/07/30 14:53:38 christos Exp $ +# $File: sql,v 1.24 2022/07/17 15:32:48 christos Exp $ # sql: file(1) magic for SQL files # # From: "Marty Leisner" @@ -35214,6 +36235,12 @@ # H2 Database from https://www.h2database.com/ 0 string --\ H2\ 0.5/B\ --\ \n H2 Database file + +# DuckDB database file from https://duckdb.org +8 string DUCK DuckDB database file +>12 lequad x \b, version %lld +#>20 lequad x \b, flags %#llx +#>28 lequad x \b, flags %#llx # Type: OpenSSH key files # From: Nicolas Collignon @@ -35319,6 +36346,44 @@ 0 string \\\ Stata Data File >&0 regex [0-9]+ (Release %s) +#------------------------------------------------------------------------------ +# $File: subtitle,v 1.2 2022/09/07 11:29:09 christos Exp $ +# subtitle: file(1) magic for subtitles files + +# EBU-STL +# https://tech.ebu.ch/docs/tech/tech3264.pdf +3 string STL EBU-STL subtitles +>6 regex =^[0-9][0-9] \b, rate %s +>>8 string .01 \b, v1 +!:mime application/x-ebu-stl +>>>16 regex =^[^\ ]{0,32} \b, title "%s" +>>>>224 regex =^[0-9]{2} \b, created %-.2s +>>>>>&0 regex =^[0-9]{2} \b-%-.2s +>>>>>>&0 regex =^[0-9]{2} \b-%-.2s +!:ext stl + +# SubRip (srt) subtitles +0 regex/20 =^1[\r\n]+0[01]:[0-9]{2}:[0-9]{2},[0-9]{3}\040--> SubRip +!:mime application/x-subrip +!:ext srt + +# WebVTT subtitles +# https://www.w3.org/TR/webvtt1/ +0 string/t WEBVTT +>&0 regex/255 =[0-9]{2}:[0-9]{2}\\.[0-9]{3}\040--> WebVTT subtitles +!:mime text/vtt +!:ext vtt + +# XML TTML subtitles +# https://www.w3.org/TR/ttml2/ +0 string/t \20 search/400 \020xmlns= +>>&0 regex ['"]http://www.w3.org/ns/ttml TTML subtitles +!:mime application/ttml+xml +# Augment strength to beat plain XML +!:strength * 3 +!:ext ttml + #------------------------------------------------------------------------------ # $File: sun,v 1.28 2019/04/19 00:42:27 christos Exp $ # sun: file(1) magic for Sun machines @@ -37040,7 +38105,7 @@ 43 string SFDU_LABEL VICAR label file #------------------------------------------------------------------------------ -# $File: virtual,v 1.16 2022/01/18 14:08:15 christos Exp $ +# $File: virtual,v 1.17 2022/08/23 08:00:54 christos Exp $ # From: James Nobis # Microsoft hard disk images for: # Virtual Server @@ -37049,10 +38114,10 @@ # URL: http://fileformats.archiveteam.org/wiki/VHD_(Virtual_Hard_Disk) # Reference: https://download.microsoft.com/download/f/f/e/ffef50a5-07dd-4cf8-aaa3-442c0673a029/ # Virtual%20Hard%20Disk%20Format%20Spec_10_18_06.doc -0 string connectix Microsoft Disk Image, Virtual Server or Virtual PC +0 string conectix Microsoft Disk Image, Virtual Server or Virtual PC # alternative shorter names -#0 string connectix Microsoft Virtual Hard Disk image -#0 string connectix Microsoft Virtual HD image +#0 string conectix Microsoft Virtual Hard Disk image +#0 string conectix Microsoft Virtual HD image !:mime application/x-virtualbox-vhd !:ext vhd # Features is a bit field used to indicate specific feature support @@ -37638,7 +38703,7 @@ !:mime application/vnd.hdt !:ext hdt #------------------------------------------------------------------------------ -# $File: webassembly,v 1.3 2019/04/19 00:42:27 christos Exp $ +# $File: webassembly,v 1.4 2022/08/16 11:16:39 christos Exp $ # webassembly: file(1) magic for WebAssembly modules # # WebAssembly is a virtual architecture developed by a W3C Community @@ -37651,10 +38716,12 @@ 0 string \0asm WebAssembly (wasm) binary module >4 lelong =1 version %#x (MVP) +!:mime application/wasm +!:ext wasm >4 lelong >1 version %#x #------------------------------------------------------------------------------ -# $File: windows,v 1.44 2022/05/31 17:39:08 christos Exp $ +# $File: windows,v 1.46 2022/07/02 17:46:09 christos Exp $ # windows: file(1) magic for Microsoft Windows # # This file is mainly reserved for files where programs @@ -37669,14 +38736,84 @@ # Summary: Outlook Express DBX file -# Extension: .dbx # Created by: Christophe Monniez -0 string \xCF\xAD\x12\xFE MS Outlook Express DBX file ->4 byte =0xC5 \b, message database ->4 byte =0xC6 \b, folder database ->4 byte =0xC7 \b, account information ->4 byte =0x30 \b, offline database +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Outlook_Express_Database +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/d/dbx.trid.xml +# https://sourceforge.net/projects/ol2mbox/files/LibDBX/ +# v1.0.4/libdbx_1.0.4.tar.gz/FILE-FORMAT +# Note: called "Outlook Express Database" by TrID and DROID via PUID fmt/838 fmt/839 +# and partly verified by `undbx --verbosity 4 Posteingang.dbx` +0 string \xCF\xAD\x12\xFE +# skip DROID fmt-838-signature-id-1193.dbx fmt-839-signature-id-1194.dbx by check for valid file size +>0x7C ulelong >0 MS Outlook Express DBX file +#!:mime application/octet-stream +#!:mime application/vnd.ms-outlook +!:mime application/x-ms-dbx +!:ext dbx +>>4 byte =0xC5 \b, message database +>>4 byte =0xC6 \b, folder database +>>4 byte =0xC7 \b, account information +>>4 byte =0x30 \b, offline database +# version like: 5.2 5.5 (typical) +>>20 ulequad !0x0000000500000005 \b, version +# major version +>>>24 ulelong x %u +# minor version +>>>20 ulelong x \b.%u +# CLSID: 6F74FDC5-E366-11d1-9A4E-00C04FA309D4~Message 6F74FDC6-E366-11D1-9A4E-00C04FA309D4~Folder +# 26FE9D30-1A8F-11D2-AABF-006097D474C4~offline +#>>4 guid x \b, CLSID %s +# file size; total size of file; sometimes real size a little bit higher +>>0x7C ulelong x \b, ~ %u bytes +# highest Email ID; the next email will have a number one higher than this +>>0x5c ulelong x \b, highest ID %#x +# item count; number of items stored in this DBX file +>>0xC4 ulelong x \b, %u item +# plural s +>>0xC4 ulelong !1 \bs +# index pointer; file offset pointing to a page of Data Indexes +>>0xE4 ulelong >0 \b, index pointer %#x +# From: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Nickfile +# https://www.nirsoft.net/utils/outlook_nk2_edit.html +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/n/nk2.trid.xml +# https://github.com/libyal/libnk2/blob/main/documentation +# Nickfile%20(NK2)%20format.asciidoc +# Note: called "Outlook Nickfile" by TrID & TestDisk and +# "Outlook Nickname File" by Microsoft Outlook and +# "Outlook AutoComplete File" by Nirsoft NK2Edit +# partly verfied by NK2Edit Raw Text Edit Mode +0 ubelong 0x0DF0ADBA MS Outlook Nickfile +#!:mime application/octet-stream +#!:mime application/vnd.ms-outlook +!:mime application/x-ms-nickfile +!:ext nk2/dat/bak +# nick is used by "older" Outlook; dat is used by "newer" Outlook (probably 2010 - 2016); bak is used for backup +#!:ext nick/nk2/dat/bak +# Unknown; probably a version indicator like: 0000000Ah 0000000Ch +>4 ulelong x \b, probably version %u +# Unknown2; probably a version indicator like: 1 0 +>8 ulelong x \b.%u +# number of rows (nickname or alias items) in file +>12 ulelong x \b, %u items +# number of item entries/columns/properties value like: 17h +>16 ulelong x \b, %u entries +# value type/property tag: 001Fh~4 bytes for data size of UTF-16 LE string +>20 uleshort x \b, value type %#4.4x +# entry type/property identifier: 6001h~PR_DOTSTUFF_STATE/PR_NICK_NAME_W +>22 uleshort x \b, entry type %#4.4x +# Reserved like: 0013FD90h +#>24 ulelong x \b, reserved %#8.8x +# value data array/Irrelevant Union like: 0000000004E31A80h +#>28 ulequad x \b, data %#16.16llx +# UTF-16 +>20 uleshort =0x001F +# unicode string bytes like: 2Ch +>>36 ulelong x \b, %u bytes +# unicode string value PT_UNICODE like: janesmith@contoso.org +>>40 lestring16 x "%s" # Summary: Windows crash dump # Extension: .dmp @@ -38083,9 +39220,95 @@ # Summary: Outlook Personal Folders # Created by: unknown -0 lelong 0x4E444221 Microsoft Outlook email folder ->10 leshort 0x0e (<=2002) ->10 leshort 0x17 (>=2003) +# Update: Joerg Jenderek +# URL: http://fileformats.archiveteam.org/wiki/Personal_Folder_File +# https://en.wikipedia.org/wiki/Personal_Storage_Table +# Reference: https://interoperability.blob.core.windows.net/files/MS-PST/%5bMS-PST%5d.pdf +# http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml +# dwMagic !BDN +0 lelong 0x4E444221 +# skip DROID x-fmt-75-signature-id-472.pab x-fmt-248-signature-id-260.pst x-fmt-249-signature-id-261.pst +# by check for existance of bPlatformCreate value +>14 ubyte x Microsoft Outlook +#!:mime application/octet-stream +# NOT official registered ! +!:mime application/vnd.ms-outlook +# dwCRCPartial; 32-bit cyclic redundancy check (CRC) value of followin 471 bytes; zero for 64-bit +#>>4 ulelong !0 \b, CRC %#x +# wMagicClient; AB (4142h) is used for PAB files; SM (534Dh) is used for PST files; SO (534Fh) is used for OST files +#>>8 leshort x \b, wMagicClient=%#x +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pab.trid.xml +# Note: called "Microsoft Personal Address Book" by TrID and +# "Microsoft Outlook Personal Address Book" by DROID via x-fmt/75 +>>8 leshort 0x4142 Personal Address Book +#!:mime application/x-ms-pab +!:ext pab +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/pst.trid.xml +# http://mark0.net/download/triddefs_xml.7z/defs/p/pst-unicode.trid.xml +# Note: called "Microsoft OutLook Personal Folder" by TrID and +# by DROID via x-fmt/248 for ANSI and via x-fmt/249 for Unicode +#>>8 leshort 0x4D53 \b, PST~ +# called "Microsoft Outlook email folder" in ./windows version 1.37 and older +>>8 leshort 0x4D53 Personal Storage +#!:mime application/x-ms-pst +!:ext pst +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/o/ost.trid.xml +# Note: called "Outlook Exchange Offline Storage" by TrID +>>8 leshort 0x4F53 Offline Storage +#!:mime application/x-ms-ost +!:ext ost +# wVer; file format version. 14 or 15 if the file is ANSI; > 21 or 23(=17h) if Unicode; 37 for written by Outlook with WIP +>>10 uleshort x ( +# probably NO intermediate versions exist +>>10 leshort <0x10 \b<=2002, ANSI, +>>10 leshort >0x14 \b>=2003, Unicode, +>>10 uleshort x version %u) +# wVerClient; client file format version like: 19 22 +#>>12 uleshort x \b, wVerClient=%u +# bPlatformCreate; This value MUST be set to 1 but also found 2 +>>14 ubyte >1 \b, bPlatformCreate=%u +# bPlatformAccess; This value MUST be set to 1 but also found 2 +>>15 ubyte >1 \b, bPlatformAccess=%u +# dwReserved1; SHOULD ignore and NOT modify this value; SHOULD initialize to zero +>>16 ulelong !0 \b, dwReserved1=%#x +# dwReserved2; SHOULD ignore and NOT modify this value; SHOULD initialize to zero +>>20 ulelong !0 \b, dwReserved2=%#x +# ANSI 32-bit variant Outlook 1997-2002 +>>10 uleshort <16 +# bidNextB; next BlockID (ANSI 4 bytes) +#>>>24 ulelong !0 \b, bidNextB=%#x +# bidNextP; Next available back BlockID pointer +#>>>28 ulelong !0 \b, bidNextP=%#x +# dwUnique; value monotonically increased when modifying PST; so CRC is changing +>>>32 ulelong !0 \b, dwUnique=%#x +# rgnid[128]; A fixed array of 32 NodeIDs, each corresponding to one of the 32 possible NID_TYPEs +#>>>36 ubequad x \b, rgnid=%#llx... +# dwReserved; Implementations SHOULD ignore this value and SHOULD NOT modify it; Initialized zero +>>>164 ulelong !0 \b, dwReserved=%#x +# ibFileEof; the size of the PST file, in bytes (ANSI 4 bytes) +>>>168 ulelong x \b, %u bytes +# ibAMapLast; offset to the last AMap page +#>>>172 ulelong x \b, ibAMapLast=%#x +# bSentinel; MUST be set to 0x80 +>>>460 ubyte !0x80 \b, bSentinel=%#x +# bCryptMethod: 0~No encryption 1~encryption with permutation 2~encryption with cyclic 16~encryption with Windows Information Protection (WIP) +>>>461 ubyte >0 \b, bCryptMethod=%u +# UNICODE 64-bit variant Outlook 2003-2007 +>>10 uleshort >20 +# bidUnused; Unused 8 bytes padding (Unicode only); sometimes like: 0x0000000100000004 +>>>24 ulequad !0x0000000100000004 \b, bidUnused=%#16.16llx +# dwUnique; value monotonically increased when modifying PST; so CRC is changing +>>>40 ulelong !0 \b, dwUnique=%#x +# rgnid[] (128 bytes): A fixed array of 32 NIDs, each corresponding to one of the 32 possible +#>>>44 ubequad x \b, rgnid=%#llx... +# ibFileEof; the size of the PST file, in bytes (Unicode 8 bytes) +>>>184 ulequad x \b, %llu bytes +# bSentinel; MUST be set to 0x80 +>>>512 ubyte !0x80 \b, bSentinel=%#x +# bCryptMethod; Encryption type like: 0 1 2 16 +>>>513 ubyte >0 \b, bCryptMethod=%u +# dwCRC; 32-bit CRC of the of the previous 516 bytes +>>>524 ulelong x \b, CRC32 %#x # Summary: Windows help cache @@ -38877,7 +40100,7 @@ >4 belong 19 (Version 1) #------------------------------------------------------------------------------ -# $File: wordprocessors,v 1.27 2021/12/06 15:05:16 christos Exp $ +# $File: wordprocessors,v 1.31 2022/08/31 08:00:53 christos Exp $ # wordprocessors: file(1) magic fo word processors. # ####### PWP file format used on Smith Corona Personal Word Processors: @@ -38905,35 +40128,170 @@ !:ext wps # Corel/WordPerfect +# URL: https://en.wikipedia.org/wiki/WordPerfect +# Reference: https://github.com/OneWingedShark/WordPerfect/blob/master/doc/SDK_Help/FileFormats/WPFF_DocumentStructure.htm +# http://mark0.net/download/triddefs_xml.7z/defs/w/wp-generic.trid.xml 0 string \xffWPC # WordPerfect >8 byte 1 +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/w/wpm-macro.trid.xml +# Note: there exist other macro variants >>9 byte 1 WordPerfect macro +#!:mime application/octet-stream +!:mime application/x-wordperfect-wpm +# like: ALTD.WPM ENDFOOT.WPM FOOTEND.WPM LABELS.WPM REVEALTX.WPM +!:ext wpm +# Note: used in WordPerfect 5.1; there exist other FIL variants >>9 byte 2 WordPerfect help file +#!:mime application/octet-stream +!:mime application/x-wordperfect-help +# like: WPHELP.FIL +!:ext fil +# pointer to document area like: 10h +>>>4 ulelong !0x10 \b, at %#x document area >>9 byte 3 WordPerfect keyboard file +#!:mime application/octet-stream +!:mime application/x-wordperfect-keyboard +!:ext wpk +# no document area, so point to end of file; so this is file size like: 23381 2978 32835 3355 3775 919 +>>>4 ulelong x \b, %u bytes +>>9 byte 4 WordPerfect VAX keyboard definition +#!:mime application/octet-stream +!:mime application/x-wordperfect-keyboard +#!:ext foo +# URL: http://fileformats.archiveteam.org/wiki/WordPerfect +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/w/wpd-doc-gen.trid.xml >>9 byte 10 WordPerfect document +# https://www.iana.org/assignments/media-types/application/vnd.wordperfect +!:mime application/vnd.wordperfect +#!:apple ????WPC2 +# TODO: distinguish different suffix +!:ext wpd/wpt/wkb/icr/tut/sty/tst/crs >>9 byte 11 WordPerfect dictionary >>9 byte 12 WordPerfect thesaurus >>9 byte 13 WordPerfect block >>9 byte 14 WordPerfect rectangular block >>9 byte 15 WordPerfect column block >>9 byte 16 WordPerfect printer data +#!:mime application/octet-stream +!:mime application/x-wordperfect-prs +# like: STANDARD.PRS WORKBOOK.PRS +!:ext prs +# like: "Standard Printer" "Workbook Printer" +>>>0x64 pstring/B >A "%s" +#>>9 byte 18 WordPerfect Prefix information file +# printer resource .ALL >>9 byte 19 WordPerfect printer data +#!:mime application/octet-stream +!:mime application/x-wordperfect-all +!:ext all +# display Resource >>9 byte 20 WordPerfect driver resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-drs +# like: WPSMALL.DRS +!:ext drs +# pointer to index area with string "smalldrs" like: 46h +>>>4 uleshort !0x46 \b, at %#x index area +>>9 byte 21 WordPerfect Overlay file +#!:mime application/octet-stream +!:mime application/x-wordperfect-fil +# like: WP.FIL +!:ext fil +# URL: http://fileformats.archiveteam.org/wiki/WordPerfect_Graphics +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/b/bitmap-wpg.trid.xml +# Note: called "WordPerfect Graphics bitmap" by TrID and +# "WordPerfect Graphics Metafile" by DROID via x-fmt/395 fmt/1042 +# "WPG (Word Perfect Graphics)" by ImageMagick `identify -verbose BUTTRFLY.WPG` >>9 byte 22 WordPerfect graphic image +# TODO: skip DROID x-fmt-395-signature-id-132.wpg by check for existing document area +#>>>4 ulelong >15 WordPerfect_graphic_OK +#!:mime application/octet-stream +# http://extension.nirsoft.net/wpg +!:mime image/x-wordperfect-graphics +# https://reposcope.com/mimetype/application/x-wpg +#!:mime application/x-wpg +# like: BUTTRFLY.WPG STAR-5.WPG input.wpg WORDPFCT.WPG +!:ext wpg +# pointer to document area like: 10h 1Ah +>>>4 ulelong !0x1A \b, at %#x document area >>9 byte 23 WordPerfect hyphenation code >>9 byte 24 WordPerfect hyphenation data >>9 byte 25 WordPerfect macro resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-mrs +# like: WP.MRS +!:ext mrs >>9 byte 27 WordPerfect hyphenation lex >>9 byte 29 WordPerfect wordlist >>9 byte 30 WordPerfect equation resource data +#!:mime application/octet-stream +!:mime application/x-wordperfect-qrs +# like: WQ.QRS wpDE.qrs wpen.qrs +!:ext qrs +# jump to document area with some marker and equation +>>>(4.l) ubyte x +# equation like: "Fraction: x OVER y" +>>>>&1 string >A (...%-.19s...) +# pointer to document area like: 17C4h +>>>4 ulelong x \b, at %#x document area +#>>9 byte 31 reserved +#>>9 byte 32 WordPerfect VAX .SET >>9 byte 33 WordPerfect spell rules >>9 byte 34 WordPerfect dictionary rules +#>>9 byte 35 reserved +# video resource device driver +# Note: filetype 26 for VRS and filetype 36 for WPD apparently is wrong +>>9 byte 36 WordPerfect Video Resource +#!:mime application/octet-stream +!:mime application/x-wordperfect-vrs +# like: STANDARD.VRS +!:ext vrs +# like: "IBM CGA (& compatibles)" +>>>0x20 string >A "%.23s" >>9 byte 39 WordPerfect spell rules (Microlytics) +#>>9 byte 40 reserved +>>9 byte 41 WordPerfect Install options +#!:mime application/octet-stream +!:mime application/x-wordperfect-ins +# like: WP51.INS +!:ext ins +# probably default directory name like: "C:\WP51\" +>>>0x12 string >A "%.8s" +# maybe mouse driver for WP5.1 +>>9 byte 42 WordPerfect Resource +#!:mime application/octet-stream +!:mime application/x-wordperfect-irs +# like: STANDARD.IRS +!:ext irs +# like: "Mouse Driver (MOUSE.COM)" +>>>0x28 string >A "%.24s" >>9 byte 43 WordPerfect settings file +# maybe Macintosh WP2.0 document >>9 byte 44 WordPerfect 3.5 document +!:mime application/vnd.wordperfect +!:apple ????WPD3 +# like: WP3.wpd +!:ext wpd >>9 byte 45 WordPerfect 4.2 document +# External spell code module (WP5.1) +#>>9 byte 46 WordPerfect external spell +# external spell dictionary .LEX +#>>9 byte 47 WordPerfect external spell dictionary +# Macintosh SOFT graphics file (SOFT (Sequential Object Format) +#>>9 byte 48 WordPerfect SOFT graphics +#>>9 byte 49 reserved +#>>9 byte 50 reserved +# WPWin 5.1 Application Resource Library added for WPWin 5.1 +#>>9 byte 51 WordPerfect application resource library >>9 byte 69 WordPerfect dialog file +# From: Joerg Jenderek +# Note: found in sub directory WritingTools inside WordPerfect 2021 program directory +>>9 byte 70 WordPerfect Writing Tools +#!:mime application/octet-stream +!:mime application/x-wordperfect-cbt +# like: Wt13cbede.cbt Wt13cbeit.cbt Wt13cbefr.cbt WT21cbede.cbt Wt13cbeEN.CBD WT21cbeEN.CBD +!:ext cbd/cbt >>9 byte 76 WordPerfect button bar >>9 default x >>>9 byte x Corel WordPerfect: Unknown filetype %d @@ -39073,11 +40431,48 @@ >>9 byte 24 GroupWise admin ADS deferment data file >>9 default x >>>9 byte x GroupWise: Unknown filetype %d +# Corel Writing Tools WT*.* +# From: Joerg Jenderek +# URL: https://support.corel.com/hc/en-us/articles/215876258-Writing-Tools-Spell-Check-Dictionary-does-not-work-in-WordPerfect-X5 +# http://wordperfect.helpmax.net/en/editing-and-formatting-documents/using-the-writing-tools/working-with-user-word-lists/ +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/u/uwl-wp.trid.xml +>8 byte 32 +>>9 byte 10 Corel Writing Tools User Word List +#!:mime application/octet-stream +!:mime application/x-wordperfect-wordlist +# personal user word list UWL under user directory like: WTDE.UWL WTUS.UWL WT21DE.UWL WT21US.UWL WT13DE.UWL ... +# and "template" SAV/HWL variant under program directory like: wt13en.hwl Wt13de.sav Wt13it.sav wt13ru.sav WT21us.sav Wtcz.sav ... +!:ext uwl/hwl/sav +# jump to document area with some marker and word list +>>>(4.l) ubyte x +# look for beginning of word list starting mostly with letter a as UTF-16 like: Wt13es.sav +# but not found in russian wt13ru.sav +>>>>&0 search/91/sb a\0 +# word list starting like: "acsesory\022accessory.\001\026acomodate\026accommodate4\001" +>>>>>&0 lestring16 x (...%-.33s...) +# pointer to document area like: 200h +>>>4 ulelong !0x200 \b, at %#x document area +# file size, not including pad characters at EOF +>>>0x14 uleshort x \b, %u bytes # IntelliTAG >8 byte 33 >>9 byte 10 IntelliTAG (SGML) compiled DTD >>9 default x >>>9 byte x IntelliTAG: Unknown filetype %d +# Summary: Corel WordPerfect WritingTools advise part +# From: Joerg Jenderek +# Reference: http://mark0.net/download/triddefs_xml.7z/defs/a/adv-wp.trid.xml +>8 byte 34 +>>9 byte 11 Corel WordPerfect dictionary advise +#!:mime application/octet-stream +!:mime application/x-wordperfect-adv +#!:mime application/vnd.wordperfect.adv +# like: WT21de.adv Wt13de.adv Wt13es.adv Wt13fr.adv wt13us.adv +!:ext adv +# advise text part often start with tag like: 580A +#>>>(16.s) ubequad x ADVISE PART %#llx +# part of advise text like: "This is too informal for most writing." +>>>(16.s+16) string x (...%-.33s...) # everything else >8 default x >>8 byte x Unknown Corel/Wordperfect product %d, @@ -39474,7 +40869,8 @@ >&0 belong 0xaa995566 Xilinx RAW bitstream (.BIN) #------------------------------------------------------------------------------ -# $File: xo65,v 1.4 2009/09/19 16:28:13 christos Exp $ +# $File: xo65,v 1.5 2022/07/17 15:36:20 christos Exp $ +# https://cc65.github.io/doc/sim65.html # xo65 object files # From: "Ullrich von Bassewitz" # @@ -39503,6 +40899,12 @@ >6 leshort&0x0003 =0x0002 alignment 4 >6 leshort&0x0003 =0x0003 alignment 256 +# sim65 executable files +0 string \x73\x69\x6d\x36\x35 sim65 executable, +>5 byte x version %d, +>6 leshort&0x0000 =0x0000 6502 +>6 leshort&0x0001 =0x0001 65C02 + #------------------------------------------------------------------------------ # $File: xwindows,v 1.13 2022/03/24 15:48:58 christos Exp $ # xwindows: file(1) magic for various X/Window system file formats.