Skip to content

Commit f99a26c

Browse files
committed
Fix issue VirusTotal#524
1 parent ec67ad7 commit f99a26c

File tree

2 files changed

+78
-55
lines changed

2 files changed

+78
-55
lines changed

libyara/include/yara/pe.h

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ typedef struct _IMAGE_OPTIONAL_HEADER64 {
290290
#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
291291
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
292292

293-
#define OptionalHeader(pe,field) \
294-
(IS_64BITS_PE(pe) ? \
295-
pe->header64->OptionalHeader.field : \
296-
pe->header->OptionalHeader.field)
297-
298293

299294
typedef struct _IMAGE_NT_HEADERS32 {
300295
DWORD Signature;
@@ -311,51 +306,6 @@ typedef struct _IMAGE_NT_HEADERS64 {
311306

312307
} IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
313308

314-
315-
//
316-
// Imports are stored in a linked list. Each node (IMPORTED_DLL) contains the
317-
// name of the DLL and a pointer to another linked list of IMPORTED_FUNCTION
318-
// structures containing the names of imported functions.
319-
//
320-
321-
typedef struct _IMPORTED_DLL
322-
{
323-
char *name;
324-
325-
struct _IMPORTED_FUNCTION *functions;
326-
struct _IMPORTED_DLL *next;
327-
328-
} IMPORTED_DLL, *PIMPORTED_DLL;
329-
330-
331-
typedef struct _IMPORTED_FUNCTION
332-
{
333-
char *name;
334-
uint8_t has_ordinal;
335-
uint16_t ordinal;
336-
337-
struct _IMPORTED_FUNCTION *next;
338-
339-
} IMPORTED_FUNCTION, *PIMPORTED_FUNCTION;
340-
341-
342-
typedef struct _PE
343-
{
344-
uint8_t* data;
345-
size_t data_size;
346-
347-
union {
348-
PIMAGE_NT_HEADERS32 header;
349-
PIMAGE_NT_HEADERS64 header64;
350-
};
351-
352-
YR_OBJECT* object;
353-
IMPORTED_DLL* imported_dlls;
354-
uint32_t resources;
355-
356-
} PE;
357-
358-
359309
// IMAGE_FIRST_SECTION doesn't need 32/64 versions since the file header is
360310
// the same either way.
361311

@@ -535,5 +485,6 @@ typedef struct _RICH_SIGNATURE {
535485
#define RICH_DANS 0x536e6144 // "DanS"
536486
#define RICH_RICH 0x68636952 // "Rich"
537487

488+
538489
#pragma pack(pop)
539490
#endif

libyara/include/yara/pe_utils.h

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,61 @@
55

66
#define MAX_PE_SECTIONS 96
77

8+
89
#define IS_64BITS_PE(pe) \
910
(pe->header64->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
1011

12+
13+
#define OptionalHeader(pe,field) \
14+
(IS_64BITS_PE(pe) ? \
15+
pe->header64->OptionalHeader.field : \
16+
pe->header->OptionalHeader.field)
17+
18+
19+
//
20+
// Imports are stored in a linked list. Each node (IMPORTED_DLL) contains the
21+
// name of the DLL and a pointer to another linked list of IMPORTED_FUNCTION
22+
// structures containing the names of imported functions.
23+
//
24+
25+
typedef struct _IMPORTED_DLL
26+
{
27+
char *name;
28+
29+
struct _IMPORTED_FUNCTION *functions;
30+
struct _IMPORTED_DLL *next;
31+
32+
} IMPORTED_DLL, *PIMPORTED_DLL;
33+
34+
35+
typedef struct _IMPORTED_FUNCTION
36+
{
37+
char *name;
38+
uint8_t has_ordinal;
39+
uint16_t ordinal;
40+
41+
struct _IMPORTED_FUNCTION *next;
42+
43+
} IMPORTED_FUNCTION, *PIMPORTED_FUNCTION;
44+
45+
46+
typedef struct _PE
47+
{
48+
uint8_t* data;
49+
size_t data_size;
50+
51+
union {
52+
PIMAGE_NT_HEADERS32 header;
53+
PIMAGE_NT_HEADERS64 header64;
54+
};
55+
56+
YR_OBJECT* object;
57+
IMPORTED_DLL* imported_dlls;
58+
uint32_t resources;
59+
60+
} PE;
61+
62+
1163
#define fits_in_pe(pe, pointer, size) \
1264
((size_t) size <= pe->data_size && \
1365
(uint8_t*) (pointer) >= pe->data && \
@@ -16,11 +68,31 @@
1668
#define struct_fits_in_pe(pe, pointer, struct_type) \
1769
fits_in_pe(pe, pointer, sizeof(struct_type))
1870

19-
PIMAGE_NT_HEADERS32 pe_get_header(uint8_t* data, size_t data_size);
20-
PIMAGE_DATA_DIRECTORY pe_get_directory_entry(PE* pe, int entry);
21-
PIMAGE_DATA_DIRECTORY pe_get_directory_entry(PE* pe, int entry);
22-
int64_t pe_rva_to_offset(PE* pe, uint64_t rva);
23-
char *ord_lookup(char *dll, uint16_t ord);
71+
72+
PIMAGE_NT_HEADERS32 pe_get_header(
73+
uint8_t* data,
74+
size_t data_size);
75+
76+
77+
PIMAGE_DATA_DIRECTORY pe_get_directory_entry(
78+
PE* pe,
79+
int entry);
80+
81+
82+
PIMAGE_DATA_DIRECTORY pe_get_directory_entry(
83+
PE* pe,
84+
int entry);
85+
86+
87+
int64_t pe_rva_to_offset(
88+
PE* pe,
89+
uint64_t rva);
90+
91+
92+
char *ord_lookup(
93+
char *dll,
94+
uint16_t ord);
95+
2496

2597
#if HAVE_LIBCRYPTO
2698
#include <openssl/asn1.h>

0 commit comments

Comments
 (0)