首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ReadProcessMemory

如何使用ReadProcessMemory
EN

Stack Overflow用户
提问于 2017-09-26 16:45:45
回答 1查看 14K关注 0票数 1

因此,我一直试图用ReadProcessMemory读取变量,并发现作弊引擎中的附件工作得很好,但一开始编程,我就遇到了一些问题。我在欺骗引擎中搜索弹药和健康地址,健康是一个一级指针,弹药是一个三级指针。我试着阅读它,但是每次我读它时,它都返回0。

代码语言:javascript
复制
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();

    }
}

}

代码语言:javascript
复制
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);**


    }
}

}

下面是到欺骗引擎中的地址的链接,不能在这里上传:P

http://prntscr.com/gp1ko0

http://prntscr.com/gp1ksu

如何在代码中正确地使用来自欺骗引擎的指针和偏移量,以及如何在代码中实现多级指针?请原谅我糟糕的英语。

EN

回答 1

Stack Overflow用户

发布于 2017-09-26 17:06:03

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

hProcess in 具有正在读取的内存的进程的句柄。句柄必须具有对进程的PROCESS_VM_READ访问权限。

要获得这个句柄,您需要使用OpenProcess

代码语言:javascript
复制
[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, ...);

编辑:还确保您的应用程序以提升的权限运行,这意味着您应该使用Run as Admin启动VStudio或应用程序。

EDIT2:您应该为lpBuffer使用ref,以避免进入unsafe区域:

代码语言:javascript
复制
    [DllImport("kernel32", SetLastError = true)]
    public static extern int ReadProcessMemory(
        IntPtr hProcess,
        int lpBase,
        ref int lpBuffer,
        int nSize,
        int lpNumberOfBytesRead
        );

对于多层指针,您读取基地址的值,并添加偏移量和读取一次又一次。

代码语言:javascript
复制
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);

或者,您可以在Pointer中使用我的Xy.DataAnalysis类。用法示例可在Xy.PerfectWorld.Modelshttps://github.com/Xiaoy312/Xy.PerfectWorld/tree/master/Xy.DataAnalysis中找到

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46431860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档