C# ReadProcessMemory

PeterParty

Lt. Junior Grade
Registriert
Aug. 2008
Beiträge
282
Hallo,

Ich möchte im Memory von einem bestimmten Prozess nach einem String suchen.

Er soll im Memory von : 0000000000000000
bis: 7fffffffffffffff

alles durchsuchen und mir dann die Adresse Anzeigen.


Nun wollte ich fragen ob das mit C# und ReadProcessMemory umsetzbar ist?


Viele Grüße
Peter
 
Nach meinem Kenntnisstand sollte das gehen. Versuchs doch einfach, so viel code ist das nicht
 
Code:
ReadProcessMemory(readHandle, (IntPtr)charNameAddress, bytes, (UIntPtr)24, ref rw);
string text = Encoding.UTF8.GetString(bytes);
 
Ich habe es nun geschafft an einer Adresse einen String zu Lesen und einen neuen zu Schreiben.

Ich brauche jetzt noch einen gedankenanstoß um die Adresse, mit der ich Lesen und Schreiben will herrauszufinden.

Hier mal mein Code:

Klasse:

Code:
        public static int proccID;
        public static IntPtr pHandle;
        public static int base_adress;

        #region DllImports

        [DllImport("kernel32.dll")]
        private static extern bool WriteProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesWritten);

        [DllImportAttribute("User32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("kernel32.dll")]
        private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll", EntryPoint = "CloseHandle")]
        private static extern bool _CloseHandle(IntPtr hObject);

        [DllImport("kernel32.dll")]
        private static extern bool ReadProcessMemory(IntPtr hProcess, UIntPtr lpBaseAddress, [Out] byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesRead);
        #endregion


        public static string ReadString(long Address)
        {
            byte[] buffer = new byte[50];

            ReadProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)50, IntPtr.Zero);

            string ret = Encoding.Unicode.GetString(buffer);

            if (ret.IndexOf('\0') != -1)
                ret = ret.Remove(ret.IndexOf('\0'));
            return ret;
        }

        public static void OpenProcess()
        {
            Process[] procs = Process.GetProcessesByName("processname");
            if (procs.Length == 0)
            {
                proccID = 0;
            }
            else
            {
                proccID = procs[0].Id;
                pHandle = OpenProcess(0x1F0FFF, false, proccID);
                
            }

        }

        public static void WriteString(long Address, string value)
        {
            byte[] buffer = Encoding.ASCII.GetBytes(value);
            WriteProcessMemory(pHandle, (UIntPtr)Address, buffer, (UIntPtr)buffer.Length, IntPtr.Zero);         
        }
 
Zurück
Oben