|
@@ -32,7 +32,7 @@
|
|
#include "file.h"
|
|
#include "file.h"
|
|
|
|
|
|
#ifndef lint
|
|
#ifndef lint
|
|
-FILE_RCSID("@(#)$File: apprentice.c,v 1.326 2022/09/13 18:46:07 christos Exp $")
|
|
|
|
|
|
+FILE_RCSID("@(#)$File: apprentice.c,v 1.339 2022/12/26 17:31:14 christos Exp $")
|
|
#endif /* lint */
|
|
#endif /* lint */
|
|
|
|
|
|
#include "magic.h"
|
|
#include "magic.h"
|
|
@@ -112,25 +112,25 @@ const size_t file_nformats = FILE_NAMES_SIZE;
|
|
const char *file_names[FILE_NAMES_SIZE];
|
|
const char *file_names[FILE_NAMES_SIZE];
|
|
const size_t file_nnames = FILE_NAMES_SIZE;
|
|
const size_t file_nnames = FILE_NAMES_SIZE;
|
|
|
|
|
|
-private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
|
|
|
|
-private int hextoint(int);
|
|
|
|
-private const char *getstr(struct magic_set *, struct magic *, const char *,
|
|
|
|
|
|
+file_private int getvalue(struct magic_set *ms, struct magic *, const char **, int);
|
|
|
|
+file_private int hextoint(int);
|
|
|
|
+file_private const char *getstr(struct magic_set *, struct magic *, const char *,
|
|
int);
|
|
int);
|
|
-private int parse(struct magic_set *, struct magic_entry *, const char *,
|
|
|
|
|
|
+file_private int parse(struct magic_set *, struct magic_entry *, const char *,
|
|
size_t, int);
|
|
size_t, int);
|
|
-private void eatsize(const char **);
|
|
|
|
-private int apprentice_1(struct magic_set *, const char *, int);
|
|
|
|
-private ssize_t apprentice_magic_strength_1(const struct magic *);
|
|
|
|
-private size_t apprentice_magic_strength(const struct magic *, size_t);
|
|
|
|
-private int apprentice_sort(const void *, const void *);
|
|
|
|
-private void apprentice_list(struct mlist *, int );
|
|
|
|
-private struct magic_map *apprentice_load(struct magic_set *,
|
|
|
|
|
|
+file_private void eatsize(const char **);
|
|
|
|
+file_private int apprentice_1(struct magic_set *, const char *, int);
|
|
|
|
+file_private ssize_t apprentice_magic_strength_1(const struct magic *);
|
|
|
|
+file_private size_t apprentice_magic_strength(const struct magic *, size_t);
|
|
|
|
+file_private int apprentice_sort(const void *, const void *);
|
|
|
|
+file_private void apprentice_list(struct mlist *, int );
|
|
|
|
+file_private struct magic_map *apprentice_load(struct magic_set *,
|
|
const char *, int);
|
|
const char *, int);
|
|
-private struct mlist *mlist_alloc(void);
|
|
|
|
-private void mlist_free_all(struct magic_set *);
|
|
|
|
-private void mlist_free(struct mlist *);
|
|
|
|
-private void byteswap(struct magic *, uint32_t);
|
|
|
|
-private void bs1(struct magic *);
|
|
|
|
|
|
+file_private struct mlist *mlist_alloc(void);
|
|
|
|
+file_private void mlist_free_all(struct magic_set *);
|
|
|
|
+file_private void mlist_free(struct mlist *);
|
|
|
|
+file_private void byteswap(struct magic *, uint32_t);
|
|
|
|
+file_private void bs1(struct magic *);
|
|
|
|
|
|
#if defined(HAVE_BYTESWAP_H)
|
|
#if defined(HAVE_BYTESWAP_H)
|
|
#define swap2(x) bswap_16(x)
|
|
#define swap2(x) bswap_16(x)
|
|
@@ -141,37 +141,37 @@ private void bs1(struct magic *);
|
|
#define swap4(x) bswap32(x)
|
|
#define swap4(x) bswap32(x)
|
|
#define swap8(x) bswap64(x)
|
|
#define swap8(x) bswap64(x)
|
|
#else
|
|
#else
|
|
-private uint16_t swap2(uint16_t);
|
|
|
|
-private uint32_t swap4(uint32_t);
|
|
|
|
-private uint64_t swap8(uint64_t);
|
|
|
|
|
|
+file_private uint16_t swap2(uint16_t);
|
|
|
|
+file_private uint32_t swap4(uint32_t);
|
|
|
|
+file_private uint64_t swap8(uint64_t);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-private char *mkdbname(struct magic_set *, const char *, int);
|
|
|
|
-private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
|
|
|
|
|
|
+file_private char *mkdbname(struct magic_set *, const char *, int);
|
|
|
|
+file_private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
|
|
size_t);
|
|
size_t);
|
|
-private struct magic_map *apprentice_map(struct magic_set *, const char *);
|
|
|
|
-private int check_buffer(struct magic_set *, struct magic_map *, const char *);
|
|
|
|
-private void apprentice_unmap(struct magic_map *);
|
|
|
|
-private int apprentice_compile(struct magic_set *, struct magic_map *,
|
|
|
|
|
|
+file_private struct magic_map *apprentice_map(struct magic_set *, const char *);
|
|
|
|
+file_private int check_buffer(struct magic_set *, struct magic_map *, const char *);
|
|
|
|
+file_private void apprentice_unmap(struct magic_map *);
|
|
|
|
+file_private int apprentice_compile(struct magic_set *, struct magic_map *,
|
|
const char *);
|
|
const char *);
|
|
-private int check_format_type(const char *, int, const char **);
|
|
|
|
-private int check_format(struct magic_set *, struct magic *);
|
|
|
|
-private int get_op(char);
|
|
|
|
-private int parse_mime(struct magic_set *, struct magic_entry *, const char *,
|
|
|
|
|
|
+file_private int check_format_type(const char *, int, const char **);
|
|
|
|
+file_private int check_format(struct magic_set *, struct magic *);
|
|
|
|
+file_private int get_op(char);
|
|
|
|
+file_private int parse_mime(struct magic_set *, struct magic_entry *, const char *,
|
|
size_t);
|
|
size_t);
|
|
-private int parse_strength(struct magic_set *, struct magic_entry *,
|
|
|
|
|
|
+file_private int parse_strength(struct magic_set *, struct magic_entry *,
|
|
const char *, size_t);
|
|
const char *, size_t);
|
|
-private int parse_apple(struct magic_set *, struct magic_entry *, const char *,
|
|
|
|
|
|
+file_private int parse_apple(struct magic_set *, struct magic_entry *, const char *,
|
|
size_t);
|
|
size_t);
|
|
-private int parse_ext(struct magic_set *, struct magic_entry *, const char *,
|
|
|
|
|
|
+file_private int parse_ext(struct magic_set *, struct magic_entry *, const char *,
|
|
size_t);
|
|
size_t);
|
|
|
|
|
|
|
|
|
|
-private size_t magicsize = sizeof(struct magic);
|
|
|
|
|
|
+file_private size_t magicsize = sizeof(struct magic);
|
|
|
|
|
|
-private const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
|
|
|
|
|
|
+file_private const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
|
|
|
|
|
|
-private struct {
|
|
|
|
|
|
+file_private struct {
|
|
const char *name;
|
|
const char *name;
|
|
size_t len;
|
|
size_t len;
|
|
int (*fun)(struct magic_set *, struct magic_entry *, const char *,
|
|
int (*fun)(struct magic_set *, struct magic_entry *, const char *,
|
|
@@ -313,7 +313,7 @@ static const struct type_tbl_s special_tbl[] = {
|
|
# undef XX
|
|
# undef XX
|
|
# undef XX_NULL
|
|
# undef XX_NULL
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
|
|
get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
|
|
{
|
|
{
|
|
const struct type_tbl_s *p;
|
|
const struct type_tbl_s *p;
|
|
@@ -328,7 +328,7 @@ get_type(const struct type_tbl_s *tbl, const char *l, const char **t)
|
|
return p->type;
|
|
return p->type;
|
|
}
|
|
}
|
|
|
|
|
|
-private off_t
|
|
|
|
|
|
+file_private off_t
|
|
maxoff_t(void) {
|
|
maxoff_t(void) {
|
|
if (/*CONSTCOND*/sizeof(off_t) == sizeof(int))
|
|
if (/*CONSTCOND*/sizeof(off_t) == sizeof(int))
|
|
return CAST(off_t, INT_MAX);
|
|
return CAST(off_t, INT_MAX);
|
|
@@ -337,7 +337,7 @@ maxoff_t(void) {
|
|
return 0x7fffffff;
|
|
return 0x7fffffff;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
get_standard_integer_type(const char *l, const char **t)
|
|
get_standard_integer_type(const char *l, const char **t)
|
|
{
|
|
{
|
|
int type;
|
|
int type;
|
|
@@ -422,7 +422,7 @@ get_standard_integer_type(const char *l, const char **t)
|
|
return type;
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
init_file_tables(void)
|
|
init_file_tables(void)
|
|
{
|
|
{
|
|
static int done = 0;
|
|
static int done = 0;
|
|
@@ -440,7 +440,7 @@ init_file_tables(void)
|
|
assert(p - type_tbl == FILE_NAMES_SIZE);
|
|
assert(p - type_tbl == FILE_NAMES_SIZE);
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
|
|
add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
|
|
{
|
|
{
|
|
struct mlist *ml;
|
|
struct mlist *ml;
|
|
@@ -471,12 +471,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map, size_t idx)
|
|
/*
|
|
/*
|
|
* Handle one file or directory.
|
|
* Handle one file or directory.
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
apprentice_1(struct magic_set *ms, const char *fn, int action)
|
|
apprentice_1(struct magic_set *ms, const char *fn, int action)
|
|
{
|
|
{
|
|
struct magic_map *map;
|
|
struct magic_map *map;
|
|
#ifndef COMPILE_ONLY
|
|
#ifndef COMPILE_ONLY
|
|
- struct mlist *ml;
|
|
|
|
size_t i;
|
|
size_t i;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -498,7 +497,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
|
|
map = apprentice_map(ms, fn);
|
|
map = apprentice_map(ms, fn);
|
|
if (map == NULL) {
|
|
if (map == NULL) {
|
|
if (ms->flags & MAGIC_CHECK)
|
|
if (ms->flags & MAGIC_CHECK)
|
|
- file_magwarn(ms, "using regular magic file `%s'", fn);
|
|
|
|
|
|
+ file_magwarn(NULL, "using regular magic file `%s'", fn);
|
|
map = apprentice_load(ms, fn, action);
|
|
map = apprentice_load(ms, fn, action);
|
|
if (map == NULL)
|
|
if (map == NULL)
|
|
return -1;
|
|
return -1;
|
|
@@ -511,7 +510,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
|
|
apprentice_unmap(map);
|
|
apprentice_unmap(map);
|
|
else
|
|
else
|
|
mlist_free_all(ms);
|
|
mlist_free_all(ms);
|
|
- file_oomem(ms, sizeof(*ml));
|
|
|
|
|
|
+ file_oomem(ms, sizeof(*ms->mlist[0]));
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -531,7 +530,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action)
|
|
#endif /* COMPILE_ONLY */
|
|
#endif /* COMPILE_ONLY */
|
|
}
|
|
}
|
|
|
|
|
|
-protected void
|
|
|
|
|
|
+file_protected void
|
|
file_ms_free(struct magic_set *ms)
|
|
file_ms_free(struct magic_set *ms)
|
|
{
|
|
{
|
|
size_t i;
|
|
size_t i;
|
|
@@ -548,14 +547,14 @@ file_ms_free(struct magic_set *ms)
|
|
free(ms);
|
|
free(ms);
|
|
}
|
|
}
|
|
|
|
|
|
-protected struct magic_set *
|
|
|
|
|
|
+file_protected struct magic_set *
|
|
file_ms_alloc(int flags)
|
|
file_ms_alloc(int flags)
|
|
{
|
|
{
|
|
struct magic_set *ms;
|
|
struct magic_set *ms;
|
|
size_t i, len;
|
|
size_t i, len;
|
|
|
|
|
|
if ((ms = CAST(struct magic_set *, calloc(CAST(size_t, 1u),
|
|
if ((ms = CAST(struct magic_set *, calloc(CAST(size_t, 1u),
|
|
- sizeof(struct magic_set)))) == NULL)
|
|
|
|
|
|
+ sizeof(*ms)))) == NULL)
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
if (magic_setflags(ms, flags) == -1) {
|
|
if (magic_setflags(ms, flags) == -1) {
|
|
@@ -594,7 +593,7 @@ free:
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
apprentice_unmap(struct magic_map *map)
|
|
apprentice_unmap(struct magic_map *map)
|
|
{
|
|
{
|
|
size_t i;
|
|
size_t i;
|
|
@@ -628,7 +627,7 @@ apprentice_unmap(struct magic_map *map)
|
|
free(map);
|
|
free(map);
|
|
}
|
|
}
|
|
|
|
|
|
-private struct mlist *
|
|
|
|
|
|
+file_private struct mlist *
|
|
mlist_alloc(void)
|
|
mlist_alloc(void)
|
|
{
|
|
{
|
|
struct mlist *mlist;
|
|
struct mlist *mlist;
|
|
@@ -639,7 +638,7 @@ mlist_alloc(void)
|
|
return mlist;
|
|
return mlist;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
mlist_free_all(struct magic_set *ms)
|
|
mlist_free_all(struct magic_set *ms)
|
|
{
|
|
{
|
|
size_t i;
|
|
size_t i;
|
|
@@ -650,7 +649,7 @@ mlist_free_all(struct magic_set *ms)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
mlist_free_one(struct mlist *ml)
|
|
mlist_free_one(struct mlist *ml)
|
|
{
|
|
{
|
|
size_t i;
|
|
size_t i;
|
|
@@ -670,7 +669,7 @@ mlist_free_one(struct mlist *ml)
|
|
free(ml);
|
|
free(ml);
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
mlist_free(struct mlist *mlist)
|
|
mlist_free(struct mlist *mlist)
|
|
{
|
|
{
|
|
struct mlist *ml, *next;
|
|
struct mlist *ml, *next;
|
|
@@ -688,12 +687,11 @@ mlist_free(struct mlist *mlist)
|
|
|
|
|
|
#ifndef COMPILE_ONLY
|
|
#ifndef COMPILE_ONLY
|
|
/* void **bufs: an array of compiled magic files */
|
|
/* void **bufs: an array of compiled magic files */
|
|
-protected int
|
|
|
|
|
|
+file_protected int
|
|
buffer_apprentice(struct magic_set *ms, struct magic **bufs,
|
|
buffer_apprentice(struct magic_set *ms, struct magic **bufs,
|
|
size_t *sizes, size_t nbufs)
|
|
size_t *sizes, size_t nbufs)
|
|
{
|
|
{
|
|
size_t i, j;
|
|
size_t i, j;
|
|
- struct mlist *ml;
|
|
|
|
struct magic_map *map;
|
|
struct magic_map *map;
|
|
|
|
|
|
if (nbufs == 0)
|
|
if (nbufs == 0)
|
|
@@ -706,7 +704,7 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs,
|
|
for (i = 0; i < MAGIC_SETS; i++) {
|
|
for (i = 0; i < MAGIC_SETS; i++) {
|
|
mlist_free(ms->mlist[i]);
|
|
mlist_free(ms->mlist[i]);
|
|
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
|
|
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
|
|
- file_oomem(ms, sizeof(*ms->mlist[i]));
|
|
|
|
|
|
+ file_oomem(ms, sizeof(*ms->mlist[0]));
|
|
goto fail;
|
|
goto fail;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -718,7 +716,7 @@ buffer_apprentice(struct magic_set *ms, struct magic **bufs,
|
|
|
|
|
|
for (j = 0; j < MAGIC_SETS; j++) {
|
|
for (j = 0; j < MAGIC_SETS; j++) {
|
|
if (add_mlist(ms->mlist[j], map, j) == -1) {
|
|
if (add_mlist(ms->mlist[j], map, j) == -1) {
|
|
- file_oomem(ms, sizeof(*ml));
|
|
|
|
|
|
+ file_oomem(ms, sizeof(*ms->mlist[0]));
|
|
goto fail;
|
|
goto fail;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -732,7 +730,7 @@ fail:
|
|
#endif
|
|
#endif
|
|
|
|
|
|
/* const char *fn: list of magic files and directories */
|
|
/* const char *fn: list of magic files and directories */
|
|
-protected int
|
|
|
|
|
|
+file_protected int
|
|
file_apprentice(struct magic_set *ms, const char *fn, int action)
|
|
file_apprentice(struct magic_set *ms, const char *fn, int action)
|
|
{
|
|
{
|
|
char *p, *mfn;
|
|
char *p, *mfn;
|
|
@@ -754,7 +752,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
|
|
for (i = 0; i < MAGIC_SETS; i++) {
|
|
for (i = 0; i < MAGIC_SETS; i++) {
|
|
mlist_free(ms->mlist[i]);
|
|
mlist_free(ms->mlist[i]);
|
|
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
|
|
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
|
|
- file_oomem(ms, sizeof(*ms->mlist[i]));
|
|
|
|
|
|
+ file_oomem(ms, sizeof(*ms->mlist[0]));
|
|
for (j = 0; j < i; j++) {
|
|
for (j = 0; j < i; j++) {
|
|
mlist_free(ms->mlist[j]);
|
|
mlist_free(ms->mlist[j]);
|
|
ms->mlist[j] = NULL;
|
|
ms->mlist[j] = NULL;
|
|
@@ -822,7 +820,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
|
|
* - regular characters or escaped magic characters count 1
|
|
* - regular characters or escaped magic characters count 1
|
|
* - 0 length expressions count as one
|
|
* - 0 length expressions count as one
|
|
*/
|
|
*/
|
|
-private size_t
|
|
|
|
|
|
+file_private size_t
|
|
nonmagic(const char *str)
|
|
nonmagic(const char *str)
|
|
{
|
|
{
|
|
const char *p;
|
|
const char *p;
|
|
@@ -862,7 +860,7 @@ nonmagic(const char *str)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-private size_t
|
|
|
|
|
|
+file_private size_t
|
|
typesize(int type)
|
|
typesize(int type)
|
|
{
|
|
{
|
|
switch (type) {
|
|
switch (type) {
|
|
@@ -932,7 +930,7 @@ typesize(int type)
|
|
/*
|
|
/*
|
|
* Get weight of this magic entry, for sorting purposes.
|
|
* Get weight of this magic entry, for sorting purposes.
|
|
*/
|
|
*/
|
|
-private ssize_t
|
|
|
|
|
|
+file_private ssize_t
|
|
apprentice_magic_strength_1(const struct magic *m)
|
|
apprentice_magic_strength_1(const struct magic *m)
|
|
{
|
|
{
|
|
#define MULT 10U
|
|
#define MULT 10U
|
|
@@ -942,8 +940,8 @@ apprentice_magic_strength_1(const struct magic *m)
|
|
switch (m->type) {
|
|
switch (m->type) {
|
|
case FILE_DEFAULT: /* make sure this sorts last */
|
|
case FILE_DEFAULT: /* make sure this sorts last */
|
|
if (m->factor_op != FILE_FACTOR_OP_NONE) {
|
|
if (m->factor_op != FILE_FACTOR_OP_NONE) {
|
|
- fprintf(stderr, "Bad factor_op %d", m->factor_op);
|
|
|
|
- abort();
|
|
|
|
|
|
+ file_magwarn(NULL, "Usupported factor_op in default %d",
|
|
|
|
+ m->factor_op);
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
@@ -1069,7 +1067,7 @@ apprentice_magic_strength_1(const struct magic *m)
|
|
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
/*ARGSUSED*/
|
|
-private size_t
|
|
|
|
|
|
+file_private size_t
|
|
apprentice_magic_strength(const struct magic *m,
|
|
apprentice_magic_strength(const struct magic *m,
|
|
size_t nmagic __attribute__((__unused__)))
|
|
size_t nmagic __attribute__((__unused__)))
|
|
{
|
|
{
|
|
@@ -1130,7 +1128,7 @@ apprentice_magic_strength(const struct magic *m,
|
|
/*
|
|
/*
|
|
* Sort callback for sorting entries by "strength" (basically length)
|
|
* Sort callback for sorting entries by "strength" (basically length)
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
apprentice_sort(const void *a, const void *b)
|
|
apprentice_sort(const void *a, const void *b)
|
|
{
|
|
{
|
|
const struct magic_entry *ma = CAST(const struct magic_entry *, a);
|
|
const struct magic_entry *ma = CAST(const struct magic_entry *, a);
|
|
@@ -1148,7 +1146,7 @@ apprentice_sort(const void *a, const void *b)
|
|
/*
|
|
/*
|
|
* Shows sorted patterns list in the order which is used for the matching
|
|
* Shows sorted patterns list in the order which is used for the matching
|
|
*/
|
|
*/
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
apprentice_list(struct mlist *mlist, int mode)
|
|
apprentice_list(struct mlist *mlist, int mode)
|
|
{
|
|
{
|
|
uint32_t magindex, descindex, mimeindex, lineindex;
|
|
uint32_t magindex, descindex, mimeindex, lineindex;
|
|
@@ -1169,14 +1167,16 @@ apprentice_list(struct mlist *mlist, int mode)
|
|
* description/mimetype.
|
|
* description/mimetype.
|
|
*/
|
|
*/
|
|
lineindex = descindex = mimeindex = magindex;
|
|
lineindex = descindex = mimeindex = magindex;
|
|
- for (magindex++; magindex < ml->nmagic &&
|
|
|
|
- ml->magic[magindex].cont_level != 0; magindex++) {
|
|
|
|
|
|
+ for (; magindex + 1 < ml->nmagic &&
|
|
|
|
+ ml->magic[magindex + 1].cont_level != 0;
|
|
|
|
+ magindex++) {
|
|
|
|
+ uint32_t mi = magindex + 1;
|
|
if (*ml->magic[descindex].desc == '\0'
|
|
if (*ml->magic[descindex].desc == '\0'
|
|
- && *ml->magic[magindex].desc)
|
|
|
|
- descindex = magindex;
|
|
|
|
|
|
+ && *ml->magic[mi].desc)
|
|
|
|
+ descindex = mi;
|
|
if (*ml->magic[mimeindex].mimetype == '\0'
|
|
if (*ml->magic[mimeindex].mimetype == '\0'
|
|
- && *ml->magic[magindex].mimetype)
|
|
|
|
- mimeindex = magindex;
|
|
|
|
|
|
+ && *ml->magic[mi].mimetype)
|
|
|
|
+ mimeindex = mi;
|
|
}
|
|
}
|
|
|
|
|
|
printf("Strength = %3" SIZE_T_FORMAT "u@%u: %s [%s]\n",
|
|
printf("Strength = %3" SIZE_T_FORMAT "u@%u: %s [%s]\n",
|
|
@@ -1188,7 +1188,7 @@ apprentice_list(struct mlist *mlist, int mode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
set_test_type(struct magic *mstart, struct magic *m)
|
|
set_test_type(struct magic *mstart, struct magic *m)
|
|
{
|
|
{
|
|
switch (m->type) {
|
|
switch (m->type) {
|
|
@@ -1279,7 +1279,7 @@ set_test_type(struct magic *mstart, struct magic *m)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
addentry(struct magic_set *ms, struct magic_entry *me,
|
|
addentry(struct magic_set *ms, struct magic_entry *me,
|
|
struct magic_entry_set *mset)
|
|
struct magic_entry_set *mset)
|
|
{
|
|
{
|
|
@@ -1308,7 +1308,7 @@ addentry(struct magic_set *ms, struct magic_entry *me,
|
|
/*
|
|
/*
|
|
* Load and parse one file.
|
|
* Load and parse one file.
|
|
*/
|
|
*/
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
load_1(struct magic_set *ms, int action, const char *fn, int *errs,
|
|
load_1(struct magic_set *ms, int action, const char *fn, int *errs,
|
|
struct magic_entry_set *mset)
|
|
struct magic_entry_set *mset)
|
|
{
|
|
{
|
|
@@ -1396,14 +1396,14 @@ load_1(struct magic_set *ms, int action, const char *fn, int *errs,
|
|
* parse a file or directory of files
|
|
* parse a file or directory of files
|
|
* const char *fn: name of magic file or directory
|
|
* const char *fn: name of magic file or directory
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
cmpstrp(const void *p1, const void *p2)
|
|
cmpstrp(const void *p1, const void *p2)
|
|
{
|
|
{
|
|
return strcmp(*RCAST(char *const *, p1), *RCAST(char *const *, p2));
|
|
return strcmp(*RCAST(char *const *, p1), *RCAST(char *const *, p2));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-private uint32_t
|
|
|
|
|
|
+file_private uint32_t
|
|
set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
uint32_t starttest)
|
|
uint32_t starttest)
|
|
{
|
|
{
|
|
@@ -1436,7 +1436,7 @@ set_text_binary(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
return i;
|
|
return i;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
|
|
set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
|
|
{
|
|
{
|
|
uint32_t i;
|
|
uint32_t i;
|
|
@@ -1457,7 +1457,7 @@ set_last_default(struct magic_set *ms, struct magic_entry *me, uint32_t nme)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
struct magic **ma, uint32_t *nma)
|
|
struct magic **ma, uint32_t *nma)
|
|
{
|
|
{
|
|
@@ -1489,7 +1489,7 @@ coalesce_entries(struct magic_set *ms, struct magic_entry *me, uint32_t nme,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
magic_entry_free(struct magic_entry *me, uint32_t nme)
|
|
magic_entry_free(struct magic_entry *me, uint32_t nme)
|
|
{
|
|
{
|
|
uint32_t i;
|
|
uint32_t i;
|
|
@@ -1500,7 +1500,7 @@ magic_entry_free(struct magic_entry *me, uint32_t nme)
|
|
free(me);
|
|
free(me);
|
|
}
|
|
}
|
|
|
|
|
|
-private struct magic_map *
|
|
|
|
|
|
+file_private struct magic_map *
|
|
apprentice_load(struct magic_set *ms, const char *fn, int action)
|
|
apprentice_load(struct magic_set *ms, const char *fn, int action)
|
|
{
|
|
{
|
|
int errs = 0;
|
|
int errs = 0;
|
|
@@ -1591,7 +1591,7 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
|
|
i = set_text_binary(ms, mset[j].me, mset[j].count, i);
|
|
i = set_text_binary(ms, mset[j].me, mset[j].count, i);
|
|
}
|
|
}
|
|
if (mset[j].me)
|
|
if (mset[j].me)
|
|
- qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me),
|
|
|
|
|
|
+ qsort(mset[j].me, mset[j].count, sizeof(*mset[0].me),
|
|
apprentice_sort);
|
|
apprentice_sort);
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -1626,7 +1626,7 @@ out:
|
|
/*
|
|
/*
|
|
* extend the sign bit if the comparison is to be signed
|
|
* extend the sign bit if the comparison is to be signed
|
|
*/
|
|
*/
|
|
-protected uint64_t
|
|
|
|
|
|
+file_protected uint64_t
|
|
file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
|
|
file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
|
|
{
|
|
{
|
|
if (!(m->flag & UNSIGNED)) {
|
|
if (!(m->flag & UNSIGNED)) {
|
|
@@ -1712,7 +1712,7 @@ file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
|
|
return v;
|
|
return v;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
string_modifier_check(struct magic_set *ms, struct magic *m)
|
|
string_modifier_check(struct magic_set *ms, struct magic *m)
|
|
{
|
|
{
|
|
if ((ms->flags & MAGIC_CHECK) == 0)
|
|
if ((ms->flags & MAGIC_CHECK) == 0)
|
|
@@ -1771,7 +1771,7 @@ string_modifier_check(struct magic_set *ms, struct magic *m)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
get_op(char c)
|
|
get_op(char c)
|
|
{
|
|
{
|
|
switch (c) {
|
|
switch (c) {
|
|
@@ -1797,7 +1797,7 @@ get_op(char c)
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef ENABLE_CONDITIONALS
|
|
#ifdef ENABLE_CONDITIONALS
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
get_cond(const char *l, const char **t)
|
|
get_cond(const char *l, const char **t)
|
|
{
|
|
{
|
|
static const struct cond_tbl_s {
|
|
static const struct cond_tbl_s {
|
|
@@ -1823,7 +1823,7 @@ get_cond(const char *l, const char **t)
|
|
return p->cond;
|
|
return p->cond;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
|
|
check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
|
|
{
|
|
{
|
|
int last_cond;
|
|
int last_cond;
|
|
@@ -1867,7 +1867,7 @@ check_cond(struct magic_set *ms, int cond, uint32_t cont_level)
|
|
}
|
|
}
|
|
#endif /* ENABLE_CONDITIONALS */
|
|
#endif /* ENABLE_CONDITIONALS */
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
|
|
parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
|
|
{
|
|
{
|
|
const char *l = *lp;
|
|
const char *l = *lp;
|
|
@@ -1888,7 +1888,7 @@ parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
|
|
parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
|
|
int op)
|
|
int op)
|
|
{
|
|
{
|
|
@@ -1905,7 +1905,7 @@ parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
|
|
*lp = l;
|
|
*lp = l;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
|
|
parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
|
|
{
|
|
{
|
|
const char *l = *lp;
|
|
const char *l = *lp;
|
|
@@ -2012,7 +2012,7 @@ out:
|
|
/*
|
|
/*
|
|
* parse one line from magic file, put into magic[index++] if valid
|
|
* parse one line from magic file, put into magic[index++] if valid
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t lineno, int action)
|
|
size_t lineno, int action)
|
|
{
|
|
{
|
|
@@ -2429,13 +2429,14 @@ parse(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
* if valid
|
|
* if valid
|
|
*/
|
|
*/
|
|
/*ARGSUSED*/
|
|
/*ARGSUSED*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t len __attribute__((__unused__)))
|
|
size_t len __attribute__((__unused__)))
|
|
{
|
|
{
|
|
const char *l = line;
|
|
const char *l = line;
|
|
char *el;
|
|
char *el;
|
|
unsigned long factor;
|
|
unsigned long factor;
|
|
|
|
+ char sbuf[512];
|
|
struct magic *m = &me->mp[0];
|
|
struct magic *m = &me->mp[0];
|
|
|
|
|
|
if (m->factor_op != FILE_FACTOR_OP_NONE) {
|
|
if (m->factor_op != FILE_FACTOR_OP_NONE) {
|
|
@@ -2446,12 +2447,15 @@ parse_strength(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
}
|
|
}
|
|
if (m->type == FILE_NAME) {
|
|
if (m->type == FILE_NAME) {
|
|
file_magwarn(ms, "%s: Strength setting is not supported in "
|
|
file_magwarn(ms, "%s: Strength setting is not supported in "
|
|
- "\"name\" magic entries", m->value.s);
|
|
|
|
|
|
+ "\"name\" magic entries",
|
|
|
|
+ file_printable(ms, sbuf, sizeof(sbuf), m->value.s,
|
|
|
|
+ sizeof(m->value.s)));
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
EATAB;
|
|
EATAB;
|
|
switch (*l) {
|
|
switch (*l) {
|
|
case FILE_FACTOR_OP_NONE:
|
|
case FILE_FACTOR_OP_NONE:
|
|
|
|
+ break;
|
|
case FILE_FACTOR_OP_PLUS:
|
|
case FILE_FACTOR_OP_PLUS:
|
|
case FILE_FACTOR_OP_MINUS:
|
|
case FILE_FACTOR_OP_MINUS:
|
|
case FILE_FACTOR_OP_TIMES:
|
|
case FILE_FACTOR_OP_TIMES:
|
|
@@ -2485,13 +2489,13 @@ out:
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
goodchar(unsigned char x, const char *extra)
|
|
goodchar(unsigned char x, const char *extra)
|
|
{
|
|
{
|
|
return (isascii(x) && isalnum(x)) || strchr(extra, x);
|
|
return (isascii(x) && isalnum(x)) || strchr(extra, x);
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t llen, off_t off, size_t len, const char *name, const char *extra,
|
|
size_t llen, off_t off, size_t len, const char *name, const char *extra,
|
|
int nt)
|
|
int nt)
|
|
@@ -2544,7 +2548,7 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
* Parse an Apple CREATOR/TYPE annotation from magic file and put it into
|
|
* Parse an Apple CREATOR/TYPE annotation from magic file and put it into
|
|
* magic[index - 1]
|
|
* magic[index - 1]
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t len)
|
|
size_t len)
|
|
{
|
|
{
|
|
@@ -2556,7 +2560,7 @@ parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
/*
|
|
/*
|
|
* Parse a comma-separated list of extensions
|
|
* Parse a comma-separated list of extensions
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t len)
|
|
size_t len)
|
|
{
|
|
{
|
|
@@ -2569,7 +2573,7 @@ parse_ext(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
* parse a MIME annotation line from magic file, put into magic[index - 1]
|
|
* parse a MIME annotation line from magic file, put into magic[index - 1]
|
|
* if valid
|
|
* if valid
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
size_t len)
|
|
size_t len)
|
|
{
|
|
{
|
|
@@ -2578,7 +2582,7 @@ parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line,
|
|
sizeof(me->mp[0].mimetype), "MIME", "+-/.$?:{}", 1);
|
|
sizeof(me->mp[0].mimetype), "MIME", "+-/.$?:{}", 1);
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
check_format_type(const char *ptr, int type, const char **estr)
|
|
check_format_type(const char *ptr, int type, const char **estr)
|
|
{
|
|
{
|
|
int quad = 0, h;
|
|
int quad = 0, h;
|
|
@@ -2762,6 +2766,7 @@ check_format_type(const char *ptr, int type, const char **estr)
|
|
}
|
|
}
|
|
invalid:
|
|
invalid:
|
|
*estr = "not valid";
|
|
*estr = "not valid";
|
|
|
|
+ return -1;
|
|
toolong:
|
|
toolong:
|
|
*estr = "too long";
|
|
*estr = "too long";
|
|
return -1;
|
|
return -1;
|
|
@@ -2771,7 +2776,7 @@ toolong:
|
|
* Check that the optional printf format in description matches
|
|
* Check that the optional printf format in description matches
|
|
* the type of the magic.
|
|
* the type of the magic.
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
check_format(struct magic_set *ms, struct magic *m)
|
|
check_format(struct magic_set *ms, struct magic *m)
|
|
{
|
|
{
|
|
char *ptr;
|
|
char *ptr;
|
|
@@ -2827,11 +2832,12 @@ check_format(struct magic_set *ms, struct magic *m)
|
|
* pointer, according to the magic type. Update the string pointer to point
|
|
* pointer, according to the magic type. Update the string pointer to point
|
|
* just after the number read. Return 0 for success, non-zero for failure.
|
|
* just after the number read. Return 0 for success, non-zero for failure.
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
{
|
|
{
|
|
char *ep;
|
|
char *ep;
|
|
uint64_t ull;
|
|
uint64_t ull;
|
|
|
|
+ int y;
|
|
|
|
|
|
switch (m->type) {
|
|
switch (m->type) {
|
|
case FILE_BESTRING16:
|
|
case FILE_BESTRING16:
|
|
@@ -2853,8 +2859,8 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
}
|
|
}
|
|
if (m->type == FILE_REGEX) {
|
|
if (m->type == FILE_REGEX) {
|
|
file_regex_t rx;
|
|
file_regex_t rx;
|
|
- int rc = file_regcomp(ms, &rx, m->value.s,
|
|
|
|
- REG_EXTENDED);
|
|
|
|
|
|
+ int rc =
|
|
|
|
+ file_regcomp(ms, &rx, m->value.s, REG_EXTENDED);
|
|
if (rc == 0) {
|
|
if (rc == 0) {
|
|
file_regfree(&rx);
|
|
file_regfree(&rx);
|
|
}
|
|
}
|
|
@@ -2899,6 +2905,7 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
m->value.q = file_signextend(ms, m, ull);
|
|
m->value.q = file_signextend(ms, m, ull);
|
|
if (*p == ep) {
|
|
if (*p == ep) {
|
|
file_magwarn(ms, "Unparsable number `%s'", *p);
|
|
file_magwarn(ms, "Unparsable number `%s'", *p);
|
|
|
|
+ return -1;
|
|
} else {
|
|
} else {
|
|
size_t ts = typesize(m->type);
|
|
size_t ts = typesize(m->type);
|
|
uint64_t x;
|
|
uint64_t x;
|
|
@@ -2908,32 +2915,38 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
file_magwarn(ms,
|
|
file_magwarn(ms,
|
|
"Expected numeric type got `%s'",
|
|
"Expected numeric type got `%s'",
|
|
type_tbl[m->type].name);
|
|
type_tbl[m->type].name);
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
for (q = *p; isspace(CAST(unsigned char, *q)); q++)
|
|
for (q = *p; isspace(CAST(unsigned char, *q)); q++)
|
|
continue;
|
|
continue;
|
|
- if (*q == '-')
|
|
|
|
|
|
+ if (*q == '-' && ull != UINT64_MAX)
|
|
ull = -CAST(int64_t, ull);
|
|
ull = -CAST(int64_t, ull);
|
|
switch (ts) {
|
|
switch (ts) {
|
|
case 1:
|
|
case 1:
|
|
x = CAST(uint64_t, ull & ~0xffULL);
|
|
x = CAST(uint64_t, ull & ~0xffULL);
|
|
|
|
+ y = (x & ~0xffULL) != ~0xffULL;
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
x = CAST(uint64_t, ull & ~0xffffULL);
|
|
x = CAST(uint64_t, ull & ~0xffffULL);
|
|
|
|
+ y = (x & ~0xffffULL) != ~0xffffULL;
|
|
break;
|
|
break;
|
|
case 4:
|
|
case 4:
|
|
x = CAST(uint64_t, ull & ~0xffffffffULL);
|
|
x = CAST(uint64_t, ull & ~0xffffffffULL);
|
|
|
|
+ y = (x & ~0xffffffffULL) != ~0xffffffffULL;
|
|
break;
|
|
break;
|
|
case 8:
|
|
case 8:
|
|
x = 0;
|
|
x = 0;
|
|
|
|
+ y = 0;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
fprintf(stderr, "Bad width %zu", ts);
|
|
fprintf(stderr, "Bad width %zu", ts);
|
|
abort();
|
|
abort();
|
|
}
|
|
}
|
|
- if (x) {
|
|
|
|
|
|
+ if (x && y) {
|
|
file_magwarn(ms, "Overflow for numeric"
|
|
file_magwarn(ms, "Overflow for numeric"
|
|
" type `%s' value %#" PRIx64,
|
|
" type `%s' value %#" PRIx64,
|
|
type_tbl[m->type].name, ull);
|
|
type_tbl[m->type].name, ull);
|
|
|
|
+ return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (errno == 0) {
|
|
if (errno == 0) {
|
|
@@ -2950,7 +2963,7 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p, int action)
|
|
* Copy the converted version to "m->value.s", and the length in m->vallen.
|
|
* Copy the converted version to "m->value.s", and the length in m->vallen.
|
|
* Return updated scan pointer as function result. Warn if set.
|
|
* Return updated scan pointer as function result. Warn if set.
|
|
*/
|
|
*/
|
|
-private const char *
|
|
|
|
|
|
+file_private const char *
|
|
getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
|
|
getstr(struct magic_set *ms, struct magic *m, const char *s, int warn)
|
|
{
|
|
{
|
|
const char *origs = s;
|
|
const char *origs = s;
|
|
@@ -3128,7 +3141,7 @@ out:
|
|
|
|
|
|
|
|
|
|
/* Single hex char to int; -1 if not a hex char. */
|
|
/* Single hex char to int; -1 if not a hex char. */
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
hextoint(int c)
|
|
hextoint(int c)
|
|
{
|
|
{
|
|
if (!isascii(CAST(unsigned char, c)))
|
|
if (!isascii(CAST(unsigned char, c)))
|
|
@@ -3146,7 +3159,7 @@ hextoint(int c)
|
|
/*
|
|
/*
|
|
* Print a string containing C character escapes.
|
|
* Print a string containing C character escapes.
|
|
*/
|
|
*/
|
|
-protected void
|
|
|
|
|
|
+file_protected void
|
|
file_showstr(FILE *fp, const char *s, size_t len)
|
|
file_showstr(FILE *fp, const char *s, size_t len)
|
|
{
|
|
{
|
|
char c;
|
|
char c;
|
|
@@ -3206,7 +3219,7 @@ file_showstr(FILE *fp, const char *s, size_t len)
|
|
/*
|
|
/*
|
|
* eatsize(): Eat the size spec from a number [eg. 10UL]
|
|
* eatsize(): Eat the size spec from a number [eg. 10UL]
|
|
*/
|
|
*/
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
eatsize(const char **p)
|
|
eatsize(const char **p)
|
|
{
|
|
{
|
|
const char *l = *p;
|
|
const char *l = *p;
|
|
@@ -3232,7 +3245,7 @@ eatsize(const char **p)
|
|
/*
|
|
/*
|
|
* handle a buffer containing a compiled file.
|
|
* handle a buffer containing a compiled file.
|
|
*/
|
|
*/
|
|
-private struct magic_map *
|
|
|
|
|
|
+file_private struct magic_map *
|
|
apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
|
|
apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
|
|
{
|
|
{
|
|
struct magic_map *map;
|
|
struct magic_map *map;
|
|
@@ -3255,7 +3268,7 @@ apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
|
|
* handle a compiled file.
|
|
* handle a compiled file.
|
|
*/
|
|
*/
|
|
|
|
|
|
-private struct magic_map *
|
|
|
|
|
|
+file_private struct magic_map *
|
|
apprentice_map(struct magic_set *ms, const char *fn)
|
|
apprentice_map(struct magic_set *ms, const char *fn)
|
|
{
|
|
{
|
|
int fd;
|
|
int fd;
|
|
@@ -3331,7 +3344,7 @@ error:
|
|
return rv;
|
|
return rv;
|
|
}
|
|
}
|
|
|
|
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
|
|
check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
|
|
{
|
|
{
|
|
uint32_t *ptr;
|
|
uint32_t *ptr;
|
|
@@ -3390,7 +3403,7 @@ check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
|
|
/*
|
|
/*
|
|
* handle an mmaped file.
|
|
* handle an mmaped file.
|
|
*/
|
|
*/
|
|
-private int
|
|
|
|
|
|
+file_private int
|
|
apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
|
|
apprentice_compile(struct magic_set *ms, struct magic_map *map, const char *fn)
|
|
{
|
|
{
|
|
static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
|
|
static const size_t nm = sizeof(*map->nmagic) * MAGIC_SETS;
|
|
@@ -3443,11 +3456,11 @@ out:
|
|
return rv;
|
|
return rv;
|
|
}
|
|
}
|
|
|
|
|
|
-private const char ext[] = ".mgc";
|
|
|
|
|
|
+file_private const char ext[] = ".mgc";
|
|
/*
|
|
/*
|
|
* make a dbname
|
|
* make a dbname
|
|
*/
|
|
*/
|
|
-private char *
|
|
|
|
|
|
+file_private char *
|
|
mkdbname(struct magic_set *ms, const char *fn, int strip)
|
|
mkdbname(struct magic_set *ms, const char *fn, int strip)
|
|
{
|
|
{
|
|
const char *p, *q;
|
|
const char *p, *q;
|
|
@@ -3494,7 +3507,7 @@ mkdbname(struct magic_set *ms, const char *fn, int strip)
|
|
/*
|
|
/*
|
|
* Byteswap an mmap'ed file if needed
|
|
* Byteswap an mmap'ed file if needed
|
|
*/
|
|
*/
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
byteswap(struct magic *magic, uint32_t nmagic)
|
|
byteswap(struct magic *magic, uint32_t nmagic)
|
|
{
|
|
{
|
|
uint32_t i;
|
|
uint32_t i;
|
|
@@ -3506,7 +3519,7 @@ byteswap(struct magic *magic, uint32_t nmagic)
|
|
/*
|
|
/*
|
|
* swap a short
|
|
* swap a short
|
|
*/
|
|
*/
|
|
-private uint16_t
|
|
|
|
|
|
+file_private uint16_t
|
|
swap2(uint16_t sv)
|
|
swap2(uint16_t sv)
|
|
{
|
|
{
|
|
uint16_t rv;
|
|
uint16_t rv;
|
|
@@ -3520,7 +3533,7 @@ swap2(uint16_t sv)
|
|
/*
|
|
/*
|
|
* swap an int
|
|
* swap an int
|
|
*/
|
|
*/
|
|
-private uint32_t
|
|
|
|
|
|
+file_private uint32_t
|
|
swap4(uint32_t sv)
|
|
swap4(uint32_t sv)
|
|
{
|
|
{
|
|
uint32_t rv;
|
|
uint32_t rv;
|
|
@@ -3536,7 +3549,7 @@ swap4(uint32_t sv)
|
|
/*
|
|
/*
|
|
* swap a quad
|
|
* swap a quad
|
|
*/
|
|
*/
|
|
-private uint64_t
|
|
|
|
|
|
+file_private uint64_t
|
|
swap8(uint64_t sv)
|
|
swap8(uint64_t sv)
|
|
{
|
|
{
|
|
uint64_t rv;
|
|
uint64_t rv;
|
|
@@ -3565,7 +3578,7 @@ swap8(uint64_t sv)
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-protected uintmax_t
|
|
|
|
|
|
+file_protected uintmax_t
|
|
file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
|
|
file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
|
|
{
|
|
{
|
|
uintmax_t x = 0;
|
|
uintmax_t x = 0;
|
|
@@ -3598,7 +3611,7 @@ file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
|
|
/*
|
|
/*
|
|
* byteswap a single magic entry
|
|
* byteswap a single magic entry
|
|
*/
|
|
*/
|
|
-private void
|
|
|
|
|
|
+file_private void
|
|
bs1(struct magic *m)
|
|
bs1(struct magic *m)
|
|
{
|
|
{
|
|
m->cont_level = swap2(m->cont_level);
|
|
m->cont_level = swap2(m->cont_level);
|
|
@@ -3615,7 +3628,7 @@ bs1(struct magic *m)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-protected size_t
|
|
|
|
|
|
+file_protected size_t
|
|
file_pstring_length_size(struct magic_set *ms, const struct magic *m)
|
|
file_pstring_length_size(struct magic_set *ms, const struct magic *m)
|
|
{
|
|
{
|
|
switch (m->str_flags & PSTRING_LEN) {
|
|
switch (m->str_flags & PSTRING_LEN) {
|
|
@@ -3634,7 +3647,7 @@ file_pstring_length_size(struct magic_set *ms, const struct magic *m)
|
|
return FILE_BADSIZE;
|
|
return FILE_BADSIZE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-protected size_t
|
|
|
|
|
|
+file_protected size_t
|
|
file_pstring_get_length(struct magic_set *ms, const struct magic *m,
|
|
file_pstring_get_length(struct magic_set *ms, const struct magic *m,
|
|
const char *ss)
|
|
const char *ss)
|
|
{
|
|
{
|
|
@@ -3687,7 +3700,7 @@ file_pstring_get_length(struct magic_set *ms, const struct magic *m,
|
|
return len;
|
|
return len;
|
|
}
|
|
}
|
|
|
|
|
|
-protected int
|
|
|
|
|
|
+file_protected int
|
|
file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
|
|
file_magicfind(struct magic_set *ms, const char *name, struct mlist *v)
|
|
{
|
|
{
|
|
uint32_t i, j;
|
|
uint32_t i, j;
|