之前我没接触过 detuor hook
我看了个HOOK CreateFile 的一个实例 如下:static HANDLE (WINAPI *SysCreateFile)(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
)=CreateFileA;
HANDLE _stdcall HookCreateFileA(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
)
{
::MessageBox(NULL,"拦截成功",0,MB_OK);
return 0;
}
WinMain(....)
{
.......
DetourAttach(&(PVOID &)SysCreateFile,HookCreateFileA);
.....
}大致如上
这是一个HOOK CreateFileA 的一个实例 CreateFileA 是一个系统API函数
而我想HOOK 一个类的函数
比如 IDirect3D9* d3d9 = 0;
d3d9->CreateDevice(....)
我想HOOK CreateDevice 这函数 我就不知道怎么做了...求高手帮忙解答 万分感激
上面那个D3D9->CreateDevice (是一个D3D编程里面的函数)分是少了点 没办法╮(╯▽╰)╭ 我只剩下这么一点了
我看了个HOOK CreateFile 的一个实例 如下:static HANDLE (WINAPI *SysCreateFile)(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
)=CreateFileA;
HANDLE _stdcall HookCreateFileA(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
)
{
::MessageBox(NULL,"拦截成功",0,MB_OK);
return 0;
}
WinMain(....)
{
.......
DetourAttach(&(PVOID &)SysCreateFile,HookCreateFileA);
.....
}大致如上
这是一个HOOK CreateFileA 的一个实例 CreateFileA 是一个系统API函数
而我想HOOK 一个类的函数
比如 IDirect3D9* d3d9 = 0;
d3d9->CreateDevice(....)
我想HOOK CreateDevice 这函数 我就不知道怎么做了...求高手帮忙解答 万分感激
上面那个D3D9->CreateDevice (是一个D3D编程里面的函数)分是少了点 没办法╮(╯▽╰)╭ 我只剩下这么一点了
IDirect3D9* d3d9 = ...;
(void*)&d3d9->CreateDevice = new_fun;大约这样就可以了。楼主可以试验试验。
*(void*)&d3d9->CreateDevice = new_fun;
UINT Adapter,
D3DDEVTYPE DeviceType,
HWND hFocusWindow,
DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS * pPresentationParameters,
IDirect3DDevice9 ** ppReturnedDeviceInterface
IDirect3D9* d3d9 = ...;
(void*)&d3d9->CreateDevice = SysCreateDevice;);
这样吗?
执行d3d9->CreateDevice 会执行 new_fun 还是detuor hook吧 呵呵声明一个 IDirect3D9::CreateDevice 的指针 但是通不过编译ingstatic HRESULT (IDirect3D9:: *SysCreateDevice)(
UINT Adapter,
D3DDEVTYPE DeviceType,
HWND hFocusWindow,
DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS * pPresentationParameters,
IDirect3DDevice9 ** ppReturnedDeviceInterface
)=IDirect3D9::CreateDevice;
也不知哪里错了
C:\1\hxwdllwx\hxwdllwx.cpp(24) : error C2440: 'initializing' : cannot convert from 'long (__stdcall IDirect3D9::*)(unsigned int,enum _D3DDEVTYPE,struct HWND__ *,unsigned long,struct _D3DPRESENT_PARAMETERS_ *,struct IDirect3DDevice9 ** )' to 'long (_
_thiscall IDirect3D9::*)(unsigned int,enum _D3DDEVTYPE,struct HWND__ *,unsigned long,struct _D3DPRESENT_PARAMETERS_ *,struct IDirect3DDevice9 ** )'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.
我不知怎么声明了static HRESULT (WINAPI *SysCreateDevice)(
UINT Adapter,
D3DDEVTYPE DeviceType,
HWND hFocusWindow,
DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS * pPresentationParameters,
IDirect3DDevice9 ** ppReturnedDeviceInterface
)=IDirect3D9::CreateDevice;//这样通不过编译
声明指向IDirect3D9::CreateDevice的指针