Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 2662d13

Browse files
Changed some functions to static (to not export them to the shared library).
Added FIXME comments.
1 parent 05f4371 commit 2662d13

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

misc.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <math.h>
2929
#include <string.h>
3030

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) {
3232
double entropy = 0.;
3333

3434
for (size_t i = 0; i < 256; i++) {
@@ -54,6 +54,7 @@ double pe_calculate_entropy_file(pe_ctx_t *ctx) {
5454
}
5555

5656
bool pe_fpu_trick(pe_ctx_t *ctx) {
57+
// NOTE: What 0xdf has to do with fpu?
5758
return !! memmem( ctx->map_addr, ctx->map_size, "\xdf\xdf\xdf\xdf", 4 );
5859

5960
// const char *opcode_ptr = ctx->map_addr;
@@ -101,7 +102,10 @@ int cpl_analysis(pe_ctx_t *ctx) {
101102
| IMAGE_FILE_DEBUG_STRIPPED
102103
| IMAGE_FILE_DLL);
103104

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
105109
if ((hdr_coff_ptr->TimeDateStamp == 708992537 ||
106110
hdr_coff_ptr->TimeDateStamp > 1354555867)
107111
&& (hdr_coff_ptr->Characteristics == characteristics1 || // equals 0xa18e
@@ -169,7 +173,7 @@ uint32_t pe_get_tls_directory(pe_ctx_t *ctx) {
169173
return directory->VirtualAddress;
170174
}
171175

172-
int count_tls_callbacks(pe_ctx_t *ctx) {
176+
static int count_tls_callbacks(pe_ctx_t *ctx) {
173177
int ret = 0;
174178

175179
const IMAGE_OPTIONAL_HEADER *optional_hdr = pe_optional(ctx);
@@ -192,14 +196,15 @@ int count_tls_callbacks(pe_ctx_t *ctx) {
192196
for (uint16_t i=0, j=0; i < num_sections; i++) {
193197
const bool can_process = tls_addr >= sections[i]->VirtualAddress
194198
&& tls_addr < (sections[i]->VirtualAddress + sections[i]->SizeOfRawData);
199+
195200
if (!can_process)
196201
continue;
197-
198202

199203
ofs = tls_addr - sections[i]->VirtualAddress + sections[i]->PointerToRawData;
200204

201205
switch (optional_hdr->type) {
202-
default: return 0;
206+
default:
207+
return 0;
203208
case MAGIC_PE32:
204209
{
205210
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) {
234239

235240
uint32_t funcaddr = 0;
236241

242+
// FIXME: Why this loop if 'funcaddr' isn't updated?
237243
do {
238244
const uint32_t *funcaddr_ptr = LIBPE_PTR_ADD(ctx->map_addr, ofs);
239245
if (!pe_can_read(ctx, funcaddr_ptr, sizeof(*funcaddr_ptr))) {
240246
// TODO: Should we report something?
241247
return 0;
242248
}
243249

250+
// FIXME: This funcaddr is declared in block scope!
244251
uint32_t funcaddr = *funcaddr_ptr;
245252
if (funcaddr) {
246253
ret = ++j; // function found

0 commit comments

Comments
 (0)