I am used to coding in AutoIt. I am trying to move my project into C# but I have only about 2-3 weeks of experience.
In AutoIt, I have this code here that reads the process memory and returns a value.
I am trying desperately to convert this to C# language and I need some help. Here is what I have so far.
Using this works, but I don't know how to add the necessary offsets to the address. If someone could help me out with this one. That would be greatly appreciated.
Here is the class that I am using.
Thanks in advance.
PS. I would also like to have a message box that will show me the value that is returned when the address is read.
In AutoIt, I have this code here that reads the process memory and returns a value.
Code:
$map = _MemoryRead(0x00B5CCB8, $handle) // Pointer address 0x00B5CCB8 $map = _MemoryRead($map + 0x02, $handle) // Offset 0x02 $map = _MemoryRead($map + 0xBD, $handle) // Second Offset 0xBD
Code:
Process process = Process.GetProcessesByName("My Process").FirstOrDefault();
int address = 0x00B5CCB8;
int offset1 = 0x02;
int offset2 = 0xBD;
int bytesRead;
byte[] pointer = ProcessMemoryReaderApi.ReadMemory(process, address, 4, out bytesRead);
Here is the class that I am using.
Code:
class ProcessMemoryReaderApi
{
// constants information can be found in <winnt.h>
[Flags]
public enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VMOperation = 0x00000008,
VMRead = 0x00000010,
VMWrite = 0x00000020,
DupHandle = 0x00000040,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
Synchronize = 0x00100000
}
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out int lpNumberOfBytesRead);
[DllImport("kernel32.dll")]
public static extern Int32 CloseHandle(IntPtr hProcess);
public static byte[] ReadMemory(Process process, int address, int numOfBytes, out int bytesRead)
{
IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);
byte[] buffer = new byte[numOfBytes];
ReadProcessMemory(hProc, new IntPtr(address), buffer, numOfBytes, out bytesRead);
return buffer;
}
PS. I would also like to have a message box that will show me the value that is returned when the address is read.