Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

ReadProcessMemory and WriteProcessMemory

in my scenario I do want the task manager to reflect the change :) Anyway I have a way around that. If I can get it working on 64bit I have a workable solution. Tried with "AnyCPU" compiling, no luck, fails to write back change as before. When you say need 64 bit address, what part of the code is 32 bit specific?

Thanks
(Oct 16, 2019 12:02 PM)ProtectedOverride Wrote:  in my scenario I do want the task manager to reflect the change :) Anyway I have a way around that. If I can get it working on 64bit I have a workable solution. Tried with "AnyCPU" compiling, no luck, fails to write back change as before. When you say need 64 bit address, what part of the code is 32 bit specific?

Thanks

What changes from x86 to x64 is offsets from PEB base address since different data types are used and so IntPtr size is 8 instead of 4

like here :

Code
if (!ReadProcessMemory(hProcess, peb + 0x10, (IntPtr)(&rtlUserProcParamsAddress), Marshal.SizeOf(typeof(IntPtr)), out intOutput))

Take a look at this website : https://www.geoffchappell.com/studies/wi.../index.htm


peb + 0x10 would become peb + 0x20

Regards,
Paskowsky 🤝
(Oct 16, 2019 12:44 PM)Paskowsky Wrote:  What changes from x86 to x64 is offsets from PEB base address since different data types are used and so IntPtr size is 8 instead of 4

like here :

Code
if (!ReadProcessMemory(hProcess, peb + 0x10, (IntPtr)(&rtlUserProcParamsAddress), Marshal.SizeOf(typeof(IntPtr)), out intOutput))

Take a look at this website : https://www.geoffchappell.com/studies/windows/win32/ntdll/structs/peb/index.htm


peb + 0x10 would become peb + 0x20

Regards,
Paskowsky 🤝

Thank you @Paskowsky, this has helped a lot, made some progress but having trouble allocting memory in 64bit process, presumably I need to change this:

/* allocate memory for Input /
Current_ImageBase.Length = (ushort)(input.Length
2);
pNewAddr = VirtualAllocEx(hProcess, IntPtr.Zero, Current_ImageBase.Length, /* AllocationType.Commit / 0x1000 | / AllocationType.Reserve / 0x2000, / MemoryProtection.ExecuteReadWrite */ 0x40);
if (pNewAddr == IntPtr.Zero)
{
Console.WriteLine("ERROR: Could not allocate memory in target process.\n");
return false;
}
(Oct 16, 2019 02:52 PM)ProtectedOverride Wrote:  Thank you @Paskowsky, this has helped a lot, made some progress but having trouble allocting memory in 64bit process, presumably I need to change this:

/* allocate memory for Input /
           Current_ImageBase.Length = (ushort)(input.Length
2);
           pNewAddr = VirtualAllocEx(hProcess, IntPtr.Zero, Current_ImageBase.Length, /* AllocationType.Commit / 0x1000 | / AllocationType.Reserve / 0x2000, / MemoryProtection.ExecuteReadWrite */ 0x40);
           if (pNewAddr == IntPtr.Zero)
           {
               Console.WriteLine("_error_: Could not allocate memory in target process.\n");
               return false;
           }

[code]
throw new Win32Exception(Marshal.GetLastWin32Error());
[code]

inside the if, it will show what error you are getting from windows.
(Oct 16, 2019 02:52 PM)ProtectedOverride Wrote:  Thank you @Paskowsky, this has helped a lot, made some progress but having trouble allocting memory in 64bit process, presumably I need to change this:

/* allocate memory for Input /
           Current_ImageBase.Length = (ushort)(input.Length
2);
           pNewAddr = VirtualAllocEx(hProcess, IntPtr.Zero, Current_ImageBase.Length, /* AllocationType.Commit / 0x1000 | / AllocationType.Reserve / 0x2000, / MemoryProtection.ExecuteReadWrite */ 0x40);
           if (pNewAddr == IntPtr.Zero)
           {
               Console.WriteLine("_error_: Could not allocate memory in target process.\n");
               return false;
           }

Are both your own process & the remote process running as the same architecture? (64 bit, not wow64)
Does hProcess have the PROCESS_VM_OPERATION process access right?
My issue was i had changed the memory protection setting on VirtualAllocEx. I made some progress in that CommandLine was being blanked. Away for a couple of days but ill do some more testing when I get back to see if I can figure what I might have missed.
Thanks for all the help, got this working, my final problem was I was using 0x78 rather then 0x70. Updated this and got it working on x64 :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by LogikJul 10, 2020 03:07 PM 2 152 Jul 10, 2020 03:07 PM
Last Post: Logik
[C] by hansbaldMay 29, 2018 07:50 PM 12 959 May 29, 2018 07:50 PM
Last Post: XMR Miner
[C] by MalentorOct 30, 2017 01:24 PM 7 310 Oct 30, 2017 01:24 PM
Last Post: int main()