如何使用 C# 在 Windows 中获取另一个进程库地址

How can I get another process base adress in Windows using C#?

本文关键字:另一个 进程 地址 获取 何使用 Windows      更新时间:2023-10-16

当我发现华硕的一个旧驱动程序容易受到物理内存读/写的攻击时,我正在浏览exploitdb。有一个完全有效的 PoC 显示如何从 RAM 读取。问题是我有一个偏移量(假设0x31E4(,指示我在程序内存中需要的值的相对位置,但驱动程序返回绝对窗口地址的信息。如何在物理内存中获取基本进程地址(最好在 C# 中(?甚至可能吗?

伪代码示例:

DWORD offset = 0x31E4; // Offset
int size = sizeof(float); // Size of float
float output = Read(ProgramBase + offset, size); // Read function that read absolute value from RAM, for that I need ProgramBase

如果你想找到内存的起始块和结束块,这段代码应该这样做:

  Process p = Process.GetCurrentProcess();
  IntPtr startMemory= p.MainModule.BaseAddress; 
  IntPtr endMemory= IntPtr.Add(startMemory,p.MainModule.ModuleMemorySize);

当然,您可以获得任何其他进程,而不是当前进程,例如:

Process.GetProcessById(processId)