c# readprocessmemory with Cheat Engine

2.6k views Asked by At

I'm trying to get string value from address which i found using cheat engine. I found for example 0x01742A38 and this is main part of my program (regular windows form application):

            Process[] processes = Process.GetProcessesByName("Tibia");

            foreach (Process p in processes)
            {
                IntPtr windowHandle = p.MainWindowHandle;
                byte[] bufor = new byte[50];
                uint baseAddress = (uint)p.MainModule.BaseAddress.ToInt32();
                IntPtr addr = ((IntPtr)(baseAddress + 0x01742A38));
                uint o = 0;
                UInt32 k = 30;
                if (ReadProcessMemory(windowHandle, addr, bufor, k, ref o))
                {
                    label3.Text = "Success!";
                }
                else
                {
                    label3.Text = "Fail : (";
                }
            }
1

There are 1 answers

0
Jämes On

Assuming your static address is correct, you have to open the target process using the OpenProcess function with at least the right PROCESS_VM_READ (0x0010).

I also suggest you to use a more suitable pinvoke signature for the function ReadProcessMemory:

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);