I had recently this situation where in a program I was debugging I found:
03CD38D4: 8B15 8C5FF703 MOV EDX, DWORD PTR DS:[3F75F8C]
If I look for these bytes in the physical file I found nothing. I assumed this is because the reference to 3F75F8C
, which might change over each instance of the program, is being randomised by Windows. So I could not change the value directly in an hexed - say change 3F75F8C
to 3F75F88
(I suppose I can do it with some math involving the base
, though).
- Can someone explain in detail how Windows proceeds when loading the PE file to randomise all these bytes? I have found posts and info on how ASLR works, but I am more thinking on the steps that the OS makes to put the file in memory with the randomised addresses - i.e. how it goes from the actual bytes in the executable "8B15 XXXX" to "8B15 8C5FF703" as in my example.
- How the OS knows where the bytes that have to be randomised are (which exact addresses), and do it in a timely fashion?
- Will this OS process breaks if I
NOP
the whole instruction? (I am asking because I do not know if there is some sort of predefined index table, I only know there is a flag in the PE to mark ASLR)
EDIT
As per the answer, what I undestood is that Windows will look into the .reloc
section and will change one by one the references pointed in the section based on the random base. Then, if I modify the bytes of the instruction, since they have been defined in the .reloc
section, my new bytes will be modified (probably I am wrong, but this is what I understood)
However, I am not able to find out how Windows "obtains" the instruction:
03CD38D4: 8B15 8C5FF703 MOV EDX, DWORD PTR DS:[3F75F8C]
Which is in file offset 482CD4
stored as:
MOV EDX, DWORD PTR DS:[B25F8C]
The image base is 400000
and base of code 1000
.
I cannot find anything in the .reloc
section that points to 03CD38D4
,482CD4
or similar.