代码之家  ›  专栏  ›  技术社区  ›  Burak Tamtürk

指向未知类函数的任意指针-类型转换无效

  •  0
  • Burak Tamtürk  · 技术社区  · 15 年前

    我有一个黑客程序;它向目标进程中注入一些函数来控制它。程序用C++编写,内嵌汇编。

    class GameProcMain {
     // this just a class
    };
    
    GameProcMain* mainproc; // there is no problem I can do =(GameProcMain*)0xC1EA90
    

    现在我想定义一个类函数(将ecx设置为类指针),而不是编写程序集。

    PPLYDATA GetNearblyMob(__Vector3* cordinate) {
        __asm {
        mov ecx, 0xC1EA90
        enter code here
        push cordinate
        mov edi, 0x4A8010
        call edi
        }
    }
    

    我想给它下个定义,这样称呼它。

    PPLYDATA (DLPL::*GetNearblyMob)(__Vector3* cordinate);
    
    mainproc->GetNearblyMob(ADDR_CHRB->kordinat)
    

    GetNearblyMob=(PPLYDATA (DLPL::*)(__Vector3*)) 0x4A8010;

    error: invalid type conversion: "int" to "PPLYDATA (DLPL::*)(int, int)"

    但我可以这样设置指针:

    void initializeHack() {
    __asm {
    LEA edi, GetNearblyMob
    MOV eax, 0x4A8010
    MOV [edi], eax
    }
    }
    

    2 回复  |  直到 15 年前
        1
  •  1
  •   Potatoswatter    15 年前

    this 指针。有时您可以在成员函数和非成员函数之间进行强制转换,但我认为没有必要强制转换任何函数。

    所以,我建议

    PPLYDATA (*GetNearblyMob)(DLPL *main_obj, __Vector3* cordinate) = 0x12345UL;
    

    然后定义自己的函数

    class DLPL {
        GetNearblyMob( __Vector3* cordinate ) {
            return ::GetNearblyMob( this, cordinate );
        }
        // ... other program functions
    };
    
        2
  •  1
  •   Eugene Smith    15 年前

    我有点惊讶,你不会那样投的。

    你可以试着做一些

    GetNearblyMob=reinterpret_cast<PPLYDATA (DLPL::*)(__Vector3*)> (0x4A8010);
    

    如果仍然不起作用,试试看

    *(int*)(&GetNearblyMob) = 0x4A8010;