Skip to content

Commit 4f7ad49

Browse files
committed
Merge branch 'issue-6' of github.com:BNETDocs/bncsutil
2 parents b690376 + 0a34f56 commit 4f7ad49

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/bncsutil/pe.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,21 @@ 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=0;
410+
for(; i<pe->header.section_count; ++i)
411+
{
412+
if(strncmp(sect[i].name,".rsrc",sizeof(sect[i].name))==0)
413+
{
414+
sect = &sect[i];
415+
break;
416+
}
417+
}
418+
if(i == pe->header.section_count) // no resources ???
419+
return 0;
420+
}
407421
#if BIGENDIAN
408422
uint32_t check = 0xBD04EFFE;
409423
#else
@@ -412,7 +426,6 @@ MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res,
412426
uint32_t rva;
413427
uint32_t size;
414428
uint32_t offset;
415-
uint32_t align;
416429

417430
if (!pe || !res || !ver)
418431
return 0;
@@ -429,9 +442,7 @@ MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res,
429442
#endif
430443

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

0 commit comments

Comments
 (0)