- FileLength = SectionHeader->PointerToRawData + Optional32->DataDirectory[5].Size;\r
- FileLength = (FileLength + 7) & 0xfffffff8;\r
- RelocSize = FileLength - SectionHeader->PointerToRawData;\r
+ SectionHeader->Misc.VirtualSize = Optional32->DataDirectory[5].Size;\r
+ AllignedRelocSize = (Optional32->DataDirectory[5].Size + Optional32->FileAlignment - 1) & (~(Optional32->FileAlignment - 1));\r
+ //\r
+ // Check to see if there is zero padding at the end of the base relocations\r
+ //\r
+ if (AllignedRelocSize < SectionHeader->SizeOfRawData) {\r
+ //\r
+ // Check to see if the base relocations are at the end of the file\r
+ //\r
+ if (SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData == Optional32->SizeOfImage) {\r
+ //\r
+ // All the required conditions are met to strip the zero padding of the end of the base relocations section\r
+ //\r
+ Optional32->SizeOfImage -= (SectionHeader->SizeOfRawData - AllignedRelocSize);\r
+ Optional32->SizeOfInitializedData -= (SectionHeader->SizeOfRawData - AllignedRelocSize);\r
+ SectionHeader->SizeOfRawData = AllignedRelocSize;\r
+ FileLength = Optional32->SizeOfImage;\r
+ }\r
+ }\r