Skip to content

Commit 1d8a9f6

Browse files
CHOB-HETcarlbennett
authored andcommitted
Fix PE parsing of VersionString
1 parent 4f753af commit 1d8a9f6

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/bncsutil/pe.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,22 @@ MEXP(int) cm_pe_unload_resources(cm_pe_resdir_t* root)
403403
MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res,
404404
cm_pe_version_t* ver)
405405
{
406-
cm_pe_section_t* sect = (pe->sections + 3);
406+
// find ".rsrc" section
407+
cm_pe_section_t* sect = pe->sections;
408+
{
409+
int i,RsrcFound = 0;
410+
for(i=0; i<pe->header.section_count; i++)
411+
{
412+
if(strcmp(sect->name,".rsrc")==0)
413+
{
414+
RsrcFound = 1;
415+
break;
416+
}
417+
sect += 1;
418+
}
419+
if(RsrcFound==0) // no resources ???
420+
return 0;
421+
}
407422
#if BIGENDIAN
408423
uint32_t check = 0xBD04EFFE;
409424
#else
@@ -412,7 +427,6 @@ MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res,
412427
uint32_t rva;
413428
uint32_t size;
414429
uint32_t offset;
415-
uint32_t align;
416430

417431
if (!pe || !res || !ver)
418432
return 0;
@@ -429,9 +443,7 @@ MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res,
429443
#endif
430444

431445
offset = sect->raw_data_offset + (rva - sect->virtual_address) + 0x26;
432-
align = 4 -(offset & 0xF % 4);
433-
if (align < 4)
434-
offset += align;
446+
offset = (offset+3) & 0xFFFFFFFC; // align 4 byte
435447
if (fseek(pe->f, offset, SEEK_SET) == -1)
436448
return 0;
437449
if (fread(ver, sizeof(cm_pe_version_t), 1, pe->f) != 1)

0 commit comments

Comments
 (0)