Need Help with Trainer
I am making a trainer for Super Meat Boy in C++ and it is crashing. It does however work if I fill the code I am patching with nop's. I am trying to set the time to 1 on the level, however that causes it to crash. I have the code jumping from the place I patch to memory I allocated in the process. And I have it execute the code to make the time go to 1 and I jump back.
Since it works when I write the nop's, I think that's the right place and my write function is working. I'm thinking that it maybe my jump function that isn't working. Can you guys see where I am going wrong?
So here's the line I am replacing:
D99E7C030000 OR fstp DWORD PTR [esi+0x37c] which is at SuperMeatBoy + DD78
Since it works when I write the nop's, I think that's the right place and my write function is working. I'm thinking that it maybe my jump function that isn't working. Can you guys see where I am going wrong?
So here's the line I am replacing:
D99E7C030000 OR fstp DWORD PTR [esi+0x37c] which is at SuperMeatBoy + DD78
Code:
void timeChanger(Process *stuff, procInfo info) {
BYTE readBytes[16];
BYTE nop[6] = {0};
BYTE original[] = {0xD9, 0x9E, 0x7C, 0x03, 0x00, 0x00}; // D99E7C030000 OR fstp DWORD PTR [esi+0x37c]
BYTE timeBuffer[] = {0xC7, 0x86, 0x7C, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; // C7867C03000001000000 OR mov DWORD PTR [esi+0x37c],0x1
ExAddress space = (DWORD)VirtualAllocEx(info.hProcess, NULL, 50, MEM_COMMIT, PAGE_EXECUTE_READ);
/*if (GetAsyncKeyState(VK_F1))
stuff->Write(info.baseAddr + 0xDD78, nop, 6); // this write works
else if (GetAsyncKeyState(VK_F2))
stuff->Write(info.baseAddr + 0xDD78, original, 6);
//DWORD key = stuff->exUnProtect(info.baseAddr + 0xDD78, 6);
stuff->Write(space, timeBuffer, 6); // My code I run in new space
stuff->writeJump(space + 6, info.baseAddr + 0xDD7E); // jump back 6 bytes ahead of first
stuff->writeJump(info.baseAddr + 0xDD78, space);*/ // jump to space. 0xDD78 is where fstp DWORD PTR [esi+0x37c] is.
//stuff->exProtect(info.baseAddr + 0xDD78, 6, key);
}
Code:
void Process::writeJump(DWORD address, DWORD destination) {
BYTE buffer[4];
BYTE jump[2] = {0xFF, 0x25};
addrToLittleEndian(destination, buffer);
BYTE fullJump[6] = {jump[0], jump[1], buffer[0], buffer[1], buffer[2], buffer[3]};
if (!WriteProcessMemory(info.hProcess, (LPVOID)address, fullJump, 6, NULL))
cout << "Failed jmp write. Error: " << GetLastError << endl;
}
Code:
void Process::addrToLittleEndian(DWORD address, BYTE* buffer) {
DWORD bitMask = {0x000000FF};
for (int i = 0; i < 4; ++i) {
buffer[i] = (BYTE)((address & bitMask) >> i*8);
bitMask <<= 8;
}
