- using System;
- using System.Runtime.InteropServices;
- namespace CS_WowInjection
- {
- internal static class NativeMethods
- {
- [DllImport("kernel32.dll")]
- public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress,
- out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);
- [StructLayout(LayoutKind.Sequential)]
- public struct MEMORY_BASIC_INFORMATION
- {
- public IntPtr BaseAddress;
- public IntPtr AllocationBase;
- public MBI_Protect AllocationProtect;
- public ulong RegionSize;
- public MBI_State State;
- public MBI_Protect Protect;
- public MBI_Type Type;
- }
- public enum MBI_Protect : uint
- {
- PAGE_EXECUTE = 0x00000010,
- PAGE_EXECUTE_READ = 0x00000020,
- PAGE_EXECUTE_READWRITE = 0x00000040,
- PAGE_EXECUTE_WRITECOPY = 0x00000080,
- PAGE_NOACCESS = 0x00000001,
- PAGE_READONLY = 0x00000002,
- PAGE_READWRITE = 0x00000004,
- PAGE_WRITECOPY = 0x00000008,
- PAGE_GUARD = 0x00000100,
- PAGE_NOCACHE = 0x00000200,
- PAGE_WRITECOMBINE = 0x00000400
- }
- public enum MBI_State : uint
- {
- MEM_COMMIT = 0x1000,
- MEM_FREE = 0x10000,
- MEM_RESERVE = 0x2000
- }
- public enum MBI_Type : uint
- {
- MEM_IMAGE = 0x1000000,
- MEM_MAPPED = 0x40000,
- MEM_PRIVATE = 0x20000
- }
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool ReadProcessMemory(
- IntPtr hProcess,
- IntPtr lpBaseAddress,
- [Out] byte[] lpBuffer,
- int dwSize,
- out int lpNumberOfBytesRead
- );
- }
- }