I am reading a book on reversing and I am curious about one of the assembly snippet i have read in it.
There is a simple disassembly of the function RtlNumberGenericTableElements and it looks like this:
push ebp
mov ebp, esp
mov eax, dword ptr [ebp+8]
mov eax, dword ptr [eax+14]
pop ebp
ret 4
And it occured to me, say there is a member of a structure that is a pointer to some other structure. How would I go about dereferencing that member?
struct example {
int member1;
*object member2;
};
Would I be dereferencing member 2 like so (pointer to struct comes as first param):
mov eax, [ebp+8]
mov eax, dword ptr [eax]
mov eax, [eax+8] ; this would get me the pointer to member2???
any input appreciated
EDIT:
I see, your explanation was understandable, thank you, I appreciate it.
I have one more question that popped up from my mind. Say in your example, member 2 is a pointer to an int, then
mov eax, [ebp + 8] ; eax contains pointer to struct and its first member
mov eax, [eax + 4] ; eax contains a pointer to member2 (this is a pointer to an int)
Say i would like to get the value of member to into ecx i would carry on like this:
mov eax, [eax]
mov ecx, [eax]
So the whole thing would read like so:
mov eax, [ebp + 8] ; eax contains pointer to struct and its first member
mov eax, [eax + 4] ; eax contains a pointer to member2 (this is a pointer to an int)
mov eax, [eax] ; dereferenfce the pointer that is pointing to member2
mov ecx, [eax] ; dereference member2 itself that is a pointer to an int
Is this correct?