Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "alignment", and how to convert from one alignment to another?

Here's the steps to convert from section alignment to file alignment:

  1. Find the RVA for the data
  2. From the RVA, derive the section to which the data referenced belongs. This is trivial, since sections don’t overlap. The starting addresses of the various sections are available in the file header
  3. Find the difference between the RVA and the starting address of the section to find the data offset, ie, offset of that data within a section.
  4. From the file header, for the same section, find the location of the same section in the file.
  5. Add the data offset to the location of section in the file, to find the address of the data in the file.

But I just don't understand that, can someone elaborate with more details?

like image 885
wamp Avatar asked Sep 21 '10 02:09

wamp


People also ask

What is computer alignment?

Align or alignment is a term used to describe how text is placed on the screen. For example, left-aligned text creates a straight line of text on the left side of the page (like this paragraph). Text can be aligned along the edge of a page, cell, div, table, or another visible or non-visible line.

How do I copy alignment in Civil 3D to another drawing?

Within Civil 3D, zoom in to where you can see both the Alignment and Profile at the same time and select an Alignment to copy. Move the copied Alignment so it is offset such that you can see it graphically. By doing this, you will see that the Profile is also copied and offset by the same amount.


1 Answers

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:

  • Section .text will be rounded up to 1024 bytes on file.
  • Section .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.

like image 197
joveha Avatar answered Nov 15 '22 11:11

joveha