Skip to content

stoplog 函数详解 ​

⏹ r0capture.py 的停止/清理逻辑。

📎 源码在线查看:r0capture.py#L502-L509(stoplog)

做什么 ​

用户 Ctrl+C 或脚本结束时,stoplog 负责:

  • 关闭 pcap 文件句柄(flush 残留)
  • 关闭日志文件
  • 卸载 frida session(detach)
  • 打印退出统计(抓了多少包)

异常安全 ​

stoplog 通常包在 try/finally 或 atexit 注册里,确保即使中途异常也能正确关闭文件,避免 pcap 损坏。

python
try:
    # 主循环
finally:
    stoplog()

Ctrl+C 处理 ​

frida-python 的 script.load() 阻塞主线程,Ctrl+C 抛 KeyboardInterrupt,stoplog 在 except 里被调,关 pcap。

pcap 完整性 ​

stoplog 关 pcap 文件前 flush,确保已抓的包都落盘。若没正确关闭,pcap 可能缺尾部包但仍可打开(pcap 格式容错好)。

相关文档 ​

基于 VitePress 构建 · 教学用途