C# 从C中dll处的进程读取内存#
我试图从C#中的进程读取内存。我了解了如何从特定地址阅读:C# 从C中dll处的进程读取内存#,c#,memory,C#,Memory,我试图从C#中的进程读取内存。我了解了如何从特定地址阅读: public static byte[] ReadMemory(Process process, int address, int numOfBytes, out int bytesRead) { IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id); byte[] buffer = new byte[n
public static byte[] ReadMemory(Process process, int address, int numOfBytes, out int bytesRead)
{
IntPtr hProc = OpenProcess(ProcessAccessFlags.All, false, process.Id);
byte[] buffer = new byte[numOfBytes];
ReadProcessMemory(hProc, new IntPtr(address), buffer, numOfBytes, out bytesRead);
return buffer;
}
private int getVal(Process proc, int address)
{
int bytesRead;
byte[] value = ReadMemory(proc, address, 4, out bytesRead);
int am = BitConverter.ToInt32(value, 0);
return am;
}
public void threadFunction()
{
Process[] processes = Process.GetProcessesByName("gta_sa");
foreach (Process process in processes)
{
int ServerPointer = getVal(process, 0xB6F5F0);//Its about this line
MessageBox.Show(ServerPointer.ToString());
}
}
但当我在网上浏览时,我发现:
但是我实际上需要读取地址samp.dll+2071C0(我在web上找到的这个地址),而不是0xB6F5F0
有人知道我怎么做吗
提前感谢如果您试图从dll读取数据,为什么不 a。如果DLL在内存中,并且是一个已知结构(例如.NET),则从它的数据结构中读取(例如.NET类的静态字段或通过头的C++)。
b。如果没有,请像加载二进制文件一样加载dll并从文件中读取。如果您试图从dll中读取数据,为什么不 a。如果DLL在内存中,并且是一个已知结构(例如.NET),则从它的数据结构中读取(例如.NET类的静态字段或通过头的C++)。
b。如果没有,请像加载二进制文件一样加载dll并从文件中读取。您需要知道dll的基址。这可以通过Process.Modules随时获得,您需要ProcessModule.BaseAddress属性值。例如:
using System;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
var prc = Process.Start("notepad.exe");
prc.WaitForInputIdle();
foreach (ProcessModule module in prc.Modules) {
if (string.Compare(module.ModuleName, "user32.dll", true) == 0) {
Console.WriteLine("User32 loaded at 0x{0:X16}", (long)module.BaseAddress);
break;
}
}
prc.Kill();
Console.ReadLine();
}
}
输出:
User32在0x0000000076F20000处加载
您需要知道DLL的基址。这可以通过Process.Modules随时获得,您需要ProcessModule.BaseAddress属性值。例如:
using System;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
var prc = Process.Start("notepad.exe");
prc.WaitForInputIdle();
foreach (ProcessModule module in prc.Modules) {
if (string.Compare(module.ModuleName, "user32.dll", true) == 0) {
Console.WriteLine("User32 loaded at 0x{0:X16}", (long)module.BaseAddress);
break;
}
}
prc.Kill();
Console.ReadLine();
}
}
输出:
User32在0x0000000076F20000处加载