使用新参数再次调用函数

逆向工程 ollydbg C++ 函数挂钩
2021-07-02 06:44:21

我开发网络游戏。我有服务器的完整资源,但我使用的游戏客户端是闭源的,所以我需要在那里做一些逆向工程。所以 2 周以来,我一直在尝试正确调用 draw_rectangle 函数。在下图中,您可以看到来自 OLLY 的屏幕截图。有功能:

DRAW_BLACK_BAR(健康栏黑框),

DRAW_COLORED_BAR(里面的健康),

DRAW_NICK(已上钩)

在此处输入图片说明

CALL DWORD PTR DS:[EDX+14] 总是指向 0x4EB2F0

所以地址在调试器中包含该函数:

在此处输入图片说明

如您所见,堆栈中有参数,例如:Surface_id、位置、大小、颜色、指向生物的指针。

所以这是我的钩子:

superHook(dwHandle, 0x4C8C28, (unsigned int)newFunc); //instead of call print rectangle func for colored bar
 
void superHook(HANDLE dwHandle, int adr, unsigned int targetFunction)
{
    //its not normal CALL ADDR which takes 5 bytes (E8 + 4x bytes for address)
    //It is CALL DWORD PTR DS:[EDX+14] which takes 3bytes, so we will take more space
    //and we will rebuild the function
     
     
    // jmp to address +2x nop
    BYTE bytes[7] = { 0xE9, 0xFF, 0xFF, 0xFF, 0xFF, 0x90, 0x90};
    DWORD targetAddr = targetFunction - adr - 5;
    *(DWORD*)(bytes + 1) = targetAddr;
    WriteProcessMemory(dwHandle, (void *)adr, bytes, 7, NULL);
}
 
void newFunc()
{
    //Rebuild the function (Earsed commands to be able to put JMP address)
    __asm {
            MOV ECX, DWORD PTR SS : [EBP - 0x18]
            PUSH ESI
    }
 
    //Here I can access all the registers and stack before CALL will be executed
     
 
    //call draw rectangle
    __asm {
            CALL DWORD PTR DS : [EDX + 0x14]//always call 0x4EB2F0?
    }
 
 
    //go back
    __asm {
        PUSH 0x4C8C2F
            RET
    }
 
}

它工作正常,我可以访问堆栈上的参数并修改它们(更改颜色、大小、位置等)。但是我希望能够创建另一个矩形,例如下一个具有另一种颜色和位置的矩形。我尝试了很多组合,使用 params 调用 func 设置新堆栈,然后使用原始堆栈再次调用它,但我总是以客户端崩溃告终。

这是我尝试创建新电话 + 恢复旧电话的示例之一 https://pastebin.com/RUmaPGya(pastebin不会让这篇文章太长)

请帮忙:)

0个回答
没有发现任何回复~