Hooking class methoods (DirectInput)

c++ / delphi package - dll injection and api hooking
ginsoaked
Posts: 10
Joined: Thu Sep 30, 2004 12:46 am

Post by ginsoaked »

GetInterfaceMethod is returning NULL.. Even though my call to DirectInput8Create() via my DI8CreateNextHook() function returned DI_OK which indicates success.
I also tried it without the cast to IDirectInput8, but it still returns NULL.

My GetInterfaceMethod() is defined as:

Code: Select all

PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex)
{
   return *(PVOID*)(*(DWORD*)intf + methodIndex * 4);
} 
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Please check what pointer "DI" contains. Also please check what GetInterfaceMethod returns. Perhaps you need to give in "&DI" into GetInterfaceMethod? I've no idea. I'm not sure how C++ handles interfaces internally. You can see in my HookDirect3D.cpp that I've avoided the interfaces.
ginsoaked
Posts: 10
Joined: Thu Sep 30, 2004 12:46 am

Post by ginsoaked »

Hmm you're right.. I just remembered that DI is a pointer to a pointer to an IDirectInput object.. I bet it will work if I remove one of those levels of indirection.
ginsoaked
Posts: 10
Joined: Thu Sep 30, 2004 12:46 am

Post by ginsoaked »

Well I'm able to hook it now and my function is called. But now the program is crashing. At the moment all I'm doing is running CreateDevice() as normal and it should be functioning just like it should..

Here's what my CreateDevice() callback looks like:

Code: Select all

HRESULT DICreateDeviceCallback(LPVOID Self, REFGUID rguid, LPDIRECTINPUTDEVICE *lplpDirectInputDevice, LPUNKNOWN pUnkOuter)
{
	sprintf((char*) &s, "Got DirectInput::CreateDevice!\n");
	WriteFile(hStdOut, &s, strlen(s), &x, NULL);

	HRESULT res = DICreateDeviceNextHook(Self, rguid, lplpDirectInputDevice , pUnkOuter);

	return res;	
}
It doesn't crash in this function, it returns correctly with a value of DI_OK, indicating success. The crash happens after the return at some point. (Presumably when the application I'm hooking tried to use the device I rturned..) lplpDirectInputDevice isn't NULL or anything, so I don't know what the problem could be..
Any ideas , anyone?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I think you're missing WINAPI or am I wrong?
ginsoaked
Posts: 10
Joined: Thu Sep 30, 2004 12:46 am

Post by ginsoaked »

Yeah, I removed the WINAPI a while ago to see if it would make any difference, but adding it back in doesn't change anything.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

It definately belongs there. How does the full DLL code look like?
Sirmabus
Posts: 89
Joined: Fri May 28, 2004 6:20 pm

Post by Sirmabus »

Opps didn't check the forums for a while.

I think the biggest problem is the handling of the this/self pointer.

One way to troubleshoot is to use a kernel debugger like SoftIce. Just put a "_asm int 3;" in there and trace what happens.

Look for the post I made about DirectInput. I'll paste a little example I have working for DirectInput 7.
Post Reply