git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@720 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/08/05 00:40:35... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Aug 4 17:34:46 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav: petite: big-endian fixes |
|
4 |
+ * libclamav: pe: activate Petite unpacker |
|
5 |
+ |
|
1 | 6 |
Tue Aug 3 20:20:11 CEST 2004 (tk) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav: matcher-bm: fix segfault with short files (problem reported by |
... | ... |
@@ -556,7 +556,6 @@ int cli_scanpe(int desc, const char **virname, long int *scanned, const struct c |
556 | 556 |
|
557 | 557 |
/* Petite */ |
558 | 558 |
|
559 |
- /* |
|
560 | 559 |
found = 2; |
561 | 560 |
|
562 | 561 |
lseek(desc, ep, SEEK_SET); |
... | ... |
@@ -646,7 +645,6 @@ int cli_scanpe(int desc, const char **virname, long int *scanned, const struct c |
646 | 646 |
} |
647 | 647 |
} |
648 | 648 |
} |
649 |
- */ |
|
650 | 649 |
|
651 | 650 |
/* to be continued ... */ |
652 | 651 |
|
... | ... |
@@ -60,14 +60,8 @@ |
60 | 60 |
#include "others.h" |
61 | 61 |
|
62 | 62 |
#if WORDS_BIGENDIAN == 0 |
63 |
-#define EC16(v) (v) |
|
64 | 63 |
#define EC32(v) (v) |
65 | 64 |
#else |
66 |
-static inline uint16_t EC16(uint16_t v) |
|
67 |
-{ |
|
68 |
- return ((v >> 8) + (v << 8)); |
|
69 |
-} |
|
70 |
- |
|
71 | 65 |
static inline uint32_t EC32(uint32_t v) |
72 | 66 |
{ |
73 | 67 |
return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
... | ... |
@@ -178,18 +172,19 @@ int petite_inflate2x_1to9(char *buf, uint32_t minrva, int bufsz, struct pe_image |
178 | 178 |
|
179 | 179 |
while ( (char *)thunk >=buf && (char *)thunk<buf+bufsz-4 && dummy ) { |
180 | 180 |
uint32_t api; |
181 |
- |
|
181 |
+ |
|
182 | 182 |
if (! *thunk ) { |
183 | 183 |
workdone = 1; |
184 | 184 |
break; |
185 | 185 |
} |
186 | 186 |
|
187 |
- imports = (uint32_t *) (adjbuf + *thunk++); |
|
187 |
+ imports = (uint32_t *) (adjbuf + EC32(*thunk++)); |
|
188 | 188 |
dummy = 0; |
189 | 189 |
|
190 | 190 |
while ( (char *)imports >=buf && (char *)imports<buf+bufsz-4 ) { |
191 | 191 |
dummy = 0; |
192 |
- if ( ! (api = *imports++) ) { |
|
192 |
+ |
|
193 |
+ if ( ! (api = EC32(*imports++)) ) { |
|
193 | 194 |
dummy = 1; |
194 | 195 |
break; |
195 | 196 |
} |
... | ... |
@@ -32,6 +32,10 @@ |
32 | 32 |
** Raw alignment is a waste and therefore is not performed. |
33 | 33 |
*/ |
34 | 34 |
|
35 |
+#if HAVE_CONFIG_H |
|
36 |
+#include "clamav-config.h" |
|
37 |
+#endif |
|
38 |
+ |
|
35 | 39 |
#include <stdio.h> |
36 | 40 |
#include <string.h> |
37 | 41 |
#include <stdlib.h> |
... | ... |
@@ -40,7 +44,21 @@ |
40 | 40 |
#include "rebuildpe.h" |
41 | 41 |
#include "others.h" |
42 | 42 |
|
43 |
-#define cli_writeint32(offset,value) *(uint32_t *)(offset) = (value) |
|
43 |
+#if WORDS_BIGENDIAN == 0 |
|
44 |
+#define EC32(v) (v) |
|
45 |
+#define EC16(v) (v) |
|
46 |
+#else |
|
47 |
+static inline uint32_t EC32(uint32_t v) |
|
48 |
+{ |
|
49 |
+ return ((v >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | (v << 24)); |
|
50 |
+} |
|
51 |
+static inline uint16_t EC16(uint16_t v) |
|
52 |
+{ |
|
53 |
+ return ((v >> 8) + (v << 8)); |
|
54 |
+} |
|
55 |
+#endif |
|
56 |
+ |
|
57 |
+#define cli_writeint32(offset,value) *(uint32_t *)(offset) = EC32(value) |
|
44 | 58 |
|
45 | 59 |
struct IMAGE_PE_HEADER { |
46 | 60 |
uint32_t Signature; |
... | ... |
@@ -126,12 +144,12 @@ char *rebuildpe(char *buffer, struct SECTION *sections, int sects, uint32_t base |
126 | 126 |
memcpy(pefile, HEADERS, 0x148); |
127 | 127 |
|
128 | 128 |
fakepe = (struct IMAGE_PE_HEADER *)(pefile+0xd0); |
129 |
- fakepe->NumberOfSections=sects; |
|
130 |
- fakepe->AddressOfEntryPoint=ep; |
|
131 |
- fakepe->ImageBase=base; |
|
129 |
+ fakepe->NumberOfSections = EC16(sects); |
|
130 |
+ fakepe->AddressOfEntryPoint = EC32(ep); |
|
131 |
+ fakepe->ImageBase = EC32(base); |
|
132 | 132 |
memset(pefile+0x148, 0, 0x80); |
133 |
- *(uint32_t*)(pefile+0x148+0x10) = ResRva; |
|
134 |
- *(uint32_t*)(pefile+0x148+0x14) = ResSize; |
|
133 |
+ cli_writeint32(pefile+0x148+0x10, ResRva); |
|
134 |
+ cli_writeint32(pefile+0x148+0x14, ResSize); |
|
135 | 135 |
curpe = pefile+0x148+0x80; |
136 | 136 |
|
137 | 137 |
for (i=0; i < sects; i++) { |