All-
I'm trying to un protect some memory (in the DLL space w/in wow) by using VirtualQueryEx, then writing memory. But of course, I'm always receiving ERROR_INVALID_ADDRESS, even though I believe it's a valid memory address. My theory is that my app is 64-bit, and the wow process is 32-bit, and that's why there are some problems.
Although I will say I'll open cheat engine, view the address, and it tells me it's in a dll's memory space, but it's all question marks (probably b/c read isn't enabled on those pages?)
Anyone have any ideas which would allow me to do this?
Here is the code I'm trying:
Code:
[DllImport("kernel32", SetLastError = true)]
static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] Bytes, int dwSize, out int lpBytesWritten);
[DllImport("kernel32", SetLastError = true)]
internal static extern int VirtualProtectEx(IntPtr hProcess, IntPtr lpBaseAddress, int dwSize, uint newProtect, out uint oldProtect);
void PatchBytes(int Address, byte[] NewBytes)
{
uint OldProtect;
if (VirtualProtectEx(hProcess, new IntPtr(Address), NewBytes.Length, PAGE_READWRITE, out OldProtect) == 0)
{
Int32 error = Imports.GetLastError();
throw new Exception(String.Format("PatchBytes VirtualProtectEx Fail 1 {0:X} Error: {1}", Address, error));
}
WriteBytes(Address, NewBytes);
if (VirtualProtectEx(hProcess, new IntPtr(Address), NewBytes.Length, OldProtect, out OldProtect) == 0)
{
Int32 error = Imports.GetLastError();
throw new Exception(String.Format("PatchBytes VirtualProtectEx Fail 2 {0:X} Error: {1}", Address, error));
}
}
void WriteBytes(int Address, byte[] TheBytes)
{
int BytesWritten;
//Console.WriteLine("WriteBytes @ 0x" + Address.ToString("x") + " (0x" + TheBytes.Length.ToString("x") + " bytes)");
WriteProcessMemory(hProcess, new IntPtr(Address), TheBytes, TheBytes.Length, out BytesWritten);
}
Thanks in advance!
~ Tanaris