I am reading Eldad Eilam's reverse engineering book and trying to follow his RtlInitializeGenericTable example.
The first part of it is fairly straightfoward-
7C921A39 MOV EDI,EDI
7C921A3B PUSH EBP
7C921A3C MOV EBP,ESP
7C921A3E MOV EAX,DWORD PTR SS:[EBP+8] ; eax = UnknownStruct->Member1
7C921A41 XOR EDX,EDX
7C921A43 LEA ECX,DWORD PTR DS:[EAX+4] ; ecx = UnknownStruct->Member2
7C921A46 MOV DWORD PTR DS:[EAX],EDX ; UnknownStruct->Member1 = 0;
7C921A48 MOV DWORD PTR DS:[ECX+4],ECX ; UnknownStruct->Member3 = &UnknownStruct->Member2;
7C921A4B MOV DWORD PTR DS:[ECX],ECX ; UnkownStruct->Member2 = &UnknownStruct->Member2;
7C921A4D MOV DWORD PTR DS:[EAX+C],ECX ; UnknownStruct->Member4 = &UnknownStruct->Member2;
Where I get confused is in the second part:
7C921A50 MOV ECX,DWORD PTR SS:[EBP+C] ; ecx = UnknownStruct->Member2
7C921A53 MOV DWORD PTR DS:[EAX+18],ECX; UnknownStruct->Member7 = UnknownStruct->Member2;
7C921A56 MOV ECX,DWORD PTR SS:[EBP+10]; ecx = UnknownStruct->Member3
7C921A59 MOV DWORD PTR DS:[EAX+1C],ECX; UnknownStruct->Member8 = UnknownStruct->Member3;
In this part, offsets to the EBP are used to access variables and set their value. However, in his decompiled-c-equivalent output, it is shown that memory addresses are not being used as the initialization value, i.e.
UnknownStruct->Member7 = UnknownStruct->Member2;
whereas in the first part, they are:
UnknownStruct->Member3 = &UnknownStruct->Member2;
Why is this the case? As far as I can tell both parts should be the same- the only difference between the first and second is the LEA instruction, but that should only calculate the offset to the base pointer, the same as what is done in the second part.
Thanks.
lea
to encode arithmetic operations. It allows to perform an addition together with a multiplication by a constant at once and it is known to be much quicker than calling theadd
orimul
instructions. It seems to be the case here.