Re lldb

From dslsdzc/rev-skills · View interactive version

Re lldb is an AI agent skill from the GitHub repository dslsdzc/rev-skills. lldb 调试(macOS/iOS):attach、expr、image。 触发词:lldb、macOS调试、iOS调试

How to use this skill

Skill file

lldb 动态调试(macOS/iOS)

何时使用 / 何时不用

工具准备

参考 [[re-analyze/platform-tips]] macOS 分支——SIP 与 TCC 限制 attach,需 Developer Tools 授权。

lldb

SIP 关闭或授权(attach 前置)

操作步骤

  1. Developer Tools 权限确认:

```sh

lldb -p <测试进程pid> # 若报 "please check the developer mode" / 权限拒绝 → 去系统设置授权终端

```

授权后重启终端;仍失败再检查 SIP 状态: csrutil status。

注意: TCC 授权弹窗需在系统设置手动确认,无法命令行绕过。

  1. attach/启动:

```

(lldb) process attach --pid <pid> # 附加

(lldb) process attach --name Safari # 按名字附加(需唯一)

(lldb) target create ./sample # 或直接启动

(lldb) run --args arg1

(lldb) continue / c

```

iOS 设备: platform select remote-ios + process connect connect://<device>(需配合调试服务,越狱/证书要求见 [[re-mobile]])

  1. image lookup 符号:

```

(lldb) image lookup -n main # 按名字查符号

(lldb) image lookup -a $pc # 按地址查当前所在函数/源行

(lldb) image list # 已加载镜像(dylib 基址表)

(lldb) image lookup -rn dispatch # 正则匹配符号

```

stripped 二进制用 image lookup -a 反查地址归属模块,配合 image dump symtab

  1. 内存表达式 expr:

```

(lldb) expr $rax

(lldb) expr $rax = 0 # 写寄存器

(lldb) expr (char*)0x100000000 # 类型化读地址

(lldb) expr -O -- @"hello" # Objective-C 求值(objc 运行时)

(lldb) memory read -c 20 -s 4 -f x $rsp # 读内存(缺 -f x 会报格式冲突错误)

(lldb) memory write -s 1 0x100000000 0x90 # 写字节(绕过校验)

```

  1. 断点与脚本:

```

(lldb) breakpoint set -n main

(lldb) breakpoint set -a 0x100004000 -c '(int)($rsp) == 0x1234' # 条件断点

(lldb) breakpoint command add 1

> frame variable

> expr $rax

> continue

> DONE

```

Python 自动化: lldb 内置 Python——script import lldb,或用 lldb -s script.lldb 批处理。

  1. 单步/栈/线程:

```

(lldb) thread step-over / step-into / step-out # 步过/步入/出函数(别名 next/step/finish)

(lldb) thread backtrace # 当前线程栈(别名 bt)

(lldb) thread list # 全部线程

(lldb) frame select 1 # 切栈帧

(lldb) frame variable # 当前帧局部变量

(lldb) register read # 全部寄存器

```

  1. 内存搜索与区域:

```

(lldb) memory find 0x100000000 0x101000000 -e 0xdeadbeef # 区间内搜值/字节串

(lldb) memory find -s "password" 0x100000000 0x101000000 # 搜字符串

(lldb) memory region 0x100004000 # 该地址所属区域权限/边界

```

  1. 证据核对(收尾):断点命中记录、frame variable/expr 输出、memory read 转储(memory read --force -o 文件 导出)对照 [[re-triage]] 初勘值入档,结论写 [[re-analyze/analysis-contract]]

跨域联合

常见坑与陷阱

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.