1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace CS_WowInjection
  4. {
  5. internal static class NativeMethods
  6. {
  7. [DllImport("kernel32.dll")]
  8. public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress,
  9. out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength);
  10. [StructLayout(LayoutKind.Sequential)]
  11. public struct MEMORY_BASIC_INFORMATION
  12. {
  13. public IntPtr BaseAddress;
  14. public IntPtr AllocationBase;
  15. public MBI_Protect AllocationProtect;
  16. public ulong RegionSize;
  17. public MBI_State State;
  18. public MBI_Protect Protect;
  19. public MBI_Type Type;
  20. }
  21. public enum MBI_Protect : uint
  22. {
  23. PAGE_EXECUTE = 0x00000010,
  24. PAGE_EXECUTE_READ = 0x00000020,
  25. PAGE_EXECUTE_READWRITE = 0x00000040,
  26. PAGE_EXECUTE_WRITECOPY = 0x00000080,
  27. PAGE_NOACCESS = 0x00000001,
  28. PAGE_READONLY = 0x00000002,
  29. PAGE_READWRITE = 0x00000004,
  30. PAGE_WRITECOPY = 0x00000008,
  31. PAGE_GUARD = 0x00000100,
  32. PAGE_NOCACHE = 0x00000200,
  33. PAGE_WRITECOMBINE = 0x00000400
  34. }
  35. public enum MBI_State : uint
  36. {
  37. MEM_COMMIT = 0x1000,
  38. MEM_FREE = 0x10000,
  39. MEM_RESERVE = 0x2000
  40. }
  41. public enum MBI_Type : uint
  42. {
  43. MEM_IMAGE = 0x1000000,
  44. MEM_MAPPED = 0x40000,
  45. MEM_PRIVATE = 0x20000
  46. }
  47. [DllImport("kernel32.dll", SetLastError = true)]
  48. [return: MarshalAs(UnmanagedType.Bool)]
  49. public static extern bool ReadProcessMemory(
  50. IntPtr hProcess,
  51. IntPtr lpBaseAddress,
  52. [Out] byte[] lpBuffer,
  53. int dwSize,
  54. out int lpNumberOfBytesRead
  55. );
  56. }
  57. }
Comments powered by Disqus