I've been trying to mess with injection and I'm building a general DLL that will injects anything I want into an existing process. The objective is currently to achieve a custom screen size for the Conquer Online Client.
I currently have this piece of code:
Code: Select all
DWORD idProcess = GetCurrentProcessId();
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, idProcess);
if (hProcess)
{
const LPVOID BASE_W_ADDR = (LPVOID) (0x00469DEF + 6);
const LPVOID BASE_H_ADDR = (LPVOID) (0x00469DFC + 6);
int width = GetPrivateProfileIntA("GameResolution", "Width", 1024, CONFIG_FILE);
int height = GetPrivateProfileIntA("GameResolution", "Height", 768, CONFIG_FILE);
int read = 0;
SIZE_T bytes_read = 0, bytes_written = 0;
DWORD error = 0;
if (ReadProcessMemory(hProcess, BASE_W_ADDR, &read, 4, &bytes_read) || GetLastError() == ERROR_PARTIAL_COPY) {
if (bytes_read == 0)
MessageBoxA(NULL, "Could not get width memory offset.", "ReadProcessMemory error", MB_OK);
if (!WriteProcessMemory(hProcess, BASE_W_ADDR, (LPCVOID)width, 4, &bytes_written))
MessageBoxA(NULL, "Could not write to width memory offset.", "WriteProcessMemory error", MB_OK);
error = GetLastError();
if (error != 0)
{
sprintf_s(msg, "Error writing to memory! %d" , error);
MessageBoxA(NULL, msg, "WriteProcessMemory error", MB_OK);
}
else
{
sprintf_s(msg, "Width edited with success! :D Old X: %d", read);
MessageBoxA(NULL, msg, "Success?", MB_OK);
}
error = 0;
}
if (ReadProcessMemory(hProcess, BASE_H_ADDR, &read, 4, &bytes_read) || GetLastError() == ERROR_PARTIAL_COPY) {
if (bytes_read == 0)
MessageBoxA(NULL, "Could not get height memory offset.", "ReadProcessMemory error", MB_OK);
if (!WriteProcessMemory(hProcess, BASE_H_ADDR, (LPCVOID)height, 4, &bytes_written))
MessageBoxA(NULL, "Could not write to height memory offset.", "WriteProcessMemory error", MB_OK);
error = GetLastError();
if (error != 0)
{
sprintf_s(msg, "Error writing to memory! %d", error);
MessageBoxA(NULL, msg, "WriteProcessMemory error", MB_OK);
}
else
{
sprintf_s(msg, "Height edited with success! :D Old X: %d", read);
MessageBoxA(NULL, msg, "Success?", MB_OK);
}
}
}
Any lights on this?