git-svn: trunk@1899
Tomasz Kojm authored on 2006/04/08 08:31:41... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Sat Apr 8 01:22:47 CEST 2006 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav: code cleanup: move repeated endian conversion and other (MAX, |
|
4 |
+ MIN, etc.) macros into others.h. Patch by Andrey J. Melnikoff |
|
5 |
+ |
|
1 | 6 |
Fri Apr 7 21:09:25 CEST 2006 (tk) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav: initial support for Sensory Networks' NodalCore Accelerator |
... | ... |
@@ -46,11 +46,6 @@ |
46 | 46 |
#include "mspack/lzx.h" |
47 | 47 |
#include "cltypes.h" |
48 | 48 |
|
49 |
-#define FALSE (0) |
|
50 |
-#define TRUE (1) |
|
51 |
- |
|
52 |
-#define MIN(a,b) ((a < b) ? a : b) |
|
53 |
- |
|
54 | 49 |
#ifndef HAVE_ATTRIB_PACKED |
55 | 50 |
#define __attribute__(x) |
56 | 51 |
#endif |
... | ... |
@@ -149,39 +144,9 @@ typedef struct lzx_content_tag { |
149 | 149 |
#pragma pack() |
150 | 150 |
#endif |
151 | 151 |
|
152 |
-#if WORDS_BIGENDIAN == 0 |
|
153 |
-#define chm_endian_convert_16(v) (v) |
|
154 |
-#else |
|
155 |
-static uint16_t chm_endian_convert_16(uint16_t v) |
|
156 |
-{ |
|
157 |
- return ((v >> 8) + (v << 8)); |
|
158 |
-} |
|
159 |
-#endif |
|
160 |
- |
|
161 |
-#if WORDS_BIGENDIAN == 0 |
|
162 |
-#define chm_endian_convert_32(v) (v) |
|
163 |
-#else |
|
164 |
-static uint32_t chm_endian_convert_32(uint32_t v) |
|
165 |
-{ |
|
166 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | |
|
167 |
- ((v & 0x0000FF00) << 8) | (v << 24)); |
|
168 |
-} |
|
169 |
-#endif |
|
170 |
- |
|
171 |
-#if WORDS_BIGENDIAN == 0 |
|
172 |
-#define chm_endian_convert_64(v) (v) |
|
173 |
-#else |
|
174 |
-static uint64_t chm_endian_convert_64(uint64_t v) |
|
175 |
-{ |
|
176 |
- return ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | |
|
177 |
- ((v & 0x0000FF0000000000LL) >> 24) | |
|
178 |
- ((v & 0x000000FF00000000LL) >> 8) | |
|
179 |
- ((v & 0x00000000FF000000LL) << 8) | |
|
180 |
- ((v & 0x0000000000FF0000LL) << 24) | |
|
181 |
- ((v & 0x000000000000FF00LL) << 40) | |
|
182 |
- (v << 56)); |
|
183 |
-} |
|
184 |
-#endif |
|
152 |
+#define chm_endian_convert_16(x) le16_to_host(x) |
|
153 |
+#define chm_endian_convert_32(x) le32_to_host(x) |
|
154 |
+#define chm_endian_convert_64(x) le64_to_host(x) |
|
185 | 155 |
|
186 | 156 |
/* Read in a block of data from either the mmap area or the given fd */ |
187 | 157 |
int chm_read_data(int fd, unsigned char *dest, off_t offset, off_t len, |
... | ... |
@@ -45,11 +45,7 @@ int cli_msexpand(FILE *in, FILE *out) |
45 | 45 |
return -1; |
46 | 46 |
} |
47 | 47 |
|
48 |
-#if WORDS_BIGENDIAN == 1 |
|
49 |
- if(magic1 == 0x535A4444L) |
|
50 |
-#else |
|
51 |
- if(magic1 == 0x44445A53L) |
|
52 |
-#endif |
|
48 |
+ if(magic1 == le32_to_host(0x44445A53L)) |
|
53 | 49 |
{ |
54 | 50 |
if(fread(&magic2, sizeof(magic2), 1, in) != 1) { |
55 | 51 |
return -1; |
... | ... |
@@ -63,22 +59,14 @@ int cli_msexpand(FILE *in, FILE *out) |
63 | 63 |
return -1; |
64 | 64 |
} |
65 | 65 |
|
66 |
-#if WORDS_BIGENDIAN == 1 |
|
67 |
- if(magic2 != 0x88F02733L) |
|
68 |
-#else |
|
69 |
- if(magic2 != 0x3327F088L) |
|
70 |
-#endif |
|
66 |
+ if(magic2 != le32_to_host(0x3327F088L)) |
|
71 | 67 |
{ |
72 | 68 |
cli_warnmsg("msexpand: Not a MS-compressed file\n"); |
73 | 69 |
return -1; |
74 | 70 |
} |
75 | 71 |
|
76 | 72 |
} else |
77 |
-#if WORDS_BIGENDIAN == 1 |
|
78 |
- if(magic1 == 0x4B57414AL) |
|
79 |
-#else |
|
80 |
- if(magic1 == 0x4A41574BL) |
|
81 |
-#endif |
|
73 |
+ if(magic1 == le32_to_host(0x4A41574BL)) |
|
82 | 74 |
{ |
83 | 75 |
if(fread(&magic2, sizeof(magic2), 1, in) != 1) { |
84 | 76 |
return -1; |
... | ... |
@@ -92,11 +80,7 @@ int cli_msexpand(FILE *in, FILE *out) |
92 | 92 |
return -1; |
93 | 93 |
} |
94 | 94 |
|
95 |
-#if WORDS_BIGENDIAN == 1 |
|
96 |
- if(magic2 != 0x88F027D1L || magic3 != 0x03001200L) |
|
97 |
-#else |
|
98 |
- if(magic2 != 0xD127F088L || magic3 != 0x00120003L) |
|
99 |
-#endif |
|
95 |
+ if(magic2 != le32_to_host(0xD127F088L) || magic3 != le32_to_host(0x00120003L)) |
|
100 | 96 |
{ |
101 | 97 |
cli_warnmsg("msexpand: Not a MS-compressed file\n"); |
102 | 98 |
return -1; |
... | ... |
@@ -46,33 +46,8 @@ |
46 | 46 |
#include "others.h" |
47 | 47 |
#include "ole2_extract.h" |
48 | 48 |
|
49 |
-#ifndef FALSE |
|
50 |
-#define FALSE (0) |
|
51 |
-#define TRUE (1) |
|
52 |
-#endif |
|
53 |
- |
|
54 |
-#ifndef MIN |
|
55 |
-#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
56 |
-#endif |
|
57 |
- |
|
58 |
-#if WORDS_BIGENDIAN == 0 |
|
59 |
-#define ole2_endian_convert_16(v) (v) |
|
60 |
-#else |
|
61 |
-static uint16_t ole2_endian_convert_16(uint16_t v) |
|
62 |
-{ |
|
63 |
- return ((v >> 8) + (v << 8)); |
|
64 |
-} |
|
65 |
-#endif |
|
66 |
- |
|
67 |
-#if WORDS_BIGENDIAN == 0 |
|
68 |
-#define ole2_endian_convert_32(v) (v) |
|
69 |
-#else |
|
70 |
-static uint32_t ole2_endian_convert_32(uint32_t v) |
|
71 |
-{ |
|
72 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | |
|
73 |
- ((v & 0x0000FF00) << 8) | (v << 24)); |
|
74 |
-} |
|
75 |
-#endif |
|
49 |
+#define ole2_endian_convert_16(v) le16_to_host(v) |
|
50 |
+#define ole2_endian_convert_32(v) le32_to_host(v) |
|
76 | 51 |
|
77 | 52 |
#ifndef HAVE_ATTRIB_PACKED |
78 | 53 |
#define __attribute__(x) |
... | ... |
@@ -64,6 +64,51 @@ typedef struct { |
64 | 64 |
#define BLOCKMAX (ctx->options & CL_SCAN_BLOCKMAX) |
65 | 65 |
#define DETECT_BROKEN (ctx->options & CL_SCAN_BLOCKBROKEN) |
66 | 66 |
|
67 |
+#if WORDS_BIGENDIAN == 0 |
|
68 |
+/* new macros from A. Melnikoff */ |
|
69 |
+#define le16_to_host(v) (v) |
|
70 |
+#define le32_to_host(v) (v) |
|
71 |
+#define le64_to_host(v) (v) |
|
72 |
+#define be16_to_host(v) ((v >> 8) | (v << 8)) |
|
73 |
+#define be32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \ |
|
74 |
+ ((v & 0x0000FF00) << 8) | (v << 24)) |
|
75 |
+#define be64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \ |
|
76 |
+ ((v & 0x0000FF0000000000LL) >> 24) | \ |
|
77 |
+ ((v & 0x000000FF00000000LL) >> 8) | \ |
|
78 |
+ ((v & 0x00000000FF000000LL) << 8) | \ |
|
79 |
+ ((v & 0x0000000000FF0000LL) << 24) | \ |
|
80 |
+ ((v & 0x000000000000FF00LL) << 40) | \ |
|
81 |
+ (v << 56)) |
|
82 |
+#else |
|
83 |
+#define le16_to_host(v) ((v >> 8) | (v << 8)) |
|
84 |
+#define le32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \ |
|
85 |
+ ((v & 0x0000FF00) << 8) | (v << 24)) |
|
86 |
+#define le64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \ |
|
87 |
+ ((v & 0x0000FF0000000000LL) >> 24) | \ |
|
88 |
+ ((v & 0x000000FF00000000LL) >> 8) | \ |
|
89 |
+ ((v & 0x00000000FF000000LL) << 8) | \ |
|
90 |
+ ((v & 0x0000000000FF0000LL) << 24) | \ |
|
91 |
+ ((v & 0x000000000000FF00LL) << 40) | \ |
|
92 |
+ (v << 56)) |
|
93 |
+#define be16_to_host(v) (v) |
|
94 |
+#define be32_to_host(v) (v) |
|
95 |
+#define be64_to_host(v) (v) |
|
96 |
+#endif |
|
97 |
+ |
|
98 |
+/* used by: spin, yc (C) aCaB */ |
|
99 |
+#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
100 |
+#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
101 |
+ |
|
102 |
+#define FALSE (0) |
|
103 |
+#define TRUE (1) |
|
104 |
+ |
|
105 |
+#ifndef MIN |
|
106 |
+#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
107 |
+#endif |
|
108 |
+#ifndef MAX |
|
109 |
+#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
|
110 |
+#endif |
|
111 |
+ |
|
67 | 112 |
typedef struct bitset_tag |
68 | 113 |
{ |
69 | 114 |
unsigned char *bitset; |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
* along with this program; if not, write to the Free Software |
16 | 16 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | 17 |
*/ |
18 |
-static char const rcsid[] = "$Id: pdf.c,v 1.45 2006/03/11 15:54:09 nigelhorne Exp $"; |
|
18 |
+static char const rcsid[] = "$Id: pdf.c,v 1.46 2006/04/07 23:31:41 kojm Exp $"; |
|
19 | 19 |
|
20 | 20 |
#if HAVE_CONFIG_H |
21 | 21 |
#include "clamav-config.h" |
... | ... |
@@ -53,10 +53,6 @@ static char const rcsid[] = "$Id: pdf.c,v 1.45 2006/03/11 15:54:09 nigelhorne Ex |
53 | 53 |
#include "pdf.h" |
54 | 54 |
#include "md5.h" |
55 | 55 |
|
56 |
-#ifndef MIN |
|
57 |
-#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
58 |
-#endif |
|
59 |
- |
|
60 | 56 |
static int flatedecode(const unsigned char *buf, size_t len, int fout, const cli_ctx *ctx); |
61 | 57 |
static int ascii85decode(const char *buf, size_t len, unsigned char *output); |
62 | 58 |
static const char *pdf_nextlinestart(const char *ptr, size_t len); |
... | ... |
@@ -55,20 +55,8 @@ |
55 | 55 |
#define UPX_NRV2D "\x83\xf0\xff\x74\x78\xd1\xf8\x89\xc5\xeb\x0b\x01\xdb\x75\x07\x8b\x1e\x83\xee\xfc\x11\xdb\x11\xc9" |
56 | 56 |
#define UPX_NRV2E "\xeb\x52\x31\xc9\x83\xe8\x03\x72\x11\xc1\xe0\x08\x8a\x06\x46\x83\xf0\xff\x74\x75\xd1\xf8\x89\xc5" |
57 | 57 |
|
58 |
-#if WORDS_BIGENDIAN == 0 |
|
59 |
-#define EC16(v) (v) |
|
60 |
-#define EC32(v) (v) |
|
61 |
-#else |
|
62 |
-static inline uint16_t EC16(uint16_t v) |
|
63 |
-{ |
|
64 |
- return ((v >> 8) + (v << 8)); |
|
65 |
-} |
|
66 |
- |
|
67 |
-static inline uint32_t EC32(uint32_t v) |
|
68 |
-{ |
|
69 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
70 |
-} |
|
71 |
-#endif |
|
58 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
59 |
+#define EC16(x) le16_to_host(x) |
|
72 | 60 |
|
73 | 61 |
extern short cli_leavetemps_flag; |
74 | 62 |
|
... | ... |
@@ -59,16 +59,7 @@ |
59 | 59 |
#include "rebuildpe.h" |
60 | 60 |
#include "others.h" |
61 | 61 |
|
62 |
-#if WORDS_BIGENDIAN == 0 |
|
63 |
-#define EC32(v) (v) |
|
64 |
-#else |
|
65 |
-static inline uint32_t EC32(uint32_t v) |
|
66 |
-{ |
|
67 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
68 |
-} |
|
69 |
-#endif |
|
70 |
- |
|
71 |
-#define MAX(a,b) ((a > b) ? a : b) |
|
62 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
72 | 63 |
|
73 | 64 |
static int doubledl(char **scur, uint8_t *mydlptr, char *buffer, uint32_t buffersize) |
74 | 65 |
{ |
... | ... |
@@ -45,19 +45,8 @@ |
45 | 45 |
#include "rebuildpe.h" |
46 | 46 |
#include "others.h" |
47 | 47 |
|
48 |
-#if WORDS_BIGENDIAN == 0 |
|
49 |
-#define EC32(v) (v) |
|
50 |
-#define EC16(v) (v) |
|
51 |
-#else |
|
52 |
-static inline uint32_t EC32(uint32_t v) |
|
53 |
-{ |
|
54 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
55 |
-} |
|
56 |
-static inline uint16_t EC16(uint16_t v) |
|
57 |
-{ |
|
58 |
- return ((v >> 8) + (v << 8)); |
|
59 |
-} |
|
60 |
-#endif |
|
48 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
49 |
+#define EC16(x) le16_to_host(x) /* Convert little endian to host */ |
|
61 | 50 |
|
62 | 51 |
struct IMAGE_PE_HEADER { |
63 | 52 |
uint32_t Signature; |
... | ... |
@@ -44,20 +44,8 @@ |
44 | 44 |
#include "clamav.h" |
45 | 45 |
#include "sis.h" |
46 | 46 |
|
47 |
-#if WORDS_BIGENDIAN == 0 |
|
48 |
-#define EC16(v) (v) |
|
49 |
-#define EC32(v) (v) |
|
50 |
-#else |
|
51 |
-static inline uint16_t EC16(uint16_t v) |
|
52 |
-{ |
|
53 |
- return ((v >> 8) + (v << 8)); |
|
54 |
-} |
|
55 |
- |
|
56 |
-static inline uint32_t EC32(uint32_t v) |
|
57 |
-{ |
|
58 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
59 |
-} |
|
60 |
-#endif |
|
47 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
48 |
+#define EC16(x) le16_to_host(x) /* Convert little endian to host */ |
|
61 | 49 |
|
62 | 50 |
extern short cli_leavetemps_flag; |
63 | 51 |
|
... | ... |
@@ -30,29 +30,11 @@ |
30 | 30 |
#include "cltypes.h" |
31 | 31 |
#include "special.h" |
32 | 32 |
|
33 |
-#define FALSE (0) |
|
34 |
-#define TRUE (1) |
|
35 |
- |
|
36 | 33 |
/* NOTE: Photoshop stores data in BIG ENDIAN format, this is the opposite |
37 | 34 |
to virtually everything else */ |
38 |
-#if WORDS_BIGENDIAN == 0 |
|
39 |
-static uint16_t special_endian_convert_16(uint16_t v) |
|
40 |
-{ |
|
41 |
- return ((v >> 8) + (v << 8)); |
|
42 |
-} |
|
43 |
-#else |
|
44 |
-#define special_endian_convert_16(v) (v) |
|
45 |
-#endif |
|
46 | 35 |
|
47 |
-#if WORDS_BIGENDIAN == 0 |
|
48 |
-static uint32_t special_endian_convert_32(uint32_t v) |
|
49 |
-{ |
|
50 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | |
|
51 |
- ((v & 0x0000FF00) << 8) | (v << 24)); |
|
52 |
-} |
|
53 |
-#else |
|
54 |
-#define special_endian_convert_32(v) (v) |
|
55 |
-#endif |
|
36 |
+#define special_endian_convert_16(v) be16_to_host(v) |
|
37 |
+#define special_endian_convert_32(v) be32_to_host(v) |
|
56 | 38 |
|
57 | 39 |
int cli_check_mydoom_log(int desc, const char **virname) |
58 | 40 |
{ |
... | ... |
@@ -243,21 +225,10 @@ int cli_check_jpeg_exploit(int fd) |
243 | 243 |
|
244 | 244 |
static uint32_t riff_endian_convert_32(uint32_t value, int big_endian) |
245 | 245 |
{ |
246 |
- if (big_endian) { |
|
247 |
-#if WORDS_BIGENDIAN == 0 |
|
248 |
- return ((value >> 24) | ((value & 0x00FF0000) >> 8) | |
|
249 |
- ((value & 0x0000FF00) << 8) | (value << 24)); |
|
250 |
-#else |
|
251 |
- return value; |
|
252 |
-#endif |
|
253 |
- } else { |
|
254 |
-#if WORDS_BIGENDIAN == 0 |
|
255 |
- return value; |
|
256 |
-#else |
|
257 |
- return ((value >> 24) | ((value & 0x00FF0000) >> 8) | |
|
258 |
- ((value & 0x0000FF00) << 8) | (value << 24)); |
|
259 |
-#endif |
|
260 |
- } |
|
246 |
+ if (big_endian) |
|
247 |
+ return be32_to_host(value); |
|
248 |
+ else |
|
249 |
+ return le32_to_host(value); |
|
261 | 250 |
} |
262 | 251 |
|
263 | 252 |
static int riff_read_chunk(int fd, int big_endian, int rec_level) |
... | ... |
@@ -63,18 +63,7 @@ |
63 | 63 |
#include "others.h" |
64 | 64 |
#include "spin.h" |
65 | 65 |
|
66 |
-#if WORDS_BIGENDIAN == 0 |
|
67 |
-#define EC32(v) (v) |
|
68 |
-#else |
|
69 |
-static inline uint32_t EC32(uint32_t v) |
|
70 |
-{ |
|
71 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
72 |
-} |
|
73 |
-#endif |
|
74 |
- |
|
75 |
-#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
76 |
-#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
77 |
- |
|
66 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
78 | 67 |
|
79 | 68 |
static char exec86(uint8_t aelle, uint8_t cielle, char *curremu) { |
80 | 69 |
int len = 0; |
... | ... |
@@ -24,7 +24,7 @@ |
24 | 24 |
#include "clamav-config.h" |
25 | 25 |
#endif |
26 | 26 |
|
27 |
-static char const rcsid[] = "$Id: tnef.c,v 1.31 2006/03/14 11:39:43 nigelhorne Exp $"; |
|
27 |
+static char const rcsid[] = "$Id: tnef.c,v 1.32 2006/04/07 23:31:41 kojm Exp $"; |
|
28 | 28 |
|
29 | 29 |
#include <stdio.h> |
30 | 30 |
#include <fcntl.h> |
... | ... |
@@ -54,14 +54,8 @@ static int tnef_header(FILE *fp, uint8_t *part, uint16_t *type, uint16_t *tag, i |
54 | 54 |
#define attTNEFVERSION 0x9006 |
55 | 55 |
#define attOEMCODEPAGE 0x9007 |
56 | 56 |
|
57 |
-#if WORDS_BIGENDIAN == 0 |
|
58 |
-#define host16(v) (v) |
|
59 |
-#define host32(v) (v) |
|
60 |
-#else |
|
61 |
-#define host16(v) ((v >> 8) | (v << 8)) |
|
62 |
-#define host32(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \ |
|
63 |
- ((v & 0x0000FF00) << 8) | (v << 24)) |
|
64 |
-#endif |
|
57 |
+#define host16(v) le16_to_host(v) |
|
58 |
+#define host32(v) le32_to_host(v) |
|
65 | 59 |
|
66 | 60 |
extern short cli_debug_flag; |
67 | 61 |
|
... | ... |
@@ -44,6 +44,8 @@ |
44 | 44 |
#include "cltypes.h" |
45 | 45 |
|
46 | 46 |
#define int64to32(x) ((uint)(x)) |
47 |
+#define rar_endian_convert_16(v) le16_to_host(v) |
|
48 |
+#define rar_endian_convert_32(v) le32_to_host(v) |
|
47 | 49 |
|
48 | 50 |
#ifdef RAR_HIGH_DEBUG |
49 | 51 |
#define rar_dbgmsg printf |
... | ... |
@@ -129,25 +131,6 @@ static void dump_tables(unpack_data_t *unpack_data) |
129 | 129 |
cli_dbgmsg("\n"); |
130 | 130 |
} |
131 | 131 |
|
132 |
-#if WORDS_BIGENDIAN == 0 |
|
133 |
-#define rar_endian_convert_16(v) (v) |
|
134 |
-#else |
|
135 |
-static uint16_t rar_endian_convert_16(uint16_t v) |
|
136 |
-{ |
|
137 |
- return ((v >> 8) + (v << 8)); |
|
138 |
-} |
|
139 |
-#endif |
|
140 |
- |
|
141 |
-#if WORDS_BIGENDIAN == 0 |
|
142 |
-#define rar_endian_convert_32(v) (v) |
|
143 |
-#else |
|
144 |
-static uint32_t rar_endian_convert_32(uint32_t v) |
|
145 |
-{ |
|
146 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | |
|
147 |
- ((v & 0x0000FF00) << 8) | (v << 24)); |
|
148 |
-} |
|
149 |
-#endif |
|
150 |
- |
|
151 | 132 |
static uint64_t copy_file_data(int ifd, int ofd, uint64_t len) |
152 | 133 |
{ |
153 | 134 |
unsigned char data[8192]; |
... | ... |
@@ -39,13 +39,6 @@ |
39 | 39 |
#include "vba_extract.h" |
40 | 40 |
#include "others.h" |
41 | 41 |
|
42 |
-#define FALSE (0) |
|
43 |
-#define TRUE (1) |
|
44 |
- |
|
45 |
-#ifndef MIN |
|
46 |
-#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
47 |
-#endif |
|
48 |
- |
|
49 | 42 |
typedef struct vba_version_tag { |
50 | 43 |
unsigned char signature[4]; |
51 | 44 |
const char *name; |
... | ... |
@@ -56,38 +49,18 @@ typedef struct vba_version_tag { |
56 | 56 |
|
57 | 57 |
static uint16_t vba_endian_convert_16(uint16_t value, int is_mac) |
58 | 58 |
{ |
59 |
- if (is_mac) { |
|
60 |
-#if WORDS_BIGENDIAN == 0 |
|
61 |
- return ((value >> 8) + (value << 8)); |
|
62 |
-#else |
|
63 |
- return value; |
|
64 |
-#endif |
|
65 |
- } else { |
|
66 |
-#if WORDS_BIGENDIAN == 0 |
|
67 |
- return value; |
|
68 |
-#else |
|
69 |
- return ((value >> 8) + (value << 8)); |
|
70 |
-#endif |
|
71 |
- } |
|
59 |
+ if (is_mac) |
|
60 |
+ return be16_to_host(value); |
|
61 |
+ else |
|
62 |
+ return le16_to_host(value); |
|
72 | 63 |
} |
73 | 64 |
|
74 | 65 |
static uint32_t vba_endian_convert_32(uint32_t value, int is_mac) |
75 | 66 |
{ |
76 |
- if (is_mac) { |
|
77 |
-#if WORDS_BIGENDIAN == 0 |
|
78 |
- return ((value >> 24) | ((value & 0x00FF0000) >> 8) | |
|
79 |
- ((value & 0x0000FF00) << 8) | (value << 24)); |
|
80 |
-#else |
|
81 |
- return value; |
|
82 |
-#endif |
|
83 |
- } else { |
|
84 |
-#if WORDS_BIGENDIAN == 0 |
|
85 |
- return value; |
|
86 |
-#else |
|
87 |
- return ((value >> 24) | ((value & 0x00FF0000) >> 8) | |
|
88 |
- ((value & 0x0000FF00) << 8) | (value << 24)); |
|
89 |
-#endif |
|
90 |
- } |
|
67 |
+ if (is_mac) |
|
68 |
+ return be32_to_host(value); |
|
69 |
+ else |
|
70 |
+ return le32_to_host(value); |
|
91 | 71 |
} |
92 | 72 |
|
93 | 73 |
typedef struct byte_array_tag { |
... | ... |
@@ -34,25 +34,8 @@ |
34 | 34 |
#include "pe.h" |
35 | 35 |
#include "others.h" |
36 | 36 |
|
37 |
- |
|
38 |
-/* Macros were created by aCaB */ |
|
39 |
-#define ROL(a,b) a = ( a << (b % (sizeof(a)<<3) )) | (a >> ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
40 |
-#define ROR(a,b) a = ( a >> (b % (sizeof(a)<<3) )) | (a << ( (sizeof(a)<<3) - (b % (sizeof(a)<<3 )) ) ) |
|
41 |
- |
|
42 |
-#if WORDS_BIGENDIAN == 0 |
|
43 |
-#define EC16(v) (v) |
|
44 |
-#define EC32(v) (v) |
|
45 |
-#else |
|
46 |
-static inline uint16_t EC16(uint16_t v) |
|
47 |
-{ |
|
48 |
- return ((v >> 8) + (v << 8)); |
|
49 |
-} |
|
50 |
- |
|
51 |
-static inline uint32_t EC32(uint32_t v) |
|
52 |
-{ |
|
53 |
- return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
54 |
-} |
|
55 |
-#endif |
|
37 |
+#define EC32(x) le32_to_host(x) /* Convert little endian to host */ |
|
38 |
+#define EC16(x) le16_to_host(x) /* Convert little endian to host */ |
|
56 | 39 |
|
57 | 40 |
/* ========================================================================== */ |
58 | 41 |
/* "Emulates" the poly decryptors */ |