我对PC寻址有不好的信息,而且我认为我的代码有误,因此无法从地址中找到某些我需要的信息。
我使用Google并找到了一种从内存地址读取字符串的方法。
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
const int PROCESS_WM_READ = 0x0010;
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
public static void Main(string[] args)
{
Process process = Process.GetProcessById(10828);
IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
int bytesRead = 0;
byte[] buffer = new byte[24]; //'Hello World!' takes 12*2 bytes because of Unicode
// 0x0046A3B8 is the address where I found the string, replace it with what you found
ReadProcessMemory((int)processHandle, 0x00C716EC, buffer, buffer.Length, ref bytesRead);
Console.WriteLine(Encoding.Unicode.GetString(buffer) + " (" + bytesRead.ToString() + "bytes)");
Console.ReadLine();
}
}
现在向您解释我想要什么以及我的问题是什么有一个运行名称为gta-sa.exe的应用程序它的在线游戏,并具有textdraw在游戏屏幕上显示一些字符串我用作弊引擎找到了显示的那个字符串的地址作弊引擎信息被打击进程000036F4-gta_sa.exe地址值00C716EC昵称
如您所见
ReadProcessMemory((int)processHandle, 0x00C716EC, buffer, buffer.Length, ref bytesRead);
我使用0x00C716EC
作为地址,但显示的是奇怪的信息,例如????在安慰!我如何获取该NickName字符串?您能告诉我并帮助我理解我的错误吗?
要从内存中读取以空值终止的宽字符串,可以使用此功能
public static string ReadNullTerminatedWString(IntPtr handle, IntPtr addr, int maxlength)
{
var bytearray = new byte[maxlength*2];
IntPtr bytesread = IntPtr.Zero;
ReadProcessMemory(handle, addr, bytearray, maxlength*2, out bytesread);
int nullterm = 0;
while (nullterm < bytesread.ToInt64() && bytearray[nullterm] != 0)
{
nullterm = nullterm + 2;
}
string s = Encoding.Unicode.GetString(bytearray, 0, nullterm);
return s;
}
您必须以管理员身份运行,必须以与目标进程相同的位数进行编译。如果目标是x86,则编译为x86。