I have this code in python:
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
I tried to rewrite it in C#.
In C#, I have this: Magner is a class with imports of user32 and kernel
pHandle = Manager.OpenProcess(Manager.PROCESS_VM_READ | Manager.PROCESS_VM_WRITE | Manager.PROCESS_VM_OPERATION, false, pId);
public static T Read<T>(Int64 address)
{
byte[] Buffer = new byte[Marshal.SizeOf(typeof(T))];
IntPtr ByteRead;
Manager.ReadProcessMemory(pHandle, address, Buffer, (uint)Buffer.Length, out ByteRead);
GCHandle handle = GCHandle.Alloc(Buffer, GCHandleType.Pinned);
T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
return stuff;
}
Magner code:
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(UInt32 dwAccess, bool inherit, int pid);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ReadProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, [In, Out] byte[] lpBuffer, UInt64 dwSize, out IntPtr lpNumberOfBytesRead);
// READ FLAGS
public static uint PROCESS_VM_READ = 0x0010;
public static uint PROCESS_VM_WRITE = 0x0020;
public static uint PROCESS_VM_OPERATION = 0x0008;
public static uint PAGE_READWRITE = 0x0004;
The problem is, the C# code works for normal readings, but here I need to get a process module by the name. The code in python works but I don't know how to make this in C#. I'm stuck here for the last 2 weeks.
EDIT:
THIS CODE IN THE PICTURE DOESN'T WORK