2017-09-26 4 views
-1

그래서 ReadProcessMemory를 사용하여 변수를 읽으려고했는데 치트 엔진에서 주소를 찾는 것이 완벽하게 이루어졌지만 프로그래밍을 마치 자마자 몇 가지 문제가 발생했습니다. 치트 엔진에서 탄약과 건강 주소를 검색했고 건강 상태가 한 수준의 포인터 였고 탄약이 3 단계 포인터였습니다. 나는 건강을 읽는했지만, 매번 나는,이 치트 엔진에 주소를 0으로사용 방법 ReadProcessMemory

namespace AssaultCubeTrainer 

{ 

public partial class MainWindow : Window 
{ 

    [DllImport("kernel32.dll", SetLastError = true)] 
    public static extern bool ReadProcessMemory(IntPtr pHandle, IntPtr Address, byte[] Buffer, int Size, IntPtr NumberofBytesRead); 

    public static Process myProc; 

    public static Player p1; 

    public MainWindow() 
    { 
     InitializeComponent(); 

     p1 = new Player(); 

     MessageBox.Show("Please press the attach button as soon as the game has started", " Information",MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); 



    } 

    private void AttachProcButton_Click(object sender, RoutedEventArgs e) 
    { 

     try 
     { 
      myProc = Process.GetProcessesByName("ac_client")[0]; 


      if (myProc.Handle != null) 
      { 
       MessageBox.Show("Process successfully attached", "Success", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); 
      } 
     } 

     catch 
     { 
      MessageBox.Show("The process was not found","Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); 
     } 

    } 

    private void ButtonTest_Click(object sender, RoutedEventArgs e) 
    { 

      lbHealthInfo.Content = p1.GetHealthInfo(); 

    } 
} 

}

namespace AssaultCubeTrainer 
{ 
    public class Player 
{ 

    private byte[] buffer; 

    public bool ReadSuccess; 

    public int HealthAddress; 
    public int HealthOffset; 

    public int AmmoAddress; 
    public int AmmoOffset; 

    public int Health; 
    public int Ammo; 

    public IntPtr bytesRead; 

    public Player() 
    { 
     HealthAddress = 0x00509B74; 
     HealthOffset = 0xF8; 

     AmmoAddress = 0x00509B74; 
     AmmoOffset = 0x374; 

     Health = HealthAddress + HealthOffset; 
     Ammo = AmmoAddress + AmmoOffset; 

    } 


//Here I have the problem when reading variable 
public int GetHealthInfo() 
     { 
      **buffer = new byte[4]; 
      ReadSuccess = MainWindow.ReadProcessMemory(MainWindow.myProc.Handle, (IntPtr)Health, buffer, buffer.Length, bytesRead); 
      return BitConverter.ToInt32(buffer, 0);** 


    } 
} 

}

을 Heres 링크를 반환 읽어 을 couldnt가 업로드 여기 : P

http://prntscr.com/gp1ko0

http://prntscr.com/gp1ksu

내 코드에서 치트 엔진의 포인터와 오프셋을 올바르게 사용하려면 어떻게해야하며 코드에 다중 레벨 포인터를 구현하려면 어떻게해야합니까? 제 엿 같은 영어를 용서하십시오.

+0

난 당신이'OpenProcess' API를 사용하여 프로세스를 열 필요가 두려워 - [이] (확인 https://stackoverflow.com/questions/34467311/c-sharp-readprocessmemory -how-to-read-a-64-bit- 메모리 주소). – vasek

답변

1

ReadProcessMemory(MainWindow.myProc.Handle, ...)


[IN]

hProcess 판독되는 메모리 프로세스에 대한 핸들. 핸들은 프로세스에 PROCESS_VM_READ 액세스 권한을 가져야합니다.

이 핸들을 얻으려면, 당신은 OpenProcess를 사용해야합니다 :

[DllImport("kernel32", SetLastError = true)] 
public static extern IntPtr OpenProcess(
      int dwDesiredAccess, 
      IntPtr bInheritHandle, 
      IntPtr dwProcessId 
      ); 
public const int PROCESS_VM_READ = 0x10; 

var handle = OpenProcess(PROCESS_VM_READ, IntPtr.Zero, new IntPtr(MainWindow.myProc.Id)); // note: use the id 
ReadProcessMemory(handle, ...); 

편집 : 또한 응용 프로그램은 당신이 VStudio 또는 Run as Admin 사용하여 응용 프로그램을 시작해야 의미, 높은 권한에서 실행해야합니다.

EDIT2 : 당신은 unsafe 영토로 스테핑 방지하기 위해 lpBuffer에 대한 ref를 사용해야합니다, 당신은 기본 주소의 값을 읽어 다단계 포인터에 관해서는

[DllImport("kernel32", SetLastError = true)] 
    public static extern int ReadProcessMemory(
     IntPtr hProcess, 
     int lpBase, 
     ref int lpBuffer, 
     int nSize, 
     int lpNumberOfBytesRead 
     ); 

및 오프셋을 추가하고 다시 읽고 다시.

ReadProcessMemory(handle, BaseAddress, ref value, sizeof(int), 0); 
ReadProcessMemory(handle, value + 0x508, ref value, sizeof(int), 0); 
ReadProcessMemory(handle, value + 0xF8, ref value, sizeof(int), 0); 

또는, 당신은 Xy.DataAnalysisPointer 클래스를 사용할 수 있습니다. 사용 예는 Xy.PerfectWorld.Models에서 찾을 수 있습니다 https://github.com/Xiaoy312/Xy.PerfectWorld/tree/master/Xy.DataAnalysis

+0

코드를 편집하고 응용 프로그램을 관리자로 실행했지만 여전히 0을 읽었습니다. – Celmos

+0

주소가 틀리면'ReadSuccess'가 true입니까? ['GetLastError'] (https://msdn.microsoft.com/en-ca/library/windows/desktop/ms679360 (v = vs.85) .aspx)를 호출하지 않고 오류 코드 – Xiaoy312

+0

을 확인하십시오. ReadSuccess가 true입니다. 그래서 내 주소가 잘못 됐다는 뜻인가? – Celmos

관련 문제