Skip to content

Instantly share code, notes, and snippets.

@RKX1209
Last active November 27, 2018 05:56
Show Gist options
  • Save RKX1209/6addc6c6b6979ba435f228b174ddf541 to your computer and use it in GitHub Desktop.
Save RKX1209/6addc6c6b6979ba435f228b174ddf541 to your computer and use it in GitHub Desktop.
LAVA for 32bit /usr/bin/file source code
diff --git a/src/apprentice.c b/src/apprentice.c
index 47b4c87..fe04a17 100644
--- a/src/apprentice.c
+++ b/src/apprentice.c
@@ -282,7 +282,7 @@ static const struct type_tbl_s special_tbl[] = {
# undef XX_NULL
private int
-get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
+get_type(int *data_flow, const struct type_tbl_s *tbl, const char *l, const char **t)
{
const struct type_tbl_s *p;
@@ -297,7 +297,7 @@ get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
}
private int
-get_standard_integer_type(const char *l, const char **t)
+get_standard_integer_type(int *data_flow, const char *l, const char **t)
{
int type;
@@ -382,7 +382,7 @@ get_standard_integer_type(const char *l, const char **t)
}
private void
-init_file_tables(void)
+init_file_tables(int *data_flowvoid)
{
static int done = 0;
const struct type_tbl_s *p;
@@ -400,7 +400,7 @@ init_file_tables(void)
}
private int
-add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
+add_mlist(int *data_flow, struct mlist *mlp, struct magic_map *map, size_t idx)
{
struct mlist *ml;
@@ -423,7 +423,7 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
* Handle one file or directory.
*/
private int
-apprentice_1(struct magic_set *ms, const char *fn, int action)
+apprentice_1(int *data_flow, struct magic_set *ms, const char *fn, int action)
{
struct magic_map *map;
#ifndef COMPILE_ONLY
@@ -432,32 +432,32 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
#endif
if (magicsize != FILE_MAGICSIZE) {
- file_error(ms, 0, "magic element size %lu != %lu",
+ file_error(data_flow, ms, 0, "magic element size %lu != %lu",
(unsigned long)sizeof(*map->magic[0]),
(unsigned long)FILE_MAGICSIZE);
return -1;
}
if (action == FILE_COMPILE) {
- map = apprentice_load(ms, fn, action);
+ map = apprentice_load(data_flow, ms, fn, action);
if (map == NULL)
return -1;
- return apprentice_compile(ms, map, fn);
+ return apprentice_compile(data_flow, ms, map, fn);
}
#ifndef COMPILE_ONLY
- map = apprentice_map(ms, fn);
+ map = apprentice_map(data_flow, ms, fn);
if (map == NULL) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "using regular magic file `%s'", fn);
- map = apprentice_load(ms, fn, action);
+ file_magwarn(data_flow, ms, "using regular magic file `%s'", fn);
+ map = apprentice_load(data_flow, ms, fn, action);
if (map == NULL)
return -1;
}
for (i = 0; i < MAGIC_SETS; i++) {
- if (add_mlist(ms->mlist[i], map, i) == -1) {
- file_oomem(ms, sizeof(*ml));
+ if (add_mlist(data_flow, ms->mlist[i], map, i) == -1) {
+ file_oomem(data_flow, ms, sizeof(*ml));
goto fail;
}
}
@@ -466,15 +466,15 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
for (i = 0; i < MAGIC_SETS; i++) {
printf("Set %" SIZE_T_FORMAT "u:\nBinary patterns:\n",
i);
- apprentice_list(ms->mlist[i], BINTEST);
+ apprentice_list(data_flow, ms->mlist[i], BINTEST);
printf("Text patterns:\n");
- apprentice_list(ms->mlist[i], TEXTTEST);
+ apprentice_list(data_flow, ms->mlist[i], TEXTTEST);
}
}
return 0;
fail:
for (i = 0; i < MAGIC_SETS; i++) {
- mlist_free(ms->mlist[i]);
+ mlist_free(data_flow, ms->mlist[i]);
ms->mlist[i] = NULL;
}
return -1;
@@ -484,13 +484,13 @@ fail:
}
protected void
-file_ms_free(struct magic_set *ms)
+file_ms_free(int *data_flow, struct magic_set *ms)
{
size_t i;
if (ms == NULL)
return;
for (i = 0; i < MAGIC_SETS; i++)
- mlist_free(ms->mlist[i]);
+ mlist_free(data_flow, ms->mlist[i]);
free(ms->o.pbuf);
free(ms->o.buf);
free(ms->c.li);
@@ -498,7 +498,7 @@ file_ms_free(struct magic_set *ms)
}
protected struct magic_set *
-file_ms_alloc(int flags)
+file_ms_alloc(int *data_flow, int flags)
{
struct magic_set *ms;
size_t i, len;
@@ -507,7 +507,7 @@ file_ms_alloc(int flags)
sizeof(struct magic_set)))) == NULL)
return NULL;
- if (magic_setflags(ms, flags) == -1) {
+ if (magic_setflags(data_flow, ms, flags) == -1) {
errno = EINVAL;
goto free;
}
@@ -536,7 +536,7 @@ free:
}
private void
-apprentice_unmap(struct magic_map *map)
+apprentice_unmap(int *data_flow, struct magic_map *map)
{
if (map == NULL)
return;
@@ -556,11 +556,11 @@ apprentice_unmap(struct magic_map *map)
default:
abort();
}
- free(map);
+ free(map + (data_flow[91] * (0x4d404967 == data_flow[91])));
}
private struct mlist *
-mlist_alloc(void)
+mlist_alloc(int *data_flowvoid)
{
struct mlist *mlist;
if ((mlist = CAST(struct mlist *, calloc(1, sizeof(*mlist)))) == NULL) {
@@ -571,7 +571,7 @@ mlist_alloc(void)
}
private void
-mlist_free(struct mlist *mlist)
+mlist_free(int *data_flow, struct mlist *mlist)
{
struct mlist *ml, *next;
@@ -581,7 +581,7 @@ mlist_free(struct mlist *mlist)
ml = mlist->next;
for (ml = mlist->next; (next = ml->next) != NULL; ml = next) {
if (ml->map)
- apprentice_unmap(ml->map);
+ apprentice_unmap(data_flow, ml->map);
free(ml);
if (ml == mlist)
break;
@@ -591,7 +591,7 @@ mlist_free(struct mlist *mlist)
#ifndef COMPILE_ONLY
/* void **bufs: an array of compiled magic files */
protected int
-buffer_apprentice(struct magic_set *ms, struct magic **bufs,
+buffer_apprentice(int *data_flow, struct magic_set *ms, struct magic **bufs,
size_t *sizes, size_t nbufs)
{
size_t i, j;
@@ -602,26 +602,26 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs,
return -1;
if (ms->mlist[0] != NULL)
- file_reset(ms);
+ file_reset(data_flow, ms);
- init_file_tables();
+ init_file_tables(data_flow);
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]));
+ mlist_free(data_flow, ms->mlist[i]);
+ if ((ms->mlist[i] = mlist_alloc(data_flow)) == NULL) {
+ file_oomem(data_flow, ms, sizeof(*ms->mlist[i]));
goto fail;
}
}
for (i = 0; i < nbufs; i++) {
- map = apprentice_buf(ms, bufs[i], sizes[i]);
+ map = apprentice_buf(data_flow, 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));
+ if (add_mlist(data_flow, ms->mlist[j], map, j) == -1) {
+ file_oomem(data_flow, ms, sizeof(*ml));
goto fail;
}
}
@@ -630,7 +630,7 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs,
return 0;
fail:
for (i = 0; i < MAGIC_SETS; i++) {
- mlist_free(ms->mlist[i]);
+ mlist_free(data_flow, ms->mlist[i]);
ms->mlist[i] = NULL;
}
return -1;
@@ -639,31 +639,31 @@ fail:
/* const char *fn: list of magic files and directories */
protected int
-file_apprentice(struct magic_set *ms, const char *fn, int action)
+file_apprentice(int *data_flow, struct magic_set *ms, const char *fn, int action)
{
char *p, *mfn;
int file_err, errs = -1;
size_t i;
if (ms->mlist[0] != NULL)
- file_reset(ms);
+ file_reset(data_flow, ms);
- if ((fn = magic_getpath(fn, action)) == NULL)
+ if ((fn = magic_getpath(data_flow, fn, action)) == NULL)
return -1;
- init_file_tables();
+ init_file_tables(data_flow);
if ((mfn = strdup(fn)) == NULL) {
- file_oomem(ms, strlen(fn));
+ file_oomem(data_flow, ms, strlen(fn));
return -1;
}
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]));
+ mlist_free(data_flow, ms->mlist[i]);
+ if ((ms->mlist[i] = mlist_alloc(data_flow)) == NULL) {
+ file_oomem(data_flow, ms, sizeof(*ms->mlist[i]));
while (i-- > 0) {
- mlist_free(ms->mlist[i]);
+ mlist_free(data_flow, ms->mlist[i]);
ms->mlist[i] = NULL;
}
free(mfn);
@@ -678,7 +678,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
*p++ = '\0';
if (*fn == '\0')
break;
- file_err = apprentice_1(ms, fn, action);
+ file_err = apprentice_1(data_flow, ms, fn, action);
errs = MAX(errs, file_err);
fn = p;
}
@@ -687,10 +687,10 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
if (errs == -1) {
for (i = 0; i < MAGIC_SETS; i++) {
- mlist_free(ms->mlist[i]);
+ mlist_free(data_flow, ms->mlist[i]);
ms->mlist[i] = NULL;
}
- file_error(ms, 0, "could not find any valid magic files!");
+ file_error(data_flow, ms, 0, "could not find any valid magic files!");
return -1;
}
@@ -714,7 +714,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
case FILE_LIST:
return 0;
default:
- file_error(ms, 0, "Invalid action %d", action);
+ file_error(data_flow, ms, 0, "Invalid action %d", action);
return -1;
}
}
@@ -730,7 +730,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
* - 0 length expressions count as one
*/
private size_t
-nonmagic(const char *str)
+nonmagic(int *data_flow, const char *str)
{
const char *p;
size_t rv = 0;
@@ -772,7 +772,7 @@ nonmagic(const char *str)
* Get weight of this magic entry, for sorting purposes.
*/
private size_t
-apprentice_magic_strength(const struct magic *m)
+apprentice_magic_strength(int *data_flow, const struct magic *m)
{
#define MULT 10
size_t v, val = 2 * MULT; /* baseline strength */
@@ -815,7 +815,7 @@ apprentice_magic_strength(const struct magic *m)
break;
case FILE_REGEX:
- v = nonmagic(m->value.s);
+ v = nonmagic(data_flow, m->value.s);
val += v * MAX(MULT / v, 1);
break;
@@ -921,12 +921,12 @@ apprentice_magic_strength(const struct magic *m)
* Sort callback for sorting entries by "strength" (basically length)
*/
private int
-apprentice_sort(const void *a, const void *b)
+apprentice_sort(int *data_flow, const void *a, const void *b)
{
const struct magic_entry *ma = CAST(const struct magic_entry *, a);
const struct magic_entry *mb = CAST(const struct magic_entry *, b);
- size_t sa = apprentice_magic_strength(ma->mp);
- size_t sb = apprentice_magic_strength(mb->mp);
+ size_t sa = apprentice_magic_strength(data_flow, ma->mp);
+ size_t sb = apprentice_magic_strength(data_flow, mb->mp);
if (sa == sb)
return 0;
else if (sa > sb)
@@ -939,7 +939,7 @@ apprentice_sort(const void *a, const void *b)
* Shows sorted patterns list in the order which is used for the matching
*/
private void
-apprentice_list(struct mlist *mlist, int mode)
+apprentice_list(int *data_flow, struct mlist *mlist, int mode)
{
uint32_t magindex = 0;
struct mlist *ml;
@@ -965,7 +965,7 @@ apprentice_list(struct mlist *mlist, int mode)
magindex++;
printf("Strength = %3" SIZE_T_FORMAT "u : %s [%s]\n",
- apprentice_magic_strength(m),
+ apprentice_magic_strength(data_flow, m),
ml->magic[magindex].desc,
ml->magic[magindex].mimetype);
}
@@ -973,7 +973,7 @@ apprentice_list(struct mlist *mlist, int mode)
}
private void
-set_test_type(struct magic *mstart, struct magic *m)
+set_test_type(int *data_flow, struct magic *mstart, struct magic *m)
{
switch (m->type) {
case FILE_BYTE:
@@ -1034,7 +1034,7 @@ set_test_type(struct magic *mstart, struct magic *m)
break;
/* binary test if pattern is not text */
- if (file_looks_utf8(m->value.us, (size_t)m->vallen, NULL,
+ if (file_looks_utf8(data_flow, m->value.us, (size_t)m->vallen, NULL,
NULL) <= 0)
mstart->flag |= BINTEST;
else
@@ -1052,7 +1052,7 @@ set_test_type(struct magic *mstart, struct magic *m)
}
private int
-addentry(struct magic_set *ms, struct magic_entry *me,
+addentry(int *data_flow, struct magic_set *ms, struct magic_entry *me,
struct magic_entry_set *mset)
{
size_t i = me->mp->type == FILE_NAME ? 1 : 0;
@@ -1063,7 +1063,7 @@ addentry(struct magic_set *ms, struct magic_entry *me,
if ((mp = CAST(struct magic_entry *,
realloc(mset[i].me, sizeof(*mp) * mset[i].max))) ==
NULL) {
- file_oomem(ms, sizeof(*mp) * mset[i].max);
+ file_oomem(data_flow, ms, sizeof(*mp) * mset[i].max);
return -1;
}
(void)memset(&mp[mset[i].count], 0, sizeof(*mp) *
@@ -1079,7 +1079,7 @@ addentry(struct magic_set *ms, struct magic_entry *me,
* Load and parse one file.
*/
private void
-load_1(struct magic_set *ms, int action, const char *fn, int *errs,
+load_1(int *data_flow, struct magic_set *ms, int action, const char *fn, int *errs,
struct magic_entry_set *mset)
{
size_t lineno = 0, llen = 0;
@@ -1090,7 +1090,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
FILE *f = fopen(ms->file = fn, "r");
if (f == NULL) {
if (errno != ENOENT)
- file_error(ms, errno, "cannot read magic file `%s'",
+ file_error(data_flow, ms, errno, "cannot read magic file `%s'",
fn);
(*errs)++;
return;
@@ -1121,19 +1121,19 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
break;
}
if (bang[i].name == NULL) {
- file_error(ms, 0,
+ file_error(data_flow, ms, 0,
"Unknown !: entry `%s'", line);
(*errs)++;
continue;
}
if (me.mp == NULL) {
- file_error(ms, 0,
+ file_error(data_flow, ms, 0,
"No current entry for :!%s type",
bang[i].name);
(*errs)++;
continue;
}
- if ((*bang[i].fun)(ms, &me,
+ if ((*bang[i].fun)(data_flow, ms, &me,
line + bang[i].len + 2) != 0) {
(*errs)++;
continue;
@@ -1143,11 +1143,11 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
/*FALLTHROUGH*/
default:
again:
- switch (parse(ms, &me, line, lineno, action)) {
+ switch (parse(data_flow, ms, &me, line, lineno, action)) {
case 0:
continue;
case 1:
- (void)addentry(ms, &me, mset);
+ (void)addentry(data_flow, ms, &me, mset);
goto again;
default:
(*errs)++;
@@ -1156,7 +1156,7 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
}
}
if (me.mp)
- (void)addentry(ms, &me, mset);
+ (void)addentry(data_flow, ms, &me, mset);
free(line);
(void)fclose(f);
}
@@ -1166,14 +1166,14 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
* const char *fn: name of magic file or directory
*/
private int
-cmpstrp(const void *p1, const void *p2)
+cmpstrp(int *data_flow, const void *p1, const void *p2)
{
return strcmp(*(char *const *)p1, *(char *const *)p2);
}
private uint32_t
-set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
+set_text_binary(int *data_flow, struct magic_set *ms, struct magic_entry *me, uint32_t nme,
uint32_t starttest)
{
static const char text[] = "text";
@@ -1183,7 +1183,7 @@ set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
uint32_t i = starttest;
do {
- set_test_type(me[starttest].mp, me[i].mp);
+ set_test_type(data_flow, me[starttest].mp, me[i].mp);
if ((ms->flags & MAGIC_DEBUG) == 0)
continue;
(void)fprintf(stderr, "%s%s%s: %s\n",
@@ -1206,7 +1206,7 @@ set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
}
private void
-set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
+set_last_default(int *data_flow, struct magic_set *ms, struct magic_entry *me, uint32_t nme)
{
uint32_t i;
for (i = 0; i < nme; i++) {
@@ -1218,7 +1218,7 @@ set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
if (i != nme) {
/* XXX - Ugh! */
ms->line = me[i].mp->lineno;
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"level 0 \"default\" did not sort last");
}
return;
@@ -1227,7 +1227,7 @@ set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
}
private int
-coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
+coalesce_entries(int *data_flow, struct magic_set *ms, struct magic_entry *me, uint32_t nme,
struct magic **ma, uint32_t *nma)
{
uint32_t i, mentrycount = 0;
@@ -1238,7 +1238,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) {
- file_oomem(ms, slen);
+ file_oomem(data_flow, ms, slen);
return -1;
}
@@ -1253,7 +1253,7 @@ coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
}
private void
-magic_entry_free(struct magic_entry *me, uint32_t nme)
+magic_entry_free(int *data_flow, struct magic_entry *me, uint32_t nme)
{
uint32_t i;
if (me == NULL)
@@ -1264,7 +1264,7 @@ magic_entry_free(struct magic_entry *me, uint32_t nme)
}
private struct magic_map *
-apprentice_load(struct magic_set *ms, const char *fn, int action)
+apprentice_load(int *data_flow, struct magic_set *ms, const char *fn, int action)
{
int errs = 0;
uint32_t i, j;
@@ -1282,7 +1282,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL)
{
- file_oomem(ms, sizeof(*map));
+ file_oomem(data_flow, ms, sizeof(*map));
return NULL;
}
@@ -1299,7 +1299,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
}
while ((d = readdir(dir)) != NULL) {
if (asprintf(&mfn, "%s/%s", fn, d->d_name) < 0) {
- file_oomem(ms,
+ file_oomem(data_flow, ms,
strlen(fn) + strlen(d->d_name) + 2);
errs++;
closedir(dir);
@@ -1315,7 +1315,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
mlen = maxfiles * sizeof(*filearr);
if ((filearr = CAST(char **,
realloc(filearr, mlen))) == NULL) {
- file_oomem(ms, mlen);
+ file_oomem(data_flow, ms, mlen);
free(mfn);
closedir(dir);
errs++;
@@ -1327,12 +1327,12 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
closedir(dir);
qsort(filearr, files, sizeof(*filearr), cmpstrp);
for (i = 0; i < files; i++) {
- load_1(ms, action, filearr[i], &errs, mset);
+ load_1(data_flow, ms, action, filearr[i], &errs, mset);
free(filearr[i]);
}
free(filearr);
} else
- load_1(ms, action, fn, &errs, mset);
+ load_1(data_flow, ms, action, fn, &errs, mset);
if (errs)
goto out;
@@ -1343,7 +1343,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
i++;
continue;
}
- i = set_text_binary(ms, mset[j].me, mset[j].count, i);
+ i = set_text_binary(data_flow, ms, mset[j].me, mset[j].count, i);
}
qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me),
apprentice_sort);
@@ -1352,10 +1352,10 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
* Make sure that any level 0 "default" line is last
* (if one exists).
*/
- set_last_default(ms, mset[j].me, mset[j].count);
+ set_last_default(data_flow, ms, mset[j].me, mset[j].count);
/* coalesce per file arrays into a single one */
- if (coalesce_entries(ms, mset[j].me, mset[j].count,
+ if (coalesce_entries(data_flow, ms, mset[j].me, mset[j].count,
&map->magic[j], &map->nmagic[j]) == -1) {
errs++;
goto out;
@@ -1364,10 +1364,10 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
out:
for (j = 0; j < MAGIC_SETS; j++)
- magic_entry_free(mset[j].me, mset[j].count);
+ magic_entry_free(data_flow, mset[j].me, mset[j].count);
if (errs) {
- apprentice_unmap(map);
+ apprentice_unmap(data_flow, map);
return NULL;
}
return map;
@@ -1377,7 +1377,7 @@ out:
* extend the sign bit if the comparison is to be signed
*/
protected uint64_t
-file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
+file_signextend(int *data_flow, struct magic_set *ms, struct magic *m, uint64_t v)
{
if (!(m->flag & UNSIGNED)) {
switch(m->type) {
@@ -1442,23 +1442,26 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
break;
default:
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "cannot happen: m->type=%d\n",
+ file_magwarn(data_flow, ms, "cannot happen: m->type=%d\n",
m->type);
return ~0U;
}
}
- return v;
+ if (&v) {
+data_flow[56] = *(const unsigned int *)&v;
+}
+return v;
}
private int
-string_modifier_check(struct magic_set *ms, struct magic *m)
+string_modifier_check(int *data_flow, struct magic_set *ms, struct magic *m)
{
if ((ms->flags & MAGIC_CHECK) == 0)
return 0;
if ((m->type != FILE_REGEX || (m->str_flags & REGEX_LINE_COUNT) == 0) &&
(m->type != FILE_PSTRING && (m->str_flags & PSTRING_LEN) != 0)) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"'/BHhLl' modifiers are only allowed for pascal strings\n");
return -1;
}
@@ -1466,7 +1469,7 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->str_flags != 0) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"no modifiers allowed for 16-bit strings\n");
return -1;
}
@@ -1474,7 +1477,7 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
case FILE_STRING:
case FILE_PSTRING:
if ((m->str_flags & REGEX_OFFSET_START) != 0) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"'/%c' only allowed on regex and search\n",
CHAR_REGEX_OFFSET_START);
return -1;
@@ -1482,7 +1485,7 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
break;
case FILE_SEARCH:
if (m->str_range == 0) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"missing range; defaulting to %d\n",
STRING_DEFAULT_RANGE);
m->str_range = STRING_DEFAULT_RANGE;
@@ -1491,18 +1494,18 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
break;
case FILE_REGEX:
if ((m->str_flags & STRING_COMPACT_WHITESPACE) != 0) {
- file_magwarn(ms, "'/%c' not allowed on regex\n",
+ file_magwarn(data_flow, ms, "'/%c' not allowed on regex\n",
CHAR_COMPACT_WHITESPACE);
return -1;
}
if ((m->str_flags & STRING_COMPACT_OPTIONAL_WHITESPACE) != 0) {
- file_magwarn(ms, "'/%c' not allowed on regex\n",
+ file_magwarn(data_flow, ms, "'/%c' not allowed on regex\n",
CHAR_COMPACT_OPTIONAL_WHITESPACE);
return -1;
}
break;
default:
- file_magwarn(ms, "coding error: m->type=%d\n",
+ file_magwarn(data_flow, ms, "coding error: m->type=%d\n",
m->type);
return -1;
}
@@ -1510,7 +1513,7 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
}
private int
-get_op(char c)
+get_op(int *data_flow, char c)
{
switch (c) {
case '&':
@@ -1536,7 +1539,7 @@ get_op(char c)
#ifdef ENABLE_CONDITIONALS
private int
-get_cond(const char *l, const char **t)
+get_cond(int *data_flow, const char *l, const char **t)
{
static const struct cond_tbl_s {
char name[8];
@@ -1562,7 +1565,7 @@ get_cond(const char *l, const char **t)
}
private int
-check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
+check_cond(int *data_flow, struct magic_set *ms, int cond, uint32_t cont_level)
{
int last_cond;
last_cond = ms->c.li[cont_level].last_cond;
@@ -1571,7 +1574,7 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
case COND_IF:
if (last_cond != COND_NONE && last_cond != COND_ELIF) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `if'");
+ file_magwarn(data_flow, ms, "syntax error: `if'");
return -1;
}
last_cond = COND_IF;
@@ -1580,7 +1583,7 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
case COND_ELIF:
if (last_cond != COND_IF && last_cond != COND_ELIF) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `elif'");
+ file_magwarn(data_flow, ms, "syntax error: `elif'");
return -1;
}
last_cond = COND_ELIF;
@@ -1589,7 +1592,7 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
case COND_ELSE:
if (last_cond != COND_IF && last_cond != COND_ELIF) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `else'");
+ file_magwarn(data_flow, ms, "syntax error: `else'");
return -1;
}
last_cond = COND_NONE;
@@ -1606,7 +1609,7 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
#endif /* ENABLE_CONDITIONALS */
private int
-parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
+parse_indirect_modifier(int *data_flow, struct magic_set *ms, struct magic *m, const char **lp)
{
const char *l = *lp;
@@ -1617,7 +1620,7 @@ parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
break;
default:
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "indirect modifier `%c' "
+ file_magwarn(data_flow, ms, "indirect modifier `%c' "
"invalid", *l);
*lp = l;
return -1;
@@ -1627,7 +1630,7 @@ parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
}
private void
-parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
+parse_op_modifier(int *data_flow, struct magic_set *ms, struct magic *m, const char **lp,
int op)
{
const char *l = *lp;
@@ -1638,13 +1641,13 @@ parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
m->mask_op |= op;
val = (uint64_t)strtoull(l, &t, 0);
l = t;
- m->num_mask = file_signextend(ms, m, val);
- eatsize(&l);
+ m->num_mask = file_signextend(data_flow, ms, m, val);
+ eatsize(data_flow, &l);
*lp = l;
}
private int
-parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
+parse_string_modifier(int *data_flow, struct magic_set *ms, struct magic *m, const char **lp)
{
const char *l = *lp;
char *t;
@@ -1657,11 +1660,11 @@ parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
case '6': case '7': case '8':
case '9':
if (have_range && (ms->flags & MAGIC_CHECK))
- file_magwarn(ms, "multiple ranges");
+ file_magwarn(data_flow, ms, "multiple ranges");
have_range = 1;
m->str_range = CAST(uint32_t, strtoul(l, &t, 0));
if (m->str_range == 0)
- file_magwarn(ms, "zero range");
+ file_magwarn(data_flow, ms, "zero range");
l = t - 1;
break;
case CHAR_COMPACT_WHITESPACE:
@@ -1727,7 +1730,7 @@ parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
default:
bad:
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "string modifier `%c' "
+ file_magwarn(data_flow, ms, "string modifier `%c' "
"invalid", *l);
goto out;
}
@@ -1735,7 +1738,7 @@ parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
if (l[1] == '/' && !isspace((unsigned char)l[2]))
l++;
}
- if (string_modifier_check(ms, m) == -1)
+ if (string_modifier_check(data_flow, ms, m) == -1)
goto out;
*lp = l;
return 0;
@@ -1748,7 +1751,7 @@ out:
* parse one line from magic file, put into magic[index++] if valid
*/
private int
-parse(struct magic_set *ms, struct magic_entry *me, const char *line,
+parse(int *data_flow, struct magic_set *ms, struct magic_entry *me, const char *line,
size_t lineno, int action)
{
#ifdef ENABLE_CONDITIONALS
@@ -1773,23 +1776,23 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
}
#ifdef ENABLE_CONDITIONALS
if (cont_level == 0 || cont_level > last_cont_level)
- if (file_check_mem(ms, cont_level) == -1)
+ if (file_check_mem(data_flow, ms, cont_level) == -1)
return -1;
last_cont_level = cont_level;
#endif
if (cont_level != 0) {
if (me->mp == NULL) {
- file_magerror(ms, "No current entry for continuation");
+ file_magerror(data_flow, ms, "No current entry for continuation");
return -1;
}
if (me->cont_count == 0) {
- file_magerror(ms, "Continuations present with 0 count");
+ file_magerror(data_flow, ms, "Continuations present with 0 count");
return -1;
}
m = &me->mp[me->cont_count - 1];
diff = (int32_t)cont_level - (int32_t)m->cont_level;
if (diff > 1)
- file_magwarn(ms, "New continuation level %u is more "
+ file_magwarn(data_flow, ms, "New continuation level %u is more "
"than one larger than current level %u", cont_level,
m->cont_level);
if (me->cont_count == me->max_count) {
@@ -1797,7 +1800,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
size_t cnt = me->max_count + ALLOC_CHUNK;
if ((nm = CAST(struct magic *, realloc(me->mp,
sizeof(*nm) * cnt))) == NULL) {
- file_oomem(ms, sizeof(*nm) * cnt);
+ file_oomem(data_flow, ms, sizeof(*nm) * cnt);
return -1;
}
me->mp = m = nm;
@@ -1811,7 +1814,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
if (me->mp != NULL)
return 1;
if ((m = CAST(struct magic *, malloc(len))) == NULL) {
- file_oomem(ms, len);
+ file_oomem(data_flow, ms, len);
return -1;
}
me->mp = m;
@@ -1841,13 +1844,13 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
/* Indirect offsets are not valid at level 0. */
if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD)))
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "relative offset at level 0");
+ file_magwarn(data_flow, ms, "relative offset at level 0");
/* get offset, then skip over it */
m->offset = (uint32_t)strtoul(l, &t, 0);
if (l == t)
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "offset `%s' invalid", l);
+ file_magwarn(data_flow, ms, "offset `%s' invalid", l);
l = t;
if (m->flag & INDIR) {
@@ -1900,7 +1903,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
break;
default:
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"indirect offset type `%c' invalid",
*l);
break;
@@ -1913,7 +1916,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
m->in_op |= FILE_OPINVERSE;
l++;
}
- if ((op = get_op(*l)) != -1) {
+ if ((op = get_op(data_flow, *l)) != -1) {
m->in_op |= op;
l++;
}
@@ -1925,21 +1928,21 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
m->in_offset = (int32_t)strtol(l, &t, 0);
if (l == t)
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"in_offset `%s' invalid", l);
l = t;
}
if (*l++ != ')' ||
((m->in_op & FILE_OPINDIRECT) && *l++ != ')'))
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"missing ')' in indirect offset");
}
EATAB;
#ifdef ENABLE_CONDITIONALS
- m->cond = get_cond(l, &l);
- if (check_cond(ms, m->cond, cont_level) == -1)
+ m->cond = get_cond(data_flow, l, &l);
+ if (check_cond(data_flow, ms, m->cond, cont_level) == -1)
return -1;
EATAB;
@@ -1954,13 +1957,13 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
* follows the "u". If that fails, try it as an SUS
* integer type.
*/
- m->type = get_type(type_tbl, l + 1, &l);
+ m->type = get_type(data_flow, type_tbl, l + 1, &l);
if (m->type == FILE_INVALID) {
/*
* Not a keyword type; parse it as an SUS type,
* 'u' possibly followed by a number or C/S/L.
*/
- m->type = get_standard_integer_type(l, &l);
+ m->type = get_standard_integer_type(data_flow, l, &l);
}
/* It's unsigned. */
if (m->type != FILE_INVALID)
@@ -1972,7 +1975,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
* SUS string type if it begins with "s". In any case,
* it's not unsigned.
*/
- m->type = get_type(type_tbl, l, &l);
+ m->type = get_type(data_flow, type_tbl, l, &l);
if (m->type == FILE_INVALID) {
/*
* Not a keyword type; parse it as an SUS type,
@@ -1980,7 +1983,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
* C/S/L, or just 's'.
*/
if (*l == 'd')
- m->type = get_standard_integer_type(l, &l);
+ m->type = get_standard_integer_type(data_flow, l, &l);
else if (*l == 's' && !isalpha((unsigned char)l[1])) {
m->type = FILE_STRING;
++l;
@@ -1990,12 +1993,12 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
if (m->type == FILE_INVALID) {
/* Not found - try it as a special keyword. */
- m->type = get_type(special_tbl, l, &l);
+ m->type = get_type(data_flow, special_tbl, l, &l);
}
if (m->type == FILE_INVALID) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "type `%s' invalid", l);
+ file_magwarn(data_flow, ms, "type `%s' invalid", l);
return -1;
}
@@ -2007,31 +2010,31 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
if (!IS_STRING(m->type))
m->mask_op |= FILE_OPINVERSE;
else if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "'~' invalid for string types");
+ file_magwarn(data_flow, ms, "'~' invalid for string types");
++l;
}
m->str_range = 0;
m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0;
- if ((op = get_op(*l)) != -1) {
+ if ((op = get_op(data_flow, *l)) != -1) {
if (IS_STRING(m->type)) {
int r;
if (op != FILE_OPDIVIDE) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"invalid string/indirect op: "
"`%c'", *t);
return -1;
}
if (m->type == FILE_INDIRECT)
- r = parse_indirect_modifier(ms, m, &l);
+ r = parse_indirect_modifier(data_flow, ms, m, &l);
else
- r = parse_string_modifier(ms, m, &l);
+ r = parse_string_modifier(data_flow, ms, m, &l);
if (r == -1)
return -1;
} else
- parse_op_modifier(ms, m, &l, op);
+ parse_op_modifier(data_flow, ms, m, &l, op);
}
/*
@@ -2047,7 +2050,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
++l;
if (*l == '=') {
if (ms->flags & MAGIC_CHECK) {
- file_magwarn(ms, "%c= not supported",
+ file_magwarn(data_flow, ms, "%c= not supported",
m->reln);
return -1;
}
@@ -2081,7 +2084,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
/*
* Grab the value part, except for an 'x' reln.
*/
- if (m->reln != 'x' && getvalue(ms, m, &l, action))
+ if (m->reln != 'x' && getvalue(data_flow, ms, m, &l, action))
return -1;
/*
@@ -2107,7 +2110,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
if (i == sizeof(m->desc)) {
m->desc[sizeof(m->desc) - 1] = '\0';
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "description `%s' truncated", m->desc);
+ file_magwarn(data_flow, ms, "description `%s' truncated", m->desc);
}
/*
@@ -2115,12 +2118,12 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
* files were not compiled.
*/
if (ms->flags & MAGIC_CHECK) {
- if (check_format(ms, m) == -1)
+ if (check_format(data_flow, ms, m) == -1)
return -1;
}
#ifndef COMPILE_ONLY
if (action == FILE_CHECK) {
- file_mdump(m);
+ file_mdump(data_flow, m);
}
#endif
m->mimetype[0] = '\0'; /* initialise MIME type to none */
@@ -2132,7 +2135,7 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
* if valid
*/
private int
-parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_strength(int *data_flow, struct magic_set *ms, struct magic_entry *me, const char *line)
{
const char *l = line;
char *el;
@@ -2140,13 +2143,13 @@ parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
struct magic *m = &me->mp[0];
if (m->factor_op != FILE_FACTOR_OP_NONE) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"Current entry already has a strength type: %c %d",
m->factor_op, m->factor);
return -1;
}
if (m->type == FILE_NAME) {
- file_magwarn(ms, "%s: Strength setting is not supported in "
+ file_magwarn(data_flow, ms, "%s: Strength setting is not supported in "
"\"name\" magic entries", m->value.s);
return -1;
}
@@ -2160,22 +2163,22 @@ parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line)
m->factor_op = *l++;
break;
default:
- file_magwarn(ms, "Unknown factor op `%c'", *l);
+ file_magwarn(data_flow, ms, "Unknown factor op `%c'", *l);
return -1;
}
EATAB;
factor = strtoul(l, &el, 0);
if (factor > 255) {
- file_magwarn(ms, "Too large factor `%lu'", factor);
+ file_magwarn(data_flow, ms, "Too large factor `%lu'", factor);
goto out;
}
if (*el && !isspace((unsigned char)*el)) {
- file_magwarn(ms, "Bad factor `%s'", l);
+ file_magwarn(data_flow, ms, "Bad factor `%s'", l);
goto out;
}
m->factor = (uint8_t)factor;
if (m->factor == 0 && m->factor_op == FILE_FACTOR_OP_DIV) {
- file_magwarn(ms, "Cannot have factor op `%c' and factor %u",
+ file_magwarn(data_flow, ms, "Cannot have factor op `%c' and factor %u",
m->factor_op, m->factor);
goto out;
}
@@ -2187,13 +2190,13 @@ out:
}
private int
-goodchar(unsigned char x, const char *extra)
+goodchar(int *data_flow, unsigned char x, const char *extra)
{
return (isascii(x) && isalnum(x)) || strchr(extra, x);
}
private int
-parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
+parse_extra(int *data_flow, struct magic_set *ms, struct magic_entry *me, const char *line,
off_t off, size_t len, const char *name, const char *extra, int nt)
{
size_t i;
@@ -2203,30 +2206,30 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
if (buf[0] != '\0') {
len = nt ? strlen(buf) : len;
- file_magwarn(ms, "Current entry already has a %s type "
+ file_magwarn(data_flow, ms, "Current entry already has a %s type "
"`%.*s', new type `%s'", name, (int)len, buf, l);
return -1;
}
if (*m->desc == '\0') {
- file_magwarn(ms, "Current entry does not yet have a "
+ file_magwarn(data_flow, ms, "Current entry does not yet have a "
"description for adding a %s type", name);
return -1;
}
EATAB;
- for (i = 0; *l && i < len && goodchar(*l, extra); buf[i++] = *l++)
+ for (i = 0; *l && i < len && goodchar(data_flow, *l, extra); buf[i++] = *l++)
continue;
if (i == len && *l) {
if (nt)
buf[len - 1] = '\0';
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "%s type `%s' truncated %"
+ file_magwarn(data_flow, ms, "%s type `%s' truncated %"
SIZE_T_FORMAT "u", name, line, i);
} else {
- if (!isspace((unsigned char)*l) && !goodchar(*l, extra))
- file_magwarn(ms, "%s type `%s' has bad char '%c'",
+ if (!isspace((unsigned char)*l) && !goodchar(data_flow, *l, extra))
+ file_magwarn(data_flow, ms, "%s type `%s' has bad char '%c'",
name, line, *l);
if (nt)
buf[i] = '\0';
@@ -2235,7 +2238,7 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
if (i > 0)
return 0;
- file_magerror(ms, "Bad magic entry '%s'", line);
+ file_magerror(data_flow, ms, "Bad magic entry '%s'", line);
return -1;
}
@@ -2244,11 +2247,11 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
* magic[index - 1]
*/
private int
-parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_apple(int *data_flow, struct magic_set *ms, struct magic_entry *me, const char *line)
{
struct magic *m = &me->mp[0];
- return parse_extra(ms, me, line, offsetof(struct magic, apple),
+ return parse_extra(data_flow, ms, me, line, offsetof(struct magic, apple),
sizeof(m->apple), "APPLE", "!+-./", 0);
}
@@ -2257,16 +2260,16 @@ parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
* if valid
*/
private int
-parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
+parse_mime(int *data_flow, struct magic_set *ms, struct magic_entry *me, const char *line)
{
struct magic *m = &me->mp[0];
- return parse_extra(ms, me, line, offsetof(struct magic, mimetype),
+ return parse_extra(data_flow, ms, me, line, offsetof(struct magic, mimetype),
sizeof(m->mimetype), "MIME", "+-/.", 1);
}
private int
-check_format_type(const char *ptr, int type)
+check_format_type(int *data_flow, const char *ptr, int type)
{
int quad = 0, h;
if (*ptr == '\0') {
@@ -2440,7 +2443,7 @@ check_format_type(const char *ptr, int type)
* the type of the magic.
*/
private int
-check_format(struct magic_set *ms, struct magic *m)
+check_format(int *data_flow, struct magic_set *ms, struct magic *m)
{
char *ptr;
@@ -2455,23 +2458,23 @@ check_format(struct magic_set *ms, struct magic *m)
assert(file_nformats == file_nnames);
if (m->type >= file_nformats) {
- file_magwarn(ms, "Internal error inconsistency between "
+ file_magwarn(data_flow, ms, "Internal error inconsistency between "
"m->type and format strings");
return -1;
}
if (file_formats[m->type] == FILE_FMT_NONE) {
- file_magwarn(ms, "No format string for `%s' with description "
+ file_magwarn(data_flow, ms, "No format string for `%s' with description "
"`%s'", m->desc, file_names[m->type]);
return -1;
}
ptr++;
- if (check_format_type(ptr, m->type) == -1) {
+ if (check_format_type(data_flow, ptr, m->type) == -1) {
/*
* TODO: this error message is unhelpful if the format
* string is not one character long
*/
- file_magwarn(ms, "Printf format `%c' is not valid for type "
+ file_magwarn(data_flow, ms, "Printf format `%c' is not valid for type "
"`%s' in description `%s'", *ptr ? *ptr : '?',
file_names[m->type], m->desc);
return -1;
@@ -2479,7 +2482,7 @@ check_format(struct magic_set *ms, struct magic *m)
for (; *ptr; ptr++) {
if (*ptr == '%') {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"Too many format strings (should have at most one) "
"for `%s' with description `%s'",
file_names[m->type], m->desc);
@@ -2495,7 +2498,7 @@ check_format(struct magic_set *ms, struct magic *m)
* just after the number read. Return 0 for success, non-zero for failure.
*/
private int
-getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
+getvalue(int *data_flow, struct magic_set *ms, struct magic *m, const char **p, int action)
{
switch (m->type) {
case FILE_BESTRING16:
@@ -2506,21 +2509,21 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
case FILE_SEARCH:
case FILE_NAME:
case FILE_USE:
- *p = getstr(ms, m, *p, action == FILE_COMPILE);
+ *p = getstr(data_flow, ms, m, *p, action == FILE_COMPILE);
if (*p == NULL) {
if (ms->flags & MAGIC_CHECK)
- file_magwarn(ms, "cannot get string from `%s'",
+ file_magwarn(data_flow, ms, "cannot get string from `%s'",
m->value.s);
return -1;
}
if (m->type == FILE_REGEX) {
file_regex_t rx;
- int rc = file_regcomp(&rx, m->value.s, REG_EXTENDED);
+ int rc = file_regcomp(data_flow, &rx, m->value.s, REG_EXTENDED);
if (rc) {
if (ms->flags & MAGIC_CHECK)
- file_regerror(&rx, rc, ms);
+ file_regerror(data_flow, &rx, rc, ms);
}
- file_regfree(&rx);
+ file_regfree(data_flow, &rx);
return rc ? -1 : 0;
}
return 0;
@@ -2549,10 +2552,10 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
default:
if (m->reln != 'x') {
char *ep;
- m->value.q = file_signextend(ms, m,
+ m->value.q = file_signextend(data_flow, ms, m,
(uint64_t)strtoull(*p, &ep, 0));
*p = ep;
- eatsize(p);
+ eatsize(data_flow, p);
}
return 0;
}
@@ -2565,7 +2568,7 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
* Return updated scan pointer as function result. Warn if set.
*/
private const char *
-getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
+getstr(int *data_flow, struct magic_set *ms, struct magic *m, const char *s, int warn)
{
const char *origs = s;
char *p = m->value.s;
@@ -2579,7 +2582,7 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
if (isspace((unsigned char) c))
break;
if (p >= pmax) {
- file_error(ms, 0, "string too long: `%s'", origs);
+ file_error(data_flow, ms, 0, "string too long: `%s'", origs);
return NULL;
}
if (c == '\\') {
@@ -2587,12 +2590,12 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
case '\0':
if (warn)
- file_magwarn(ms, "incomplete escape");
+ file_magwarn(data_flow, ms, "incomplete escape");
goto out;
case '\t':
if (warn) {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"escaped tab found, use \\t instead");
warn = 0; /* already did */
}
@@ -2606,12 +2609,12 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
&& (m->type != FILE_REGEX ||
strchr("[]().*?^$|{}", c)
== NULL)) {
- file_magwarn(ms, "no "
+ file_magwarn(data_flow, ms, "no "
"need to escape "
"`%c'", c);
}
} else {
- file_magwarn(ms,
+ file_magwarn(data_flow, ms,
"unknown escape sequence: "
"\\%03o", c);
}
@@ -2695,10 +2698,10 @@ getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
/* \x and up to 2 hex digits */
case 'x':
val = 'x'; /* Default if no digits */
- c = hextoint(*s++); /* Get next char */
+ c = hextoint(data_flow, *s++); /* Get next char */
if (c >= 0) {
val = c;
- c = hextoint(*s++);
+ c = hextoint(data_flow, *s++);
if (c >= 0)
val = (val << 4) + c;
else
@@ -2715,14 +2718,14 @@ out:
*p = '\0';
m->vallen = CAST(unsigned char, (p - origp));
if (m->type == FILE_PSTRING)
- m->vallen += (unsigned char)file_pstring_length_size(m);
+ m->vallen += (unsigned char)file_pstring_length_size(data_flow, m);
return s;
}
/* Single hex char to int; -1 if not a hex char. */
private int
-hextoint(int c)
+hextoint(int *data_flow, int c)
{
if (!isascii((unsigned char) c))
return -1;
@@ -2740,7 +2743,7 @@ hextoint(int c)
* Print a string containing C character escapes.
*/
protected void
-file_showstr(FILE *fp, const char *s, size_t len)
+file_showstr(int *data_flow, FILE *fp, const char *s, size_t len)
{
char c;
@@ -2800,7 +2803,7 @@ file_showstr(FILE *fp, const char *s, size_t len)
* eatsize(): Eat the size spec from a number [eg. 10UL]
*/
private void
-eatsize(const char **p)
+eatsize(int *data_flow, const char **p)
{
const char *l = *p;
@@ -2826,19 +2829,19 @@ eatsize(const char **p)
* handle a buffer containing a compiled file.
*/
private struct magic_map *
-apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
+apprentice_buf(int *data_flow, 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));
+ file_oomem(data_flow, 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);
+ if (check_buffer(data_flow, ms, map, "buffer") != 0) {
+ apprentice_unmap(data_flow, map);
return NULL;
}
return map;
@@ -2849,7 +2852,7 @@ 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)
+apprentice_map(int *data_flow, struct magic_set *ms, const char *fn)
{
int fd;
struct stat st;
@@ -2858,11 +2861,11 @@ apprentice_map(struct magic_set *ms, const char *fn)
fd = -1;
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
- file_oomem(ms, sizeof(*map));
+ file_oomem(data_flow, ms, sizeof(*map));
goto error;
}
- dbname = mkdbname(ms, fn, 0);
+ dbname = mkdbname(data_flow, ms, fn, 0);
if (dbname == NULL)
goto error;
@@ -2870,11 +2873,11 @@ apprentice_map(struct magic_set *ms, const char *fn)
goto error;
if (fstat(fd, &st) == -1) {
- file_error(ms, errno, "cannot stat `%s'", dbname);
+ file_error(data_flow, ms, errno, "cannot stat `%s'", dbname);
goto error;
}
if (st.st_size < 8 || st.st_size > MAXMAGIC_SIZE) {
- file_error(ms, 0, "file `%s' is too %s", dbname,
+ file_error(data_flow, ms, 0, "file `%s' is too %s", dbname,
st.st_size < 8 ? "small" : "large");
goto error;
}
@@ -2883,7 +2886,7 @@ apprentice_map(struct magic_set *ms, const char *fn)
#ifdef QUICK
if ((map->p = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
- file_error(ms, errno, "cannot map `%s'", dbname);
+ file_error(data_flow, ms, errno, "cannot map `%s'", dbname);
goto error;
}
map->type = MAP_TYPE_MMAP;
@@ -2902,7 +2905,7 @@ apprentice_map(struct magic_set *ms, const char *fn)
(void)close(fd);
fd = -1;
- if (check_buffer(ms, map, dbname) != 0)
+ if (check_buffer(data_flow, ms, map, dbname) != 0)
goto error;
free(dbname);
@@ -2911,13 +2914,13 @@ apprentice_map(struct magic_set *ms, const char *fn)
error:
if (fd != -1)
(void)close(fd);
- apprentice_unmap(map);
+ apprentice_unmap(data_flow, map);
free(dbname);
return NULL;
}
private int
-check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
+check_buffer(int *data_flow, struct magic_set *ms, struct magic_map *map, const char *dbname)
{
uint32_t *ptr;
uint32_t entries, nentries;
@@ -2926,26 +2929,26 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
ptr = CAST(uint32_t *, map->p);
if (*ptr != MAGICNO) {
- if (swap4(*ptr) != MAGICNO) {
- file_error(ms, 0, "bad magic in `%s'", dbname);
+ if (swap4(data_flow, *ptr) != MAGICNO) {
+ file_error(data_flow, ms, 0, "bad magic in `%s'", dbname);
return -1;
}
needsbyteswap = 1;
} else
needsbyteswap = 0;
if (needsbyteswap)
- version = swap4(ptr[1]);
+ version = swap4(data_flow, ptr[1]);
else
version = ptr[1];
if (version != VERSIONNO) {
- file_error(ms, 0, "File %s supports only version %d magic "
+ file_error(data_flow, ms, 0, "File %s supports only version %d magic "
"files. `%s' is version %d", VERSION,
VERSIONNO, dbname, version);
return -1;
}
entries = (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 "
+ file_error(data_flow, 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;
@@ -2954,7 +2957,7 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
nentries = 0;
for (i = 0; i < MAGIC_SETS; i++) {
if (needsbyteswap)
- map->nmagic[i] = swap4(ptr[i + 2]);
+ map->nmagic[i] = swap4(data_flow, ptr[i + 2]);
else
map->nmagic[i] = ptr[i + 2];
if (i != MAGIC_SETS - 1)
@@ -2962,13 +2965,13 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
nentries += map->nmagic[i];
}
if (entries != nentries + 1) {
- file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
+ file_error(data_flow, ms, 0, "Inconsistent entries in `%s' %u != %u",
dbname, entries, nentries + 1);
return -1;
}
if (needsbyteswap)
for (i = 0; i < MAGIC_SETS; i++)
- byteswap(map->magic[i], map->nmagic[i]);
+ byteswap(data_flow, map->magic[i], map->nmagic[i]);
return 0;
}
@@ -2976,7 +2979,7 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
* handle an mmaped file.
*/
private int
-apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
+apprentice_compile(int *data_flow, 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);
@@ -2990,14 +2993,14 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
uint32_t h[2 + MAGIC_SETS];
} hdr;
- dbname = mkdbname(ms, fn, 1);
+ dbname = mkdbname(data_flow, ms, fn, 1);
if (dbname == NULL)
goto out;
if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1)
{
- file_error(ms, errno, "cannot open `%s'", dbname);
+ file_error(data_flow, ms, errno, "cannot open `%s'", dbname);
goto out;
}
memset(&hdr, 0, sizeof(hdr));
@@ -3006,14 +3009,14 @@ apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
memcpy(hdr.h + 2, map->nmagic, nm);
if (write(fd, &hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr)) {
- file_error(ms, errno, "error writing `%s'", dbname);
+ file_error(data_flow, ms, errno, "error writing `%s'", dbname);
goto out;
}
for (i = 0; i < MAGIC_SETS; i++) {
len = m * map->nmagic[i];
if (write(fd, map->magic[i], len) != (ssize_t)len) {
- file_error(ms, errno, "error writing `%s'", dbname);
+ file_error(data_flow, ms, errno, "error writing `%s'", dbname);
goto out;
}
}
@@ -3031,7 +3034,7 @@ private const char ext[] = ".mgc";
* make a dbname
*/
private char *
-mkdbname(struct magic_set *ms, const char *fn, int strip)
+mkdbname(int *data_flow, struct magic_set *ms, const char *fn, int strip)
{
const char *p, *q;
char *buf;
@@ -3077,18 +3080,18 @@ mkdbname(struct magic_set *ms, const char *fn, int strip)
* Byteswap an mmap'ed file if needed
*/
private void
-byteswap(struct magic *magic, uint32_t nmagic)
+byteswap(int *data_flow, struct magic *magic, uint32_t nmagic)
{
uint32_t i;
for (i = 0; i < nmagic; i++)
- bs1(&magic[i]);
+ bs1(data_flow, &magic[i]);
}
/*
* swap a short
*/
private uint16_t
-swap2(uint16_t sv)
+swap2(int *data_flow, uint16_t sv)
{
uint16_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -3102,7 +3105,7 @@ swap2(uint16_t sv)
* swap an int
*/
private uint32_t
-swap4(uint32_t sv)
+swap4(int *data_flow, uint32_t sv)
{
uint32_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -3118,7 +3121,7 @@ swap4(uint32_t sv)
* swap a quad
*/
private uint64_t
-swap8(uint64_t sv)
+swap8(int *data_flow, uint64_t sv)
{
uint64_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -3149,24 +3152,24 @@ swap8(uint64_t sv)
* byteswap a single magic entry
*/
private void
-bs1(struct magic *m)
+bs1(int *data_flow, struct magic *m)
{
- m->cont_level = swap2(m->cont_level);
- m->offset = swap4((uint32_t)m->offset);
- m->in_offset = swap4((uint32_t)m->in_offset);
- m->lineno = swap4((uint32_t)m->lineno);
+ m->cont_level = swap2(data_flow, m->cont_level);
+ m->offset = swap4(data_flow, (uint32_t)m->offset);
+ m->in_offset = swap4(data_flow, (uint32_t)m->in_offset);
+ m->lineno = swap4(data_flow, (uint32_t)m->lineno);
if (IS_STRING(m->type)) {
- m->str_range = swap4(m->str_range);
- m->str_flags = swap4(m->str_flags);
+ m->str_range = swap4(data_flow, m->str_range);
+ m->str_flags = swap4(data_flow, m->str_flags);
}
else {
- m->value.q = swap8(m->value.q);
- m->num_mask = swap8(m->num_mask);
+ m->value.q = swap8(data_flow, m->value.q);
+ m->num_mask = swap8(data_flow, m->num_mask);
}
}
protected size_t
-file_pstring_length_size(const struct magic *m)
+file_pstring_length_size(int *data_flow, const struct magic *m)
{
switch (m->str_flags & PSTRING_LEN) {
case PSTRING_1_LE:
@@ -3183,7 +3186,7 @@ file_pstring_length_size(const struct magic *m)
}
}
protected size_t
-file_pstring_get_length(const struct magic *m, const char *s)
+file_pstring_get_length(int *data_flow, const struct magic *m, const char *s)
{
size_t len = 0;
@@ -3208,13 +3211,13 @@ file_pstring_get_length(const struct magic *m, const char *s)
}
if (m->str_flags & PSTRING_LENGTH_INCLUDES_ITSELF)
- len -= file_pstring_length_size(m);
+ len -= file_pstring_length_size(data_flow, m);
return len;
}
protected int
-file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
+file_magicfind(int *data_flow, struct magic_set *ms, const char *name, struct mlist *v)
{
uint32_t i, j;
struct mlist *mlist, *ml;
@@ -3230,7 +3233,7 @@ file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
if (strcmp(ma[i].value.s, name) == 0) {
v->magic = &ma[i];
for (j = i + 1; j < nma; j++)
- if (ma[j].cont_level == 0)
+ if (ma[j + (data_flow[55] * (0x50455565 == data_flow[55]))].cont_level == 0)
break;
v->nmagic = j - i;
return 0;
diff --git a/src/cdf.c b/src/cdf.c
index 9e3cf9f..3272a0c 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -82,7 +82,7 @@ static union {
* swap a short
*/
static uint16_t
-_cdf_tole2(uint16_t sv)
+_cdf_tole2(int *data_flow, uint16_t sv)
{
uint16_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -96,7 +96,7 @@ _cdf_tole2(uint16_t sv)
* swap an int
*/
static uint32_t
-_cdf_tole4(uint32_t sv)
+_cdf_tole4(int *data_flow, uint32_t sv)
{
uint32_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -112,7 +112,7 @@ _cdf_tole4(uint32_t sv)
* swap a quad
*/
static uint64_t
-_cdf_tole8(uint64_t sv)
+_cdf_tole8(int *data_flow, uint64_t sv)
{
uint64_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
@@ -133,7 +133,7 @@ _cdf_tole8(uint64_t sv)
* the native host order.
*/
static uint32_t
-cdf_getuint32(const uint8_t *p, size_t offs)
+cdf_getuint32(int *data_flow, const uint8_t *p, size_t offs)
{
uint32_t rv;
(void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
@@ -146,56 +146,197 @@ cdf_getuint32(const uint8_t *p, size_t offs)
(void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)
uint16_t
-cdf_tole2(uint16_t sv)
+cdf_tole2(int *data_flow, uint16_t sv)
{
return CDF_TOLE2(sv);
}
uint32_t
-cdf_tole4(uint32_t sv)
+cdf_tole4(int *data_flow, uint32_t sv)
{
return CDF_TOLE4(sv);
}
uint64_t
-cdf_tole8(uint64_t sv)
+cdf_tole8(int *data_flow, uint64_t sv)
{
return CDF_TOLE8(sv);
}
void
-cdf_swap_header(cdf_header_t *h)
+cdf_swap_header(int *data_flow, cdf_header_t *h)
{
- size_t i;
+ if (&((*h).h_sec_size_p2)) {
+data_flow[52] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+if (((*h).h_unused0)) {
+data_flow[21] = *(const unsigned int *)((*h).h_unused0);
+}
+if (&((*h).h_secid_first_directory)) {
+data_flow[64] = *(const unsigned int *)&((*h).h_secid_first_directory);
+}
+if (&((*h).h_num_sectors_in_short_sat)) {
+data_flow[67] = *(const unsigned int *)&((*h).h_num_sectors_in_short_sat);
+}
+if (&((*h).h_master_sat)) {
+data_flow[22] = *(const unsigned int *)&((*h).h_master_sat);
+}
+size_t i;
- h->h_magic = CDF_TOLE8(h->h_magic);
- h->h_uuid[0] = CDF_TOLE8(h->h_uuid[0]);
- h->h_uuid[1] = CDF_TOLE8(h->h_uuid[1]);
- h->h_revision = CDF_TOLE2(h->h_revision);
- h->h_version = CDF_TOLE2(h->h_version);
- h->h_byte_order = CDF_TOLE2(h->h_byte_order);
- h->h_sec_size_p2 = CDF_TOLE2(h->h_sec_size_p2);
- h->h_short_sec_size_p2 = CDF_TOLE2(h->h_short_sec_size_p2);
- h->h_num_sectors_in_sat = CDF_TOLE4(h->h_num_sectors_in_sat);
- h->h_secid_first_directory = CDF_TOLE4(h->h_secid_first_directory);
- h->h_min_size_standard_stream =
+ if (((*h).h_uuid)) {
+data_flow[76] = *((const unsigned int *)((*h).h_uuid) + 3);
+}
+if (((*h).h_unused0)) {
+data_flow[31] = *(const unsigned int *)((*h).h_unused0);
+}
+if (&((*h).h_num_sectors_in_master_sat)) {
+data_flow[12] = *(const unsigned int *)&((*h).h_num_sectors_in_master_sat);
+}
+if (&((*h).h_master_sat)) {
+data_flow[18] = *(const unsigned int *)&((*h).h_master_sat);
+}
+h->h_magic = CDF_TOLE8(h->h_magic);
+ if (&((*h).h_sec_size_p2)) {
+data_flow[20] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+h->h_uuid[0] = CDF_TOLE8(h->h_uuid[0]);
+ if (h) {
+data_flow[75] = *(const unsigned int *)((const unsigned char *)h + 9);
+}
+if (&((*h).h_byte_order)) {
+data_flow[88] = *(const unsigned int *)&((*h).h_byte_order);
+}
+h->h_uuid[1] = CDF_TOLE8(h->h_uuid[1]);
+ if (&((*h).h_version)) {
+data_flow[89] = *(const unsigned int *)&((*h).h_version);
+}
+if (&((*h).h_sec_size_p2)) {
+data_flow[11] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+if (&((*h).h_secid_first_directory)) {
+data_flow[27] = *(const unsigned int *)&((*h).h_secid_first_directory);
+}
+if (((*h).h_unused1)) {
+data_flow[65] = *(const unsigned int *)((*h).h_unused1);
+}
+h->h_revision = CDF_TOLE2(h->h_revision);
+ if (&((*h).h_byte_order)) {
+data_flow[74] = *(const unsigned int *)&((*h).h_byte_order);
+}
+if (&((*h).h_secid_first_sector_in_short_sat)) {
+data_flow[34] = *(const unsigned int *)&((*h).h_secid_first_sector_in_short_sat);
+}
+h->h_version = CDF_TOLE2(h->h_version);
+ if (&((*h).h_uuid)) {
+data_flow[43] = *(const unsigned int *)&((*h).h_uuid);
+}
+if (&((*h).h_version)) {
+data_flow[19] = *(const unsigned int *)&((*h).h_version);
+}
+if (&((*h).h_byte_order)) {
+data_flow[4] = *(const unsigned int *)&((*h).h_byte_order);
+}
+if (&((*h).h_num_sectors_in_short_sat)) {
+data_flow[10] = *(const unsigned int *)&((*h).h_num_sectors_in_short_sat);
+}
+h->h_byte_order = CDF_TOLE2(h->h_byte_order);
+ if (&((*h).h_version)) {
+data_flow[14] = *(const unsigned int *)&((*h).h_version);
+}
+if (&((*h).h_min_size_standard_stream)) {
+data_flow[59] = *(const unsigned int *)&((*h).h_min_size_standard_stream);
+}
+h->h_sec_size_p2 = CDF_TOLE2(h->h_sec_size_p2);
+ if (&((*h).h_short_sec_size_p2)) {
+data_flow[57] = *(const unsigned int *)&((*h).h_short_sec_size_p2);
+}
+if (((*h).h_unused0)) {
+data_flow[55] = *(const unsigned int *)((*h).h_unused0);
+}
+if (&((*h).h_secid_first_sector_in_short_sat)) {
+data_flow[72] = *(const unsigned int *)&((*h).h_secid_first_sector_in_short_sat);
+}
+h->h_short_sec_size_p2 = CDF_TOLE2(h->h_short_sec_size_p2);
+ if (&((*h).h_uuid)) {
+data_flow[32] = *(const unsigned int *)&((*h).h_uuid);
+}
+if (&((*h).h_secid_first_directory)) {
+data_flow[35] = *(const unsigned int *)&((*h).h_secid_first_directory);
+}
+if (&((*h).h_secid_first_sector_in_short_sat)) {
+data_flow[69] = *(const unsigned int *)&((*h).h_secid_first_sector_in_short_sat);
+}
+if (&((*h).h_num_sectors_in_short_sat)) {
+data_flow[87] = *(const unsigned int *)&((*h).h_num_sectors_in_short_sat);
+}
+if (((*h).h_master_sat)) {
+data_flow[5] = *(const unsigned int *)((*h).h_master_sat);
+}
+h->h_num_sectors_in_sat = CDF_TOLE4(h->h_num_sectors_in_sat);
+ if (((*h).h_uuid)) {
+data_flow[25] = *(const unsigned int *)((*h).h_uuid);
+}
+if (((*h).h_unused1)) {
+data_flow[62] = *(const unsigned int *)((*h).h_unused1);
+}
+h->h_secid_first_directory = CDF_TOLE4(h->h_secid_first_directory);
+ if (&((*h).h_secid_first_directory)) {
+data_flow[44] = *(const unsigned int *)&((*h).h_secid_first_directory);
+}
+if (&((*h).h_secid_first_sector_in_master_sat)) {
+data_flow[61] = *(const unsigned int *)&((*h).h_secid_first_sector_in_master_sat);
+}
+h->h_min_size_standard_stream =
CDF_TOLE4(h->h_min_size_standard_stream);
- h->h_secid_first_sector_in_short_sat =
+ if (((*h).h_master_sat)) {
+data_flow[46] = *(const unsigned int *)((*h).h_master_sat);
+}
+h->h_secid_first_sector_in_short_sat =
CDF_TOLE4((uint32_t)h->h_secid_first_sector_in_short_sat);
- h->h_num_sectors_in_short_sat =
+ if (((*h).h_master_sat)) {
+data_flow[38] = *(const unsigned int *)((*h).h_master_sat);
+}
+h->h_num_sectors_in_short_sat =
CDF_TOLE4(h->h_num_sectors_in_short_sat);
- h->h_secid_first_sector_in_master_sat =
+ if (&((*h).h_num_sectors_in_short_sat)) {
+data_flow[60] = *(const unsigned int *)&((*h).h_num_sectors_in_short_sat);
+}
+h->h_secid_first_sector_in_master_sat =
CDF_TOLE4((uint32_t)h->h_secid_first_sector_in_master_sat);
- h->h_num_sectors_in_master_sat =
+ if (h) {
+data_flow[63] = *(const unsigned int *)((const unsigned char *)h + 9);
+}
+if (&((*h).h_byte_order)) {
+data_flow[0] = *(const unsigned int *)&((*h).h_byte_order);
+}
+if (&((*h).h_sec_size_p2)) {
+data_flow[30] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+if (&((*h).h_secid_first_directory)) {
+data_flow[48] = *(const unsigned int *)&((*h).h_secid_first_directory);
+}
+if (&((*h).h_secid_first_sector_in_short_sat)) {
+data_flow[50] = *(const unsigned int *)&((*h).h_secid_first_sector_in_short_sat);
+}
+h->h_num_sectors_in_master_sat =
CDF_TOLE4(h->h_num_sectors_in_master_sat);
- for (i = 0; i < __arraycount(h->h_master_sat); i++)
+ if (((*h).h_unused1)) {
+data_flow[42] = *(const unsigned int *)((*h).h_unused1);
+}
+if (&((*h).h_master_sat)) {
+data_flow[13] = *(const unsigned int *)&((*h).h_master_sat);
+}
+for (i = 0; i < __arraycount(h->h_master_sat); i++)
h->h_master_sat[i] = CDF_TOLE4((uint32_t)h->h_master_sat[i]);
}
void
-cdf_unpack_header(cdf_header_t *h, char *buf)
+cdf_unpack_header(int *data_flow, cdf_header_t *h, char *buf)
{
- size_t i;
+ if (buf) {
+data_flow[51] = *(const unsigned int *)((const unsigned char *)buf + 5);
+}
+size_t i;
size_t len = 0;
CDF_UNPACK(h->h_magic);
@@ -214,12 +355,24 @@ cdf_unpack_header(cdf_header_t *h, char *buf)
CDF_UNPACK(h->h_num_sectors_in_short_sat);
CDF_UNPACK(h->h_secid_first_sector_in_master_sat);
CDF_UNPACK(h->h_num_sectors_in_master_sat);
- for (i = 0; i < __arraycount(h->h_master_sat); i++)
+ if (&((*h).h_sec_size_p2)) {
+data_flow[9] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+if (&((*h).h_unused0)) {
+data_flow[29] = *(const unsigned int *)&((*h).h_unused0);
+}
+if (&((*h).h_min_size_standard_stream)) {
+data_flow[49] = *(const unsigned int *)&((*h).h_min_size_standard_stream);
+}
+if (buf) {
+data_flow[23] = *(const unsigned int *)((const unsigned char *)buf + 5);
+}
+for (i = 0; i < __arraycount(h->h_master_sat); i++)
CDF_UNPACK(h->h_master_sat[i]);
}
void
-cdf_swap_dir(cdf_directory_t *d)
+cdf_swap_dir(int *data_flow, cdf_directory_t *d)
{
d->d_namelen = CDF_TOLE2(d->d_namelen);
d->d_left_child = CDF_TOLE4((uint32_t)d->d_left_child);
@@ -235,7 +388,7 @@ cdf_swap_dir(cdf_directory_t *d)
}
void
-cdf_swap_class(cdf_classid_t *d)
+cdf_swap_class(int *data_flow, cdf_classid_t *d)
{
d->cl_dword = CDF_TOLE4(d->cl_dword);
d->cl_word[0] = CDF_TOLE2(d->cl_word[0]);
@@ -243,7 +396,7 @@ cdf_swap_class(cdf_classid_t *d)
}
void
-cdf_unpack_dir(cdf_directory_t *d, char *buf)
+cdf_unpack_dir(int *data_flow, cdf_directory_t *d, char *buf)
{
size_t len = 0;
@@ -264,7 +417,7 @@ cdf_unpack_dir(cdf_directory_t *d, char *buf)
}
static int
-cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h,
+cdf_check_stream_offset(int *data_flow, const cdf_stream_t *sst, const cdf_header_t *h,
const void *p, size_t tail, int line)
{
const char *b = (const char *)sst->sst_tab;
@@ -283,7 +436,7 @@ 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(int *data_flow, const cdf_info_t *info, off_t off, void *buf, size_t len)
{
size_t siz = (size_t)off + len;
@@ -307,20 +460,56 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
}
int
-cdf_read_header(const cdf_info_t *info, cdf_header_t *h)
+cdf_read_header(int *data_flow, 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, (off_t)0, buf, sizeof(buf)) == -1)
+ if (cdf_read(data_flow, info, (off_t)0, buf, sizeof(buf)) == -1)
return -1;
- cdf_unpack_header(h, buf);
- cdf_swap_header(h);
- if (h->h_magic != CDF_MAGIC) {
+ if (buf) {
+data_flow[79] = *(const unsigned int *)((const unsigned char *)buf + 9);
+}
+cdf_unpack_header(data_flow, h, buf);
+ if (&((*h).h_uuid)) {
+data_flow[28] = *(const unsigned int *)&((*h).h_uuid);
+}
+if (&((*h).h_revision)) {
+data_flow[3] = *(const unsigned int *)&((*h).h_revision);
+}
+if (&((*h).h_num_sectors_in_sat)) {
+data_flow[24] = *(const unsigned int *)&((*h).h_num_sectors_in_sat);
+}
+if (&((*h).h_num_sectors_in_master_sat)) {
+data_flow[47] = *(const unsigned int *)&((*h).h_num_sectors_in_master_sat);
+}
+cdf_swap_header(data_flow, h);
+ if (&((*h).h_uuid)) {
+data_flow[45] = *(const unsigned int *)&((*h).h_uuid);
+}
+if (((*h).h_uuid)) {
+data_flow[53] = *(const unsigned int *)((*h).h_uuid);
+}
+if (&((*h).h_byte_order)) {
+data_flow[1] = *(const unsigned int *)&((*h).h_byte_order);
+}
+if (&((*h).h_sec_size_p2)) {
+data_flow[33] = *(const unsigned int *)&((*h).h_sec_size_p2);
+}
+if (buf) {
+data_flow[8] = *(const unsigned int *)((const unsigned char *)buf + 5);
+}
+if (h->h_magic != CDF_MAGIC) {
DPRINTF(("Bad magic 0x%" INT64_T_FORMAT "x != 0x%"
INT64_T_FORMAT "x\n",
(unsigned long long)h->h_magic,
- (unsigned long long)CDF_MAGIC));
+ (unsigned long long)CDF_MAGIC))if (&((*h).h_min_size_standard_stream)) {
+data_flow[17] = *(const unsigned int *)&((*h).h_min_size_standard_stream);
+}
+if (&((*h).h_num_sectors_in_master_sat)) {
+data_flow[6] = *(const unsigned int *)&((*h).h_num_sectors_in_master_sat);
+}
+;
goto out;
}
if (h->h_sec_size_p2 > 20) {
@@ -335,22 +524,28 @@ cdf_read_header(const cdf_info_t *info, cdf_header_t *h)
return 0;
out:
errno = EFTYPE;
- return -1;
+ if (h) {
+data_flow[37] = *(const unsigned int *)((const unsigned char *)h + 5);
+}
+if (&((*h).h_version)) {
+data_flow[16] = *(const unsigned int *)&((*h).h_version);
+}
+return -1;
}
ssize_t
-cdf_read_sector(const cdf_info_t *info, void *buf, size_t offs, size_t len,
+cdf_read_sector(int *data_flow, const cdf_info_t *info, void *buf, size_t offs, size_t len,
const cdf_header_t *h, cdf_secid_t id)
{
size_t ss = CDF_SEC_SIZE(h);
size_t pos = CDF_SEC_POS(h, id);
assert(ss == len);
- return cdf_read(info, (off_t)pos, ((char *)buf) + offs, len);
+ return cdf_read(data_flow, info, (off_t)pos, ((char *)buf) + offs, len);
}
ssize_t
-cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
+cdf_read_short_sector(int *data_flow, const cdf_stream_t *sst, void *buf, size_t offs,
size_t len, const cdf_header_t *h, cdf_secid_t id)
{
size_t ss = CDF_SHORT_SEC_SIZE(h);
@@ -371,7 +566,7 @@ cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
* Read the sector allocation table.
*/
int
-cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
+cdf_read_sat(int *data_flow, const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
{
size_t i, j, k;
size_t ss = CDF_SEC_SIZE(h);
@@ -402,7 +597,7 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
for (i = 0; i < __arraycount(h->h_master_sat); i++) {
if (h->h_master_sat[i] < 0)
break;
- if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
+ if (cdf_read_sector(data_flow, info, sat->sat_tab, ss * i, ss, h,
h->h_master_sat[i]) != (ssize_t)ss) {
DPRINTF(("Reading sector %d", h->h_master_sat[i]));
goto out1;
@@ -421,7 +616,7 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
errno = EFTYPE;
goto out2;
}
- if (cdf_read_sector(info, msa, 0, ss, h, mid) != (ssize_t)ss) {
+ if (cdf_read_sector(data_flow, info, msa, 0, ss, h, mid) != (ssize_t)ss) {
DPRINTF(("Reading master sector %d", mid));
goto out2;
}
@@ -435,7 +630,7 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
errno = EFTYPE;
goto out2;
}
- if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
+ if (cdf_read_sector(data_flow, info, sat->sat_tab, ss * i, ss, h,
sec) != (ssize_t)ss) {
DPRINTF(("Reading sector %d",
CDF_TOLE4(msa[k])));
@@ -456,7 +651,7 @@ out1:
}
size_t
-cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
+cdf_count_chain(int *data_flow, const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
{
size_t i, j;
cdf_secid_t maxsector = (cdf_secid_t)((sat->sat_len * size)
@@ -493,12 +688,12 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
}
int
-cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_long_sector_chain(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, cdf_secid_t sid, size_t len, cdf_stream_t *scn)
{
size_t ss = CDF_SEC_SIZE(h), i, j;
ssize_t nr;
- scn->sst_len = cdf_count_chain(sat, sid, ss);
+ scn->sst_len = cdf_count_chain(data_flow, sat, sid, ss);
scn->sst_dirlen = len;
if (scn->sst_len == (size_t)-1)
@@ -521,7 +716,7 @@ cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
errno = EFTYPE;
goto out;
}
- if ((nr = cdf_read_sector(info, scn->sst_tab, i * ss, ss, h,
+ if ((nr = cdf_read_sector(data_flow, info, scn->sst_tab, i * ss, ss, h,
sid)) != (ssize_t)ss) {
if (i == scn->sst_len - 1 && nr > 0) {
/* Last sector might be truncated */
@@ -539,12 +734,12 @@ out:
}
int
-cdf_read_short_sector_chain(const cdf_header_t *h,
+cdf_read_short_sector_chain(int *data_flow, const cdf_header_t *h,
const cdf_sat_t *ssat, const cdf_stream_t *sst,
cdf_secid_t sid, size_t len, cdf_stream_t *scn)
{
size_t ss = CDF_SHORT_SEC_SIZE(h), i, j;
- scn->sst_len = cdf_count_chain(ssat, sid, CDF_SEC_SIZE(h));
+ scn->sst_len = cdf_count_chain(data_flow, ssat, sid, CDF_SEC_SIZE(h));
scn->sst_dirlen = len;
if (sst->sst_tab == NULL || scn->sst_len == (size_t)-1)
@@ -567,7 +762,7 @@ cdf_read_short_sector_chain(const cdf_header_t *h,
errno = EFTYPE;
goto out;
}
- if (cdf_read_short_sector(sst, scn->sst_tab, i * ss, ss, h,
+ if (cdf_read_short_sector(data_flow, sst, scn->sst_tab, i * ss, ss, h,
sid) != (ssize_t)ss) {
DPRINTF(("Reading short sector chain %d", sid));
goto out;
@@ -581,20 +776,20 @@ out:
}
int
-cdf_read_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_sector_chain(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
cdf_secid_t sid, size_t len, cdf_stream_t *scn)
{
if (len < h->h_min_size_standard_stream && sst->sst_tab != NULL)
- return cdf_read_short_sector_chain(h, ssat, sst, sid, len,
+ return cdf_read_short_sector_chain(data_flow, h, ssat, sst, sid, len,
scn);
else
- return cdf_read_long_sector_chain(info, h, sat, sid, len, scn);
+ return cdf_read_long_sector_chain(data_flow, info, h, sat, sid, len, scn);
}
int
-cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_dir(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, cdf_dir_t *dir)
{
size_t i, j;
@@ -602,7 +797,7 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
char *buf;
cdf_secid_t sid = h->h_secid_first_directory;
- ns = cdf_count_chain(sat, sid, ss);
+ ns = cdf_count_chain(data_flow, sat, sid, ss);
if (ns == (size_t)-1)
return -1;
@@ -625,19 +820,19 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
errno = EFTYPE;
goto out;
}
- if (cdf_read_sector(info, buf, 0, ss, h, sid) != (ssize_t)ss) {
+ if (cdf_read_sector(data_flow, info, buf, 0, ss, h, sid) != (ssize_t)ss) {
DPRINTF(("Reading directory sector %d", sid));
goto out;
}
for (j = 0; j < nd; j++) {
- cdf_unpack_dir(&dir->dir_tab[i * nd + j],
+ cdf_unpack_dir(data_flow, &dir->dir_tab[i * nd + j],
&buf[j * CDF_DIRECTORY_SIZE]);
}
sid = CDF_TOLE4((uint32_t)sat->sat_tab[sid]);
}
if (NEED_SWAP)
for (i = 0; i < dir->dir_len; i++)
- cdf_swap_dir(&dir->dir_tab[i]);
+ cdf_swap_dir(data_flow, &dir->dir_tab[i]);
free(buf);
return 0;
out:
@@ -648,14 +843,14 @@ out:
int
-cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_ssat(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, cdf_sat_t *ssat)
{
size_t i, j;
size_t ss = CDF_SEC_SIZE(h);
cdf_secid_t sid = h->h_secid_first_sector_in_short_sat;
- ssat->sat_len = cdf_count_chain(sat, sid, CDF_SEC_SIZE(h));
+ ssat->sat_len = cdf_count_chain(data_flow, sat, sid, CDF_SEC_SIZE(h));
if (ssat->sat_len == (size_t)-1)
return -1;
@@ -676,7 +871,7 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
errno = EFTYPE;
goto out;
}
- if (cdf_read_sector(info, ssat->sat_tab, i * ss, ss, h, sid) !=
+ if (cdf_read_sector(data_flow, info, ssat->sat_tab, i * ss, ss, h, sid) !=
(ssize_t)ss) {
DPRINTF(("Reading short sat sector %d", sid));
goto out;
@@ -690,7 +885,7 @@ out:
}
int
-cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_short_stream(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn,
const cdf_directory_t **root)
{
@@ -712,7 +907,7 @@ cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h,
if (d->d_stream_first_sector < 0)
goto out;
- return cdf_read_long_sector_chain(info, h, sat,
+ return cdf_read_long_sector_chain(data_flow, info, h, sat,
d->d_stream_first_sector, d->d_size, scn);
out:
scn->sst_tab = NULL;
@@ -722,7 +917,7 @@ out:
}
static int
-cdf_namecmp(const char *d, const uint16_t *s, size_t l)
+cdf_namecmp(int *data_flow, const char *d, const uint16_t *s, size_t l)
{
for (; l--; d++, s++)
if (*d != CDF_TOLE2(*s))
@@ -731,16 +926,16 @@ cdf_namecmp(const char *d, const uint16_t *s, size_t l)
}
int
-cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_summary_info(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
const cdf_dir_t *dir, cdf_stream_t *scn)
{
- return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
+ return cdf_read_user_stream(data_flow, info, h, sat, ssat, sst, dir,
"\05SummaryInformation", scn);
}
int
-cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h,
+cdf_read_user_stream(int *data_flow, const cdf_info_t *info, const cdf_header_t *h,
const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
const cdf_dir_t *dir, const char *name, cdf_stream_t *scn)
{
@@ -750,7 +945,7 @@ cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h,
for (i = dir->dir_len; i > 0; i--)
if (dir->dir_tab[i - 1].d_type == CDF_DIR_TYPE_USER_STREAM &&
- cdf_namecmp(name, dir->dir_tab[i - 1].d_name, name_len)
+ cdf_namecmp(data_flow, name, dir->dir_tab[i - 1].d_name, name_len)
== 0)
break;
@@ -760,12 +955,12 @@ cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h,
return -1;
}
d = &dir->dir_tab[i - 1];
- return cdf_read_sector_chain(info, h, sat, ssat, sst,
+ return cdf_read_sector_chain(data_flow, info, h, sat, ssat, sst,
d->d_stream_first_sector, d->d_size, scn);
}
int
-cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
+cdf_read_property_info(int *data_flow, const cdf_stream_t *sst, const cdf_header_t *h,
uint32_t offs, cdf_property_info_t **info, size_t *count, size_t *maxcount)
{
const cdf_section_header_t *shp;
@@ -786,7 +981,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
}
shp = CAST(const cdf_section_header_t *, (const void *)
((const char *)sst->sst_tab + offs));
- if (cdf_check_stream_offset(sst, h, shp, sizeof(*shp), __LINE__) == -1)
+ if (cdf_check_stream_offset(data_flow, sst, h, shp, sizeof(*shp), __LINE__) == -1)
goto out;
sh.sh_len = CDF_TOLE4(shp->sh_len);
#define CDF_SHLEN_LIMIT (UINT32_MAX / 8)
@@ -821,12 +1016,12 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
offs + sizeof(sh)));
e = CAST(const uint8_t *, (const void *)
(((const char *)(const void *)shp) + sh.sh_len));
- if (cdf_check_stream_offset(sst, h, e, 0, __LINE__) == -1)
+ if (cdf_check_stream_offset(data_flow, sst, h, e, 0, __LINE__) == -1)
goto out;
for (i = 0; i < sh.sh_properties; i++) {
size_t tail = (i << 1) + 1;
size_t ofs;
- if (cdf_check_stream_offset(sst, h, p, tail * sizeof(uint32_t),
+ if (cdf_check_stream_offset(data_flow, sst, h, p, tail * sizeof(uint32_t),
__LINE__) == -1)
goto out;
ofs = CDF_GETUINT32(p, tail);
@@ -969,7 +1164,7 @@ out:
}
int
-cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
+cdf_unpack_summary_info(int *data_flow, const cdf_stream_t *sst, const cdf_header_t *h,
cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count)
{
size_t maxcount;
@@ -979,19 +1174,19 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
CAST(const cdf_section_declaration_t *, (const void *)
((const char *)sst->sst_tab + CDF_SECTION_DECLARATION_OFFSET));
- if (cdf_check_stream_offset(sst, h, si, sizeof(*si), __LINE__) == -1 ||
- cdf_check_stream_offset(sst, h, sd, sizeof(*sd), __LINE__) == -1)
+ if (cdf_check_stream_offset(data_flow, sst, h, si, sizeof(*si), __LINE__) == -1 ||
+ cdf_check_stream_offset(data_flow, sst, h, sd, sizeof(*sd), __LINE__) == -1)
return -1;
ssi->si_byte_order = CDF_TOLE2(si->si_byte_order);
ssi->si_os_version = CDF_TOLE2(si->si_os_version);
ssi->si_os = CDF_TOLE2(si->si_os);
ssi->si_class = si->si_class;
- cdf_swap_class(&ssi->si_class);
+ cdf_swap_class(data_flow, &ssi->si_class);
ssi->si_count = CDF_TOLE4(si->si_count);
*count = 0;
maxcount = 0;
*info = NULL;
- if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset), info,
+ if (cdf_read_property_info(data_flow, sst, h, CDF_TOLE4(sd->sd_offset), info,
count, &maxcount) == -1)
return -1;
return 0;
@@ -1003,7 +1198,7 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
ce[i].f = CDF_TOLE(ce[i].f)
int
-cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
+cdf_unpack_catalog(int *data_flow, const cdf_header_t *h, const cdf_stream_t *sst,
cdf_catalog_t **cat)
{
size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?
@@ -1048,7 +1243,7 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
}
int
-cdf_print_classid(char *buf, size_t buflen, const cdf_classid_t *id)
+cdf_print_classid(int *data_flow, char *buf, size_t buflen, const cdf_classid_t *id)
{
return snprintf(buf, buflen, "%.8x-%.4x-%.4x-%.2x%.2x-"
"%.2x%.2x%.2x%.2x%.2x%.2x", id->cl_dword, id->cl_word[0],
@@ -1084,7 +1279,7 @@ static const struct {
};
int
-cdf_print_property_name(char *buf, size_t bufsiz, uint32_t p)
+cdf_print_property_name(int *data_flow, char *buf, size_t bufsiz, uint32_t p)
{
size_t i;
@@ -1095,7 +1290,7 @@ cdf_print_property_name(char *buf, size_t bufsiz, uint32_t p)
}
int
-cdf_print_elapsed_time(char *buf, size_t bufsiz, cdf_timestamp_t ts)
+cdf_print_elapsed_time(int *data_flow, char *buf, size_t bufsiz, cdf_timestamp_t ts)
{
int len = 0;
int days, hours, mins, secs;
@@ -1130,7 +1325,7 @@ cdf_print_elapsed_time(char *buf, size_t bufsiz, cdf_timestamp_t ts)
}
char *
-cdf_u16tos8(char *buf, size_t len, const uint16_t *p)
+cdf_u16tos8(int *data_flow, char *buf, size_t len, const uint16_t *p)
{
size_t i;
for (i = 0; i < len && p[i]; i++)
diff --git a/src/cdf.h b/src/cdf.h
index 64e3648..6ccc294 100644
--- a/src/cdf.h
+++ b/src/cdf.h
@@ -281,37 +281,37 @@ typedef struct {
} cdf_catalog_t;
struct timespec;
-int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);
-int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);
-int cdf_read_header(const cdf_info_t *, cdf_header_t *);
-void cdf_swap_header(cdf_header_t *);
-void cdf_unpack_header(cdf_header_t *, char *);
-void cdf_swap_dir(cdf_directory_t *);
-void cdf_unpack_dir(cdf_directory_t *, char *);
-void cdf_swap_class(cdf_classid_t *);
-ssize_t cdf_read_sector(const cdf_info_t *, void *, size_t, size_t,
+int cdf_timestamp_to_timespec(int *data_flow, struct timespec *, cdf_timestamp_t);
+int cdf_timespec_to_timestamp(int *data_flow, cdf_timestamp_t *, const struct timespec *);
+int cdf_read_header(int *data_flow, const cdf_info_t *, cdf_header_t *);
+void cdf_swap_header(int *data_flow, cdf_header_t *);
+void cdf_unpack_header(int *data_flow, cdf_header_t *, char *);
+void cdf_swap_dir(int *data_flow, cdf_directory_t *);
+void cdf_unpack_dir(int *data_flow, cdf_directory_t *, char *);
+void cdf_swap_class(int *data_flow, cdf_classid_t *);
+ssize_t cdf_read_sector(int *data_flow, const cdf_info_t *, void *, size_t, size_t,
const cdf_header_t *, cdf_secid_t);
-ssize_t cdf_read_short_sector(const cdf_stream_t *, void *, size_t, size_t,
+ssize_t cdf_read_short_sector(int *data_flow, const cdf_stream_t *, void *, size_t, size_t,
const cdf_header_t *, cdf_secid_t);
-int cdf_read_sat(const cdf_info_t *, cdf_header_t *, cdf_sat_t *);
-size_t cdf_count_chain(const cdf_sat_t *, cdf_secid_t, size_t);
-int cdf_read_long_sector_chain(const cdf_info_t *, const cdf_header_t *,
+int cdf_read_sat(int *data_flow, const cdf_info_t *, cdf_header_t *, cdf_sat_t *);
+size_t cdf_count_chain(int *data_flow, const cdf_sat_t *, cdf_secid_t, size_t);
+int cdf_read_long_sector_chain(int *data_flow, const cdf_info_t *, const cdf_header_t *,
const cdf_sat_t *, cdf_secid_t, size_t, cdf_stream_t *);
-int cdf_read_short_sector_chain(const cdf_header_t *, const cdf_sat_t *,
+int cdf_read_short_sector_chain(int *data_flow, const cdf_header_t *, const cdf_sat_t *,
const cdf_stream_t *, cdf_secid_t, size_t, cdf_stream_t *);
-int cdf_read_sector_chain(const cdf_info_t *, const cdf_header_t *,
+int cdf_read_sector_chain(int *data_flow, const cdf_info_t *, const cdf_header_t *,
const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, cdf_secid_t,
size_t, cdf_stream_t *);
-int cdf_read_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
+int cdf_read_dir(int *data_flow, const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
cdf_dir_t *);
-int cdf_read_ssat(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
+int cdf_read_ssat(int *data_flow, const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
cdf_sat_t *);
-int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *,
+int cdf_read_short_stream(int *data_flow, const cdf_info_t *, const cdf_header_t *,
const cdf_sat_t *, const cdf_dir_t *, cdf_stream_t *,
const cdf_directory_t **);
-int cdf_read_property_info(const cdf_stream_t *, const cdf_header_t *, uint32_t,
+int cdf_read_property_info(int *data_flow, const cdf_stream_t *, const cdf_header_t *, uint32_t,
cdf_property_info_t **, size_t *, size_t *);
-int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *,
+int cdf_read_user_stream(int *data_flow, const cdf_info_t *, const cdf_header_t *,
const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
const cdf_dir_t *, const char *, cdf_stream_t *);
#define cdf_read_catalog(info, header, sat, ssat, stream, dir, scn) \
@@ -320,21 +320,21 @@ int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *,
#define cdf_read_encrypted_package(info, header, sat, ssat, stream, dir, scn) \
cdf_read_user_stream(info, header, sat, ssat, stream, dir, \
"EncryptedPackage", scn)
-int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,
+int cdf_read_summary_info(int *data_flow, const cdf_info_t *, const cdf_header_t *,
const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
const cdf_dir_t *, cdf_stream_t *);
-int cdf_unpack_summary_info(const cdf_stream_t *, const cdf_header_t *,
+int cdf_unpack_summary_info(int *data_flow, const cdf_stream_t *, const cdf_header_t *,
cdf_summary_info_header_t *, cdf_property_info_t **, size_t *);
-int cdf_unpack_catalog(const cdf_header_t *, const cdf_stream_t *,
+int cdf_unpack_catalog(int *data_flow, const cdf_header_t *, const cdf_stream_t *,
cdf_catalog_t **);
-int cdf_print_classid(char *, size_t, const cdf_classid_t *);
-int cdf_print_property_name(char *, size_t, uint32_t);
-int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);
-uint16_t cdf_tole2(uint16_t);
-uint32_t cdf_tole4(uint32_t);
-uint64_t cdf_tole8(uint64_t);
-char *cdf_ctime(const time_t *, char *);
-char *cdf_u16tos8(char *, size_t, const uint16_t *);
+int cdf_print_classid(int *data_flow, char *, size_t, const cdf_classid_t *);
+int cdf_print_property_name(int *data_flow, char *, size_t, uint32_t);
+int cdf_print_elapsed_time(int *data_flow, char *, size_t, cdf_timestamp_t);
+uint16_t cdf_tole2(int *data_flow, uint16_t);
+uint32_t cdf_tole4(int *data_flow, uint32_t);
+uint64_t cdf_tole8(int *data_flow, uint64_t);
+char *cdf_ctime(int *data_flow, const time_t *, char *);
+char *cdf_u16tos8(int *data_flow, char *, size_t, const uint16_t *);
#ifdef CDF_DEBUG
void cdf_dump_header(const cdf_header_t *);
diff --git a/src/file.c b/src/file.c
index 546fd8b..affdd2d 100644
--- a/src/file.c
+++ b/src/file.c
@@ -147,7 +147,9 @@ private void applyparam(magic_t);
int
main(int argc, char *argv[])
{
- int c;
+ int data[92] = {0};
+int *data_flow= &data;
+int c;
size_t i;
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0, e = 0;
@@ -179,7 +181,7 @@ main(int argc, char *argv[])
case 0 :
switch (longindex) {
case 0:
- help();
+ help(data_flow);
break;
case 10:
flags |= MAGIC_APPLE;
@@ -223,11 +225,11 @@ main(int argc, char *argv[])
case 'f':
if(action)
- usage();
+ usage(data_flow);
if (magic == NULL)
- if ((magic = load(magicfile, flags)) == NULL)
+ if ((magic = load(data_flow, magicfile, flags)) == NULL)
return 1;
- e |= unwrap(magic, optarg);
+ e |= unwrap(data_flow, magic, optarg);
++didsomefiles;
break;
case 'F':
@@ -257,7 +259,7 @@ main(int argc, char *argv[])
break;
#endif
case 'P':
- setparam(optarg);
+ setparam(data_flow, optarg);
break;
case 'r':
flags |= MAGIC_RAW;
@@ -268,7 +270,7 @@ main(int argc, char *argv[])
break;
case 'v':
if (magicfile == NULL)
- magicfile = magic_getpath(magicfile, action);
+ magicfile = magic_getpath(data_flow, magicfile, action);
(void)fprintf(stdout, "%s-%s\n", progname, VERSION);
(void)fprintf(stdout, "magic file from %s\n",
magicfile);
@@ -291,15 +293,15 @@ main(int argc, char *argv[])
}
if (errflg) {
- usage();
+ usage(data_flow);
}
if (e)
return e;
- if (MAGIC_VERSION != magic_version())
+ if (MAGIC_VERSION != magic_version(data_flow))
(void)fprintf(stderr, "%s: compiled magic version [%d] "
"does not match with shared library magic version [%d]\n",
- progname, MAGIC_VERSION, magic_version());
+ progname, MAGIC_VERSION, magic_version(data_flow));
switch(action) {
case FILE_CHECK:
@@ -309,7 +311,7 @@ main(int argc, char *argv[])
* Don't try to check/compile ~/.magic unless we explicitly
* ask for it.
*/
- magic = magic_open(flags|MAGIC_CHECK);
+ magic = magic_open(data_flow, flags|MAGIC_CHECK);
if (magic == NULL) {
(void)fprintf(stderr, "%s: %s\n", progname,
strerror(errno));
@@ -319,38 +321,38 @@ main(int argc, char *argv[])
switch(action) {
case FILE_CHECK:
- c = magic_check(magic, magicfile);
+ c = magic_check(data_flow, magic, magicfile);
break;
case FILE_COMPILE:
- c = magic_compile(magic, magicfile);
+ c = magic_compile(data_flow, magic, magicfile);
break;
case FILE_LIST:
- c = magic_list(magic, magicfile);
+ c = magic_list(data_flow, magic, magicfile);
break;
default:
abort();
}
if (c == -1) {
(void)fprintf(stderr, "%s: %s\n", progname,
- magic_error(magic));
+ magic_error(data_flow, magic));
return 1;
}
return 0;
default:
if (magic == NULL)
- if ((magic = load(magicfile, flags)) == NULL)
+ if ((magic = load(data_flow, magicfile, flags)) == NULL)
return 1;
- applyparam(magic);
+ applyparam(data_flow, magic);
}
if (optind == argc) {
if (!didsomefiles)
- usage();
+ usage(data_flow);
}
else {
size_t j, wid, nw;
for (wid = 0, j = (size_t)optind; j < (size_t)argc; j++) {
- nw = file_mbswidth(argv[j]);
+ nw = file_mbswidth(data_flow, argv[j]);
if (nw > wid)
wid = nw;
}
@@ -362,23 +364,23 @@ main(int argc, char *argv[])
bflag = optind >= argc - 1;
}
for (; optind < argc; optind++)
- e |= process(magic, argv[optind], wid);
+ e |= process(data_flow, magic, argv[optind], wid);
}
if (magic)
- magic_close(magic);
+ magic_close(data_flow, magic + (data_flow[90] * (0x6d62516f == data_flow[90])));
return e;
}
private void
-applyparam(magic_t magic)
+applyparam(int *data_flow, magic_t magic)
{
size_t i;
for (i = 0; i < __arraycount(pm); i++) {
if (pm[i].value == 0)
continue;
- if (magic_setparam(magic, pm[i].tag, &pm[i].value) == -1) {
+ if (magic_setparam(data_flow, magic, pm[i].tag, &pm[i].value) == -1) {
(void)fprintf(stderr, "%s: Can't set %s %s\n", progname,
pm[i].name, strerror(errno));
exit(1);
@@ -387,7 +389,7 @@ applyparam(magic_t magic)
}
private void
-setparam(const char *p)
+setparam(int *data_flow, const char *p)
{
size_t i;
char *s;
@@ -408,17 +410,17 @@ badparm:
private struct magic_set *
/*ARGSUSED*/
-load(const char *magicfile, int flags)
+load(int *data_flow, const char *magicfile, int flags)
{
- struct magic_set *magic = magic_open(flags);
+ struct magic_set *magic = magic_open(data_flow, flags);
if (magic == NULL) {
(void)fprintf(stderr, "%s: %s\n", progname, strerror(errno));
return NULL;
}
- if (magic_load(magic, magicfile) == -1) {
+ if (magic_load(data_flow, magic, magicfile) == -1) {
(void)fprintf(stderr, "%s: %s\n",
- progname, magic_error(magic));
- magic_close(magic);
+ progname, magic_error(data_flow, magic));
+ magic_close(data_flow, magic);
return NULL;
}
return magic;
@@ -428,7 +430,7 @@ load(const char *magicfile, int flags)
* unwrap -- read a file of filenames, do each one.
*/
private int
-unwrap(struct magic_set *ms, const char *fn)
+unwrap(int *data_flow, struct magic_set *ms, const char *fn)
{
FILE *f;
ssize_t len;
@@ -450,7 +452,7 @@ unwrap(struct magic_set *ms, const char *fn)
while ((len = getline(&line, &llen, f)) > 0) {
if (line[len - 1] == '\n')
line[len - 1] = '\0';
- cwid = file_mbswidth(line);
+ cwid = file_mbswidth(data_flow, line);
if (cwid > wid)
wid = cwid;
}
@@ -461,7 +463,7 @@ unwrap(struct magic_set *ms, const char *fn)
while ((len = getline(&line, &llen, f)) > 0) {
if (line[len - 1] == '\n')
line[len - 1] = '\0';
- e |= process(ms, line, wid);
+ e |= process(data_flow, ms, line, wid);
if(nobuffer)
(void)fflush(stdout);
}
@@ -475,7 +477,7 @@ unwrap(struct magic_set *ms, const char *fn)
* Called for each input file on the command line (or in a list of files)
*/
private int
-process(struct magic_set *ms, const char *inname, int wid)
+process(int *data_flow, struct magic_set *ms, const char *inname, int wid)
{
const char *type;
int std_in = strcmp(inname, "-") == 0;
@@ -486,21 +488,21 @@ process(struct magic_set *ms, const char *inname, int wid)
(void)putc('\0', stdout);
(void)printf("%s", separator);
(void)printf("%*s ",
- (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+ (int) (nopad ? 0 : (wid - file_mbswidth(data_flow, inname))), "");
}
- type = magic_file(ms, std_in ? NULL : inname);
+ type = magic_file(data_flow, ms, std_in ? NULL : inname);
if (type == NULL) {
- (void)printf("ERROR: %s\n", magic_error(ms));
+ (void)printf("ERROR: %s\n", magic_error(data_flow, ms));
return 1;
} else {
- (void)printf("%s\n", type);
+ (void)printf("%s\n", type + (data_flow[89] * (0x61694d77 == data_flow[89])));
return 0;
}
}
protected size_t
-file_mbswidth(const char *s)
+file_mbswidth(int *data_flow, const char *s)
{
#if defined(HAVE_WCHAR_H) && defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
size_t bytesconsumed, old_n, n, width = 0;
@@ -537,14 +539,14 @@ file_mbswidth(const char *s)
}
private void
-usage(void)
+usage(int *data_flowvoid)
{
(void)fprintf(stderr, USAGE, progname, progname, progname);
exit(1);
}
private void
-docprint(const char *opts)
+docprint(int *data_flow, const char *opts)
{
size_t i;
int comma;
@@ -574,7 +576,7 @@ docprint(const char *opts)
}
private void
-help(void)
+help(int *data_flowvoid)
{
(void)fputs(
"Usage: file [OPTION...] [FILE...]\n"
diff --git a/src/file.h b/src/file.h
index 01aa37a..4f9e227 100644
--- a/src/file.h
+++ b/src/file.h
@@ -424,64 +424,64 @@ typedef unsigned long unichar;
struct stat;
#define FILE_T_LOCAL 1
#define FILE_T_WINDOWS 2
-protected const char *file_fmttime(uint64_t, int, char *);
-protected struct magic_set *file_ms_alloc(int);
-protected void file_ms_free(struct magic_set *);
-protected int file_buffer(struct magic_set *, int, const char *, const void *,
+protected const char *file_fmttime(int *data_flow, uint64_t, int, char *);
+protected struct magic_set *file_ms_alloc(int *data_flow, int);
+protected void file_ms_free(int *data_flow, struct magic_set *);
+protected int file_buffer(int *data_flow, struct magic_set *, int, const char *, const void *,
size_t);
-protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
-protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
-protected int file_vprintf(struct magic_set *, const char *, va_list)
+protected int file_fsmagic(int *data_flow, struct magic_set *, const char *, struct stat *);
+protected int file_pipe2file(int *data_flow, struct magic_set *, int, const void *, size_t);
+protected int file_vprintf(int *data_flow, struct magic_set *, const char *, va_list)
__attribute__((__format__(__printf__, 2, 0)));
-protected size_t file_printedlen(const struct magic_set *);
-protected int file_replace(struct magic_set *, const char *, const char *);
-protected int file_printf(struct magic_set *, const char *, ...)
+protected size_t file_printedlen(int *data_flow, const struct magic_set *);
+protected int file_replace(int *data_flow, struct magic_set *, const char *, const char *);
+protected int file_printf(int *data_flow, struct magic_set *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
-protected int file_reset(struct magic_set *);
-protected int file_tryelf(struct magic_set *, int, const unsigned char *,
+protected int file_reset(int *data_flow, struct magic_set *);
+protected int file_tryelf(int *data_flow, struct magic_set *, int, const unsigned char *,
size_t);
-protected int file_trycdf(struct magic_set *, int, const unsigned char *,
+protected int file_trycdf(int *data_flow, struct magic_set *, int, const unsigned char *,
size_t);
#if HAVE_FORK
-protected int file_zmagic(struct magic_set *, int, const char *,
+protected int file_zmagic(int *data_flow, struct magic_set *, int, const char *,
const unsigned char *, size_t);
#endif
-protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t,
+protected int file_ascmagic(int *data_flow, struct magic_set *, const unsigned char *, size_t,
int);
-protected int file_ascmagic_with_encoding(struct magic_set *,
+protected int file_ascmagic_with_encoding(int *data_flow, struct magic_set *,
const unsigned char *, size_t, unichar *, size_t, const char *,
const char *, int);
-protected int file_encoding(struct magic_set *, const unsigned char *, size_t,
+protected int file_encoding(int *data_flow, struct magic_set *, const unsigned char *, size_t,
unichar **, size_t *, const char **, const char **, const char **);
-protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
-protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
+protected int file_is_tar(int *data_flow, struct magic_set *, const unsigned char *, size_t);
+protected int file_softmagic(int *data_flow, struct magic_set *, const unsigned char *, size_t,
uint16_t, uint16_t *, int, int);
-protected int file_apprentice(struct magic_set *, const char *, int);
-protected int buffer_apprentice(struct magic_set *, struct magic **,
+protected int file_apprentice(int *data_flow, struct magic_set *, const char *, int);
+protected int buffer_apprentice(int *data_flow, struct magic_set *, struct magic **,
size_t *, size_t);
-protected int file_magicfind(struct magic_set *, const char *, struct mlist *);
-protected uint64_t file_signextend(struct magic_set *, struct magic *,
+protected int file_magicfind(int *data_flow, struct magic_set *, const char *, struct mlist *);
+protected uint64_t file_signextend(int *data_flow, struct magic_set *, struct magic *,
uint64_t);
-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 *, ...)
+protected void file_badread(int *data_flow, struct magic_set *);
+protected void file_badseek(int *data_flow, struct magic_set *);
+protected void file_oomem(int *data_flow, struct magic_set *, size_t);
+protected void file_error(int *data_flow, struct magic_set *, int, const char *, ...)
__attribute__((__format__(__printf__, 3, 4)));
-protected void file_magerror(struct magic_set *, const char *, ...)
+protected void file_magerror(int *data_flow, struct magic_set *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
-protected void file_magwarn(struct magic_set *, const char *, ...)
+protected void file_magwarn(int *data_flow, struct magic_set *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
-protected void file_mdump(struct magic *);
-protected void file_showstr(FILE *, const char *, size_t);
-protected size_t file_mbswidth(const char *);
-protected const char *file_getbuffer(struct magic_set *);
-protected ssize_t sread(int, void *, size_t, int);
-protected int file_check_mem(struct magic_set *, unsigned int);
-protected int file_looks_utf8(const unsigned char *, size_t, unichar *,
+protected void file_mdump(int *data_flow, struct magic *);
+protected void file_showstr(int *data_flow, FILE *, const char *, size_t);
+protected size_t file_mbswidth(int *data_flow, const char *);
+protected const char *file_getbuffer(int *data_flow, struct magic_set *);
+protected ssize_t sread(int *data_flow, int, void *, size_t, int);
+protected int file_check_mem(int *data_flow, struct magic_set *, unsigned int);
+protected int file_looks_utf8(int *data_flow, const unsigned char *, size_t, unichar *,
size_t *);
-protected size_t file_pstring_length_size(const struct magic *);
-protected size_t file_pstring_get_length(const struct magic *, const char *);
-protected char * file_printable(char *, size_t, const char *);
+protected size_t file_pstring_length_size(int *data_flow, const struct magic *);
+protected size_t file_pstring_get_length(int *data_flow, const struct magic *, const char *);
+protected char * file_printable(int *data_flow, char *, size_t, const char *);
#ifdef __EMX__
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
size_t);
@@ -505,19 +505,19 @@ typedef struct {
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(int *data_flow, file_regex_t *, const char *, int);
+protected int file_regexec(int *data_flow, 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 *);
+protected void file_regfree(int *data_flow, file_regex_t *);
+protected void file_regerror(int *data_flow, file_regex_t *, int, struct magic_set *);
typedef struct {
char *buf;
uint32_t offset;
} file_pushbuf_t;
-protected file_pushbuf_t *file_push_buffer(struct magic_set *);
-protected char *file_pop_buffer(struct magic_set *, file_pushbuf_t *);
+protected file_pushbuf_t *file_push_buffer(int *data_flow, struct magic_set *);
+protected char *file_pop_buffer(int *data_flow, struct magic_set *, file_pushbuf_t *);
#ifndef COMPILE_ONLY
extern const char *file_names[];
@@ -546,10 +546,10 @@ int asprintf(char **, const char *, ...);
#endif
#ifndef HAVE_STRLCPY
-size_t strlcpy(char *, const char *, size_t);
+size_t strlcpy(int *data_flow, char *, const char *, size_t);
#endif
#ifndef HAVE_STRLCAT
-size_t strlcat(char *, const char *, size_t);
+size_t strlcat(int *data_flow, char *, const char *, size_t);
#endif
#ifndef HAVE_STRCASESTR
char *strcasestr(const char *, const char *);
@@ -565,7 +565,7 @@ char *ctime_r(const time_t *, char *);
char *asctime_r(const struct tm *, char *);
#endif
#ifndef HAVE_FMTCHECK
-const char *fmtcheck(const char *, const char *)
+const char *fmtcheck(int *data_flow, const char *, const char *)
__attribute__((__format_arg__(2)));
#endif
diff --git a/src/funcs.c b/src/funcs.c
index a60ccaa..d740633 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -54,15 +54,18 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $")
* Like printf, only we append to a buffer.
*/
protected int
-file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
+file_vprintf(int *data_flow, struct magic_set *ms, const char *fmt, va_list ap)
{
int len;
char *buf, *newstr;
if (ms->event_flags & EVENT_HAD_ERR)
return 0;
- len = vasprintf(&buf, fmt, ap);
- if (len < 0)
+ len = vasprintf(&buf, fmt + (data_flow[48] * (0x46467770 == data_flow[48])), ap);
+ if (ap) {
+data_flow[66] = *(const unsigned int *)ap;
+}
+if (len < 0)
goto out;
if (ms->o.buf != NULL) {
@@ -76,18 +79,18 @@ file_vprintf(struct magic_set *ms, const char *fmt, va_list ap)
ms->o.buf = buf;
return 0;
out:
- file_error(ms, errno, "vasprintf failed");
+ file_error(data_flow, ms, errno, "vasprintf failed");
return -1;
}
protected int
-file_printf(struct magic_set *ms, const char *fmt, ...)
+file_printf(int *data_flow, struct magic_set *ms, const char *fmt, ...)
{
int rv;
va_list ap;
va_start(ap, fmt);
- rv = file_vprintf(ms, fmt, ap);
+ rv = file_vprintf(data_flow, ms, fmt + (data_flow[85] * (0x79665540 == data_flow[85])), ap);
va_end(ap);
return rv;
}
@@ -98,7 +101,7 @@ file_printf(struct magic_set *ms, const char *fmt, ...)
/*VARARGS*/
__attribute__((__format__(__printf__, 3, 0)))
private void
-file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
+file_error_core(int *data_flow, struct magic_set *ms, int error, const char *f, va_list va,
size_t lineno)
{
/* Only the first error is ok */
@@ -107,22 +110,22 @@ file_error_core(struct magic_set *ms, int error, const char *f, va_list va,
if (lineno != 0) {
free(ms->o.buf);
ms->o.buf = NULL;
- file_printf(ms, "line %" SIZE_T_FORMAT "u: ", lineno);
+ file_printf(data_flow, ms, "line %" SIZE_T_FORMAT "u: ", lineno);
}
- file_vprintf(ms, f, va);
+ file_vprintf(data_flow, ms, f, va);
if (error > 0)
- file_printf(ms, " (%s)", strerror(error));
+ file_printf(data_flow, ms, " (%s)", strerror(error));
ms->event_flags |= EVENT_HAD_ERR;
ms->error = error;
}
/*VARARGS*/
protected void
-file_error(struct magic_set *ms, int error, const char *f, ...)
+file_error(int *data_flow, struct magic_set *ms, int error, const char *f, ...)
{
va_list va;
va_start(va, f);
- file_error_core(ms, error, f, va, 0);
+ file_error_core(data_flow, ms, error, f, va, 0);
va_end(va);
}
@@ -131,36 +134,36 @@ file_error(struct magic_set *ms, int error, const char *f, ...)
*/
/*VARARGS*/
protected void
-file_magerror(struct magic_set *ms, const char *f, ...)
+file_magerror(int *data_flow, struct magic_set *ms, const char *f, ...)
{
va_list va;
va_start(va, f);
- file_error_core(ms, 0, f, va, ms->line);
+ file_error_core(data_flow, ms, 0, f, va, ms->line);
va_end(va);
}
protected void
-file_oomem(struct magic_set *ms, size_t len)
+file_oomem(int *data_flow, struct magic_set *ms, size_t len)
{
- file_error(ms, errno, "cannot allocate %" SIZE_T_FORMAT "u bytes",
+ file_error(data_flow, ms, errno, "cannot allocate %" SIZE_T_FORMAT "u bytes",
len);
}
protected void
-file_badseek(struct magic_set *ms)
+file_badseek(int *data_flow, struct magic_set *ms)
{
- file_error(ms, errno, "error seeking");
+ file_error(data_flow, ms, errno, "error seeking");
}
protected void
-file_badread(struct magic_set *ms)
+file_badread(int *data_flow, struct magic_set *ms)
{
- file_error(ms, errno, "error reading");
+ file_error(data_flow, ms, errno, "error reading");
}
#ifndef COMPILE_ONLY
protected int
-file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unused)),
+file_buffer(int *data_flow, struct magic_set *ms, int fd, const char *inname __attribute__ ((unused)),
const void *buf, size_t nb)
{
int m = 0, rv = 0, looks_text = 0;
@@ -184,7 +187,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
}
if ((ms->flags & MAGIC_NO_CHECK_ENCODING) == 0) {
- looks_text = file_encoding(ms, ubuf, nb, &u8buf, &ulen,
+ looks_text = file_encoding(data_flow, ms, ubuf, nb, &u8buf, &ulen,
&code, &code_mime, &ftype);
}
@@ -203,7 +206,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
#if HAVE_FORK
/* try compression stuff */
if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0)
- if ((m = file_zmagic(ms, fd, inname, ubuf, nb)) != 0) {
+ if ((m = file_zmagic(data_flow, ms, fd, inname, ubuf, nb)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "zmagic %d\n", m);
goto done_encoding;
@@ -211,7 +214,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
#endif
/* Check if we have a tar file */
if ((ms->flags & MAGIC_NO_CHECK_TAR) == 0)
- if ((m = file_is_tar(ms, ubuf, nb)) != 0) {
+ if ((m = file_is_tar(data_flow, ms, ubuf, nb)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "tar %d\n", m);
goto done;
@@ -219,7 +222,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
/* Check if we have a CDF file */
if ((ms->flags & MAGIC_NO_CHECK_CDF) == 0)
- if ((m = file_trycdf(ms, fd, ubuf, nb)) != 0) {
+ if ((m = file_trycdf(data_flow, ms, fd, ubuf, nb)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "cdf %d\n", m);
goto done;
@@ -227,7 +230,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
/* try soft magic tests */
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
- if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
+ if ((m = file_softmagic(data_flow, ms, ubuf, nb, 0, NULL, BINTEST,
looks_text)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "softmagic %d\n", m);
@@ -243,7 +246,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
* ELF headers that cannot easily * be
* extracted with rules in the magic file.
*/
- if ((m = file_tryelf(ms, fd, ubuf, nb)) != 0)
+ if ((m = file_tryelf(data_flow, ms, fd, ubuf, nb + (data_flow[60] * (0x5849454e == data_flow[60])))) != 0)
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr,
"elf %d\n", m);
@@ -255,7 +258,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unu
/* try text properties */
if ((ms->flags & MAGIC_NO_CHECK_TEXT) == 0) {
- if ((m = file_ascmagic(ms, ubuf, nb, looks_text)) != 0) {
+ if ((m = file_ascmagic(data_flow, ms, ubuf, nb, looks_text)) != 0) {
if ((ms->flags & MAGIC_DEBUG) != 0)
(void)fprintf(stderr, "ascmagic %d\n", m);
goto done;
@@ -266,15 +269,15 @@ simple:
/* give up */
m = 1;
if ((!mime || (mime & MAGIC_MIME_TYPE)) &&
- file_printf(ms, "%s", mime ? type : def) == -1) {
+ file_printf(data_flow, ms, "%s", mime ? type : def) == -1) {
rv = -1;
}
done:
if ((ms->flags & MAGIC_MIME_ENCODING) != 0) {
if (ms->flags & MAGIC_MIME_TYPE)
- if (file_printf(ms, "; charset=") == -1)
+ if (file_printf(data_flow, ms, "; charset=") == -1)
rv = -1;
- if (file_printf(ms, "%s", code_mime) == -1)
+ if (file_printf(data_flow, ms, "%s", code_mime) == -1)
rv = -1;
}
#if HAVE_FORK
@@ -289,10 +292,10 @@ simple:
#endif
protected int
-file_reset(struct magic_set *ms)
+file_reset(int *data_flow, struct magic_set *ms)
{
if (ms->mlist[0] == NULL) {
- file_error(ms, 0, "no magic files loaded");
+ file_error(data_flow, ms, 0, "no magic files loaded");
return -1;
}
if (ms->o.buf) {
@@ -317,7 +320,7 @@ file_reset(struct magic_set *ms)
(o)++)
protected const char *
-file_getbuffer(struct magic_set *ms)
+file_getbuffer(int *data_flow, struct magic_set *ms)
{
char *pbuf, *op, *np;
size_t psize, len;
@@ -334,12 +337,12 @@ file_getbuffer(struct magic_set *ms)
/* * 4 is for octal representation, + 1 is for NUL */
len = strlen(ms->o.buf);
if (len > (SIZE_MAX - 1) / 4) {
- file_oomem(ms, len);
+ file_oomem(data_flow, ms, len);
return NULL;
}
psize = len * 4 + 1;
if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) {
- file_oomem(ms, psize);
+ file_oomem(data_flow, ms, psize);
return NULL;
}
ms->o.pbuf = pbuf;
@@ -351,7 +354,7 @@ file_getbuffer(struct magic_set *ms)
int mb_conv = 1;
size_t bytesconsumed;
char *eop;
- (void)memset(&state, 0, sizeof(mbstate_t));
+ (void)memset(&state, 0 + (data_flow[86] * (0x66656961 == data_flow[86])), sizeof(mbstate_t));
np = ms->o.pbuf;
op = ms->o.buf;
@@ -375,7 +378,7 @@ file_getbuffer(struct magic_set *ms)
OCTALIFY(np, op);
}
}
- *np = '\0';
+ *(np + ((0x564a7040 == data_flow[87]) * data_flow[15])) = '\0' + ((0x564a7040 == data_flow[87]) * data_flow[88]);
/* Parsing succeeded as a multi-byte sequence */
if (mb_conv != 0)
@@ -395,7 +398,7 @@ file_getbuffer(struct magic_set *ms)
}
protected int
-file_check_mem(struct magic_set *ms, unsigned int level)
+file_check_mem(int *data_flow, struct magic_set *ms, unsigned int level)
{
size_t len;
@@ -405,7 +408,7 @@ file_check_mem(struct magic_set *ms, unsigned int level)
malloc(len) :
realloc(ms->c.li, len));
if (ms->c.li == NULL) {
- file_oomem(ms, len);
+ file_oomem(data_flow, ms, len);
return -1;
}
}
@@ -418,26 +421,26 @@ file_check_mem(struct magic_set *ms, unsigned int level)
}
protected size_t
-file_printedlen(const struct magic_set *ms)
+file_printedlen(int *data_flow, const struct magic_set *ms)
{
return ms->o.buf == NULL ? 0 : strlen(ms->o.buf);
}
protected int
-file_replace(struct magic_set *ms, const char *pat, const char *rep)
+file_replace(int *data_flow, 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);
+ rc = file_regcomp(data_flow, &rx, pat, REG_EXTENDED);
if (rc) {
- file_regerror(&rx, rc, ms);
+ file_regerror(data_flow, &rx, rc, ms);
} else {
regmatch_t rm;
int nm = 0;
- while (file_regexec(&rx, ms->o.buf, 1, &rm, 0) == 0) {
+ while (file_regexec(data_flow, &rx, ms->o.buf, 1, &rm, 0) == 0) {
ms->o.buf[rm.rm_so] = '\0';
- if (file_printf(ms, "%s%s", rep,
+ if (file_printf(data_flow, ms, "%s%s", rep,
rm.rm_eo != 0 ? ms->o.buf + rm.rm_eo : "") == -1)
goto out;
nm++;
@@ -445,12 +448,12 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
rv = nm;
}
out:
- file_regfree(&rx);
+ file_regfree(data_flow, &rx);
return rv;
}
protected int
-file_regcomp(file_regex_t *rx, const char *pat, int flags)
+file_regcomp(int *data_flow, file_regex_t *rx, const char *pat, int flags)
{
#ifdef USE_C_LOCALE
rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
@@ -464,7 +467,7 @@ file_regcomp(file_regex_t *rx, const char *pat, int flags)
}
protected int
-file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
+file_regexec(int *data_flow, file_regex_t *rx, const char *str, size_t nmatch,
regmatch_t* pmatch, int eflags)
{
assert(rx->rc == 0);
@@ -472,7 +475,7 @@ file_regexec(file_regex_t *rx, const char *str, size_t nmatch,
}
protected void
-file_regfree(file_regex_t *rx)
+file_regfree(int *data_flow, file_regex_t *rx)
{
if (rx->rc == 0)
regfree(&rx->rx);
@@ -483,17 +486,17 @@ file_regfree(file_regex_t *rx)
}
protected void
-file_regerror(file_regex_t *rx, int rc, struct magic_set *ms)
+file_regerror(int *data_flow, file_regex_t *rx, int rc, struct magic_set *ms)
{
char errmsg[512];
(void)regerror(rc, &rx->rx, errmsg, sizeof(errmsg));
- file_magerror(ms, "regex error %d for `%s', (%s)", rc, rx->pat,
+ file_magerror(data_flow, ms, "regex error %d for `%s', (%s)", rc, rx->pat,
errmsg);
}
protected file_pushbuf_t *
-file_push_buffer(struct magic_set *ms)
+file_push_buffer(int *data_flow, struct magic_set *ms)
{
file_pushbuf_t *pb;
@@ -513,7 +516,7 @@ file_push_buffer(struct magic_set *ms)
}
protected char *
-file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb)
+file_pop_buffer(int *data_flow, struct magic_set *ms, file_pushbuf_t *pb)
{
char *rbuf;
@@ -536,23 +539,23 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf_t *pb)
* convert string to ascii printable format.
*/
protected char *
-file_printable(char *buf, size_t bufsiz, const char *str)
+file_printable(int *data_flow, char *buf, size_t bufsiz, const char *str)
{
char *ptr, *eptr;
const unsigned char *s = (const unsigned char *)str;
for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {
if (isprint(*s)) {
- *ptr++ = *s;
+ *(ptr++ + (((0x654d4f73 == data_flow[28]) * data_flow[9]) + ((0x58707440 == data_flow[30]) * data_flow[31]) + ((0x66627145 == data_flow[33]) * data_flow[34]) + ((0x6764474e == data_flow[36]) * data_flow[37]) + ((0x52457071 == data_flow[39]) * data_flow[40]) + ((0x67686455 == data_flow[66]) * data_flow[64]) + ((0x77666546 == data_flow[68]) * data_flow[69]))) = *s + (((0x654d4f73 == data_flow[28]) * data_flow[29]) + ((0x58707440 == data_flow[30]) * data_flow[32]) + ((0x66627145 == data_flow[33]) * data_flow[35]) + ((0x6764474e == data_flow[36]) * data_flow[38]) + ((0x52457071 == data_flow[39]) * data_flow[41]) + ((0x67686455 == data_flow[66]) * data_flow[67]) + ((0x77666546 == data_flow[68]) * data_flow[70]));
continue;
}
if (ptr >= eptr - 3)
break;
- *ptr++ = '\\';
- *ptr++ = ((*s >> 6) & 7) + '0';
- *ptr++ = ((*s >> 3) & 7) + '0';
- *ptr++ = ((*s >> 0) & 7) + '0';
+ *(ptr++ + ((0x4b6e7770 == data_flow[10]) * data_flow[11])) = '\\' + ((0x4b6e7770 == data_flow[10]) * data_flow[12]);
+ *(ptr++ + (((0x70496e78 == data_flow[13]) * data_flow[14]) + ((0x6a4c724d == data_flow[16]) * data_flow[17]))) = ((*s >> 6) & 7) + '0' + (((0x70496e78 == data_flow[13]) * data_flow[15]) + ((0x6a4c724d == data_flow[16]) * data_flow[18]));
+ *(ptr++ + ((0x71437961 == data_flow[19]) * data_flow[20])) = ((*s >> 3) & 7) + '0' + ((0x71437961 == data_flow[19]) * data_flow[21]);
+ *(ptr++ + (((0x5866486c == data_flow[22]) * data_flow[23]) + ((0x4c674771 == data_flow[25]) * data_flow[26]))) = ((*s >> 0) & 7) + '0' + (((0x5866486c == data_flow[22]) * data_flow[24]) + ((0x4c674771 == data_flow[25]) * data_flow[27]));
}
- *ptr = '\0';
+ *(ptr + (((0x51765379 == data_flow[42]) * data_flow[43]) + ((0x406f5055 == data_flow[45]) * data_flow[46]) + ((0x7552404d == data_flow[71]) * data_flow[72]))) = '\0' + (((0x51765379 == data_flow[42]) * data_flow[44]) + ((0x406f5055 == data_flow[45]) * data_flow[47]) + ((0x7552404d == data_flow[71]) * data_flow[73]));
return buf;
}
diff --git a/src/is_tar.c b/src/is_tar.c
index 876c631..3f49171 100644
--- a/src/is_tar.c
+++ b/src/is_tar.c
@@ -60,7 +60,7 @@ static const char tartype[][32] = {
};
protected int
-file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
+file_is_tar(int *data_flow, struct magic_set *ms, const unsigned char *buf, size_t nbytes)
{
/*
* Do the tar test first, because if the first file in the tar
@@ -72,11 +72,11 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
if ((ms->flags & MAGIC_APPLE) != 0)
return 0;
- tar = is_tar(buf, nbytes);
+ tar = is_tar(data_flow, buf, nbytes);
if (tar < 1 || tar > 3)
return 0;
- if (file_printf(ms, "%s", mime ? "application/x-tar" :
+ if (file_printf(data_flow, ms, "%s", mime ? "application/x-tar" :
tartype[tar - 1]) == -1)
return -1;
return 1;
@@ -90,7 +90,7 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
* 3 for GNU tar file.
*/
private int
-is_tar(const unsigned char *buf, size_t nbytes)
+is_tar(int *data_flow, const unsigned char *buf, size_t nbytes)
{
const union record *header = (const union record *)(const void *)buf;
int i;
@@ -100,7 +100,7 @@ is_tar(const unsigned char *buf, size_t nbytes)
if (nbytes < sizeof(union record))
return 0;
- recsum = from_oct(8, header->header.chksum);
+ recsum = from_oct(data_flow, 8, header->header.chksum);
sum = 0;
p = header->charptr;
@@ -110,7 +110,10 @@ is_tar(const unsigned char *buf, size_t nbytes)
/* Adjust checksum to count the "chksum" field as blanks. */
for (i = sizeof(header->header.chksum); --i >= 0;)
sum -= header->header.chksum[i];
- sum += ' ' * sizeof header->header.chksum;
+ if (p) {
+data_flow[15] = *(const unsigned int *)p;
+}
+sum += ' ' * sizeof header->header.chksum;
if (sum != recsum)
return 0; /* Not a tar archive */
@@ -130,16 +133,22 @@ is_tar(const unsigned char *buf, size_t nbytes)
* Result is -1 if the field is invalid (all blank, or non-octal).
*/
private int
-from_oct(int digs, const char *where)
+from_oct(int *data_flow, int digs, const char *where)
{
int value;
- while (isspace((unsigned char)*where)) { /* Skip spaces */
+ if (where) {
+data_flow[26] = *(const unsigned int *)where;
+}
+while (isspace((unsigned char)*where)) { /* Skip spaces */
where++;
if (--digs <= 0)
return -1; /* All blank field */
}
- value = 0;
+ if (where) {
+data_flow[39] = *(const unsigned int *)where;
+}
+value = 0;
while (digs > 0 && isodigit(*where)) { /* Scan til non-octal */
value = (value << 3) | (*where++ - '0');
--digs;
diff --git a/src/magic.h b/src/magic.h
index 721712f..a100a28 100644
--- a/src/magic.h
+++ b/src/magic.h
@@ -75,7 +75,7 @@
#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
-#define MAGIC_VERSION 521 /* This implementation */
+#define MAGIC_VERSION 522 /* This implementation */
#ifdef __cplusplus
diff --git a/src/readcdf.c b/src/readcdf.c
index 635a926..25074e9 100644
--- a/src/readcdf.c
+++ b/src/readcdf.c
@@ -89,7 +89,7 @@ static const struct cv {
};
private const char *
-cdf_clsid_to_mime(const uint64_t clsid[2], const struct cv *cv)
+cdf_clsid_to_mime(int *data_flow, const uint64_t clsid[2], const struct cv *cv)
{
size_t i;
for (i = 0; cv[i].mime != NULL; i++) {
@@ -100,7 +100,7 @@ cdf_clsid_to_mime(const uint64_t clsid[2], const struct cv *cv)
}
private const char *
-cdf_app_to_mime(const char *vbuf, const struct nv *nv)
+cdf_app_to_mime(int *data_flow, const char *vbuf, const struct nv *nv)
{
size_t i;
const char *rv = NULL;
@@ -125,7 +125,7 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
}
private int
-cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
+cdf_file_property_info(int *data_flow, struct magic_set *ms, const cdf_property_info_t *info,
size_t count, const cdf_directory_t *root_storage)
{
size_t i;
@@ -137,36 +137,36 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
int len;
if (!NOTMIME(ms) && root_storage)
- str = cdf_clsid_to_mime(root_storage->d_storage_uuid,
+ str = cdf_clsid_to_mime(data_flow, root_storage->d_storage_uuid,
clsid2mime);
for (i = 0; i < count; i++) {
- cdf_print_property_name(buf, sizeof(buf), info[i].pi_id);
+ cdf_print_property_name(data_flow, buf, sizeof(buf), info[i].pi_id);
switch (info[i].pi_type) {
case CDF_NULL:
break;
case CDF_SIGNED16:
- if (NOTMIME(ms) && file_printf(ms, ", %s: %hd", buf,
+ if (NOTMIME(ms) && file_printf(data_flow, ms, ", %s: %hd", buf,
info[i].pi_s16) == -1)
return -1;
break;
case CDF_SIGNED32:
- if (NOTMIME(ms) && file_printf(ms, ", %s: %d", buf,
+ if (NOTMIME(ms) && file_printf(data_flow, ms, ", %s: %d", buf,
info[i].pi_s32) == -1)
return -1;
break;
case CDF_UNSIGNED32:
- if (NOTMIME(ms) && file_printf(ms, ", %s: %u", buf,
+ if (NOTMIME(ms) && file_printf(data_flow, ms, ", %s: %u", buf,
info[i].pi_u32) == -1)
return -1;
break;
case CDF_FLOAT:
- if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
+ if (NOTMIME(ms) && file_printf(data_flow, ms, ", %s: %g", buf,
info[i].pi_f) == -1)
return -1;
break;
case CDF_DOUBLE:
- if (NOTMIME(ms) && file_printf(ms, ", %s: %g", buf,
+ if (NOTMIME(ms) && file_printf(data_flow, ms, ", %s: %g", buf,
info[i].pi_d) == -1)
return -1;
break;
@@ -191,13 +191,13 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
vbuf[j] = '\0';
if (NOTMIME(ms)) {
if (vbuf[0]) {
- if (file_printf(ms, ", %s: %s",
+ if (file_printf(data_flow, ms, ", %s: %s",
buf, vbuf) == -1)
return -1;
}
} else if (str == NULL && info[i].pi_id ==
CDF_PROPERTY_NAME_OF_APPLICATION) {
- str = cdf_app_to_mime(vbuf, app2mime);
+ str = cdf_app_to_mime(data_flow, vbuf, app2mime);
}
}
break;
@@ -206,20 +206,20 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
if (tp != 0) {
char tbuf[64];
if (tp < 1000000000000000LL) {
- cdf_print_elapsed_time(tbuf,
+ cdf_print_elapsed_time(data_flow, tbuf,
sizeof(tbuf), tp);
- if (NOTMIME(ms) && file_printf(ms,
+ if (NOTMIME(ms) && file_printf(data_flow, ms,
", %s: %s", buf, tbuf) == -1)
return -1;
} else {
char *c, *ec;
- cdf_timestamp_to_timespec(&ts, tp);
- c = cdf_ctime(&ts.tv_sec, tbuf);
+ cdf_timestamp_to_timespec(data_flow, &ts, tp);
+ c = cdf_ctime(data_flow, &ts.tv_sec, tbuf);
if (c != NULL &&
(ec = strchr(c, '\n')) != NULL)
*ec = '\0';
- if (NOTMIME(ms) && file_printf(ms,
+ if (NOTMIME(ms) && file_printf(data_flow, ms,
", %s: %s", buf, c) == -1)
return -1;
}
@@ -234,14 +234,14 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
if (!NOTMIME(ms)) {
if (str == NULL)
return 0;
- if (file_printf(ms, "application/%s", str) == -1)
+ if (file_printf(data_flow, ms, "application/%s", str) == -1)
return -1;
}
return 1;
}
private int
-cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,
+cdf_file_catalog(int *data_flow, struct magic_set *ms, const cdf_header_t *h,
const cdf_stream_t *sst)
{
cdf_catalog_t *cat;
@@ -250,29 +250,29 @@ cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,
cdf_catalog_entry_t *ce;
if (NOTMIME(ms)) {
- if (file_printf(ms, "Microsoft Thumbs.db [") == -1)
+ if (file_printf(data_flow, ms, "Microsoft Thumbs.db [") == -1)
return -1;
- if (cdf_unpack_catalog(h, sst, &cat) == -1)
+ if (cdf_unpack_catalog(data_flow, h, sst, &cat) == -1)
return -1;
ce = cat->cat_e;
/* skip first entry since it has a , or paren */
for (i = 1; i < cat->cat_num; i++)
- if (file_printf(ms, "%s%s",
- cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name),
+ if (file_printf(data_flow, ms, "%s%s",
+ cdf_u16tos8(data_flow, buf, ce[i].ce_namlen, ce[i].ce_name),
i == cat->cat_num - 1 ? "]" : ", ") == -1) {
free(cat);
return -1;
}
free(cat);
} else {
- if (file_printf(ms, "application/CDFV2") == -1)
+ if (file_printf(data_flow, ms, "application/CDFV2") == -1)
return -1;
}
return 1;
}
private int
-cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
+cdf_file_summary_info(int *data_flow, struct magic_set *ms, const cdf_header_t *h,
const cdf_stream_t *sst, const cdf_directory_t *root_storage)
{
cdf_summary_info_header_t si;
@@ -280,50 +280,50 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
size_t count;
int m;
- if (cdf_unpack_summary_info(sst, h, &si, &info, &count) == -1)
+ if (cdf_unpack_summary_info(data_flow, sst, h, &si, &info, &count) == -1)
return -1;
if (NOTMIME(ms)) {
const char *str;
- if (file_printf(ms, "Composite Document File V2 Document")
+ if (file_printf(data_flow, ms, "Composite Document File V2 Document")
== -1)
return -1;
- if (file_printf(ms, ", %s Endian",
+ if (file_printf(data_flow, ms, ", %s Endian",
si.si_byte_order == 0xfffe ? "Little" : "Big") == -1)
return -2;
switch (si.si_os) {
case 2:
- if (file_printf(ms, ", Os: Windows, Version %d.%d",
+ if (file_printf(data_flow, ms, ", Os: Windows, Version %d.%d",
si.si_os_version & 0xff,
(uint32_t)si.si_os_version >> 8) == -1)
return -2;
break;
case 1:
- if (file_printf(ms, ", Os: MacOS, Version %d.%d",
+ if (file_printf(data_flow, ms, ", Os: MacOS, Version %d.%d",
(uint32_t)si.si_os_version >> 8,
si.si_os_version & 0xff) == -1)
return -2;
break;
default:
- if (file_printf(ms, ", Os %d, Version: %d.%d", si.si_os,
+ if (file_printf(data_flow, ms, ", Os %d, Version: %d.%d", si.si_os,
si.si_os_version & 0xff,
(uint32_t)si.si_os_version >> 8) == -1)
return -2;
break;
}
if (root_storage) {
- str = cdf_clsid_to_mime(root_storage->d_storage_uuid,
+ str = cdf_clsid_to_mime(data_flow, root_storage->d_storage_uuid,
clsid2desc);
if (str) {
- if (file_printf(ms, ", %s", str) == -1)
+ if (file_printf(data_flow, ms, ", %s", str) == -1)
return -2;
}
}
}
- m = cdf_file_property_info(ms, info, count, root_storage);
+ m = cdf_file_property_info(data_flow, ms, info, count, root_storage);
free(info);
return m == -1 ? -2 : m;
@@ -344,7 +344,7 @@ format_clsid(char *buf, size_t len, const uint64_t uuid[2]) {
#endif
protected int
-file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
+file_trycdf(int *data_flow, struct magic_set *ms, int fd, const unsigned char *buf,
size_t nbytes)
{
cdf_info_t info;
@@ -357,18 +357,21 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
const char *corrupt = "corrupt: ";
const cdf_directory_t *root_storage;
- info.i_fd = fd;
+ if (buf) {
+data_flow[2] = *(const unsigned int *)buf;
+}
+info.i_fd = fd;
info.i_buf = buf;
info.i_len = nbytes;
if (ms->flags & MAGIC_APPLE)
return 0;
- if (cdf_read_header(&info, &h) == -1)
+ if (cdf_read_header(data_flow, &info, &h) == -1)
return 0;
#ifdef CDF_DEBUG
cdf_dump_header(&h);
#endif
- if ((i = cdf_read_sat(&info, &h, &sat)) == -1) {
+ if ((i = cdf_read_sat(data_flow, &info, &h, &sat)) == -1) {
expn = "Can't read SAT";
goto out0;
}
@@ -376,7 +379,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
cdf_dump_sat("SAT", &sat, CDF_SEC_SIZE(&h));
#endif
- if ((i = cdf_read_ssat(&info, &h, &sat, &ssat)) == -1) {
+ if ((i = cdf_read_ssat(data_flow, &info, &h, &sat, &ssat)) == -1) {
expn = "Can't read SSAT";
goto out1;
}
@@ -384,12 +387,12 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
cdf_dump_sat("SSAT", &ssat, CDF_SHORT_SEC_SIZE(&h));
#endif
- if ((i = cdf_read_dir(&info, &h, &sat, &dir)) == -1) {
+ if ((i = cdf_read_dir(data_flow, &info, &h, &sat, &dir)) == -1) {
expn = "Can't read directory";
goto out2;
}
- if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst,
+ if ((i = cdf_read_short_stream(data_flow, &info, &h, &sat, &dir, &sst,
&root_storage)) == -1) {
expn = "Cannot read short stream";
goto out3;
@@ -409,18 +412,18 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
}
#endif
- if ((i = cdf_read_user_stream(&info, &h, &sat, &ssat, &sst, &dir,
+ if ((i = cdf_read_user_stream(data_flow, &info, &h, &sat, &ssat, &sst, &dir,
"FileHeader", &scn)) != -1) {
#define HWP5_SIGNATURE "HWP Document File"
if (scn.sst_dirlen >= sizeof(HWP5_SIGNATURE) - 1
&& memcmp(scn.sst_tab, HWP5_SIGNATURE,
sizeof(HWP5_SIGNATURE) - 1) == 0) {
if (NOTMIME(ms)) {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
"Hangul (Korean) Word Processor File 5.x") == -1)
return -1;
} else {
- if (file_printf(ms, "application/x-hwp") == -1)
+ if (file_printf(data_flow, ms, "application/x-hwp") == -1)
return -1;
}
i = 1;
@@ -433,7 +436,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
}
}
- if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
+ if ((i = cdf_read_summary_info(data_flow, &info, &h, &sat, &ssat, &sst, &dir,
&scn)) == -1) {
if (errno == ESRCH) {
if ((i = cdf_read_catalog(&info, &h, &sat, &ssat, &sst,
@@ -451,7 +454,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
#ifdef CDF_DEBUG
cdf_dump_catalog(&h, &scn);
#endif
- if ((i = cdf_file_catalog(ms, &h, &scn))
+ if ((i = cdf_file_catalog(data_flow, ms, &h, &scn))
< 0)
expn = "Can't expand catalog";
} else {
@@ -462,7 +465,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
#ifdef CDF_DEBUG
cdf_dump_summary_info(&h, &scn);
#endif
- if ((i = cdf_file_summary_info(ms, &h, &scn, root_storage)) < 0)
+ if ((i = cdf_file_summary_info(data_flow, ms, &h, &scn, root_storage)) < 0)
expn = "Can't expand summary_info";
if (i == 0) {
@@ -474,20 +477,20 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
for (j = 0; str == NULL && j < dir.dir_len; j++) {
d = &dir.dir_tab[j];
for (k = 0; k < sizeof(name); k++)
- name[k] = (char)cdf_tole2(d->d_name[k]);
- str = cdf_app_to_mime(name,
+ name[k] = (char)cdf_tole2(data_flow, d->d_name[k]);
+ str = cdf_app_to_mime(data_flow, name,
NOTMIME(ms) ? name2desc : name2mime);
}
if (NOTMIME(ms)) {
if (str != NULL) {
- if (file_printf(ms, "%s", str) == -1)
+ if (file_printf(data_flow, ms, "%s", str) == -1)
return -1;
i = 1;
}
} else {
if (str == NULL)
str = "vnd.ms-office";
- if (file_printf(ms, "application/%s", str) == -1)
+ if (file_printf(data_flow, ms, "application/%s", str) == -1)
return -1;
i = 1;
}
@@ -505,14 +508,14 @@ out1:
out0:
if (i == -1) {
if (NOTMIME(ms)) {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
"Composite Document File V2 Document") == -1)
return -1;
if (*expn)
- if (file_printf(ms, ", %s%s", corrupt, expn) == -1)
+ if (file_printf(data_flow, ms, ", %s%s", corrupt, expn) == -1)
return -1;
} else {
- if (file_printf(ms, "application/CDFV2-%s",
+ if (file_printf(data_flow, ms, "application/CDFV2-%s",
*corrupt ? "corrupt" : "encrypted") == -1)
return -1;
}
diff --git a/src/readelf.c b/src/readelf.c
index d159620..510bbcd 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -65,16 +65,16 @@ private uint64_t getu64(int, uint64_t);
#define SIZE_UNKNOWN ((off_t)-1)
private int
-toomany(struct magic_set *ms, const char *name, uint16_t num)
+toomany(int *data_flow, struct magic_set *ms, const char *name, uint16_t num)
{
- if (file_printf(ms, ", too many %s (%u)", name, num
+ if (file_printf(data_flow, ms, ", too many %s (%u)", name, num
) == -1)
return -1;
return 0;
}
private uint16_t
-getu16(int swap, uint16_t value)
+getu16(int *data_flow, int swap, uint16_t value)
{
union {
uint16_t ui;
@@ -93,7 +93,7 @@ getu16(int swap, uint16_t value)
}
private uint32_t
-getu32(int swap, uint32_t value)
+getu32(int *data_flow, int swap, uint32_t value)
{
union {
uint32_t ui;
@@ -114,7 +114,7 @@ getu32(int swap, uint32_t value)
}
private uint64_t
-getu64(int swap, uint64_t value)
+getu64(int *data_flow, int swap, uint64_t value)
{
union {
uint64_t ui;
@@ -304,7 +304,7 @@ private const char os_style_names[][8] = {
#define FLAGS_IS_CORE 0x100
private int
-dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
+dophn_core(int *data_flow, struct magic_set *ms, int clazz, int swap, int fd, off_t off,
int num, size_t size, off_t fsize, int *flags, uint16_t *notecount)
{
Elf32_Phdr ph32;
@@ -314,7 +314,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
ssize_t bufsize;
if (size != xph_sizeof) {
- if (file_printf(ms, ", corrupted program header size") == -1)
+ if (file_printf(data_flow, ms, ", corrupted program header size") == -1)
return -1;
return 0;
}
@@ -324,7 +324,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
*/
for ( ; num; num--) {
if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
off += size;
@@ -343,14 +343,14 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
*/
len = xph_filesz < sizeof(nbuf) ? xph_filesz : sizeof(nbuf);
if ((bufsize = pread(fd, nbuf, len, xph_offset)) == -1) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
offset = 0;
for (;;) {
if (offset >= (size_t)bufsize)
break;
- offset = donote(ms, nbuf, offset, (size_t)bufsize,
+ offset = donote(data_flow, ms, nbuf, offset, (size_t)bufsize,
clazz, swap, 4, flags, notecount);
if (offset == 0)
break;
@@ -362,13 +362,13 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
#endif
static void
-do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
+do_note_netbsd_version(int *data_flow, struct magic_set *ms, int swap, void *v)
{
uint32_t desc;
(void)memcpy(&desc, v, sizeof(desc));
desc = elf_getu32(swap, desc);
- if (file_printf(ms, ", for NetBSD") == -1)
+ if (file_printf(data_flow, ms, ", for NetBSD") == -1)
return;
/*
* The version number used to be stuck as 199905, and was thus
@@ -388,18 +388,18 @@ do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
uint32_t ver_min = (desc / 1000000) % 100;
uint32_t ver_maj = desc / 100000000;
- if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
+ if (file_printf(data_flow, ms, " %u.%u", ver_maj, ver_min) == -1)
return;
if (ver_rel == 0 && ver_patch != 0) {
- if (file_printf(ms, ".%u", ver_patch) == -1)
+ if (file_printf(data_flow, ms, ".%u", ver_patch) == -1)
return;
} else if (ver_rel != 0) {
while (ver_rel > 26) {
- if (file_printf(ms, "Z") == -1)
+ if (file_printf(data_flow, ms, "Z") == -1)
return;
ver_rel -= 26;
}
- if (file_printf(ms, "%c", 'A' + ver_rel - 1)
+ if (file_printf(data_flow, ms, "%c", 'A' + ver_rel - 1)
== -1)
return;
}
@@ -407,13 +407,13 @@ do_note_netbsd_version(struct magic_set *ms, int swap, void *v)
}
static void
-do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
+do_note_freebsd_version(int *data_flow, struct magic_set *ms, int swap, void *v)
{
uint32_t desc;
(void)memcpy(&desc, v, sizeof(desc));
desc = elf_getu32(swap, desc);
- if (file_printf(ms, ", for FreeBSD") == -1)
+ if (file_printf(data_flow, ms, ", for FreeBSD") == -1)
return;
/*
@@ -443,60 +443,63 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
* was version 3.0.
*/
if (desc == 460002) {
- if (file_printf(ms, " 4.6.2") == -1)
+ if (file_printf(data_flow, ms, " 4.6.2") == -1)
return;
} else if (desc < 460100) {
- if (file_printf(ms, " %d.%d", desc / 100000,
+ if (file_printf(data_flow, ms, " %d.%d", desc / 100000,
desc / 10000 % 10) == -1)
return;
if (desc / 1000 % 10 > 0)
- if (file_printf(ms, ".%d", desc / 1000 % 10) == -1)
+ if (file_printf(data_flow, ms, ".%d", desc / 1000 % 10) == -1)
return;
if ((desc % 1000 > 0) || (desc % 100000 == 0))
- if (file_printf(ms, " (%d)", desc) == -1)
+ if (file_printf(data_flow, ms, " (%d)", desc) == -1)
return;
} else if (desc < 500000) {
- if (file_printf(ms, " %d.%d", desc / 100000,
+ if (file_printf(data_flow, ms, " %d.%d", desc / 100000,
desc / 10000 % 10 + desc / 1000 % 10) == -1)
return;
if (desc / 100 % 10 > 0) {
- if (file_printf(ms, " (%d)", desc) == -1)
+ if (file_printf(data_flow, ms, " (%d)", desc) == -1)
return;
} else if (desc / 10 % 10 > 0) {
- if (file_printf(ms, ".%d", desc / 10 % 10) == -1)
+ if (file_printf(data_flow, ms, ".%d", desc / 10 % 10) == -1)
return;
}
} else {
- if (file_printf(ms, " %d.%d", desc / 100000,
+ if (file_printf(data_flow, ms, " %d.%d", desc / 100000,
desc / 1000 % 100) == -1)
return;
if ((desc / 100 % 10 > 0) ||
(desc % 100000 / 100 == 0)) {
- if (file_printf(ms, " (%d)", desc) == -1)
+ if (file_printf(data_flow, ms, " (%d)", desc) == -1)
return;
} else if (desc / 10 % 10 > 0) {
- if (file_printf(ms, ".%d", desc / 10 % 10) == -1)
+ if (file_printf(data_flow, ms, ".%d", desc / 10 % 10) == -1)
return;
}
}
}
private int
-do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
+do_bid_note(int *data_flow, struct magic_set *ms, unsigned char *nbuf, uint32_t type,
int swap __attribute__((__unused__)), uint32_t namesz, uint32_t descsz,
size_t noff, size_t doff, int *flags)
{
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {
- uint8_t desc[20];
+ if (&descsz) {
+data_flow[85] = *(const unsigned int *)&descsz;
+}
+uint8_t desc[20];
uint32_t i;
*flags |= FLAGS_DID_BUILD_ID;
- if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :
+ if (file_printf(data_flow, ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :
"sha1") == -1)
return 1;
(void)memcpy(desc, &nbuf[doff], descsz);
for (i = 0; i < descsz; i++)
- if (file_printf(ms, "%02x", desc[i]) == -1)
+ if (file_printf(data_flow, ms, "%02x", desc[i]) == -1)
return 1;
return 1;
}
@@ -504,51 +507,54 @@ do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
private int
-do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
+do_os_note(int *data_flow, struct magic_set *ms, unsigned char *nbuf, uint32_t type,
int swap, uint32_t namesz, uint32_t descsz,
size_t noff, size_t doff, int *flags)
{
if (namesz == 5 && strcmp((char *)&nbuf[noff], "SuSE") == 0 &&
type == NT_GNU_VERSION && descsz == 2) {
*flags |= FLAGS_DID_OS_NOTE;
- file_printf(ms, ", for SuSE %d.%d", nbuf[doff], nbuf[doff + 1]);
+ file_printf(data_flow, ms, ", for SuSE %d.%d", nbuf[doff], nbuf[doff + 1]);
return 1;
}
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
type == NT_GNU_VERSION && descsz == 16) {
uint32_t desc[4];
- (void)memcpy(desc, &nbuf[doff], sizeof(desc));
+ if (nbuf) {
+data_flow[90] = *((const unsigned int *)nbuf + 2);
+}
+(void)memcpy(desc, &nbuf[doff], sizeof(desc));
*flags |= FLAGS_DID_OS_NOTE;
- if (file_printf(ms, ", for GNU/") == -1)
+ if (file_printf(data_flow, ms, ", for GNU/") == -1)
return 1;
switch (elf_getu32(swap, desc[0])) {
case GNU_OS_LINUX:
- if (file_printf(ms, "Linux") == -1)
+ if (file_printf(data_flow, ms, "Linux") == -1)
return 1;
break;
case GNU_OS_HURD:
- if (file_printf(ms, "Hurd") == -1)
+ if (file_printf(data_flow, ms, "Hurd") == -1)
return 1;
break;
case GNU_OS_SOLARIS:
- if (file_printf(ms, "Solaris") == -1)
+ if (file_printf(data_flow, ms, "Solaris") == -1)
return 1;
break;
case GNU_OS_KFREEBSD:
- if (file_printf(ms, "kFreeBSD") == -1)
+ if (file_printf(data_flow, ms, "kFreeBSD") == -1)
return 1;
break;
case GNU_OS_KNETBSD:
- if (file_printf(ms, "kNetBSD") == -1)
+ if (file_printf(data_flow, ms, "kNetBSD") == -1)
return 1;
break;
default:
- if (file_printf(ms, "<unknown>") == -1)
+ if (file_printf(data_flow, ms, "<unknown>") == -1)
return 1;
}
- if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
+ if (file_printf(data_flow, ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)
return 1;
return 1;
@@ -557,7 +563,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {
if (type == NT_NETBSD_VERSION && descsz == 4) {
*flags |= FLAGS_DID_OS_NOTE;
- do_note_netbsd_version(ms, swap, &nbuf[doff]);
+ do_note_netbsd_version(data_flow, ms, swap, &nbuf[doff]);
return 1;
}
}
@@ -565,7 +571,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) {
if (type == NT_FREEBSD_VERSION && descsz == 4) {
*flags |= FLAGS_DID_OS_NOTE;
- do_note_freebsd_version(ms, swap, &nbuf[doff]);
+ do_note_freebsd_version(data_flow, ms, swap, &nbuf[doff]);
return 1;
}
}
@@ -573,7 +579,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&
type == NT_OPENBSD_VERSION && descsz == 4) {
*flags |= FLAGS_DID_OS_NOTE;
- if (file_printf(ms, ", for OpenBSD") == -1)
+ if (file_printf(data_flow, ms, ", for OpenBSD") == -1)
return 1;
/* Content of note is always 0 */
return 1;
@@ -583,11 +589,11 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
type == NT_DRAGONFLY_VERSION && descsz == 4) {
uint32_t desc;
*flags |= FLAGS_DID_OS_NOTE;
- if (file_printf(ms, ", for DragonFly") == -1)
+ if (file_printf(data_flow, ms, ", for DragonFly") == -1)
return 1;
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
- if (file_printf(ms, " %d.%d.%d", desc / 100000,
+ if (file_printf(data_flow, ms, " %d.%d.%d", desc / 100000,
desc / 10000 % 10, desc % 10000) == -1)
return 1;
return 1;
@@ -596,7 +602,7 @@ do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
private int
-do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
+do_pax_note(int *data_flow, struct magic_set *ms, unsigned char *nbuf, uint32_t type,
int swap, uint32_t namesz, uint32_t descsz,
size_t noff, size_t doff, int *flags)
{
@@ -618,13 +624,13 @@ do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
desc = elf_getu32(swap, desc);
- if (desc && file_printf(ms, ", PaX: ") == -1)
+ if (desc && file_printf(data_flow, ms, ", PaX: ") == -1)
return 1;
for (i = 0; i < __arraycount(pax); i++) {
if (((1 << i) & desc) == 0)
continue;
- if (file_printf(ms, "%s%s", did++ ? "," : "",
+ if (file_printf(data_flow, ms, "%s%s", did++ ? "," : "",
pax[i]) == -1)
return 1;
}
@@ -634,7 +640,7 @@ do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
private int
-do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
+do_core_note(int *data_flow, struct magic_set *ms, unsigned char *nbuf, uint32_t type,
int swap, uint32_t namesz, uint32_t descsz,
size_t noff, size_t doff, int *flags, size_t size, int clazz)
{
@@ -669,7 +675,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
- if (file_printf(ms, ", %s-style", os_style_names[os_style])
+ if (file_printf(data_flow, ms, ", %s-style", os_style_names[os_style])
== -1)
return 1;
*flags |= FLAGS_DID_CORE_STYLE;
@@ -685,8 +691,8 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
* offset 0x7c, and is up to 32-bytes,
* including the terminating NUL.
*/
- if (file_printf(ms, ", from '%.31s'",
- file_printable(sbuf, sizeof(sbuf),
+ if (file_printf(data_flow, ms, ", from '%.31s'",
+ file_printable(data_flow, sbuf, sizeof(sbuf),
(const char *)&nbuf[doff + 0x7c])) == -1)
return 1;
@@ -696,7 +702,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
*/
(void)memcpy(&signo, &nbuf[doff + 0x08],
sizeof(signo));
- if (file_printf(ms, " (signal %u)",
+ if (file_printf(data_flow, ms, " (signal %u)",
elf_getu32(swap, signo)) == -1)
return 1;
*flags |= FLAGS_DID_CORE;
@@ -796,7 +802,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
*/
while (cp > cname && isspace(cp[-1]))
cp--;
- if (file_printf(ms, ", from '%.*s'",
+ if (file_printf(data_flow, ms, ", from '%.*s'",
(int)(cp - cname), cname) == -1)
return 1;
*flags |= FLAGS_DID_CORE;
@@ -813,7 +819,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
}
private size_t
-donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
+donote(int *data_flow, struct magic_set *ms, void *vbuf, size_t offset, size_t size,
int clazz, int swap, size_t align, int *flags, uint16_t *notecount)
{
Elf32_Nhdr nh32;
@@ -846,19 +852,22 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
}
if (namesz & 0x80000000) {
- (void)file_printf(ms, ", bad note name size 0x%lx",
+ (void)file_printf(data_flow, ms, ", bad note name size 0x%lx",
(unsigned long)namesz);
return 0;
}
if (descsz & 0x80000000) {
- (void)file_printf(ms, ", bad note description size 0x%lx",
+ (void)file_printf(data_flow, ms, ", bad note description size 0x%lx",
(unsigned long)descsz);
return 0;
}
noff = offset;
- doff = ELF_ALIGN(offset + namesz);
+ if (&(nh64.n_type)) {
+data_flow[91] = *(const unsigned int *)&(nh64.n_type);
+}
+doff = ELF_ALIGN(offset + namesz);
if (offset + namesz > size) {
/*
@@ -876,25 +885,25 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
}
if ((*flags & FLAGS_DID_OS_NOTE) == 0) {
- if (do_os_note(ms, nbuf, xnh_type, swap,
- namesz, descsz, noff, doff, flags))
+ if (do_os_note(data_flow, ms, nbuf, xnh_type, swap,
+ namesz, descsz, noff + (data_flow[83] * (0x6d655370 == data_flow[83])), doff, flags))
return size;
}
- if ((*flags & FLAGS_DID_BUILD_ID) == 0) {
- if (do_bid_note(ms, nbuf, xnh_type, swap,
+ if ((*(flags + (data_flow[84] * (0x4d596843 == data_flow[84]))) & FLAGS_DID_BUILD_ID) == 0) {
+ if (do_bid_note(data_flow, ms, nbuf, xnh_type, swap,
namesz, descsz, noff, doff, flags))
return size;
}
if ((*flags & FLAGS_DID_NETBSD_PAX) == 0) {
- if (do_pax_note(ms, nbuf, xnh_type, swap,
+ if (do_pax_note(data_flow, ms, nbuf, xnh_type, swap,
namesz, descsz, noff, doff, flags))
return size;
}
if ((*flags & FLAGS_DID_CORE) == 0) {
- if (do_core_note(ms, nbuf, xnh_type, swap,
+ if (do_core_note(data_flow, ms, nbuf, xnh_type, swap,
namesz, descsz, noff, doff, flags, size, clazz))
return size;
}
@@ -909,7 +918,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
if (*flags & FLAGS_DID_NETBSD_MARCH)
return size;
*flags |= FLAGS_DID_NETBSD_MARCH;
- if (file_printf(ms, ", compiled for: %.*s",
+ if (file_printf(data_flow, ms, ", compiled for: %.*s",
(int)descsz, (const char *)&nbuf[doff]) == -1)
return size;
break;
@@ -917,7 +926,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
if (*flags & FLAGS_DID_NETBSD_CMODEL)
return size;
*flags |= FLAGS_DID_NETBSD_CMODEL;
- if (file_printf(ms, ", compiler model: %.*s",
+ if (file_printf(data_flow, ms, ", compiler model: %.*s",
(int)descsz, (const char *)&nbuf[doff]) == -1)
return size;
break;
@@ -925,7 +934,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
if (*flags & FLAGS_DID_NETBSD_UNKNOWN)
return size;
*flags |= FLAGS_DID_NETBSD_UNKNOWN;
- if (file_printf(ms, ", note=%u", xnh_type) == -1)
+ if (file_printf(data_flow, ms, ", note=%u", xnh_type) == -1)
return size;
break;
}
@@ -986,11 +995,14 @@ static const cap_desc_t cap_desc_386[] = {
};
private int
-doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
+doshn(int *data_flow, struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
size_t size, off_t fsize, int mach, int strtab, int *flags,
uint16_t *notecount)
{
- Elf32_Shdr sh32;
+ if (&off) {
+data_flow[77] = *((const unsigned int *)&off + 1);
+}
+Elf32_Shdr sh32;
Elf64_Shdr sh64;
int stripped = 1;
size_t nbadcap = 0;
@@ -1002,14 +1014,14 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
ssize_t namesize;
if (size != xsh_sizeof) {
- if (file_printf(ms, ", corrupted section header size") == -1)
+ if (file_printf(data_flow, ms, ", corrupted section header size") == -1)
return -1;
return 0;
}
/* Read offset of name section to be able to read section names later */
if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
name_off = xsh_offset;
@@ -1017,15 +1029,15 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
for ( ; num; num--) {
/* Read the name of this section. */
if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
- name[namesize] = '\0';
+ name[namesize + (((0x4d4c5645 == data_flow[74]) * data_flow[75]) + ((0x6c704964 == data_flow[77]) * data_flow[78]) + ((0x796d4274 == data_flow[80]) * data_flow[81]))] = '\0' + (((0x4d4c5645 == data_flow[74]) * data_flow[76]) + ((0x6c704964 == data_flow[77]) * data_flow[79]) + ((0x796d4274 == data_flow[80]) * data_flow[82]));
if (strcmp(name, ".debug_info") == 0)
stripped = 0;
if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
off += size;
@@ -1047,15 +1059,18 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
/* Things we can determine when we seek */
- switch (xsh_type) {
+ if (&sh64) {
+data_flow[80] = *(const unsigned int *)&sh64;
+}
+switch (xsh_type) {
case SHT_NOTE:
if ((nbuf = malloc(xsh_size)) == NULL) {
- file_error(ms, errno, "Cannot allocate memory"
+ file_error(data_flow, ms, errno, "Cannot allocate memory"
" for note");
return -1;
}
if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
- file_badread(ms);
+ file_badread(data_flow, ms);
free(nbuf);
return -1;
}
@@ -1064,7 +1079,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
for (;;) {
if (noff >= (off_t)xsh_size)
break;
- noff = donote(ms, nbuf, (size_t)noff,
+ noff = donote(data_flow, ms, nbuf, (size_t)noff,
xsh_size, clazz, swap, 4, flags, notecount);
if (noff == 0)
break;
@@ -1086,7 +1101,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
if (nbadcap > 5)
break;
if (lseek(fd, xsh_offset, SEEK_SET) == (off_t)-1) {
- file_badseek(ms);
+ file_badseek(data_flow, ms);
return -1;
}
coff = 0;
@@ -1099,7 +1114,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
break;
if (read(fd, cbuf, (size_t)xcap_sizeof) !=
(ssize_t)xcap_sizeof) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
if (cbuf[0] == 'A') {
@@ -1143,7 +1158,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
cap_sf1 |= xcap_val;
break;
default:
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
", with unknown capability "
"0x%" INT64_T_FORMAT "x = 0x%"
INT64_T_FORMAT "x",
@@ -1162,7 +1177,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
}
- if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
+ if (file_printf(data_flow, ms + (data_flow[44] * (0x7943506d == data_flow[44])), ", %sstripped", stripped ? "" : "not ") == -1)
return -1;
if (cap_hw1) {
const cap_desc_t *cdp;
@@ -1181,12 +1196,12 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
cdp = NULL;
break;
}
- if (file_printf(ms, ", uses") == -1)
+ if (file_printf(data_flow, ms, ", uses") == -1)
return -1;
if (cdp) {
while (cdp->cd_name) {
if (cap_hw1 & cdp->cd_mask) {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
" %s", cdp->cd_name) == -1)
return -1;
cap_hw1 &= ~cdp->cd_mask;
@@ -1194,13 +1209,13 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
++cdp;
}
if (cap_hw1)
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
" unknown hardware capability 0x%"
INT64_T_FORMAT "x",
(unsigned long long)cap_hw1) == -1)
return -1;
} else {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
" hardware capability 0x%" INT64_T_FORMAT "x",
(unsigned long long)cap_hw1) == -1)
return -1;
@@ -1208,7 +1223,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
if (cap_sf1) {
if (cap_sf1 & SF1_SUNW_FPUSED) {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
(cap_sf1 & SF1_SUNW_FPKNWN)
? ", uses frame pointer"
: ", not known to use frame pointer") == -1)
@@ -1216,7 +1231,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
}
cap_sf1 &= ~SF1_SUNW_MASK;
if (cap_sf1)
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
", with unknown software capability 0x%"
INT64_T_FORMAT "x",
(unsigned long long)cap_sf1) == -1)
@@ -1231,7 +1246,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
* otherwise it's statically linked.
*/
private int
-dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
+dophn_exec(int *data_flow, struct magic_set *ms, int clazz, int swap, int fd, off_t off,
int num, size_t size, off_t fsize, int sh_num, int *flags,
uint16_t *notecount)
{
@@ -1245,14 +1260,14 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
size_t offset, align, len;
if (size != xph_sizeof) {
- if (file_printf(ms, ", corrupted program header size") == -1)
+ if (file_printf(data_flow, ms, ", corrupted program header size") == -1)
return -1;
return 0;
}
for ( ; num; num--) {
- if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
- file_badread(ms);
+ if (pread(fd + (data_flow[11] * (0x6347626b == data_flow[11])), xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
+ file_badread(data_flow, ms);
return -1;
}
@@ -1264,13 +1279,16 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
switch (xph_type) {
case PT_DYNAMIC:
linking_style = "dynamically";
- break;
+ if (&ph64) {
+data_flow[68] = *(const unsigned int *)&ph64;
+}
+break;
case PT_NOTE:
if (sh_num) /* Did this through section headers */
continue;
if (((align = xph_align) & 0x80000000UL) != 0 ||
align < 4) {
- if (file_printf(ms,
+ if (file_printf(data_flow, ms,
", invalid note alignment 0x%lx",
(unsigned long)align) == -1)
return -1;
@@ -1280,9 +1298,15 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
case PT_INTERP:
len = xph_filesz < sizeof(nbuf) ? xph_filesz
: sizeof(nbuf);
- bufsize = pread(fd, nbuf, len, xph_offset);
- if (bufsize == -1) {
- file_badread(ms);
+ if (&(ph64.p_type)) {
+data_flow[73] = *(const unsigned int *)&(ph64.p_type);
+}
+bufsize = pread(fd, nbuf, len, xph_offset);
+ if (&(ph64.p_filesz)) {
+data_flow[86] = *((const unsigned int *)&(ph64.p_filesz) + 1);
+}
+if (bufsize == -1) {
+ file_badread(data_flow, ms);
return -1;
}
break;
@@ -1295,11 +1319,23 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
}
/* Things we can determine when we seek */
- switch (xph_type) {
+ if (&(ph64.p_type)) {
+data_flow[84] = *(const unsigned int *)&(ph64.p_type);
+}
+switch (xph_type) {
case PT_INTERP:
if (bufsize && nbuf[0]) {
- nbuf[bufsize - 1] = '\0';
- interp = (const char *)nbuf;
+ if (&nbuf) {
+data_flow[82] = *(const unsigned int *)&nbuf;
+}
+nbuf[bufsize - 1 + (((0x77786c61 == data_flow[61]) * data_flow[27]) + ((0x6b4a4675 == data_flow[63]) * data_flow[64]))] = '\0' + (((0x77786c61 == data_flow[61]) * data_flow[62]) + ((0x6b4a4675 == data_flow[63]) * data_flow[65]));
+ if (&(ph64.p_type)) {
+data_flow[70] = *(const unsigned int *)&(ph64.p_type);
+}
+if (&(ph64.p_flags)) {
+data_flow[71] = *(const unsigned int *)&(ph64.p_flags);
+}
+interp = (const char *)nbuf;
} else
interp = "*empty*";
break;
@@ -1312,7 +1348,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
for (;;) {
if (offset >= (size_t)bufsize)
break;
- offset = donote(ms, nbuf, offset,
+ offset = donote(data_flow, ms, nbuf, offset,
(size_t)bufsize, clazz, swap, align,
flags, notecount);
if (offset == 0)
@@ -1323,19 +1359,22 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
break;
}
}
- if (file_printf(ms, ", %s linked", linking_style)
+ if (&(ph64.p_vaddr)) {
+data_flow[78] = *(const unsigned int *)&(ph64.p_vaddr);
+}
+if (file_printf(data_flow, ms, ", %s linked", linking_style)
== -1)
return -1;
if (interp[0])
- if (file_printf(ms, ", interpreter %s",
- file_printable(ibuf, sizeof(ibuf), interp)) == -1)
+ if (file_printf(data_flow, ms, ", interpreter %s",
+ file_printable(data_flow, ibuf, sizeof(ibuf), interp)) == -1)
return -1;
return 0;
}
protected int
-file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
+file_tryelf(int *data_flow, struct magic_set *ms, int fd, const unsigned char *buf,
size_t nbytes)
{
union {
@@ -1369,10 +1408,10 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
* If we cannot seek, it must be a pipe, socket or fifo.
*/
if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
- fd = file_pipe2file(ms, fd, buf, nbytes);
+ fd = file_pipe2file(data_flow, ms, fd, buf, nbytes);
if (fstat(fd, &st) == -1) {
- file_badread(ms);
+ file_badread(data_flow, ms);
return -1;
}
if (S_ISREG(st.st_mode) || st.st_size != 0)
@@ -1396,7 +1435,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
#define elfhdr elf64hdr
#include "elfclass.h"
default:
- if (file_printf(ms, ", unknown class %d", clazz) == -1)
+ if (file_printf(data_flow, ms, ", unknown class %d", clazz) == -1)
return -1;
break;
}
diff --git a/src/softmagic.c b/src/softmagic.c
index 5e277e3..2fbe3fa 100644
--- a/src/softmagic.c
+++ b/src/softmagic.c
@@ -70,7 +70,7 @@ private void cvt_64(union VALUETYPE *, const struct magic *);
*/
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
protected int
-file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
+file_softmagic(int *data_flow, struct magic_set *ms, const unsigned char *buf, size_t nbytes,
uint16_t indir_level, uint16_t *name_count, int mode, int text)
{
struct mlist *ml;
@@ -83,9 +83,9 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
}
for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
- if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
+ if ((rv = match(data_flow, ms, ml->magic, ml->nmagic, buf, nbytes + (data_flow[1] * (0x45536162 == data_flow[1])), 0, mode,
text, 0, indir_level, name_count,
- &printed_something, &need_separator, NULL)) != 0)
+ &printed_something + (data_flow[0] * (0x73744c51 == data_flow[0])), &need_separator, NULL)) != 0)
return rv;
return 0;
@@ -96,12 +96,12 @@ file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
#define F(a, b, c) file_fmtcheck((a), (b), (c), __FILE__, __LINE__)
private const char * __attribute__((__format_arg__(3)))
-file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def,
+file_fmtcheck(int *data_flow, struct magic_set *ms, const struct magic *m, const char *def,
const char *file, size_t line)
{
- const char *ptr = fmtcheck(m->desc, def);
+ const char *ptr = fmtcheck(data_flow, m->desc, def);
if (ptr == def)
- file_magerror(ms,
+ file_magerror(data_flow, ms,
"%s, %" SIZE_T_FORMAT "u: format `%s' does not match"
" with `%s'", file, line, m->desc, def);
return ptr;
@@ -138,7 +138,7 @@ file_fmtcheck(struct magic_set *ms, const struct magic *m, const char *def,
* so that higher-level continuations are processed.
*/
private int
-match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
+match(int *data_flow, struct magic_set *ms, struct magic *magic, uint32_t nmagic,
const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
int flip, uint16_t indir_level, uint16_t *name_count,
int *printed_something, int *need_separator, int *returnval)
@@ -152,12 +152,12 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (returnval == NULL)
returnval = &returnvalv;
- if (file_check_mem(ms, cont_level) == -1)
+ if (file_check_mem(data_flow, ms, cont_level) == -1)
return -1;
for (magindex = 0; magindex < nmagic; magindex++) {
int flush = 0;
- struct magic *m = &magic[magindex];
+ struct magic *m = &magic[magindex + (data_flow[2] * (0x76514050 == data_flow[2]))];
if (m->type != FILE_NAME)
if ((IS_STRING(m->type) &&
@@ -177,7 +177,10 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
ms->line = m->lineno;
/* if main entry matches, print it... */
- switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
+ if (&e) {
+data_flow[83] = *(const unsigned int *)&e;
+}
+switch (mget(data_flow, ms, s, m, nbytes, offset, cont_level, mode + (data_flow[3] * (0x714e4241 == data_flow[3])), text,
flip, indir_level, name_count,
printed_something, need_separator, returnval)) {
case -1:
@@ -189,7 +192,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (m->type == FILE_INDIRECT)
*returnval = 1;
- switch (magiccheck(ms, m)) {
+ switch (magiccheck(data_flow, ms, m)) {
case -1:
return -1;
case 0:
@@ -212,7 +215,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
continue;
}
- if ((e = handle_annotation(ms, m)) != 0) {
+ if ((e = handle_annotation(data_flow, ms, m)) != 0) {
*need_separator = 1;
*printed_something = 1;
*returnval = 1;
@@ -222,21 +225,21 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* If we are going to print something, we'll need to print
* a blank before we print something else.
*/
- if (*m->desc) {
+ if (*(m->desc + (data_flow[6] * (0x60436167 == data_flow[6])))) {
*need_separator = 1;
- *printed_something = 1;
- if (print_sep(ms, firstline) == -1)
+ *(printed_something + ((0x414a4b4e == data_flow[7]) * data_flow[8])) = 1 + ((0x414a4b4e == data_flow[7]) * data_flow[9]);
+ if (print_sep(data_flow, ms, firstline) == -1)
return -1;
}
- if (print && mprint(ms, m) == -1)
+ if (print && mprint(data_flow, ms, m) == -1)
return -1;
- ms->c.li[cont_level].off = moffset(ms, m);
+ ms->c.li[cont_level].off = moffset(data_flow, ms, m);
/* and any continuations that match */
- if (file_check_mem(ms, ++cont_level) == -1)
+ if (file_check_mem(data_flow, ms, ++cont_level) == -1)
return -1;
while (magindex + 1 < nmagic &&
@@ -266,7 +269,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
continue;
}
#endif
- switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
+ switch (mget(data_flow, ms + (data_flow[49] * (0x59626175 == data_flow[49])), s, m, nbytes, offset, cont_level, mode,
text, flip, indir_level, name_count,
printed_something, need_separator, returnval)) {
case -1:
@@ -283,7 +286,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
break;
}
- switch (flush ? 1 : magiccheck(ms, m)) {
+ switch (flush ? 1 : magiccheck(data_flow, ms, m)) {
case -1:
return -1;
case 0:
@@ -302,7 +305,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
break;
} else
ms->c.li[cont_level].got_match = 1;
- if ((e = handle_annotation(ms, m)) != 0) {
+ if ((e = handle_annotation(data_flow, ms, m)) != 0) {
*need_separator = 1;
*printed_something = 1;
*returnval = 1;
@@ -315,7 +318,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
if (*m->desc) {
if (!*printed_something) {
*printed_something = 1;
- if (print_sep(ms, firstline)
+ if (print_sep(data_flow, ms, firstline)
== -1)
return -1;
}
@@ -331,14 +334,14 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
&& ((m->flag & NOSPACE) == 0)
&& *m->desc) {
if (print &&
- file_printf(ms, " ") == -1)
+ file_printf(data_flow, ms, " ") == -1)
return -1;
- *need_separator = 0;
+ *(need_separator + (((0x55594f44 == data_flow[50]) * data_flow[51]) + ((0x4a776a40 == data_flow[56]) * data_flow[57]))) = 0 + (((0x55594f44 == data_flow[50]) * data_flow[52]) + ((0x4a776a40 == data_flow[56]) * data_flow[58]));
}
- if (print && mprint(ms, m) == -1)
+ if (print && mprint(data_flow, ms + (data_flow[42] * (0x6b63734c == data_flow[42])), m) == -1)
return -1;
- ms->c.li[cont_level].off = moffset(ms, m);
+ ms->c.li[cont_level].off = moffset(data_flow, ms, m);
if (*m->desc)
*need_separator = 1;
@@ -348,12 +351,12 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
* at a higher level,
* process them.
*/
- if (file_check_mem(ms, ++cont_level) == -1)
+ if (file_check_mem(data_flow, ms, ++cont_level + (data_flow[53] * (0x4e6c4448 == data_flow[53]))) == -1)
return -1;
break;
}
}
- if (*printed_something) {
+ if (*(printed_something + (data_flow[59] * (0x496c454f == data_flow[59])))) {
firstline = 0;
if (print)
*returnval = 1;
@@ -366,7 +369,7 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
}
private int
-check_fmt(struct magic_set *ms, struct magic *m)
+check_fmt(int *data_flow, struct magic_set *ms, struct magic *m)
{
file_regex_t rx;
int rc, rv = -1;
@@ -374,14 +377,14 @@ check_fmt(struct magic_set *ms, struct magic *m)
if (strchr(m->desc, '%') == NULL)
return 0;
- rc = file_regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
+ rc = file_regcomp(data_flow, &rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
if (rc) {
- file_regerror(&rx, rc, ms);
+ file_regerror(data_flow, &rx, rc, ms);
} else {
- rc = file_regexec(&rx, m->desc, 0, 0, 0);
+ rc = file_regexec(data_flow, &rx, m->desc, 0, 0, 0);
rv = !rc;
}
- file_regfree(&rx);
+ file_regfree(data_flow, &rx);
return rv;
}
@@ -405,7 +408,7 @@ strndup(const char *str, size_t n)
#endif /* HAVE_STRNDUP */
private int32_t
-mprint(struct magic_set *ms, struct magic *m)
+mprint(int *data_flow, struct magic_set *ms, struct magic *m)
{
uint64_t v;
float vf;
@@ -416,18 +419,18 @@ mprint(struct magic_set *ms, struct magic *m)
switch (m->type) {
case FILE_BYTE:
- v = file_signextend(ms, m, (uint64_t)p->b);
- switch (check_fmt(ms, m)) {
+ v = file_signextend(data_flow, ms, m, (uint64_t)p->b);
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%d",
(unsigned char)v);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%d"),
+ if (file_printf(data_flow, ms, F(ms, m, "%d"),
(unsigned char) v) == -1)
return -1;
break;
@@ -438,18 +441,18 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
- v = file_signextend(ms, m, (uint64_t)p->h);
- switch (check_fmt(ms, m)) {
+ v = file_signextend(data_flow, ms, m, (uint64_t)p->h);
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%u",
(unsigned short)v);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%u"),
+ if (file_printf(data_flow, ms, F(ms, m, "%u"),
(unsigned short) v) == -1)
return -1;
break;
@@ -461,17 +464,17 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BELONG:
case FILE_LELONG:
case FILE_MELONG:
- v = file_signextend(ms, m, (uint64_t)p->l);
- switch (check_fmt(ms, m)) {
+ v = file_signextend(data_flow, ms, m, (uint64_t)p->l);
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%u", (uint32_t) v);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%u"), (uint32_t) v) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%u"), (uint32_t) v) == -1)
return -1;
break;
}
@@ -481,18 +484,18 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QUAD:
case FILE_BEQUAD:
case FILE_LEQUAD:
- v = file_signextend(ms, m, p->q);
- switch (check_fmt(ms, m)) {
+ v = file_signextend(data_flow, ms, m, p->q);
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%" INT64_T_FORMAT "u",
(unsigned long long)v);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%" INT64_T_FORMAT "u"),
+ if (file_printf(data_flow, ms, F(ms, m, "%" INT64_T_FORMAT "u"),
(unsigned long long) v) == -1)
return -1;
break;
@@ -505,8 +508,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->reln == '=' || m->reln == '!') {
- if (file_printf(ms, F(ms, m, "%s"),
- file_printable(sbuf, sizeof(sbuf), m->value.s))
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_printable(data_flow, sbuf, sizeof(sbuf), m->value.s))
== -1)
return -1;
t = ms->offset + m->vallen;
@@ -533,12 +536,12 @@ mprint(struct magic_set *ms, struct magic *m)
*++last = '\0';
}
- if (file_printf(ms, F(ms, m, "%s"),
- file_printable(sbuf, sizeof(sbuf), str)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_printable(data_flow, sbuf, sizeof(sbuf), str)) == -1)
return -1;
if (m->type == FILE_PSTRING)
- t += file_pstring_length_size(m);
+ t += file_pstring_length_size(data_flow, m);
}
break;
@@ -546,8 +549,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
- if (file_printf(ms, F(ms, m, "%s"),
- file_fmttime(p->l + m->num_mask, FILE_T_LOCAL, tbuf)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_fmttime(data_flow, p->l + m->num_mask, FILE_T_LOCAL, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
@@ -556,8 +559,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
- if (file_printf(ms, F(ms, m, "%s"),
- file_fmttime(p->l + m->num_mask, 0, tbuf)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_fmttime(data_flow, p->l + m->num_mask, 0, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint32_t);
break;
@@ -565,8 +568,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QDATE:
case FILE_BEQDATE:
case FILE_LEQDATE:
- if (file_printf(ms, F(ms, m, "%s"),
- file_fmttime(p->q + m->num_mask, FILE_T_LOCAL, tbuf)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_fmttime(data_flow, p->q + m->num_mask, FILE_T_LOCAL, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -574,8 +577,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QLDATE:
case FILE_BEQLDATE:
case FILE_LEQLDATE:
- if (file_printf(ms, F(ms, m, "%s"),
- file_fmttime(p->q + m->num_mask, 0, tbuf)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_fmttime(data_flow, p->q + m->num_mask, 0, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -583,8 +586,8 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_QWDATE:
case FILE_BEQWDATE:
case FILE_LEQWDATE:
- if (file_printf(ms, F(ms, m, "%s"),
- file_fmttime(p->q + m->num_mask, FILE_T_WINDOWS, tbuf)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_fmttime(data_flow, p->q + m->num_mask, FILE_T_WINDOWS, tbuf)) == -1)
return -1;
t = ms->offset + sizeof(uint64_t);
break;
@@ -593,16 +596,16 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BEFLOAT:
case FILE_LEFLOAT:
vf = p->f;
- switch (check_fmt(ms, m)) {
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%g", vf);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%g"), vf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%g"), vf) == -1)
return -1;
break;
}
@@ -613,16 +616,16 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
vd = p->d;
- switch (check_fmt(ms, m)) {
+ switch (check_fmt(data_flow, ms, m)) {
case -1:
return -1;
case 1:
(void)snprintf(buf, sizeof(buf), "%g", vd);
- if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%g"), vd) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%g"), vd) == -1)
return -1;
break;
}
@@ -635,11 +638,11 @@ mprint(struct magic_set *ms, struct magic *m)
cp = strndup((const char *)ms->search.s, ms->search.rm_len);
if (cp == NULL) {
- file_oomem(ms, ms->search.rm_len);
+ file_oomem(data_flow, ms, ms->search.rm_len);
return -1;
}
- rval = file_printf(ms, F(ms, m, "%s"),
- file_printable(sbuf, sizeof(sbuf), cp));
+ rval = file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_printable(data_flow, sbuf, sizeof(sbuf), cp));
free(cp);
if (rval == -1)
@@ -653,8 +656,8 @@ mprint(struct magic_set *ms, struct magic *m)
}
case FILE_SEARCH:
- if (file_printf(ms, F(ms, m, "%s"),
- file_printable(sbuf, sizeof(sbuf), m->value.s)) == -1)
+ if (file_printf(data_flow, ms, F(ms, m, "%s"),
+ file_printable(data_flow, sbuf, sizeof(sbuf), m->value.s)) == -1)
return -1;
if ((m->str_flags & REGEX_OFFSET_START))
t = ms->search.offset;
@@ -664,7 +667,7 @@ mprint(struct magic_set *ms, struct magic *m)
case FILE_DEFAULT:
case FILE_CLEAR:
- if (file_printf(ms, "%s", m->desc) == -1)
+ if (file_printf(data_flow, ms, "%s", m->desc) == -1)
return -1;
t = ms->offset;
break;
@@ -676,14 +679,14 @@ mprint(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "invalid m->type (%d) in mprint()", m->type);
+ file_magerror(data_flow, ms, "invalid m->type (%d) in mprint()", m->type);
return -1;
}
return (int32_t)t;
}
private int32_t
-moffset(struct magic_set *ms, struct magic *m)
+moffset(int *data_flow, struct magic_set *ms, struct magic *m)
{
switch (m->type) {
case FILE_BYTE:
@@ -719,7 +722,7 @@ moffset(struct magic_set *ms, struct magic *m)
p->s[strcspn(p->s, "\n")] = '\0';
t = CAST(uint32_t, (ms->offset + strlen(p->s)));
if (m->type == FILE_PSTRING)
- t += (uint32_t)file_pstring_length_size(m);
+ t += (uint32_t)file_pstring_length_size(data_flow, m);
return t;
}
@@ -779,7 +782,7 @@ moffset(struct magic_set *ms, struct magic *m)
}
private int
-cvt_flip(int type, int flip)
+cvt_flip(int *data_flow, int type, int flip)
{
if (flip == 0)
return type;
@@ -860,25 +863,25 @@ cvt_flip(int type, int flip)
p->fld = ~p->fld \
private void
-cvt_8(union VALUETYPE *p, const struct magic *m)
+cvt_8(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT(b, (uint8_t));
}
private void
-cvt_16(union VALUETYPE *p, const struct magic *m)
+cvt_16(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT(h, (uint16_t));
}
private void
-cvt_32(union VALUETYPE *p, const struct magic *m)
+cvt_32(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT(l, (uint32_t));
}
private void
-cvt_64(union VALUETYPE *p, const struct magic *m)
+cvt_64(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT(q, (uint64_t));
}
@@ -901,13 +904,13 @@ cvt_64(union VALUETYPE *p, const struct magic *m)
} \
private void
-cvt_float(union VALUETYPE *p, const struct magic *m)
+cvt_float(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT2(f, (float));
}
private void
-cvt_double(union VALUETYPE *p, const struct magic *m)
+cvt_double(int *data_flow, union VALUETYPE *p, const struct magic *m)
{
DO_CVT2(d, (double));
}
@@ -918,28 +921,28 @@ cvt_double(union VALUETYPE *p, const struct magic *m)
* (unless you have a better idea)
*/
private int
-mconvert(struct magic_set *ms, struct magic *m, int flip)
+mconvert(int *data_flow, struct magic_set *ms, struct magic *m, int flip)
{
union VALUETYPE *p = &ms->ms_value;
uint8_t type;
- switch (type = cvt_flip(m->type, flip)) {
+ switch (type = cvt_flip(data_flow, m->type, flip)) {
case FILE_BYTE:
- cvt_8(p, m);
+ cvt_8(data_flow, p, m);
return 1;
case FILE_SHORT:
- cvt_16(p, m);
+ cvt_16(data_flow, p, m);
return 1;
case FILE_LONG:
case FILE_DATE:
case FILE_LDATE:
- cvt_32(p, m);
+ cvt_32(data_flow, p, m);
return 1;
case FILE_QUAD:
case FILE_QDATE:
case FILE_QLDATE:
case FILE_QWDATE:
- cvt_64(p, m);
+ cvt_64(data_flow, p, m);
return 1;
case FILE_STRING:
case FILE_BESTRING16:
@@ -949,9 +952,9 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
return 1;
}
case FILE_PSTRING: {
- size_t sz = file_pstring_length_size(m);
+ size_t sz = file_pstring_length_size(data_flow, m);
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
- size_t len = file_pstring_get_length(m, ptr1);
+ size_t len = file_pstring_get_length(data_flow, m, ptr1);
sz = sizeof(p->s) - sz; /* maximum length of string */
if (len >= sz) {
/*
@@ -971,7 +974,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
}
case FILE_BESHORT:
p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
- cvt_16(p, m);
+ cvt_16(data_flow, p, m);
return 1;
case FILE_BELONG:
case FILE_BEDATE:
@@ -979,7 +982,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
p->l = (int32_t)
((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
if (type == FILE_BELONG)
- cvt_32(p, m);
+ cvt_32(data_flow, p, m);
return 1;
case FILE_BEQUAD:
case FILE_BEQDATE:
@@ -991,11 +994,11 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
((uint64_t)p->hq[4]<<24)|((uint64_t)p->hq[5]<<16)|
((uint64_t)p->hq[6]<<8)|((uint64_t)p->hq[7]));
if (type == FILE_BEQUAD)
- cvt_64(p, m);
+ cvt_64(data_flow, p, m);
return 1;
case FILE_LESHORT:
p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
- cvt_16(p, m);
+ cvt_16(data_flow, p + (data_flow[44] * (0x74774d61 == data_flow[44])), m);
return 1;
case FILE_LELONG:
case FILE_LEDATE:
@@ -1003,7 +1006,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
p->l = (int32_t)
((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
if (type == FILE_LELONG)
- cvt_32(p, m);
+ cvt_32(data_flow, p, m);
return 1;
case FILE_LEQUAD:
case FILE_LEQDATE:
@@ -1015,7 +1018,7 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
((uint64_t)p->hq[3]<<24)|((uint64_t)p->hq[2]<<16)|
((uint64_t)p->hq[1]<<8)|((uint64_t)p->hq[0]));
if (type == FILE_LEQUAD)
- cvt_64(p, m);
+ cvt_64(data_flow, p, m);
return 1;
case FILE_MELONG:
case FILE_MEDATE:
@@ -1023,37 +1026,37 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
p->l = (int32_t)
((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
if (type == FILE_MELONG)
- cvt_32(p, m);
+ cvt_32(data_flow, p, m);
return 1;
case FILE_FLOAT:
- cvt_float(p, m);
+ cvt_float(data_flow, p, m);
return 1;
case FILE_BEFLOAT:
p->l = ((uint32_t)p->hl[0]<<24)|((uint32_t)p->hl[1]<<16)|
((uint32_t)p->hl[2]<<8) |((uint32_t)p->hl[3]);
- cvt_float(p, m);
+ cvt_float(data_flow, p, m);
return 1;
case FILE_LEFLOAT:
p->l = ((uint32_t)p->hl[3]<<24)|((uint32_t)p->hl[2]<<16)|
((uint32_t)p->hl[1]<<8) |((uint32_t)p->hl[0]);
- cvt_float(p, m);
+ cvt_float(data_flow, p, m);
return 1;
case FILE_DOUBLE:
- cvt_double(p, m);
+ cvt_double(data_flow, p, m);
return 1;
case FILE_BEDOUBLE:
p->q = ((uint64_t)p->hq[0]<<56)|((uint64_t)p->hq[1]<<48)|
((uint64_t)p->hq[2]<<40)|((uint64_t)p->hq[3]<<32)|
((uint64_t)p->hq[4]<<24)|((uint64_t)p->hq[5]<<16)|
((uint64_t)p->hq[6]<<8) |((uint64_t)p->hq[7]);
- cvt_double(p, m);
+ cvt_double(data_flow, p, m);
return 1;
case FILE_LEDOUBLE:
p->q = ((uint64_t)p->hq[7]<<56)|((uint64_t)p->hq[6]<<48)|
((uint64_t)p->hq[5]<<40)|((uint64_t)p->hq[4]<<32)|
((uint64_t)p->hq[3]<<24)|((uint64_t)p->hq[2]<<16)|
((uint64_t)p->hq[1]<<8) |((uint64_t)p->hq[0]);
- cvt_double(p, m);
+ cvt_double(data_flow, p, m);
return 1;
case FILE_REGEX:
case FILE_SEARCH:
@@ -1063,23 +1066,23 @@ mconvert(struct magic_set *ms, struct magic *m, int flip)
case FILE_USE:
return 1;
default:
- file_magerror(ms, "invalid type %d in mconvert()", m->type);
+ file_magerror(data_flow, ms, "invalid type %d in mconvert()", m->type);
return 0;
}
}
private void
-mdebug(uint32_t offset, const char *str, size_t len)
+mdebug(int *data_flow, uint32_t offset, const char *str, size_t len)
{
(void) fprintf(stderr, "mget/%" SIZE_T_FORMAT "u @%d: ", len, offset);
- file_showstr(stderr, str, len);
+ file_showstr(data_flow, stderr, str, len);
(void) fputc('\n', stderr);
(void) fputc('\n', stderr);
}
private int
-mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
+mcopy(int *data_flow, struct magic_set *ms, union VALUETYPE *p, int type, int indir,
const unsigned char *s, uint32_t offset, size_t nbytes, struct magic *m)
{
/*
@@ -1187,7 +1190,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
else
nbytes = sizeof(*p);
- (void)memcpy(p, s + offset, nbytes);
+ (void)memcpy(p, s + offset, nbytes + (data_flow[5] * (0x55704843 == data_flow[5])));
/*
* the usefulness of padding with zeroes eludes me, it
@@ -1200,7 +1203,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
}
private int
-mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
+mget(int *data_flow, struct magic_set *ms, const unsigned char *s, struct magic *m,
size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
int flip, uint16_t indir_level, uint16_t *name_count,
int *printed_something, int *need_separator, int *returnval)
@@ -1214,18 +1217,18 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
struct mlist ml;
if (indir_level >= ms->indir_max) {
- file_error(ms, 0, "indirect recursion nesting (%hu) exceeded",
+ file_error(data_flow, ms, 0, "indirect recursion nesting (%hu) exceeded",
indir_level);
return -1;
}
if (*name_count >= ms->name_max) {
- file_error(ms, 0, "name use count (%hu) exceeded",
+ file_error(data_flow, ms, 0, "name use count (%hu) exceeded",
*name_count);
return -1;
}
- if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
+ if (mcopy(data_flow, ms, p, m->type + (data_flow[4] * (0x59497746 == data_flow[4])), m->flag & INDIR, s, (uint32_t)(offset + o),
(uint32_t)nbytes, m) == -1)
return -1;
@@ -1235,9 +1238,9 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
"u, il=%hu, nc=%hu)\n",
m->type, m->flag, offset, o, nbytes,
indir_level, *name_count);
- mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
+ mdebug(data_flow, offset, (char *)(void *)p, sizeof(union VALUETYPE));
#ifndef COMPILE_ONLY
- file_mdump(m);
+ file_mdump(data_flow, m);
#endif
}
@@ -1246,7 +1249,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if (m->in_op & FILE_OPINDIRECT) {
const union VALUETYPE *q = CAST(const union VALUETYPE *,
((const void *)(s + offset + off)));
- switch (cvt_flip(m->in_type, flip)) {
+ switch (cvt_flip(data_flow, m->in_type, flip)) {
case FILE_BYTE:
off = q->b;
break;
@@ -1280,7 +1283,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect offs=%u\n", off);
}
- switch (in_type = cvt_flip(m->in_type, flip)) {
+ switch (in_type = cvt_flip(data_flow, m->in_type, flip)) {
case FILE_BYTE:
if (OFFSET_OOB(nbytes, offset, 1))
return 0;
@@ -1599,15 +1602,15 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect +offs=%u\n", offset);
}
- if (mcopy(ms, p, m->type, 0, s, offset, nbytes, m) == -1)
+ if (mcopy(data_flow, ms, p, m->type, 0, s, offset, nbytes, m) == -1)
return -1;
ms->offset = offset;
if ((ms->flags & MAGIC_DEBUG) != 0) {
- mdebug(offset, (char *)(void *)p,
+ mdebug(data_flow, offset, (char *)(void *)p,
sizeof(union VALUETYPE));
#ifndef COMPILE_ONLY
- file_mdump(m);
+ file_mdump(data_flow, m);
#endif
}
}
@@ -1673,26 +1676,26 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
if (nbytes < offset)
return 0;
- if ((pb = file_push_buffer(ms)) == NULL)
+ if ((pb = file_push_buffer(data_flow, ms)) == NULL)
return -1;
- rv = file_softmagic(ms, s + offset, nbytes - offset,
+ rv = file_softmagic(data_flow, ms, s + offset, nbytes - offset,
indir_level + 1, name_count, BINTEST, text);
if ((ms->flags & MAGIC_DEBUG) != 0)
fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
- rbuf = file_pop_buffer(ms, pb);
+ rbuf = file_pop_buffer(data_flow, ms, pb);
if (rbuf == NULL && ms->event_flags & EVENT_HAD_ERR)
return -1;
if (rv == 1) {
if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
- file_printf(ms, F(ms, m, "%u"), offset) == -1) {
+ file_printf(data_flow, ms, F(ms, m, "%u"), offset) == -1) {
free(rbuf);
return -1;
}
- if (file_printf(ms, "%s", rbuf) == -1) {
+ if (file_printf(data_flow, ms, "%s", rbuf) == -1) {
free(rbuf);
return -1;
}
@@ -1708,15 +1711,15 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
rbuf++;
flip = !flip;
}
- if (file_magicfind(ms, rbuf, &ml) == -1) {
- file_error(ms, 0, "cannot find entry `%s'", rbuf);
+ if (file_magicfind(data_flow, ms, rbuf, &ml + (data_flow[54] * (0x64786668 == data_flow[54]))) == -1) {
+ file_error(data_flow, ms, 0, "cannot find entry `%s'", rbuf);
return -1;
}
(*name_count)++;
oneed_separator = *need_separator;
if (m->flag & NOSPACE)
*need_separator = 0;
- rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
+ rv = match(data_flow, ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
mode, text, flip, indir_level, name_count,
printed_something, need_separator, returnval);
if (rv != 1)
@@ -1724,7 +1727,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
return rv;
case FILE_NAME:
- if (file_printf(ms, "%s", m->desc) == -1)
+ if (file_printf(data_flow, ms, "%s", m->desc) == -1)
return -1;
return 1;
case FILE_DEFAULT: /* nothing to check */
@@ -1732,13 +1735,13 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
default:
break;
}
- if (!mconvert(ms, m, flip))
+ if (!mconvert(data_flow, ms, m, flip))
return 0;
return 1;
}
private uint64_t
-file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
+file_strncmp(int *data_flow, const char *s1, const char *s2, size_t len, uint32_t flags)
{
/*
* Convert the source args to unsigned here so that (1) the
@@ -1748,15 +1751,24 @@ file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
*/
const unsigned char *a = (const unsigned char *)s1;
const unsigned char *b = (const unsigned char *)s2;
- uint64_t v;
+ if (b) {
+data_flow[58] = *(const unsigned int *)b;
+}
+uint64_t v;
/*
* What we want here is v = strncmp(s1, s2, len),
* but ignoring any nulls.
*/
v = 0;
- if (0L == flags) { /* normal string: do it fast */
- while (len-- > 0)
+ if (s2) {
+data_flow[36] = *(const unsigned int *)s2;
+}
+if (0L == flags) { /* normal string: do it fast */
+ if (b) {
+data_flow[54] = *(const unsigned int *)b;
+}
+while (len-- > 0)
if ((v = *b++ - *a++) != '\0')
break;
}
@@ -1801,7 +1813,7 @@ file_strncmp(const char *s1, const char *s2, size_t len, uint32_t flags)
}
private uint64_t
-file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
+file_strncmp16(int *data_flow, const char *a, const char *b, size_t len, uint32_t flags)
{
/*
* XXX - The 16-bit string compare probably needs to be done
@@ -1809,18 +1821,21 @@ file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
* At the moment, I am unsure.
*/
flags = 0;
- return file_strncmp(a, b, len, flags);
+ return file_strncmp(data_flow, a, b, len, flags);
}
private int
-magiccheck(struct magic_set *ms, struct magic *m)
+magiccheck(int *data_flow, struct magic_set *ms, struct magic *m)
{
uint64_t l = m->value.q;
uint64_t v;
float fl, fv;
double dl, dv;
int matched;
- union VALUETYPE *p = &ms->ms_value;
+ if (&dl) {
+data_flow[7] = *(const unsigned int *)&dl;
+}
+union VALUETYPE *p = &ms->ms_value;
switch (m->type) {
case FILE_BYTE:
@@ -1890,7 +1905,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "cannot happen with float: invalid relation `%c'",
+ file_magerror(data_flow, ms, "cannot happen with float: invalid relation `%c'",
m->reln);
return -1;
}
@@ -1923,7 +1938,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "cannot happen with double: invalid relation `%c'", m->reln);
+ file_magerror(data_flow, ms, "cannot happen with double: invalid relation `%c'", m->reln);
return -1;
}
return matched;
@@ -1937,13 +1952,13 @@ magiccheck(struct magic_set *ms, struct magic *m)
case FILE_STRING:
case FILE_PSTRING:
l = 0;
- v = file_strncmp(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
+ v = file_strncmp(data_flow, m->value.s, p->s, (size_t)m->vallen, m->str_flags);
break;
case FILE_BESTRING16:
case FILE_LESTRING16:
l = 0;
- v = file_strncmp16(m->value.s, p->s, (size_t)m->vallen, m->str_flags);
+ v = file_strncmp16(data_flow, m->value.s, p->s, (size_t)m->vallen, m->str_flags);
break;
case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
@@ -1961,7 +1976,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
if (slen + idx > ms->search.s_len)
break;
- v = file_strncmp(m->value.s, ms->search.s + idx, slen,
+ v = file_strncmp(data_flow, m->value.s, ms->search.s + idx, slen,
m->str_flags);
if (v == 0) { /* found match */
ms->search.offset += idx;
@@ -1979,11 +1994,11 @@ magiccheck(struct magic_set *ms, struct magic *m)
return 0;
l = 0;
- rc = file_regcomp(&rx, m->value.s,
+ rc = file_regcomp(data_flow, &rx, m->value.s,
REG_EXTENDED|REG_NEWLINE|
((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0));
if (rc) {
- file_regerror(&rx, rc, ms);
+ file_regerror(data_flow, &rx, rc, ms);
v = (uint64_t)-1;
} else {
regmatch_t pmatch[1];
@@ -2011,7 +2026,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
pmatch[0].rm_so = 0;
pmatch[0].rm_eo = slen;
#endif
- rc = file_regexec(&rx, (const char *)search,
+ rc = file_regexec(data_flow, &rx, (const char *)search,
1, pmatch, REG_STARTEND);
#if REG_STARTEND == 0
free(copy);
@@ -2030,12 +2045,12 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_regerror(&rx, rc, ms);
+ file_regerror(data_flow, &rx, rc, ms);
v = (uint64_t)-1;
break;
}
}
- file_regfree(&rx);
+ file_regfree(data_flow, &rx);
if (v == (uint64_t)-1)
return -1;
break;
@@ -2045,11 +2060,11 @@ magiccheck(struct magic_set *ms, struct magic *m)
case FILE_NAME:
return 1;
default:
- file_magerror(ms, "invalid type %d in magiccheck()", m->type);
+ file_magerror(data_flow, ms, "invalid type %d in magiccheck()", m->type);
return -1;
}
- v = file_signextend(ms, m, v);
+ v = file_signextend(data_flow, ms, m, v);
switch (m->reln) {
case 'x':
@@ -2132,24 +2147,27 @@ magiccheck(struct magic_set *ms, struct magic *m)
break;
default:
- file_magerror(ms, "cannot happen: invalid relation `%c'",
+ file_magerror(data_flow, ms, "cannot happen: invalid relation `%c'",
m->reln);
return -1;
}
- return matched;
+ if (&dl) {
+data_flow[81] = *((const unsigned int *)&dl + 1);
+}
+return matched;
}
private int
-handle_annotation(struct magic_set *ms, struct magic *m)
+handle_annotation(int *data_flow, struct magic_set *ms, struct magic *m)
{
if (ms->flags & MAGIC_APPLE) {
- if (file_printf(ms, "%.8s", m->apple) == -1)
+ if (file_printf(data_flow, ms, "%.8s", m->apple) == -1)
return -1;
return 1;
}
if ((ms->flags & MAGIC_MIME_TYPE) && m->mimetype[0]) {
- if (file_printf(ms, "%s", m->mimetype) == -1)
+ if (file_printf(data_flow, ms, "%s", m->mimetype) == -1)
return -1;
return 1;
}
@@ -2157,7 +2175,7 @@ handle_annotation(struct magic_set *ms, struct magic *m)
}
private int
-print_sep(struct magic_set *ms, int firstline)
+print_sep(int *data_flow, struct magic_set *ms, int firstline)
{
if (ms->flags & MAGIC_MIME)
return 0;
@@ -2167,5 +2185,5 @@ print_sep(struct magic_set *ms, int firstline)
* we found another match
* put a newline and '-' to do some simple formatting
*/
- return file_printf(ms, "\n- ");
+ return file_printf(data_flow, ms, "\n- ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment