LPVOID konvertieren in char[]?
-
Hallo
ich programmiere Trainer für PC Games und habe ein Problem mit dem Konvertieren von LPVOID ein eine Zeichenkette. Ich benötige in der Funktion TrainerBegin() einen Vergleich zwischen den in "readbuf" gespeicherten Werten und Hack[0].defbytes. Das Programm funktioniert zwar auch so ist aber relativ unsicher, weil wenn jemand eine andere Spielversion benutzt für die der Trainer nicht ausgelegt ist werden willkürlich die Hack[0].hackbytes werte in den Prozess geschrieben ohne -> Spiel würde warscheinlich abstürzen.
// Godmodehack TrainerStoreHack(0, 0x049c0ab8,"\x90\x90\x90\x90\x90\x90","\x89\x86\x10\x02\x00\x00", 0x049cc5c9,"\x90\x90\x90\x90\x90\x90","\x89\x87\x10\x02\x00\x00", 0,0,0);#include <windows.h> #include "Trainer.h" HWND Wnd; HANDLE Hproc; bool TrainerInitdone=false; struct SHack { DWORD addr1; DWORD addr2; DWORD addr3; LPVOID hackbytes1; // Die manipulierten Werte LPVOID hackbytes2; LPVOID hackbytes3; LPVOID defbytes1; // In Defbytes stehen die Originalwerte aus dem Spiel LPVOID defbytes2; LPVOID defbytes3; }; SHack Hack[16]; void TrainerStoreHack(int array_nr, DWORD processmemoryadr1, LPVOID enablebytes1, LPVOID disablebytes1, DWORD processmemoryadr2, LPVOID enablebytes2, LPVOID disablebytes2, DWORD processmemoryadr3, LPVOID enablebytes3, LPVOID disablebytes3) { Hack[array_nr].addr1=processmemoryadr1; Hack[array_nr].hackbytes1=enablebytes1; Hack[array_nr].defbytes1=disablebytes1; Hack[array_nr].addr2=processmemoryadr2; Hack[array_nr].hackbytes2=enablebytes2; Hack[array_nr].defbytes2=disablebytes2; Hack[array_nr].addr3=processmemoryadr3; Hack[array_nr].hackbytes3=enablebytes3; Hack[array_nr].defbytes3=disablebytes3; } int TrainerBegin(char *proc) { Wnd = FindWindow(NULL, proc); // retrieves a handle to the top-level window with the name 'proc' and store it in 'Wnd' if (Wnd) // If no window was found Wnd will be 0, return 0 { LPDWORD PID; if (GetWindowThreadProcessId(Wnd,(LPDWORD) &PID)) // retrieves identifier of the process that created the specified window (stored in PID) { Hproc= OpenProcess(PROCESS_ALL_ACCESS,NULL,(DWORD)PID); // get handle to the process if(Hproc) // If no process was found the handle will be 0, return 0 { LPVOID readbuf=0; if (!ReadProcessMemory(Hproc, (void*)Hack[0].addr1, &readbuf, 6,0) ) // read 0x049c0ab8, ["\x89\x86\x10\x02\x00\x00"] { MessageBox(0,"ReadProcessMemory() failed",errmsg,MB_OK); CloseHandle(Hproc); return 0; } // HIER BRAUCHE ICH EINEN VERGLEICH readbuf / Hack[0].defbytes1 // if (*readbuf* == *Hack[0].defbytes1) // { // TrainerInitdone=true; // return 1; // } } else { TrainerInitdone=false; MessageBox(0,"OpenProcess() failed",errmsg,MB_OK); return 0; } } else { TrainerInitdone=false; MessageBox(0,"GetWindowThreadProcessId() failed",errmsg,MB_OK); return 0; } } else { TrainerInitdone=false; MessageBox(0,"FindWindow() failed - did you start the game?",errmsg,MB_OK); return 0; } return 0; } void TrainerEnd() { if(Hproc) // did we have a handle? CloseHandle(Hproc); } bool TrainerWrite(DWORD addr, LPVOID newbyte) { if(Hproc) // If no process was found the handle will be 0, return 0 { bool suspended=false; if (SuspendThread(Hproc) != (DWORD) -1) // try to stop Thread - it is safer suspended=true; // on succes save this to suspended DWORD nbyte=strlen((char*)newbyte); // by checking our string 'newbyte' we can find out how many bytes we want to write FlushInstructionCache(Hproc, (LPVOID)addr , nbyte); // flush the instruction cache (for safety) DWORD ByteWriten; if ( (WriteProcessMemory (Hproc, (LPVOID)addr, newbyte, nbyte, &ByteWriten)) && ByteWriten == nbyte) // write to process { if(suspended) // If we have suspended our thread... ResumeThread(Hproc); // ...resume it return true; } else { MessageBox(0,"WriteProcessMemory () failed",errmsg,MB_OK); return false; } } MessageBox(0,"Hproc invalid",errmsg,MB_OK); return false; } bool TrainerEnableHack(int nhack) { bool status=false; if (Hack[nhack].addr1!=0) { if (!TrainerWrite(Hack[nhack].addr1, Hack[nhack].hackbytes1)) return status; } if (Hack[nhack].addr2!=0) { if(!TrainerWrite(Hack[nhack].addr2, Hack[nhack].hackbytes2)) return status; } if (Hack[nhack].addr3!=0) { if(!TrainerWrite(Hack[nhack].addr3, Hack[nhack].hackbytes3)) return status; } return status; } bool TrainerDisableHack(int nhack) { bool status=false; if (Hack[nhack].addr1!=0) { TrainerWrite(Hack[nhack].addr1, Hack[nhack].defbytes1); } if (Hack[nhack].addr2!=0) TrainerWrite(Hack[nhack].addr2, Hack[nhack].defbytes2); if (Hack[nhack].addr3!=0) TrainerWrite(Hack[nhack].addr3, Hack[nhack].defbytes3); return status; }