函数指针-DInput8.dll挂钩代码的参数用途
Function pointer - purpose of argument for DInput8.dll hook code
我一直在试图弄清楚DirectInput8挂钩项目中一个参数的用途。我在这里生成一些开源代码。为了简洁起见,我只发布了几个函数。
ULONG oldCreateDevice;
HRESULT WINAPI xCreateDevice(DWORD d1, DWORD d2, DWORD d3, DWORD d4)
{
HRESULT hr = ((HRESULT(WINAPI*)(DWORD,DWORD,DWORD,DWORD))oldCreateDevice)(d1,d2,d3,d4);
// hook only if keyboard requested
if(*(DWORD*)d2 != GUID_SysKeyboard)
return hr;
DWORD dwKeybTable = *(DWORD*)(*(DWORD*)d3);
DWORD oldprot;
VirtualProtect((LPVOID)dwKeybTable, 0x2C, PAGE_EXECUTE_READWRITE, &oldprot);
// already hooked?
if((DWORD)xGetDeviceState == *((DWORD*)(dwKeybTable+0x24))) goto ex1;
// hook it!
oldGetDeviceState = *((DWORD*)(dwKeybTable+0x24));
*((DWORD*)(dwKeybTable+0x24)) = (DWORD)xGetDeviceState;
ex1:
// already hooked?
if((DWORD)xGetDeviceData == *((DWORD*)(dwKeybTable+0x28))) goto ex2;
// hook it!
oldGetDeviceData = *((DWORD*)(dwKeybTable+0x28));
*((DWORD*)(dwKeybTable+0x28)) = (DWORD)xGetDeviceData;
ex2:
return hr;
}
ULONG oldDirectInput8Create;
HRESULT WINAPI xDirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, VOID **ppvOut, LPUNKNOWN punkOuter)
{
HRESULT ret = ((HRESULT(WINAPI*)(HINSTANCE,DWORD,REFIID,VOID**,LPUNKNOWN))oldDirectInput8Create)(hinst,dwVersion,riidltf,ppvOut,punkOuter);
DWORD dwFuncTable = (DWORD)*((DWORD*)*ppvOut);
DWORD oldprot;
VirtualProtect((LPVOID)dwFuncTable, 0x10, PAGE_EXECUTE_READWRITE, &oldprot);
//already hooked?
if((DWORD)xCreateDevice == *((DWORD*)(dwFuncTable + 0x0C))) goto ex;
//hook it
oldCreateDevice = *((DWORD*)(dwFuncTable + 0x0C));
*((DWORD*)(dwFuncTable + 0x0C)) = (DWORD)xCreateDevice;
ex:
return ret;
}
DWORD WINAPI RemoteMain(LPVOID lpParam)
{
LoadLibrary("user32.dll");
LoadLibrary("advapi32.dll");
Splice_Init();
Splice((ULONG)GetProcAddress(LoadLibrary("dinput8.dll"),"DirectInput8Create"), xDirectInput8Create, &oldDirectInput8Create);
ThreadControl(FALSE); // resume all
return 0;
}
正如您可能注意到的那样,代码正在用重定向的(挂钩的)函数替换函数。我的问题是xCreateDevice函数中的第一个参数根据我所了解的文档,对于DirectInput8,CreateDevice函数占用了3个参数。但我不确定为什么在这里使用4个参数。它是否指向原来的"oldCreateDevice"?还是别的什么?
我希望有人能指导我。感谢
它是一个接口(类)非静态方法,所以第一个参数是this指针(指向类实例的指针)。
这个(维基百科)
此(MSDN)
相关文章:
- 如何使基类的运算符对基类的可变参数数可见(请参阅下面的代码)?
- 根据编译时参数在 C 中重复代码
- 扩展C++生成的代码的模板参数类型名称
- 将函数作为参数传递以避免重复代码
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++基于输入参数的动态代码生成
- 调用参数不是原子参数的函数是此代码引发异常的原因吗?
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- 在 Metal 着色器代码中,如何定义函数的 in/out 参数变量?
- C++17.处理使用 auto 相关的模板参数.代码排序困难
- 为什么EclipseCDT代码格式化程序有时会在模板参数中引入空格
- 我写了一个类,它总是将其函数参数委托给它的成员,我该如何改进代码
- 编译器是否C++具有相同模板参数集的每个模板类实例生成代码?
- 如何将char数组声明为函数参数?或告诉我此代码中还有其他问题?
- 我的代码在作为参数传入 .begin() 时不起作用,但在我将 .begin() 转换为迭代器后工作
- 如何基于构造函数参数模板化类成员函数的代码
- 在存在错误代码的情况下输出参数与 NRVO
- 在完美转发函数中公开参数类型,避免代码重复
- 中断长代码 snprintf 格式和参数
- 使用 const double* const 作为模板参数 - 代码性能问题