View previous topic :: View next topic |
Author |
Message |
legoblock How do I cheat?
Reputation: 0
Joined: 01 Jun 2011 Posts: 9
|
Posted: Thu Jun 02, 2011 6:36 pm Post subject: Hooking a class function? |
|
|
Specifically I would like to hook IDirect3DDevice9::BeginScene.
Here is (basically) the code I have so far, using Microsoft Detours.
Code: | #include "RenderHook.h"
#include "DetourManager.h"
HRESULT (WINAPI IDirect3DDevice9::* _BeginScene)() = &IDirect3DDevice9::BeginScene;
HRESULT __fastcall BeginSceneHook(IDirect3DDevice9* This)
{
UNREFERENCED_PARAMETER(This);
// return success without actually beginning scene to stop rendering (?)
return D3D_OK;
}
BOOL HookRendering(__in BOOL bSet)
{
return ((bSet ? AttachDetour : DetachDetour)(reinterpret_cast<PVOID*>(_BeginScene), BeginSceneHook));
} |
So apparently I can't cast pointers to class functions to any other type of pointer (e.g. void*, etc.) so I can't really hook it at all. Is there another method altogether of doing this? I've heard classes are really just pointers to their methods, is there a way of changing that pointer to point to my function?
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jun 02, 2011 7:53 pm Post subject: |
|
|
that cast is undefined behavior i think.
the easy way is to just create a non member function as a wrapper and pass that.
|
|
Back to top |
|
 |
legoblock How do I cheat?
Reputation: 0
Joined: 01 Jun 2011 Posts: 9
|
Posted: Thu Jun 02, 2011 8:51 pm Post subject: |
|
|
But then how can I hook it?
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jun 02, 2011 9:00 pm Post subject: |
|
|
wrap the member function in another function and pass the instance of the class to your function wrapper function and use that as the function that you pass to the detour.
snort.
i've never used the detours library so i'm running on the assumption that you'll need to do something similar to using a member function for CreateThread()
|
|
Back to top |
|
 |
legoblock How do I cheat?
Reputation: 0
Joined: 01 Jun 2011 Posts: 9
|
Posted: Thu Jun 02, 2011 9:41 pm Post subject: |
|
|
No like, I have to pass the address of the function I want to hook. If I do that, won't my wrapper function get hooked instead?
EDIT: Apparently I needed to use the class' vtable. It's all good, thanks! (can't post the link that helped me yet)
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Jun 03, 2011 1:20 pm Post subject: |
|
|
Keep in mind Direct3D API uses __stdcall for almost all of its definitions, you need to follow their conventions or you will run into issues.
If you want to hook just a single specific function, obtain the vtable pointer for the device and overwrite the vtables pointer for that function at the proper offset. If you still need more assistance, there are quiet a few threads over on GameDeception that cover this. I would recommend not posting for help there though as you will land up just getting flamed.
_________________
- Retired. |
|
Back to top |
|
 |
|