如何运行一个外部程序,将它的内存地址传递给read/write进去?
How to run an outside program, passing it memory addresses to read/write into?
假设我有两个程序,Game.exe
和 Probe.exe
这两个都是我正在编写的程序(这不是我试图侵入我不拥有的可执行文件的场景)。我想让Probe
被Game
变成运行,并得到Game
内某些全局变量的地址,这样Probe
就可以对它们进行读写,用于调试目的。
什么是从 Game
到 运行 Probe
的安全方法,并将有效地址提供给 Game
的内存,它可以 read/write ?如果不能单独使用地址来做到这一点,那么使这成为可能的侵入性最小的方法是什么?
Game.exe
可以在启动时将所需的内存地址作为命令行参数传递 Probe.exe
.
Probe.exe
可以从命令行检索那些内存地址,然后使用ReadProcessMemory()
and WriteProcessMemory()
访问它们。为此,Probe.exe
还必须获得 HANDLE
到 Game.exe
进程:
Game.exe
可以将其进程 ID 作为命令行参数传递,然后 Probe.exe
可以将该 ID 传递给 OpenProcess()
。
或
Game.exe
可以用GetCurrentProcess()
and DuplicateHandle()
to create an inheritable copy of its own HANDLE
, and then pass that HANDLE
value to Probe.exe
via command line parameter, and let Probe.exe
inherit the actual HANDLE
object when launched (via CreateProcess()
with bInheritHandles=TRUE
, or a STARTUPINFOEX
struct - see Programmatically controlling which handles are inherited by new processes in Win32).
也就是说,更安全的选项是将所需变量简单地存储在Game.exe
和Probe.exe
可以共享的内存块中使用 CreateFileMapping()
and MapViewFromFile()
.
假设我有两个程序,Game.exe
和 Probe.exe
这两个都是我正在编写的程序(这不是我试图侵入我不拥有的可执行文件的场景)。我想让Probe
被Game
变成运行,并得到Game
内某些全局变量的地址,这样Probe
就可以对它们进行读写,用于调试目的。
什么是从 Game
到 运行 Probe
的安全方法,并将有效地址提供给 Game
的内存,它可以 read/write ?如果不能单独使用地址来做到这一点,那么使这成为可能的侵入性最小的方法是什么?
Game.exe
可以在启动时将所需的内存地址作为命令行参数传递 Probe.exe
.
Probe.exe
可以从命令行检索那些内存地址,然后使用ReadProcessMemory()
and WriteProcessMemory()
访问它们。为此,Probe.exe
还必须获得 HANDLE
到 Game.exe
进程:
Game.exe
可以将其进程 ID 作为命令行参数传递,然后Probe.exe
可以将该 ID 传递给OpenProcess()
。
或
Game.exe
可以用GetCurrentProcess()
andDuplicateHandle()
to create an inheritable copy of its ownHANDLE
, and then pass thatHANDLE
value toProbe.exe
via command line parameter, and letProbe.exe
inherit the actualHANDLE
object when launched (viaCreateProcess()
withbInheritHandles=TRUE
, or aSTARTUPINFOEX
struct - see Programmatically controlling which handles are inherited by new processes in Win32).
也就是说,更安全的选项是将所需变量简单地存储在Game.exe
和Probe.exe
可以共享的内存块中使用 CreateFileMapping()
and MapViewFromFile()
.