28
28
#include <math.h>
29
29
#include <string.h>
30
30
31
- double calculate_entropy (const unsigned int counted_bytes [256 ], const size_t total_length ) {
31
+ static double calculate_entropy (const unsigned int counted_bytes [256 ], const size_t total_length ) {
32
32
double entropy = 0. ;
33
33
34
34
for (size_t i = 0 ; i < 256 ; i ++ ) {
@@ -54,6 +54,7 @@ double pe_calculate_entropy_file(pe_ctx_t *ctx) {
54
54
}
55
55
56
56
bool pe_fpu_trick (pe_ctx_t * ctx ) {
57
+ // NOTE: What 0xdf has to do with fpu?
57
58
return !! memmem ( ctx -> map_addr , ctx -> map_size , "\xdf\xdf\xdf\xdf" , 4 );
58
59
59
60
// const char *opcode_ptr = ctx->map_addr;
@@ -101,7 +102,10 @@ int cpl_analysis(pe_ctx_t *ctx) {
101
102
| IMAGE_FILE_DEBUG_STRIPPED
102
103
| IMAGE_FILE_DLL );
103
104
104
- // Which timestamps are those?
105
+ // FIXME: Which timestamps are those?
106
+ // UNIX timestams:
107
+ // 708992537 = 19/jun/1992 @ 19:22:17
108
+ // 1354555867 = 3/dez/2012 @ 15:31:07
105
109
if ((hdr_coff_ptr -> TimeDateStamp == 708992537 ||
106
110
hdr_coff_ptr -> TimeDateStamp > 1354555867 )
107
111
&& (hdr_coff_ptr -> Characteristics == characteristics1 || // equals 0xa18e
@@ -169,7 +173,7 @@ uint32_t pe_get_tls_directory(pe_ctx_t *ctx) {
169
173
return directory -> VirtualAddress ;
170
174
}
171
175
172
- int count_tls_callbacks (pe_ctx_t * ctx ) {
176
+ static int count_tls_callbacks (pe_ctx_t * ctx ) {
173
177
int ret = 0 ;
174
178
175
179
const IMAGE_OPTIONAL_HEADER * optional_hdr = pe_optional (ctx );
@@ -192,14 +196,15 @@ int count_tls_callbacks(pe_ctx_t *ctx) {
192
196
for (uint16_t i = 0 , j = 0 ; i < num_sections ; i ++ ) {
193
197
const bool can_process = tls_addr >= sections [i ]-> VirtualAddress
194
198
&& tls_addr < (sections [i ]-> VirtualAddress + sections [i ]-> SizeOfRawData );
199
+
195
200
if (!can_process )
196
201
continue ;
197
-
198
202
199
203
ofs = tls_addr - sections [i ]-> VirtualAddress + sections [i ]-> PointerToRawData ;
200
204
201
205
switch (optional_hdr -> type ) {
202
- default : return 0 ;
206
+ default :
207
+ return 0 ;
203
208
case MAGIC_PE32 :
204
209
{
205
210
const IMAGE_TLS_DIRECTORY32 * tls_dir = LIBPE_PTR_ADD (ctx -> map_addr , ofs );
@@ -234,13 +239,15 @@ int count_tls_callbacks(pe_ctx_t *ctx) {
234
239
235
240
uint32_t funcaddr = 0 ;
236
241
242
+ // FIXME: Why this loop if 'funcaddr' isn't updated?
237
243
do {
238
244
const uint32_t * funcaddr_ptr = LIBPE_PTR_ADD (ctx -> map_addr , ofs );
239
245
if (!pe_can_read (ctx , funcaddr_ptr , sizeof (* funcaddr_ptr ))) {
240
246
// TODO: Should we report something?
241
247
return 0 ;
242
248
}
243
249
250
+ // FIXME: This funcaddr is declared in block scope!
244
251
uint32_t funcaddr = * funcaddr_ptr ;
245
252
if (funcaddr ) {
246
253
ret = ++ j ; // function found
0 commit comments