Say you have a COM Object and you call one of it's functions (It has a vtable with funcs).

Now in one of those functions you want the returnaddress of where you'll land AFTER the call, now the first entry on the stack won't be the returnaddress to where the COMObject calls but rather in vtable land or something....
I tried via asm (mov eax, ) I also tried via the intrinsic function _ReturnAddress and from multiple functions in the vtable and all returned the same address, how would I go about getting the right returnaddress, to where the COMObject is originally called via... ?
Posted on 2003-07-21 18:52:37 by SFP
If I get what you mean....

The interface pointer points to the place where the list of functions is held... so you need to derefernce it.

Object --> vtable pointer -> Func1 pointer, Funct2 pointer, ect

So to call a method you just do this psudo code does:



push paramLast
...
push param2
push param1
push IPointer
mov eax, IPointer
mov eax, [eax]
call [eax + (4 x Function Number)]


If you make a structure of the interface, you can simplify the coding with an invoke, even better, make a macro to automate it.

Take a peek at the COM section, there is a large body of work on using COM in asm (the only problem being no two people do it the same way, so you have to pick and choose what you need).
Posted on 2003-07-21 23:04:28 by Ernie
Actually I need the REVERSE...



mov eax, IPointer
mov eax, [eax]
call [eax + (4 x Function Number)]

The function you call there is my code that is when you call the function in the vtable, you are calling a function I have coded, lets call it TestFunction....

Now in TestFunction I need to get the RETURNADDRESS ! Where my app will land AFTER TestFunction. Now mov eax, will NOT work, I'm not sure why but I've done mov eax, in like 10 different functions and all give me the same returnaddress.... It doesn't seem right, maybe I'm doing it wrong or misunderstanding results...
Posted on 2003-07-22 08:24:45 by SFP
Are you doing something different like using PROC instead of an ordinary label?

PROC, by default, will add code to save EBP and add local variables, both of which will alter ESP.

Also, are you calling from ASM or calling from HLL code? If there are two procedure calls in a row, some old optimizers will stuff the address of the second procedure in place of the return address (for the first), "chaining" it.

There's also the possibility that you are finding the return address of the marshalling code. In which case, you can't know the return address (it might be in a different process).
Posted on 2003-07-22 16:12:19 by tenkey

Are you doing something different like using PROC instead of an ordinary label?

PROC, by default, will add code to save EBP and add local variables, both of which will alter ESP.

Also, are you calling from ASM or calling from HLL code? If there are two procedure calls in a row, some old optimizers will stuff the address of the second procedure in place of the return address (for the first), "chaining" it.

There's also the possibility that you are finding the return address of the marshalling code. In which case, you can't know the return address (it might be in a different process).

I'm using C++ for the main code, but I'm using asm trying to grab the retaddr.
It's like

obj = CreateFunc(param);

Then obj->somefunc(param); obj->someotherfunc(param, param );
the thing is that
if I inside the somefunc decide to check retaddr (mov eax, ) I will get the same result nomather where I call somefunc from....
if I did
obj->somefunc(param);
whatever();
obj->somefunc(param);

and check retaddr in both those somefunc calls (same function that is) I get same value at ...
Posted on 2003-07-22 17:17:48 by SFP