在调试并尝试解决这个问题几个小时之后,我正准备在放弃这个项目之前再次尝试解决这个问题。
鉴于以下代码,我尝试将 DLL 注入 Solitaire 以操纵分数,但它不起作用,应用程序在最终操纵时崩溃。
void SetGameTime(int time)
{
MessageBox(NULL, "Func just begins here - ", "Func start", MB_OK | MB_ICONHAND);
DWORD baseAddress = (DWORD) GetModuleHandle(0);
baseAddress = *(DWORD *) (baseAddress + BASE_OFS_DEF);
DWORD temp = *(DWORD *)(baseAddress + SCORE_OFS1_DEF);
DWORD temp2 = *(DWORD *)(temp + SCORE_OFS2_DEF);
*(DWORD*) temp2 = 500; // solitaire crashes right here
}
那么我做错了什么?我试图在使用产生的调试器时得到错误的逻辑,由于整个函数,'eax' 为 0。
调试器的输出:
SetGameTime(500);
703E1284 push 10h
703E1286 push 703E3170h
703E128B push 703E317Ch
703E1290 push 0
703E1292 call dword ptr ds:[703E30ACh] // GetModuleHandle operation (?)
703E1298 push 0
703E129A call dword ptr ds:[703E3000h] // base Address operation (?)
703E12A0 mov eax,dword ptr [eax+97074h] // eax keeps zero so the wrong function has to be GetModuleHandle?
703E12A6 mov eax,dword ptr [eax+2Ch] // first offset of score
703E12A9 mov eax,dword ptr [eax+10h] // and the second one...
703E12AC mov dword ptr [eax],1F4h // unhandled exception, no access to write at pos 0x00000000
return 0;