@@ -448,7 +448,7 @@ static void
448
448
verify_pe_optional_header (VerifyContext * ctx )
449
449
{
450
450
guint32 offset = pe_header_offset (ctx );
451
- guint32 header_size , file_alignment ;
451
+ guint32 header_size , section_alignment , file_alignment ;
452
452
const char * pe_header = ctx -> data + offset ;
453
453
const char * pe_optional_header = pe_header + 20 ;
454
454
@@ -484,13 +484,19 @@ verify_pe_optional_header (VerifyContext *ctx)
484
484
/* LAMESPEC MS plays around this value and ignore it during validation
485
485
if (read32 (pe_optional_header + 28) != 0x400000)
486
486
ADD_ERROR (ctx, g_strdup_printf ("Invalid Image base %x", read32 (pe_optional_header + 28)));*/
487
- if (read32 (pe_optional_header + 32 ) != 0x2000 )
488
- ADD_ERROR (ctx , g_strdup_printf ("Invalid Section Aligmnent %x" , read32 (pe_optional_header + 32 )));
487
+ section_alignment = read32 (pe_optional_header + 32 );
489
488
file_alignment = read32 (pe_optional_header + 36 );
490
- if (file_alignment != 0x200 && file_alignment != 0x1000 )
489
+
490
+ // a power of 2 between 512 and 64 K, inclusive
491
+ if (file_alignment != 0x200 && file_alignment != 0x400 && file_alignment != 0x800 && file_alignment != 0x1000 &&
492
+ file_alignment != 0x2000 && file_alignment != 0x4000 && file_alignment != 0x8000 && file_alignment != 0x10000 )
491
493
ADD_ERROR (ctx , g_strdup_printf ("Invalid file Aligmnent %x" , file_alignment ));
492
494
/* All the junk in the middle is irrelevant, specially for mono. */
493
495
496
+ // must be greater than or equal to FileAlignment
497
+ if (section_alignment < file_alignment )
498
+ ADD_ERROR (ctx , g_strdup_printf ("Invalid Section Aligmnent %x" , read32 (pe_optional_header + 32 )));
499
+
494
500
if (header_size != 224 + ctx -> pe64 )
495
501
ADD_ERROR (ctx , g_strdup_printf ("Invalid optional header size %d" , header_size ));
496
502
@@ -622,6 +628,7 @@ verify_import_table (VerifyContext *ctx)
622
628
guint32 offset = it .translated_offset ;
623
629
const char * ptr = ctx -> data + offset ;
624
630
guint32 name_rva , ilt_rva , iat_rva ;
631
+ char mscoreeBuff [SIZE_OF_MSCOREE + 1 ];
625
632
626
633
// Having no import table is structurally valid
627
634
if (it .rva == 0 && it .size == 0 )
@@ -654,8 +661,12 @@ verify_import_table (VerifyContext *ctx)
654
661
g_assert (name_rva != INVALID_OFFSET );
655
662
ptr = ctx -> data + name_rva ;
656
663
657
- if (memcmp ("mscoree.dll" , ptr , SIZE_OF_MSCOREE ))
658
- ADD_ERROR (ctx , g_strdup_printf ("Invalid Import Table Name: '%s'" , ptr ));
664
+ if (memcmp ("mscoree.dll" , ptr , SIZE_OF_MSCOREE )) {
665
+ memcpy (mscoreeBuff , ptr , SIZE_OF_MSCOREE );
666
+ mscoreeBuff [SIZE_OF_MSCOREE ] = 0 ;
667
+ if (g_strcasecmp ("mscoree.dll" , mscoreeBuff ))
668
+ ADD_ERROR (ctx , g_strdup_printf ("Invalid Import Table Name: '%s'" , ptr ));
669
+ }
659
670
}
660
671
661
672
if (ilt_rva ) {
0 commit comments