Adjusting file headers

Since we are about to append the section to an executable file, we need to make some changes to its headers so that they reflect the new reality. Let's open the Legacy.exe file in either the 010 Editor or any other hex editor you prefer and go through all its headers making modifications where necessary.

Before we proceed to update the file, we have to decide what would be the size of the new section in file (SizeOfRawData) and in memory (VirtualSize) in accordance with the FileAlignment and SectionAlignment values, respectively. Checking this values in the IMAGE_OPTIONAL_HEADER32 structure, we see that the FileAlignment value is 0x200 and SectionAlignment is 0x1000. Since the code we want to insert into the new section ...

Get Mastering Assembly Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.