C#: Search a byte[] array in another process's memory

后端 未结 5 1692
夕颜
夕颜 2020-12-09 13:23

How is it possible to search for a byte[] array in the memory of another process and then get the address at the place where the byte[] array is located?

I want to w

5条回答
  •  情话喂你
    2020-12-09 13:58

    You'll want to use these APIs:

        [DllImport("Kernel32.Dll")]
        public static extern uint VirtualQueryEx(IntPtr ProcessHandle, uint Address, ref MEMORY_BASIC_INFORMATION MemInfo, int MemInfoLength);
        [DllImport("Kernel32.Dll")]
        public static extern bool ReadProcessMemory(IntPtr ProcessHandle, uint Address, byte[] Buffer, uint Size, ref uint BytesRead);
        [DllImport("Kernel32.Dll")]
        public static extern bool WriteProcessMemory(IntPtr ProcessHandle, uint Address, byte[] Buffer, uint Size, ref uint BytesRead);
    

    pinvoke.net is a great resource for Windows API calls. I wrote a trainer for GTA: Vice City that uses these calls if you want to check out the code on sourceforge. The code isn't pretty, it was a long time ago and I just threw it together, but there are helper classes for enumerating memory regions for a process and searching for certain bytes or strings.

提交回复
热议问题