COM Interface Hook : When I call a original method, crashed.

c++ / delphi package - dll injection and api hooking
Post Reply
iamupd
Posts: 13
Joined: Tue Feb 23, 2010 4:54 am
Location: seoul, south korea

COM Interface Hook : When I call a original method, crashed.

Post by iamupd »

Hello.

I've tried hook COM Interface method and succeed. :-)
That method is IDropTargetHelper::Drop.
But When I call Original Method, it's crashed like below code.
Error message is...
" Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. "

So, I'd check calling convention and there is no problem.. i think. don't you?
Here is my code.

Code: Select all


HRESULT (WINAPI  *DropNext)(
			  IDataObject* pDataObject,
			  POINT* ppt,
			  DWORD dwEffect 
			  );
HRESULT WINAPI DropCallback (
			  IDataObject* pDataObject,
			  POINT* ppt,
			  DWORD dwEffect 
			  )
{
	return DropNext(pDataObject, ppt, dwEffect);
}

please, help me :(
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: COM Interface Hook : When I call a original method, cras

Post by madshi »

Class/Interface methods have an additional first "This" parameter. Try adding that to both DropNext and DropCallback.
pinya
Posts: 18
Joined: Tue Feb 05, 2013 4:39 am

Re: COM Interface Hook : When I call a original method, cras

Post by pinya »

How should I call HookApi for COM interface?

HookApi("dll", "IDropTargetHelper::Drop", DropCallback, *DropNext);

or

HookApi("dll", "Drop", DropCallback, *DropNext);

or

...

????
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: COM Interface Hook : When I call a original method, cras

Post by madshi »

See this old (madCodeHook 2) demo:

http://madshi.net/HookDirect3D.zip

But please replace the "GetInterfaceMethod()" in that code with the following to make it 64bit compatible:

Code: Select all

PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex)
{
  return *(PVOID*)(*(ULONG_PTR*)intf + methodIndex * sizeof(PVOID));
}
pinya
Posts: 18
Joined: Tue Feb 05, 2013 4:39 am

Re: COM Interface Hook : When I call a original method, cras

Post by pinya »

thank you for quick response.
seems to work fine.
Post Reply