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
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)