1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
HANDLE getProcessHandle(char* name){
//Given a window name, returns the process handle of that window.
//If it fails, returns NULL.
HWND hwnd = FindWindow(NULL, name);
if (hwnd == NULL)
{
return NULL;
}
LPDWORD bar;
GetWindowThreadProcessId(hwnd, bar);
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, *bar);
if (processHandle == NULL){
std::cout << "\ncouldn't get processHandle";
}
return processHandle;
}
WORD peek(HANDLE processHandle, unsigned long address){
//reads the value of the memory at the address.
WORD memContents = 0;
SIZE_T numberOfBytesRead;
if(!ReadProcessMemory(processHandle, (LPVOID)address, &memContents, 1, &numberOfBytesRead)){
return NULL;
}
return memContents;
}
bool poke(HANDLE processHandle, unsigned long address, char value){
//sets the value of the memory at the address.
SIZE_T numberOfBytesWritten;
if(!WriteProcessMemory(processHandle, (LPVOID)address, &value, 1, &numberOfBytesWritten)){return 0;}
else{return 1;}
}
|