我正在做一些逆向工程,我有一个程序,上面有一个全局定义的类指针。
#include <includesandsuch.h>
myclass* g_Class = NULL;
int WinMain( ... )
{
  g_Class = new myclass(0);
}
在我的类上,有一个我想从 dll 调用的方法,我尝试了一个函数原型,使用__thiscall它可以工作,但类this将为 0,因此由于该方法写入类成员数据而导致程序崩溃。现在,我想出了一个可行的解决方案,将其视为 SSCE 或在本例中为 SLCE。
DWORD* g_Input = 0;
void* operator new(size_t sz)
{
    cout << "mynew" << endl; //yes i'm using (using namespace std;) but please focus on the issue
    g_Input = (DWORD*)::new char [sz];
    return g_Input;
}
void *operator new [](size_t size)
{
    // if (size > MAX_SIZE) ...
    cout << "mynew" << endl;
    return malloc(size);
}
class ZInput
{
public:
    ZInput( int n );
    ~ZInput(){};
    void CallMe( int n, DWORD b );
private:
    int m_nData;
};
ZInput::ZInput( int n ){
    m_nData = n;
}
void ZInput::CallMe( int n, DWORD b ) { 
    cout << n <<" "<< b << endl;
}
void Fake_RealSpace2_Input( int n, DWORD b )
{
    __asm
    {
        mov ecx, g_Input
        mov eax, 0x012C7310 //example address of ZInput::CallMe
        push n
        push b
        call eax
    }
}
int _tmain(int argc, _TCHAR* argv[])
{
    ZInput* pInput = new ZInput(2);
    cout << pInput << endl;
    cout << g_Input << endl;
    Fake_RealSpace2_Input(4,5 );
    delete pInput;
    return 0;
}
这样我就可以成功地调用ZInput::CallMe一个有效的ZInput类对象。
现在我的问题是我想将此代码移植到 DLL,并ZInput::CallMe从那里调用(ZInput 类在主应用程序上,我想从 dll 调用它),因为我有CallMe我只需要的地址g_Class(的地址g_Class在主应用程序上,并且在主应用程序上WinMaing_Class 指针将指向new堆分配的对象),问题是我不能从 dll 重载 operator new ,原因很明显。假设在主应用程序g_Class上是唯一使用的数据类型,new我怎样才能找到g_Class指向我的 dll 的地址?