Reputation: 5969
Here's the steps to convert from section alignment to file alignment:
But I just don't understand that, can someone elaborate with more details?
Upvotes: 5
Views: 5423
Reputation: 2689
Alignment is a rounded up value. Section data size is rounded up for effeciency because the OS moves stuff around in chunks anyway.
The File Alignment is usually 512 bytes which fit the blocksize of most filesystems.
The Section Alignment is usually 4096 bytes which fit the size of a memory page.
So if you have a PE-file with a section (like ".text
") that contains 513 bytes of data:
.text
will be rounded up to 1024 bytes on file..text
will be rounded up to 4096 bytes in memory.Note the amount of slack space possible both on file and in memory.
I'm unsure about why you want to "convert from one alignment to the other". The recipe you got there leaves the goal of the exercise as a mystery. If your goal is to manipulate PE-files then all you have to consider is the File Alignment. The Windows loader will handle the Section Alignment stuff when it throws it into memory, so you usually don't need to think about that at all.
You can read more about PE here.
Upvotes: 9