2014-04-15 2 views
0

계속 인터넷을 계속 검색하면이를 파악할 수 없으므로 ReadProcessMemory이 올바르게 실행됩니다. 그러나 출력은 항상 비어 있습니다. 배열의 길이는 0입니다. 당신이 그것을 완전히 비어 (new byte[] {}) 초기화하기 때문에 당신이 그것을 채우기 위해주는 버퍼가 0의 길이를 가지고 있기 때문에RPM이 작동하고 이유를 파악할 수 없습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Runtime.InteropServices; 
using System.Diagnostics; 

namespace MemEd 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Process proc = Process.GetProcessesByName("client")[0]; 
      byte[] buff = new byte[]{}; 
      IntPtr bread; 
      IntPtr pHandle = OpenProcess(0x0010, false, proc.Id); 
      bool check = ReadProcessMemory(pHandle, (IntPtr)0x5EFF75B8, buff, 10, out bread); 
      if (!check) 
       Console.WriteLine("RPM Fail"); 

      Console.WriteLine(buff.Length); //ALWAYS returns 0, Even the value is a string "xyle" 
      Console.WriteLine(Encoding.Unicode.GetString(buff));//Always empty, tryed most of Encoding types to check still a blank result. 
      Console.ReadKey(); 
     } 


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

     [DllImport("kernel32.dll", SetLastError = true)] 
     static extern bool ReadProcessMemory(
      IntPtr hProcess, 
      IntPtr lpBaseAddress, 
      [Out] byte[] lpBuffer, 
      int dwSize, 
      out IntPtr lpNumberOfBytesRead); 
    } 
} 

답변

1

아마입니다.

또한
ReadProcessMemory(pHandle, (IntPtr)0x5EFF75B8, buff, (UInt32)buff.Length, out bread); 

, 당신은했는지 확인하십시오 : 당신의 dwSize 매개 변수로 길이를 사용하여 다음 읽고 싶은 얼마나 많은 메모리를 기반으로

byte[] buff = new byte[1024]; 

변경 수, : 그것을 여지를주는 시도 this answer을 통해 올바른 권한을 얻었습니다. 높은 권한으로 앱을 실행해야 할 수 있습니다.

+1

현재 dwSize (이 경우 1024)에 대한 버퍼 크기를 전달하십시오. 현재 가지고있는 10은 아닙니다. –

0

생성하는 동안 buff 배열의 크기를 지정하십시오.

byte[] buff = new byte[some_size]; 

그리고 또한. 나는 ReadProcessMemory 메소드 선언의 마지막 인수는 참조에 의해 전달되는

out int lpNumberOfBytesRead 

때문에 outref 인수로 대체해야한다고 생각합니다. 그런 다음 int bread을 사용하여 버퍼의 데이터에서 과도한 바이트를 잘라낼 수 있어야합니다.

+0

방금 ​​가져온 가져 오기를 복사했습니다. 나는 마지막 매개 변수를 어떻게 사용할 수 있는지 결코 알지 못했다. 사용 주셔서 감사합니다 !!. – RichardP

관련 문제