The memory could not be "read" \ "write"; Read\WriteProcessMemory - C#

Узнай цену своей работы

Формулировка задачи:

Добрый день. Вечная проблема при попытке прочитать \ записать в память, при помощи Read\WriteProcessMemory - это ошибки The memory could not be "read" \ "write". Как избежать их? Ведь этот же CheatEngine не крашится при попытке чтения \ записи. PS: находил, что можно получить pHandle процесса с привилегиями отладчика (OpenProcess), и, будто бы, проблема исчезнет. Правда ли это?

Решение задачи: «The memory could not be "read" \ "write"; Read\WriteProcessMemory»

textual
Листинг программы
  1.     class Memory
  2.     {
  3.         public static Process pWow;
  4.         public static Int64 pBaseAddress;
  5.         private static Int64 handleProcess;
  6.         public Memory()
  7.         {
  8.             pWow = Process.GetProcessesByName("Wow-64")[0];
  9.             pBaseAddress = pWow.MainModule.BaseAddress.ToInt64();
  10.             ProcessAccessFlags a = ProcessAccessFlags.PROCESS_CREATE_THREAD |
  11.                                    ProcessAccessFlags.PROCESS_QUERY_INFORMATION |
  12.                                    ProcessAccessFlags.PROCESS_SET_INFORMATION | ProcessAccessFlags.PROCESS_TERMINATE |
  13.                                    ProcessAccessFlags.PROCESS_VM_OPERATION | ProcessAccessFlags.PROCESS_VM_READ |
  14.                                    ProcessAccessFlags.PROCESS_VM_WRITE | ProcessAccessFlags.SYNCHRONIZE;
  15.  
  16.             handleProcess = OpenProcess(a, false, pWow.Id);
  17.         }
  18.  
  19.         [Flags]
  20.         public enum ProcessAccessFlags
  21.         {
  22.             DELETE = 0x00010000,
  23.  
  24.             /// <summary>
  25.             /// Required to read information in the security descriptor for the object, not including the information in the SACL.
  26.             /// To read or write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right.
  27.             /// For more information, see SACL Access Right.
  28.             /// </summary>
  29.             READ_CONTROL = 0x00020000,
  30.  
  31.             /// <summary>
  32.             /// The right to use the object for synchronization.
  33.             /// This enables a thread to wait until the object is in the signaled state.
  34.             /// </summary>
  35.             SYNCHRONIZE = 0x00100000,
  36.  
  37.             /// <summary>
  38.             /// Required to modify the DACL in the security descriptor for the object.
  39.             /// </summary>
  40.             WRITE_DAC = 0x00040000,
  41.  
  42.             /// <summary>
  43.             /// Required to change the owner in the security descriptor for the object.
  44.             /// </summary>
  45.             WRITE_OWNER = 0x00080000,
  46.  
  47.             /// <summary>
  48.             /// All possible access rights for a process object.
  49.             /// </summary>
  50.             PROCESS_ALL_ACCESS = 0x001F0FFF,
  51.  
  52.             /// <summary>
  53.             /// Required to create a process.
  54.             /// </summary>
  55.             PROCESS_CREATE_PROCESS = 0x0080,
  56.  
  57.             /// <summary>
  58.             /// Required to create a thread.
  59.             /// </summary>
  60.             PROCESS_CREATE_THREAD = 0x0002,
  61.  
  62.             /// <summary>
  63.             /// Required to create a process.
  64.             /// </summary>
  65.             PROCESS_DUP_HANDLE = 0x0040,
  66.  
  67.             /// <summary>
  68.             /// Required to retrieve certain information about a process, such as its token, exit code, and priority class
  69.             /// </summary>
  70.             PROCESS_QUERY_INFORMATION = 0x0400,
  71.  
  72.             /// <summary>
  73.             /// Required to retrieve certain information about a process (see QueryFullProcessImageName).
  74.             /// A handle that has the PROCESS_QUERY_INFORMATION access right is automatically granted PROCESS_QUERY_LIMITED_INFORMATION.
  75.             /// </summary>
  76.             PROCESS_QUERY_LIMITED_INFORMATION = 0x1000,
  77.  
  78.             /// <summary>
  79.             /// Required to set certain information about a process, such as its priority class
  80.             /// </summary>
  81.             PROCESS_SET_INFORMATION = 0x0200,
  82.  
  83.             /// <summary>
  84.             /// Required to set memory limits using SetProcessWorkingSetSize.
  85.             /// </summary>
  86.             PROCESS_SET_QUOTA = 0x0100,
  87.  
  88.             /// <summary>
  89.             /// Required to suspend or resume a process.
  90.             /// </summary>
  91.             PROCESS_SUSPEND_RESUME = 0x0800,
  92.  
  93.             /// <summary>
  94.             /// Required to terminate a process using TerminateProcess.
  95.             /// </summary>
  96.             PROCESS_TERMINATE = 0x0001,
  97.  
  98.             /// <summary>
  99.             /// Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).
  100.             /// </summary>
  101.             PROCESS_VM_OPERATION = 0x0008,
  102.  
  103.             /// <summary>
  104.             /// Required to read memory in a process using ReadProcessMemory.
  105.             /// </summary>
  106.             PROCESS_VM_READ = 0x0010,
  107.  
  108.             /// <summary>
  109.             /// Required to write to memory in a process using WriteProcessMemory.
  110.             /// </summary>
  111.             PROCESS_VM_WRITE = 0x0020,
  112.         }
  113.  
  114.         [DllImport("kernel32.dll", SetLastError = true)]
  115.         private static extern Int64 OpenProcess(ProcessAccessFlags dwDesiredAccess,
  116.                                                             [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle,
  117.                                                             Int32 dwProcessId);

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 3.667 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы