gdb python 模块读取内存内容

use*_*556 5 c++ python debugging gdb

在 gdb 中打印特定内存地址的内容,我可以运行以下命令。它以十六进制打印内容

x <memoryaddress>

(gdb) x 299395816
0x11d86ae8: 0x0ec14153
Run Code Online (Sandbox Code Playgroud)

我在 gdb 中使用 gdb python 模块,在我的 python 脚本中使用 gdb 模块读取内存位置的等效命令是什么。

geo*_*xsh 6

我想就是你想要的

(gdb) python i = gdb.inferiors()[0]
(gdb) python m = i.read_memory(0x7fffffffe39c, 4) # an int32
(gdb) python print(m.tobytes())
b'\x01\x00\x00\x00'
Run Code Online (Sandbox Code Playgroud)