C++ 钩住游戏的IAT功能

C++ 钩住游戏的IAT功能,c++,hook,portable-executable,C++,Hook,Portable Executable,我在胡闹一些dll注入/挂钩。 我已经尝试在我自己的应用程序中挂接IAT的睡眠功能,它工作得非常好,但后来我尝试在一个电脑游戏中挂接IAT的睡眠功能,结果却失败了 由于我插入了一个dll,并从dll中钩住了可执行模块的IAT,因此我看不到错误(日志),但我将错误锁定到了这一部分,它在IAT上迭代: while (impDesc->FirstThunk) { auto thunkData = getMemoryPointer<IMAGE_THUNK_DATA>((LPVO

我在胡闹一些dll注入/挂钩。 我已经尝试在我自己的应用程序中挂接IAT的睡眠功能,它工作得非常好,但后来我尝试在一个电脑游戏中挂接IAT的睡眠功能,结果却失败了

由于我插入了一个dll,并从dll中钩住了可执行模块的IAT,因此我看不到错误(日志),但我将错误锁定到了这一部分,它在IAT上迭代:

while (impDesc->FirstThunk) {
    auto thunkData = getMemoryPointer<IMAGE_THUNK_DATA>((LPVOID)(baseAddress + impDesc->OriginalFirstThunk));
    int n = 0;

    while (thunkData->u1.Function) {
        char* importFuncName = getMemoryPointer<char>((LPVOID)(baseAddress + (DWORD)thunkData->u1.AddressOfData + 2));  //the function name is stored at .AddressOfData + 2
        if (strcmp(importFuncName, funcName) == 0) {
            auto vfTable = getMemoryPointer<DWORD>((LPVOID)(baseAddress + impDesc->FirstThunk));
            DWORD original = vfTable[n];
            auto oldProtection = protectMemory<DWORD>((LPVOID)&vfTable[n], PAGE_READWRITE);
            vfTable[n] = newFunc;
            protectMemory<DWORD>((LPVOID)&vfTable[n], oldProtection);
            return original;
        }
        n++;
        thunkData++;
    }
    impDesc++;
}
while(impDesc->FirstThunk){
auto-thunkData=getMemoryPointer((LPVOID)(baseAddress+impDesc->OriginalFirstThunk));
int n=0;
同时(thunkData->u1.函数){
char*importFuncName=getMemoryPointer((LPVOID)(baseAddress+(DWORD)thunkData->u1.AddressOfData+2));//函数名存储在.AddressOfData+2
if(strcmp(importFuncName,funcName)==0){
自动vfTable=getMemoryPointer((LPVOID)(baseAddress+impDesc->FirstThunk));
DWORD original=vfTable[n];
auto-oldProtection=protectMemory((LPVOID)&vfTable[n],页\读写);
vfTable[n]=newFunc;
protectMemory((LPVOID)和vfTable[n],oldProtection);
归还原件;
}
n++;
thunkData++;
}
impDesc++;
}
执行第一个循环之前和中的代码,也执行第二个循环中的代码。但是if永远不会被调用,循环之后的代码也永远不会被调用,所以不知怎么的,代码会在其中一个循环中中断,但我不知道如何或者为什么

我已经尝试过检查impDesc或thunkData是否为NULL,但这两种情况都不会执行。我想从IAT中获得的功能是睡眠功能

有人知道为什么这个循环会中断吗?因为我在我自己的应用程序上测试了它,它在那里工作得很好

这就是impDesc:

auto impDesc = getMemoryPointer<IMAGE_IMPORT_DESCRIPTOR>((LPVOID)(baseAddress + IAT.VirtualAddress));
auto-impDesc=getMemoryPointer((LPVOID)(基地址+IAT.VirtualAddress));
编辑:在thunkData->u1崩溃之前,我发现它的地址是8000000 E。因此它在thunkData->u1.Function或char*importFuncName=getMemoryPointer时崩溃。。。当u1的值为8000000e时。为什么

编辑2: 好的,我按照建议更新while循环以忽略序数。以下是更新版本:

while (impDesc->FirstThunk) {
    IMAGE_THUNK_DATA* thunkData = getMemoryPointer<IMAGE_THUNK_DATA>((LPVOID)(baseAddress + impDesc->OriginalFirstThunk));
    int n = 0;

    while (thunkData->u1.Function) {
        if (IMAGE_SNAP_BY_ORDINAL(thunkData->u1.Function)) {
            n++;
            thunkData++;
            continue;
        }

        auto importFuncName = getMemoryPointer<char>((LPVOID)(baseAddress + (DWORD)thunkData->u1.AddressOfData + 2));   //the function name is stored at .AddressOfData + 2
        if (strcmp(importFuncName, funcName) == 0) {
            auto vfTable = getMemoryPointer<DWORD>((LPVOID)(baseAddress + impDesc->FirstThunk));
            DWORD original = vfTable[n];
            auto oldProtection = protectMemory<DWORD>((LPVOID)&vfTable[n], PAGE_EXECUTE_READWRITE);
            vfTable[n] = newFunc;
            protectMemory<DWORD>((LPVOID)&vfTable[n], oldProtection);
            return original;
        }
        n++;
        thunkData++;
    }
    impDesc++;
}
while(impDesc->FirstThunk){
IMAGE_THUNK_DATA*thunkData=getMemoryPointer((LPVOID)(baseAddress+impDesc->OriginalFirstThunk));
int n=0;
同时(thunkData->u1.函数){
if(图像按顺序捕捉(thunkData->u1.Function)){
n++;
thunkData++;
继续;
}
auto-importFuncName=getMemoryPointer((LPVOID)(baseAddress+(DWORD)thunkData->u1.AddressOfData+2));//函数名存储在.AddressOfData+2
if(strcmp(importFuncName,funcName)==0){
自动vfTable=getMemoryPointer((LPVOID)(baseAddress+impDesc->FirstThunk));
DWORD original=vfTable[n];
auto-oldProtection=protectMemory((LPVOID)&vfTable[n],第页\u执行\u读写);
vfTable[n]=newFunc;
protectMemory((LPVOID)和vfTable[n],oldProtection);
归还原件;
}
n++;
thunkData++;
}
impDesc++;
}
但现在它在这两条线之间的某个地方崩溃了:

auto oldProtection = protectMemory<DWORD>((LPVOID)&vfTable[n], PAGE_EXECUTE_READWRITE);
vfTable[n] = newFunc;
protectMemory<DWORD>((LPVOID)&vfTable[n], oldProtection);
auto-oldProtection=protectMemory((LPVOID)&vfTable[n],PAGE\u EXECUTE\u READWRITE);
vfTable[n]=newFunc;
protectMemory((LPVOID)和vfTable[n],oldProtection);
至少我现在可以在IAT中找到睡眠功能:) 但不知何故,我不能用我的函数来代替它。有人知道为什么吗?
当我为自己的应用程序执行此操作时,它仍在工作

8000000 e-这是顺序。函数可以按名称或顺序导入。你需要使用
如果(!IMAGE\u SNAP\u BY_ORDINAL(thunkData->u1.Function)){…}
谢谢,我会尝试:)我会在测试后立即更新你。如何导入序号?比如如果图片按顺序(打印名称))@RbMm更新了我的答案:)800000E-这是顺序。函数可以按名称或顺序导入。你需要使用
如果(!IMAGE\u SNAP\u BY_ORDINAL(thunkData->u1.Function)){…}
谢谢,我会尝试:)我会在测试后立即更新你。如何导入序号?比如,如果图像按顺序(打印名称)捕捉@RbMm更新了我的答案:)