I've successfully reversed and patched an application on windows, but patching the executable on disk triggers a CRC check and prevents it from loading. I've used x64dbg and have the addresses I need (they are static and don't change on reruns). However, if the unmodified executable is already loaded and running, and then the patches are applied, everything will work fine. My question is how can I write a simple loader to patch those memory addresses after execution? I've been searching for this all over the Internet and can't get my head around it. The boiler plate codes I've found are giving me headaches as fixing the c++ code errors is so confusing.
Here is my code:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
using namespace std;
int main()
{
int newValue = 0x24;
uint8_t readTest;
byte num_char[16];
HWND hwnd = FindWindowA(NULL, "Playback password authentication");
if (hwnd == NULL)
{
cout << "Cannot find window" << endl;
Sleep(3000);
exit(-1);
}
else
{
DWORD procID;
GetWindowThreadProcessId(hwnd, &procID);
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
if (procID == NULL)
{
cout << "Cannot obtain process." << endl;
Sleep(3000);
exit(-1);
}
else
{
ReadProcessMemory(handle, (PBYTE*)0x0052BD7E, &num_char, sizeof(num_char), 0);
// WriteProcessMemory(handle, (LPVOID)0x0052BD7E, &newValue, sizeof(newValue), 0);
cout << num_char << endl;
Sleep(10000);
}
}
}
First I need the code to actually read and print the hex bytes at those addresses so I can make sure the addresses and their values are actually correct. If this returns the correct values, then I think I using WriteProcessMemory won't be that hard. But the problem is the values returned for my addresses are not those I expect and see in x64dbg.