2014-10-13 13:19:07 +02:00
|
|
|
---
|
2018-10-22 10:10:34 +02:00
|
|
|
src/apprentice.c | 71 ++++---------------------------------------------------
|
2017-05-24 13:14:26 +02:00
|
|
|
src/cdf.c | 53 +++--------------------------------------
|
2018-10-22 10:10:34 +02:00
|
|
|
2 files changed, 10 insertions(+), 114 deletions(-)
|
2014-10-13 13:19:07 +02:00
|
|
|
|
2013-09-30 16:29:55 +02:00
|
|
|
--- src/apprentice.c
|
2021-10-19 11:56:46 +02:00
|
|
|
+++ src/apprentice.c 2021-10-19 08:56:33.418646912 +0000
|
2018-10-22 10:10:34 +02:00
|
|
|
@@ -50,7 +50,7 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.
|
2012-08-16 19:40:37 +02:00
|
|
|
#endif
|
2018-10-22 10:10:34 +02:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <limits.h>
|
|
|
|
-
|
2012-08-16 19:40:37 +02:00
|
|
|
+#include <byteswap.h>
|
|
|
|
|
2019-02-21 08:19:34 +01:00
|
|
|
#define EATAB {while (isascii(CAST(unsigned char, *l)) && \
|
|
|
|
isspace(CAST(unsigned char, *l))) ++l;}
|
2021-10-19 11:56:46 +02:00
|
|
|
@@ -124,9 +124,11 @@ private void mlist_free_all(struct magic
|
2013-01-22 17:19:33 +01:00
|
|
|
private void mlist_free(struct mlist *);
|
2012-08-16 19:40:37 +02:00
|
|
|
private void byteswap(struct magic *, uint32_t);
|
|
|
|
private void bs1(struct magic *);
|
|
|
|
-private uint16_t swap2(uint16_t);
|
|
|
|
-private uint32_t swap4(uint32_t);
|
|
|
|
-private uint64_t swap8(uint64_t);
|
|
|
|
+
|
2014-10-13 13:19:07 +02:00
|
|
|
+#define swap2(x) bswap_16(x)
|
|
|
|
+#define swap4(x) bswap_32(x)
|
|
|
|
+#define swap8(x) bswap_64(x)
|
2012-08-16 19:40:37 +02:00
|
|
|
+
|
|
|
|
private char *mkdbname(struct magic_set *, const char *, int);
|
2014-10-13 13:19:07 +02:00
|
|
|
private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
|
|
|
|
size_t);
|
2021-10-19 11:56:46 +02:00
|
|
|
@@ -3355,67 +3357,6 @@ byteswap(struct magic *magic, uint32_t n
|
|
|
|
bs1(&magic[i]);
|
2012-08-16 19:40:37 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 11:56:46 +02:00
|
|
|
-/*
|
2012-08-16 19:40:37 +02:00
|
|
|
- * swap a short
|
|
|
|
- */
|
|
|
|
-private uint16_t
|
|
|
|
-swap2(uint16_t sv)
|
|
|
|
-{
|
|
|
|
- uint16_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
- d[0] = s[1];
|
|
|
|
- d[1] = s[0];
|
|
|
|
- return rv;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * swap an int
|
|
|
|
- */
|
|
|
|
-private uint32_t
|
|
|
|
-swap4(uint32_t sv)
|
|
|
|
-{
|
|
|
|
- uint32_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
- d[0] = s[3];
|
|
|
|
- d[1] = s[2];
|
|
|
|
- d[2] = s[1];
|
|
|
|
- d[3] = s[0];
|
|
|
|
- return rv;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * swap a quad
|
|
|
|
- */
|
|
|
|
-private uint64_t
|
|
|
|
-swap8(uint64_t sv)
|
|
|
|
-{
|
|
|
|
- uint64_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
-#if 0
|
|
|
|
- d[0] = s[3];
|
|
|
|
- d[1] = s[2];
|
|
|
|
- d[2] = s[1];
|
|
|
|
- d[3] = s[0];
|
|
|
|
- d[4] = s[7];
|
|
|
|
- d[5] = s[6];
|
|
|
|
- d[6] = s[5];
|
|
|
|
- d[7] = s[4];
|
|
|
|
-#else
|
|
|
|
- d[0] = s[7];
|
|
|
|
- d[1] = s[6];
|
|
|
|
- d[2] = s[5];
|
|
|
|
- d[3] = s[4];
|
|
|
|
- d[4] = s[3];
|
|
|
|
- d[5] = s[2];
|
|
|
|
- d[6] = s[1];
|
|
|
|
- d[7] = s[0];
|
|
|
|
-#endif
|
|
|
|
- return rv;
|
|
|
|
-}
|
|
|
|
-
|
2021-10-19 11:56:46 +02:00
|
|
|
protected uintmax_t
|
|
|
|
file_varint2uintmax_t(const unsigned char *us, int t, size_t *l)
|
|
|
|
{
|
2013-09-30 16:29:55 +02:00
|
|
|
--- src/cdf.c
|
2021-10-19 11:56:46 +02:00
|
|
|
+++ src/cdf.c 2021-10-19 08:53:37.577690786 +0000
|
|
|
|
@@ -48,6 +48,7 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.120 202
|
2018-10-22 10:10:34 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <ctype.h>
|
2012-08-16 19:40:37 +02:00
|
|
|
#include <limits.h>
|
|
|
|
+#include <byteswap.h>
|
|
|
|
|
|
|
|
#ifndef EFTYPE
|
|
|
|
#define EFTYPE EINVAL
|
2021-10-19 11:56:46 +02:00
|
|
|
@@ -124,55 +125,9 @@ cdf_calloc(const char *file __attribute_
|
2017-05-24 13:14:26 +02:00
|
|
|
return calloc(n, u);
|
|
|
|
}
|
2012-08-16 19:40:37 +02:00
|
|
|
|
|
|
|
-/*
|
|
|
|
- * swap a short
|
|
|
|
- */
|
|
|
|
-static uint16_t
|
|
|
|
-_cdf_tole2(uint16_t sv)
|
|
|
|
-{
|
|
|
|
- uint16_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
- d[0] = s[1];
|
|
|
|
- d[1] = s[0];
|
|
|
|
- return rv;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * swap an int
|
|
|
|
- */
|
|
|
|
-static uint32_t
|
|
|
|
-_cdf_tole4(uint32_t sv)
|
|
|
|
-{
|
|
|
|
- uint32_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
- d[0] = s[3];
|
|
|
|
- d[1] = s[2];
|
|
|
|
- d[2] = s[1];
|
|
|
|
- d[3] = s[0];
|
|
|
|
- return rv;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * swap a quad
|
|
|
|
- */
|
|
|
|
-static uint64_t
|
|
|
|
-_cdf_tole8(uint64_t sv)
|
|
|
|
-{
|
|
|
|
- uint64_t rv;
|
2019-02-21 08:19:34 +01:00
|
|
|
- uint8_t *s = RCAST(uint8_t *, RCAST(void *, &sv));
|
|
|
|
- uint8_t *d = RCAST(uint8_t *, RCAST(void *, &rv));
|
2012-08-16 19:40:37 +02:00
|
|
|
- d[0] = s[7];
|
|
|
|
- d[1] = s[6];
|
|
|
|
- d[2] = s[5];
|
|
|
|
- d[3] = s[4];
|
|
|
|
- d[4] = s[3];
|
|
|
|
- d[5] = s[2];
|
|
|
|
- d[6] = s[1];
|
|
|
|
- d[7] = s[0];
|
|
|
|
- return rv;
|
|
|
|
-}
|
2019-02-21 08:19:34 +01:00
|
|
|
+#define _cdf_tole2(x) bswap_16(x)
|
|
|
|
+#define _cdf_tole4(x) bswap_32(x)
|
|
|
|
+#define _cdf_tole8(x) bswap_64(x)
|
2012-08-16 19:40:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* grab a uint32_t from a possibly unaligned address, and return it in
|