Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5e869af
daemon: state adb device access and stop guessing anti-debugging
Nov 1, 2026
7a4a18a
feat: root_watch 支持多硬件断点与事件级内存窗口(含两级指针解引用)
Nov 13, 2026
a8ec370
test: root_watch 自检覆盖读断点与两级解引用
Nov 13, 2026
cdb9c31
fix: root_watch prepare 自检期望两条事件(读+写槽)
Nov 13, 2026
49949fc
feat: 新增 root 侧单步追踪器(ptrace 单步 + 软断点对齐)
Nov 13, 2026
55408ed
feat(adh): root_watch 内存窗口支持每跳偏移(最多三级解引用)
Nov 13, 2026
8950330
feat: QBDI 交付、app_analyze 一键分析与 maps/错误码补强
taisuii Nov 14, 2026
595a54f
feat: 收敛 Android 分析主线与设备状态归因指引
taisuii Nov 15, 2026
96cf68c
fix: 修正硬件观察内存快照时序并隔离注册表门禁
taisuii Nov 15, 2026
5d85e4d
docs: 记录硬件事件排序边界与算法验收
taisuii Nov 15, 2026
ca4f92e
docs: 记录保留策略触发后的校验恢复结果
taisuii Nov 15, 2026
c0c9761
docs: 梳理 ADH 能力状态与 AI 优先改造顺序
taisuii Nov 16, 2026
7f71626
fix: 保留作用域策略并统一设置与非破坏性初始化
taisuii Nov 16, 2026
be80e29
feat: 统一操作执行与持久任务及人类控制权
taisuii Nov 16, 2026
91be0f5
feat: 完善人类任务工作台与配置冲突核对
taisuii Nov 16, 2026
258e69a
feat: 建立设备域与稳定身份并统一 USB RPC
taisuii Nov 16, 2026
fa98813
feat: 增加局域网 TLS 配对撤销与持久对账
taisuii Nov 16, 2026
de9d134
feat: 建立 Host Hook 方案库与验证缓存并迁移手机编辑器
taisuii Nov 16, 2026
f7d726e
fix: 完成P5真机隔离验收并修复早期Hook与设备通信
taisuii Nov 16, 2026
efe8e78
fix: 补齐P5沙盒验收并修复捕获串族与USB帧损坏
taisuii Nov 16, 2026
e58f2ba
test: 补齐P5正式Zygisk全链隔离真机验收
taisuii Nov 16, 2026
50b4cda
docs: 收口ADH P0至P5交付与后续边界
taisuii Nov 17, 2026
0ad72ef
fix: 卸载GOT Hook时保留外部改写并补齐收尾记录
taisuii Nov 17, 2026
2546b67
test: 补齐正式Zygisk七族捕获与LAN授权撤销验收
taisuii Nov 17, 2026
a7e6d92
docs: 更新正式Zygisk扩展验收入口
taisuii Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Never merge these layers.
- `libadh_agent.so` (in target process) — **collect / execute only**: hook, trace, dump, maps scan, light RPC. Keep it minimal, low-memory, non-blocking.
- **Host ADH Daemon** (`daemon/`, npm `adhd`) — HTTP / WebSocket / MCP / DB / index / disasm cache / analysis.
- **Device** (`device/`: `:core` + `:daemon` + `:manager`) — injection scope + module status + target process stop/restart. No analysis.
- Web UI (browser) — observe / search / visualize (frozen as a READ-ONLY viewer, 2026-10-01).
- Web UI (browser) — observe / search / visualize and, per the 2026-11-16 user direction, edit / take control through the shared Host operation layer. P1 versions and operator credentials fence old AI writes; see docs/P1_OPERATIONS.md. The former read-only freeze is superseded for this scope.

**Never** put HTTP, MCP, a database, the dex indexer, or Capstone/QBDI heavy analysis inside the agent `.so` or the Device Daemon/Manager. That causes target OOM/ANR and is easy to detect.

Expand Down Expand Up @@ -166,3 +166,11 @@ Each layer has a `MAP.md` — read it before editing that layer:
## Boundaries

- Never commit captured target data (keys, plaintext, dumps). `.gitignore` excludes `captures/`, `dumps/`, `adhd-data/`.

## P3 device-domain boundary (2026-11-16 user direction)

The existing Device Daemon now shares device control between authenticated Binder and adh.device/1 USB RPC. Installation identity, module/app/process discovery, scope, certificates and the Host endpoint remain device coordination, never analysis. The phone exposes only an authenticated abstract UDS in this slice, no HTTP/MCP/database/TCP listener. Host device:UUID controls fence writes; legacy target sessions have no inferred device association. See docs/P3_DEVICE_DOMAIN.md for capability limits and explicit unverified Android/SELinux paths. P4 pairing/TLS and agent local routing are not delivered by the P3 JVM tests. Keep current sessions and their transport mappings untouched during host-only validation.

## P4 opt-in LAN boundary (2026-11-16 user direction)

The P4 user request extends the P3 UDS-only transport boundary with an explicitly enabled TLS listener in the existing Device Daemon. Trusted USB enrolls Host public keys; every LAN capability dispatch checks its durable grant. Never accept the USB token over LAN, weaken the installation-key pin, reconnect/replay writes automatically, or silently route an unmigrated device/LAN request through legacy ADB. Device analysis/HTTP/MCP/database red lines remain unchanged. Connection recovery and authorization reductions are narrowly classified exceptions to unknown quarantine; they cannot dispatch ordinary device modifications. Preserve original unknown history and require observed versions for human resolution. See docs/P4_LAN_AUTH.md for the tested matrix and unverified Android hardware boundary.
10 changes: 9 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Never merge these layers.
- `libadh_agent.so` (in target process) — **collect / execute only**: hook, trace, dump, maps scan, light RPC. Keep it minimal, low-memory, non-blocking.
- **Host ADH Daemon** (`daemon/`, npm `adhd`) — HTTP / WebSocket / MCP / DB / index / disasm cache / analysis.
- **Device** (`device/`: `:core` + `:daemon` + `:manager`) — injection scope + module status + target process stop/restart. No analysis.
- Web UI (browser) — observe / search / visualize (frozen as a READ-ONLY viewer, 2026-10-01).
- Web UI (browser) — observe / search / visualize and, per the 2026-11-16 user direction, edit / take control through the shared Host operation layer. P1 versions and operator credentials fence old AI writes; see docs/P1_OPERATIONS.md. The former read-only freeze is superseded for this scope.

**Never** put HTTP, MCP, a database, the dex indexer, or Capstone/QBDI heavy analysis inside the agent `.so` or the Device Daemon/Manager. That causes target OOM/ANR and is easy to detect.

Expand Down Expand Up @@ -166,3 +166,11 @@ Each layer has a `MAP.md` — read it before editing that layer:
## Boundaries

- Never commit captured target data (keys, plaintext, dumps). `.gitignore` excludes `captures/`, `dumps/`, `adhd-data/`.

## P3 device-domain boundary (2026-11-16 user direction)

The existing Device Daemon now shares device control between authenticated Binder and adh.device/1 USB RPC. Installation identity, module/app/process discovery, scope, certificates and the Host endpoint remain device coordination, never analysis. The phone exposes only an authenticated abstract UDS in this slice, no HTTP/MCP/database/TCP listener. Host device:UUID controls fence writes; legacy target sessions have no inferred device association. See docs/P3_DEVICE_DOMAIN.md for capability limits and explicit unverified Android/SELinux paths. P4 pairing/TLS and agent local routing are not delivered by the P3 JVM tests. Keep current sessions and their transport mappings untouched during host-only validation.

## P4 opt-in LAN boundary (2026-11-16 user direction)

The P4 user request extends the P3 UDS-only transport boundary with an explicitly enabled TLS listener in the existing Device Daemon. Trusted USB enrolls Host public keys; every LAN capability dispatch checks its durable grant. Never accept the USB token over LAN, weaken the installation-key pin, reconnect/replay writes automatically, or silently route an unmigrated device/LAN request through legacy ADB. Device analysis/HTTP/MCP/database red lines remain unchanged. Connection recovery and authorization reductions are narrowly classified exceptions to unknown quarantine; they cannot dispatch ordinary device modifications. Preserve original unknown history and require observed versions for human resolution. See docs/P4_LAN_AUTH.md for the tested matrix and unverified Android hardware boundary.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

Android DecryptHub(ADH)是一套 Android 运行时分析工具。它把一个轻量程序注入到你勾选的应用里,观察这个应用在运行时做了什么:网络、加密、Java 方法、native 函数、内存和 DEX。重的分析放在电脑上,不放进目标应用。

P5 分支将 Hook 方案和编辑器迁到 Host。MCP `hook_plans`、Python CLI `adh call/run hook_plans` 和任务工作台共用执行层。保存、暂存和实际安装分别报告,连接不自动套用旧捕获/启动默认值。迁移与兼容边界见 [P5_HOOK_PLANS.md](docs/P5_HOOK_PLANS.md)。此分支尚未部署到现有分析现场。

P5 后续已完成真实 Android 独立沙盒验收,并在正式 Zygisk 回调/companion/post-specialize 的隔离命名空间中完成七族代表性捕获、全部禁用、LAN 授权撤销及 UID/Agent/过期等拒绝,共15/15。详见[正式链验收与未验证边界](docs/P5_ZYGISK_EXTENDED_ACCEPTANCE.md);默认模块/Manager/生产 RootDaemon 的部署升级仍待验证。

## 能做什么

**只影响勾选的应用。** 在手机上的 ADH Manager 里勾选注入范围并保存,然后重新打开该应用。主进程和 `:core` 这类子进程都会注入。没勾选的应用不会注入。

**用代理看 HTTPS。** 应用被注入之后,Java 侧的证书校验会放行。配合你自己的抓包代理(系统代理或 VPN),可以看到这个应用发出的 HTTPS。native 的 `SSL_read` / `SSL_write` 明文是另一项,要在电脑上开始采集才会装,Manager 里的「TLS 明文」开关管的是这一项。
**用代理看 HTTPS。** 手机负责系统 CA 管理;Java trust-manager bypass 由 Host 显式执行 `java_hook action=bypass`。native 的 `SSL_read` / `SSL_write` 明文由显式捕获方案控制。注入与连接本身不会自动安装这些 Hook。

**记录 Java 加密。** 注入后自动观察这些接口,原来的方法照常执行:
**记录 Java 加密。** Host 可显式执行 `java_hook action=crypto`,或用方案中的 Java 方法步骤观察这些接口;原来的方法照常执行:

| 接口 | 记下什么 |
| --- | --- |
Expand All @@ -17,7 +21,7 @@ Android DecryptHub(ADH)是一套 Android 运行时分析工具。它把一
| `java.security.MessageDigest` | `digest`。例如 MD5、SHA-256 |
| `java.security.Signature` | `initSign`、`initVerify`、`sign`、`verify`。例如 SHA256withRSA |

每条记录包含算法名、操作(加密、解密、摘要、签名等)、密钥、IV、输入和输出。Manager 里可以按应用关掉某一族(摘要、HMAC、对称、非对称、AEAD);关掉的族不会安装钩子。保存后要重启该应用。RSA 加解密跟着「对称」或 AEAD,RSA 签名跟着「非对称」。
每条记录按接口能力包含算法名、操作、密钥、IV、输入和输出。方案中的 family 控制后续 native 捕获安装资格;Manager 保留旧配置快照和缓存撤销入口,编辑方案在 Host 完成。Java 原语的覆盖边界以工具返回和实际事件为准。

这些情况记不到,或只能记到一部分:

Expand Down
10 changes: 9 additions & 1 deletion agent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.22)
project(adh_agent C CXX ASM)

# Explicit sandbox builds may select an owned port, never dial the active analysis Host.
set(ADH_AGENT_CONNECT_PORT "8761" CACHE STRING "Agent loopback RPC port")
if(NOT ADH_AGENT_CONNECT_PORT MATCHES "^[0-9]+$" OR ADH_AGENT_CONNECT_PORT LESS 1 OR ADH_AGENT_CONNECT_PORT GREATER 65535)
message(FATAL_ERROR "ADH_AGENT_CONNECT_PORT must be 1..65535")
endif()
add_compile_definitions(ADH_PORT=${ADH_AGENT_CONNECT_PORT})

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -9,6 +16,7 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(AGENT_SOURCES
src/capture/capture.c
src/bootstrap/agent_main.c
src/bootstrap/early_plan.cpp
src/bootstrap/util.c
src/bootstrap/io.c
src/bootstrap/mem.c
Expand Down Expand Up @@ -139,4 +147,4 @@ target_link_libraries(adh_agent ${log-lib} dl ${HOOK_LIBS} ${LSPLANT_LIBS})
# Keep our own code small + hidden; -Wall/-Wextra apply to C agent sources only
# (third-party hook sources get -Wno-everything above).
target_compile_options(adh_agent PRIVATE -O2 -fvisibility=hidden)
target_compile_options(adh_agent PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wall -Wextra>)
target_compile_options(adh_agent PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wall -Wextra>)
3 changes: 3 additions & 0 deletions agent/exports.map
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
adh_agent_set_package;
adh_agent_set_policy;
adh_agent_set_endpoint;
adh_agent_set_qbdi_fd;
adh_agent_set_vm;
adh_agent_start;
adh_agent_apply_early_v1;
local:
*;
};
12 changes: 11 additions & 1 deletion agent/src/MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## Layout

2026-11-17: `hook/got.c` also owns `adh_restore_pointer_if_owned`: native GOT unhook uses
atomic compare/exchange and refuses another writer's pointer. Status reports `slotOwned` and
`ownership-lost`/`slot-unreadable` before interpreting historical hits. See
[NATIVE_GOT_CLOSEOUT.md](../../docs/NATIVE_GOT_CLOSEOUT.md) for the exact runtime coverage.

2026-10-24: `trace/qbdi_trace.c` additionally owns one explicitly requested, <=65536-instruction
paged command-thread recording (allocated on request, released after Host drain); `qbdi_read`
never mixes trace IDs. The hook-time path remains replay with incomplete context, explicitly tagged.
Expand Down Expand Up @@ -41,7 +46,7 @@ never mixes trace IDs. The hook-time path remains replay with incomplete context
| `runtime/jni_onload.c` | JNI_OnLoad work: already-loaded module discovery, inline hook with prologue snapshot, manual invocation, real unhook (restores the bytes), plus the load-time watch state consumed by `runtime/dlopen_watch.c` (skip/return replacement of a load-time call) |
| `runtime/dlopen_watch.c` | Lazily-installed dlopen watch on **both** entry points (`dlopen` and `android_dlopen_ext`/`__loader_` alias, each with its own trampoline). Two consumers: the JNI_OnLoad watch (patch a module's entry before the VM calls it) and the opt-in **`module_watch`** broadcast, which emits a `MODULE_LOAD` capture event (path, handle, base, size) for every library mapped afterwards — the initial map of an already-loaded module never passes here, a runtime-decrypted payload does. Hooking only the first entry that resolved made the broadcast blind to plain-`dlopen` loads (including the agent's own `load_so`), which is what the two slots fix. |
| `trace/commands.c` | QBDI command response handling (`qbdi_trace`). The one-shot function tracer (`trace_run`) was deleted on 2026-10-01: `native_hook mode=got` + `java_call` + `native_backtrace`/`trace_digest` cover it without hardcoding a target trigger |
| `trace/qbdi_trace.c` | QBDI instruction trace, two entry points over ONE run engine and one set of guards. `adh_qbdi_trace` = standalone command-thread trace (`qbdi_call`, library loaded/unloaded per call). `adh_qbdi_run_from` / `_ex` = **in-hook** trace from an arbitrary pc with the hit's registers (`gpr` = x0-x8, x29, x30, x18), used by `native_hook { traceInsns, traceFrom }` on the TARGET thread: **per-thread VM** (`pthread_getspecific`, never a global lock), 300 ms wall clock, instruction budget, executable-range snapshot, `pc == lr` return detection, thread-local re-entrancy guard. The range snapshot is immutable once published and replaced by a pointer swap (in-hook runs read it concurrently); it is rebuilt only when the start address is not covered. An inline hook's entry carries our own Dobby branch, so that path starts in the trampoline and adds its page + the function's module explicitly (`qbdi_addInstrumentedRange`), otherwise the run reports `did-not-run`. `stopReason` is the caller's fact: `completed | instruction-budget | time-budget | ran-away | left-range | did-not-run | reentrant`. Costs (documented in `qbdi_trace.h`): the traced function EXECUTES under the emulator (twice per hit), stack-passed/float arguments are not seeded, and libQBDI.so must be loadable in the target (a real app usually needs it pushed + `load_library` first). Optional **write watch** for the run (`traceWatch: "x0:32"`, same window grammar as `mem`, armed as `qbdi_addMemRangeCB(QBDI_MEMORY_WRITE)` and deleted right after): the event then carries `traceWatch {lo, hi, count, truncated, hits:[{pc, insn, addr, size, value}]}`, i.e. WHICH instruction wrote WHICH address with WHICH value — the software stand-in for a hardware watchpoint, which app domains are denied (perf_event_open: errno 13) |
| `trace/qbdi_trace.c` | QBDI instruction trace, two entry points over ONE run engine and one set of guards. `adh_qbdi_trace` = standalone command-thread trace (`qbdi_call`, library loaded/unloaded per call). `adh_qbdi_run_from` / `_ex` = **in-hook** trace from an arbitrary pc with the hit's registers (`gpr` = x0-x8, x29, x30, x18), used by `native_hook { traceInsns, traceFrom }` on the TARGET thread: **per-thread VM** (`pthread_getspecific`, never a global lock), 300 ms wall clock, instruction budget, executable-range snapshot, `pc == lr` return detection, thread-local re-entrancy guard. The range snapshot is immutable once published and replaced by a pointer swap (in-hook runs read it concurrently); it is rebuilt only when the start address is not covered. An inline hook's entry carries our own Dobby branch, so that path starts in the trampoline and adds its page + the function's module explicitly (`qbdi_addInstrumentedRange`), otherwise the run reports `did-not-run`. `stopReason` is the caller's fact: `completed | instruction-budget | time-budget | ran-away | left-range | did-not-run | reentrant`. Costs (documented in `qbdi_trace.h`): the traced function EXECUTES under the emulator (twice per hit), stack-passed/float arguments are not seeded, and libQBDI.so must be loadable in the target (a real app usually needs it pushed + `load_library` first). Optional **write watch** for the run (`traceWatch: "x0:32"`, same window grammar as `mem`, armed as `qbdi_addMemRangeCB(QBDI_MEMORY_WRITE)` and deleted right after): the event then carries `traceWatch {lo, hi, count, truncated, hits:[{pc, insn, addr, size, value}]}`, i.e. WHICH instruction wrote WHICH address with WHICH value — the software stand-in for a hardware watchpoint, which app domains are denied (perf_event_open: errno 13). Delivery: a real target does not carry the tracer, so the injector hands over an fd it opened pre-specialize (`adh_agent_set_qbdi_fd` → `adh_qbdi_set_source_fd`); `api_load` copies it into a memfd created after specialization and `dlopen`s that, so nothing is loaded or mapped until a trace actually runs, and a standalone trace `dlclose`s it again |

## Naming

Expand All @@ -65,3 +70,8 @@ the build you think you flashed. Both the module zip and the agent must be rebui
- `tools/build_agent.sh` keeps `libadh_agent.so.debug` locally and stages only a stripped `.so`.
- `exports.map` restricts `.dynsym` to `JNI_OnLoad`, `adh_agent_set_package`, `adh_agent_set_policy`, and `adh_agent_start`.
- `compat_probe` reports bootstrap vs current exec/anon-exec/RWX counters; base injection and GOT hooks must not add true anonymous executable pages.
# P5 early-plan/1 addition

Real Android acceptance caught and fixed an invalid errno default in the early GOT consumer; failures now include a bounded reason. The explicit CMake `ADH_AGENT_CONNECT_PORT` defaults to 8761; port 18761 is used only in sandbox builds, and custom-port `--deploy` is refused. Before-agent-connect GOT hits are verified on Android, full Zygisk delivery is still unverified. See [P5_ANDROID_ACCEPTANCE.md](../../docs/P5_ANDROID_ACCEPTANCE.md).

`bootstrap/early_wire.h` is the shared bounded native validator and SHA implementation; `bootstrap/early_plan.cpp` consumes only verified named capture/GOT observation steps before `adh_agent_start`, stops on an unconfirmed installation and adds agent-reported receipts to hello. `capture_policy` explicitly sets/reads family eligibility. No .init_array timing guarantee. Full contract: [P5_HOOK_PLANS.md](../../docs/P5_HOOK_PLANS.md).
4 changes: 3 additions & 1 deletion agent/src/bootstrap/agent_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
// .so, so "which agent is flashed?" and "which module is flashed?" must not be two different
// answers. Reported by compat_probe and in the hello; the string is already compiled in either
// way, so surfacing it adds no new string to the release image (v88 unaffected).
#define AGENT_VER "0.6.0"
#define AGENT_VER "0.8.0"
#define ADH_HOST "127.0.0.1"
#ifndef ADH_PORT
#define ADH_PORT 8761
#endif
// Loopback is always tried first (adb reverse). adh_agent_set_endpoint may name one extra
// IPv4 the root companion already learned; connect_adhd uses it only after loopback fails.
#define TAG "rt.agent"
Expand Down
Loading
Loading