gdb支持通过python自动化调试,实现循环、读写内存、保存内容等复杂逻辑,不需要安装模块。
官方文档: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Python.html
官方文档直接看不太容易理解,可以结合chatgpt、文心一言等工具使用。
核心函数:
脚本示例 test.py:
启动gdb,执行如下命令调用脚本:
或者直接启动时指定脚本
hello.c
python脚本
2023/5/3
gdb.execute(command [, from_tty [, to_string]])
gdb.execute(command [, from_tty [, to_string]])
import
gdb
gdb.execute(
"break *0x12345678"
)
gdb.execute(
"continue"
)
the_line
=
gdb.execute(
"info registers eip"
, to_string
=
True
)
gdb.execute(
"dump memory /root/memory.dump $ebx $ebx+0x100"
)
import
gdb
gdb.execute(
"break *0x12345678"
)
gdb.execute(
"continue"
)
the_line
=
gdb.execute(
"info registers eip"
, to_string
=
True
)
gdb.execute(
"dump memory /root/memory.dump $ebx $ebx+0x100"
)
#include <stdio.h>
int
main(){
printf
(
"Hello World!\n"
);
return
0;
}
#include <stdio.h>
int
main(){
printf
(
"Hello World!\n"
);
return
0;
}
import
gdb
gdb.execute(
"file hello"
)
gdb.execute(
"break main"
)
gdb.execute(
"run"
)
gdb.execute(
"nexti 2"
)
frame
=
gdb.selected_frame()
rax
=
frame.read_register(
"rax"
)
print
(
"rax的值是: 0x%x"
%
rax)
inferior
=
gdb.selected_inferior()
the_mem
=
inferior.read_memory(rax,
0x20
)
print
(
"the_mem: "
, the_mem.tobytes())
import
gdb
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课