[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-108052":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":14,"stars7d":15,"stars30d":16,"stars90d":14,"forks30d":14,"starsTrendScore":13,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":9,"pushedAt":22,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":14,"starSnapshotCount":14,"syncStatus":15,"lastSyncTime":26,"discoverSource":27},108052,"KCLF","AndroidReverser-Test\u002FKCLF","AndroidReverser-Test","适用于安卓平台的内核级无痕注入框架",null,"C",76,29,1,0,2,23,47.73,"GNU General Public License v2.0",false,"main",[],"2026-11-01 10:21:03","2026-11-21 16:26:44","# KCLF 1.5.7\n\nKernel Controlled Loading Framework — Android ARM64 \u002F KernelPatch KPM\n\n[中文](#中文) · [English](#english) · [实现 \u002F Implementation](IMPLEMENTATION.md)\n\n## 中文\n\nKCLF 通过内核 `task_work` 借用目标线程，在 EL0 执行 SO 的构造\u002F析构函数。\n默认 `manual` 后端自行映射和重定位 ELF；显式 `linker` 后端调用目标 bionic loader。\n`main` 维护框架、构建配置、测试 App 和当前版本兼容性报告；历史报告、检测实验及\n完整主机\u002F设备回归夹具在 `dev`。\n\n### 1.5.7 更新与验证\n\n- manual 按 DT_STRSZ 和可读 PT_LOAD 边界读取、完整比较符号名，解除原有 255 字节\n  符号名限制；SONAME、DT_NEEDED 和版本名仍保留该限制。\n- payload 内定义的 compiler-rt emutls 允许使用，但镜像标记 `nodelete=emutls`，\n  必须驻留到目标 mm 退出；首次 `unload` 和显式 `release` 拒绝执行。\n- 未新增内核 ABI\u002F符号依赖，既有 BTF、task_work、procfs\u002Faccessor\u002FGUP 回退路径未改。\n  12 组主机测试全部通过；真实设备 BTF 解析回归通过。\n- Pixel 6 \u002F Android 16 \u002F Linux 6.1.134 \u002F ARM64 \u002F 4K 页：正式产物通过 186 项\n  原生及自有普通 App 断言；关闭 BTF\u002Fnofault 的独立测试构建通过 243 项断言。\n  两轮均安全卸载且无新增内核告警；其他内核及 16K\u002F64K 页设备未在本轮实测。\n- 1.5.6 的动态提供库表和已映射提供库结构解析保持不变。名称缓冲最多 64 MiB\n  （含 NUL），累计字符串读取预算 256 MiB；超限或分配失败会明确停止并回滚。\n\n实现、审计依据、产物 SHA-256 和证据范围见\n[1.5.7 兼容性报告](COMPATIBILITY_1.5.7.md)；产物见\n[GitHub Release](https:\u002F\u002Fgithub.com\u002FAndroidReverser-Test\u002FKCLF\u002Freleases\u002Ftag\u002Fv1.5.7)。\n\n### 编译\n\n模块需要 GNU Make、AArch64 bare-metal GCC\u002Fbinutils，以及一份 KernelPatch 源码。\n在本仓库根目录运行（Linux\u002FWSL 示例，路径按实际环境替换）：\n\n```sh\nmake KP_DIR=\u002Fpath\u002Fto\u002FKernelPatch TARGET_COMPILE=\u002Fpath\u002Fto\u002Fbin\u002Faarch64-none-elf-\n```\n\n产物为 `kclf.kpm`；`make clean` 清理模块产物。位于 KernelPatch 的\n`kpms\u002Fkclf` 时可省略 `KP_DIR`（默认 `..\u002F..`）。本仓库不内置 KernelPatch 头文件。\n\n测试 App 需要 Windows PowerShell、JDK（`java\u002Fjavac\u002Fkeytool` 在 PATH 中）、\nAndroid SDK platform 35 或更新、build-tools 和 NDK：\n\n```powershell\n.\\test\\app\\build.ps1 -SdkRoot D:\\androidSDK -NdkRoot D:\\androidSDK\\ndk\\27.0.12077973\n```\n\n生成 `build\u002Fkclf-apptest\u002Fapp.apk`，包名 `com.kclf.apptest`，包含普通、FP 状态破坏、\n延时构造三种 payload。可用 `-OutDir` 指定输出目录；调试签名密钥会在输出目录复用。\n\n### 使用\n\n设备需已安装可用的 KernelPatch，且能用 superkey 调用 `kpatch`。\n仅支持 64 位 ARM64 目标；代码适配范围为 Linux 5.x\u002F6.x，实际可用性取决于运行时 ABI、\n符号和设备配置，不能据此认为全部内核或 16K\u002F64K 页设备已通过测试。\n\n```sh\nadb install -r -t build\u002Fkclf-apptest\u002Fapp.apk\nadb shell am start -W -n com.kclf.apptest\u002F.MainActivity\nadb shell pidof com.kclf.apptest\nadb shell logcat -d -s KCLFAPP:I\nadb push kclf.kpm \u002Fdata\u002Flocal\u002Ftmp\u002Fkclf.kpm\n```\n\n以下命令在主机 shell 执行：先将 `KEY` 设为你的 superkey（不要提交到仓库），\n`TID` 设为目标线程 ID（主线程即 PID），`LIBDIR` 设为上述日志中的 `libdir`。\n\n```sh\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm load \u002Fdata\u002Flocal\u002Ftmp\u002Fkclf.kpm\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf probe\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf \"inject,$TID,$LIBDIR\u002Flibkclfapp_payload.so,wake\"\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf status\nadb shell run-as com.kclf.apptest cat \u002Fdata\u002Fuser\u002F0\u002Fcom.kclf.apptest\u002Ffiles\u002Fhit_$TID\n```\n\n此例注入主线程，因此 marker 文件后缀也是 PID。重复查看 `status`，\n直到出现 `state=done`、`via=manual`、`refs=1` 且没有 `pending=` \u002F `map=`。\n此例让 SO 保持驻留；需要卸载时按下文 `images` \u002F `release` 流程释放。\n命令返回 `queued` 只表示已排队。追加 `,linker` 可选择 bionic 后端。\n\n#### SO 路径要求\n\n`,$LIBDIR\u002Flibkclfapp_payload.so` 中的逗号是命令参数分隔符，后面才是 SO 路径。\n`LIBDIR` 是**设备上的目录**，由主机 shell 展开；本示例应填写测试 App 日志中的\n`libdir`，例如 `\u002Fdata\u002Fapp\u002F~~...\u002Fcom.kclf.apptest-...\u002Flib\u002Farm64`，并确认其中已有\n由测试 APK 安装的 `libkclfapp_payload.so`。注入其他 SO 时替换为实际完整路径。\n\n- 展开后的路径必须是设备端绝对路径，最多 255 字节，不能包含逗号、空格、制表符、\n  换行等分隔符；给命令加引号也不能让这些字符成为路径的一部分。\n- SO 必须是框架支持的 64 位小端 AArch64 ELF 共享库（`ET_DYN`）。\n- 准备阶段使用**目标进程的凭据**打开文件；目标需能读取 SO、访问各级目录，\n  并满足 SELinux 策略。控制端取得 root 不等于目标 App 获得文件访问权限。\n- `manual` 不强制使用 App 的 native library 目录，也可使用目标有权读取的\n  `\u002Fdata\u002Fuser\u002F0\u002F\u003C包名>\u002Ffiles\u002F\u003C模块>.so`；依赖仍需预先加载，映射权限仍受设备策略限制。\n  `linker` 还要求路径属于目标 linker namespace 允许的范围，并允许文件的可执行映射；\n  本示例使用安装后的 native library 目录。`\u002Fdata\u002Flocal\u002Ftmp` 不能视为普通 App 通用可用的路径。\n\n常用控制字符串（作为 `kpm ctl0 kclf` 的最后一个参数）：\n\n| 命令 | 含义 |\n| --- | --- |\n| `inject,\u003Ctid>,\u003C绝对路径>[,manual\\|linker][,wake][,unload][,keepelf][,force]` | 默认 manual；设备端路径最多 255 字节，不支持逗号或空白分隔符 |\n| `status` \u002F `probe` \u002F `sym` | 请求状态 \u002F 兼容性 \u002F 内核符号诊断 |\n| `images[,cursor]` | 枚举 manual 驻留镜像；有 `next=N` 时继续 `images,N` |\n| `release,\u003Ctid>,\u003Cimage-id>[,wake][,force]` | 释放一个 manual 引用；最后一次执行析构并解除映射 |\n| `cancel,\u003Cslot>` \u002F `reap` | 取消尚未执行的排队请求 \u002F 回收完成槽及死亡目标记录 |\n| `quiesce` | 禁止新加载并检查能否卸载；重新加载 KPM 才恢复接收 |\n\n`wake` 可唤醒可中断睡眠；省略时等待线程自然返回用户态。\n`unload` 用于一次性加载：manual 新镜像在构造函数返回后执行析构并解除映射；\nlinker 在加载后调用 `dlclose` 释放本次引用，实际卸载取决于 linker 的引用计数等规则。\n省略 `unload` 则保持驻留。它控制的是注入 SO 的生命周期。\n\n**`unload` 的副作用：框架不会自动等待 SO 创建的后台线程退出，也不会注销其异步回调、\n定时器或 hook。** 构造函数返回时这些任务可能仍在执行；解除映射后继续使用其中的代码、\n数据或函数指针，可能导致崩溃、死锁或 App 卡住。仅在所有工作已同步完成、没有后续使用者时\n使用 `unload`。需要后台任务或持续回调的 SO 应保持驻留，先通过 payload 自身的机制停止任务、\n注销回调并确认不再执行，再释放。已有 manual 驻留镜像应通过 `release` 释放引用；\n重复 `inject,...,unload` 不会替代这一步。\n\n`keepelf` 只用于 manual，保留内存 ELF 头。\n`force` 仅跳过安全点启发式。**恢复路径会改写 x16\u002FIP0，必须选择 x16 不再使用的协作边界**；\n系统调用白名单无法证明这一点，也无法证明目标未持有锁。\nmanual 要求全部依赖已加载且在 payload 存活期间保持加载，不支持 ELF PT_TLS、\n完整 C++\u002FJNI loader 集成。详见[实现与限制](IMPLEMENTATION.md)。\n\n`nodelete=emutls` \u002F `nodelete=elf` 镜像在目标 mm 存活期间不能 release；必须先让\n目标进程退出，再 `reap` 并确认 `quiesce=idle`。完全不在 dynsym 中的隐藏 emutls\n无法自动识别，payload 使用方仍需自行保证生命周期安全。\n\n卸载前先 `quiesce`；驻留模式需要通过 `images` \u002F `release` 排空所有引用，\n并先停止 payload 线程和异步回调。再执行：\n\n```sh\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf reap\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf quiesce\n# 必须确认 quiesce=idle 后再执行：\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm unload kclf\n```\n\n自动 App 回归（会安装并重启本仓库测试 App、加载和排空 KPM）：\n\n```powershell\n.\\test\\app\\device-test.ps1 -SuperKey (Read-Host 'KernelPatch superkey') -Serial '\u003CSERIAL>' -Backend manual -Repeat 10\n# -Backend linker 测试另一后端；-Apk \u002F -Kpm 可指定产物\n```\n\n## English\n\nKCLF borrows a target thread through kernel `task_work` to run SO constructors and\nfinalizers in EL0. The default `manual` backend maps and relocates ELF itself;\nthe explicit `linker` backend calls the target bionic loader.\n`main` contains the framework, build configuration, test app and current compatibility report.\nHistorical reports, detection experiments and full host\u002Fdevice regression fixtures remain on `dev`.\n\n### 1.5.7 changes and validation\n\n- Manual loading reads and compares complete symbol names within DT_STRSZ\u002Freadable PT_LOAD\n  bounds, removing the 255-byte symbol-name limit. SONAME, DT_NEEDED and version names remain bounded.\n- Payload-defined compiler-rt emutls is supported with `nodelete=emutls`: its image stays mapped\n  until the target mm exits. First-load `unload` and explicit `release` are rejected.\n- No new kernel ABI or symbol dependency; BTF, task_work and procfs\u002Faccessor\u002FGUP fallbacks are\n  unchanged. All 12 host suites and a real-device BTF parser regression passed.\n- Pixel 6 \u002F Android 16 \u002F Linux 6.1.134 \u002F ARM64 \u002F 4K: 186 native\u002Fself-owned app assertions passed\n  with the release artifact; 243 passed with a separate no-BTF\u002Fno-nofault test build. Both runs\n  drained and unloaded safely without new kernel diagnostics. Other kernels and 16K\u002F64K devices\n  were not tested in this round.\n- The 1.5.6 provider table and mapped-provider structural parsing are unchanged. Name storage\n  is capped at 64 MiB including NUL, with a 256 MiB cumulative string-read budget; resource\n  exhaustion explicitly fails and rolls back.\n\nSee the [1.5.7 compatibility report](COMPATIBILITY_1.5.7.md) for implementation, audit evidence,\nartifact SHA-256 and validation limits, and the\n[GitHub Release](https:\u002F\u002Fgithub.com\u002FAndroidReverser-Test\u002FKCLF\u002Freleases\u002Ftag\u002Fv1.5.7) for downloads.\n\n### Build\n\nThe module requires GNU Make, AArch64 bare-metal GCC\u002Fbinutils and a KernelPatch\nsource tree. Run from this repository root (Linux\u002FWSL; replace the paths):\n\n```sh\nmake KP_DIR=\u002Fpath\u002Fto\u002FKernelPatch TARGET_COMPILE=\u002Fpath\u002Fto\u002Fbin\u002Faarch64-none-elf-\n```\n\nOutput: `kclf.kpm`. Run `make clean` to remove module outputs.\n`KP_DIR` defaults to `..\u002F..`, suitable for a checkout at KernelPatch's\n`kpms\u002Fkclf`. KernelPatch headers are external dependencies.\n\nThe test app requires Windows PowerShell, a JDK with `java\u002Fjavac\u002Fkeytool` on PATH,\nAndroid SDK platform 35 or newer, build-tools and an NDK:\n\n```powershell\n.\\test\\app\\build.ps1 -SdkRoot D:\\androidSDK -NdkRoot D:\\androidSDK\\ndk\\27.0.12077973\n```\n\nOutput: `build\u002Fkclf-apptest\u002Fapp.apk`, package `com.kclf.apptest`.\nIt includes normal, FP-clobbering and delayed-constructor payloads.\n`-OutDir` changes the output location; the debug signing key is reused there.\n\n### Use\n\nThe device must already run KernelPatch and allow superkey-authenticated\n`kpatch` commands. Targets must be 64-bit ARM64. The implementation addresses\nLinux 5.x\u002F6.x ABIs; availability still depends on runtime ABI, symbols and device\nconfiguration. This does not certify all kernels or 16K\u002F64K devices.\n\n```sh\nadb install -r -t build\u002Fkclf-apptest\u002Fapp.apk\nadb shell am start -W -n com.kclf.apptest\u002F.MainActivity\nadb shell pidof com.kclf.apptest\nadb shell logcat -d -s KCLFAPP:I\nadb push kclf.kpm \u002Fdata\u002Flocal\u002Ftmp\u002Fkclf.kpm\n```\n\nFor the host-shell commands below, set `KEY` to your superkey (never commit it),\n`TID` to the target thread ID (PID for the main thread), and `LIBDIR` to the\n`libdir` printed in the app log.\n\n```sh\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm load \u002Fdata\u002Flocal\u002Ftmp\u002Fkclf.kpm\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf probe\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf \"inject,$TID,$LIBDIR\u002Flibkclfapp_payload.so,wake\"\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf status\nadb shell run-as com.kclf.apptest cat \u002Fdata\u002Fuser\u002F0\u002Fcom.kclf.apptest\u002Ffiles\u002Fhit_$TID\n```\n\nThis example targets the main thread, so the marker suffix is also the PID.\nPoll `status` until it reports `state=done`, `via=manual`, `refs=1`, with no\n`pending=` or `map=`. This example keeps the SO resident; use the `images` \u002F\n`release` procedure below when it is ready to unload. A `queued` response only\nacknowledges scheduling. Append `,linker` for bionic loading.\n\n#### SO path requirements\n\nIn `,$LIBDIR\u002Flibkclfapp_payload.so`, the comma separates command arguments; the\nSO path follows it. `LIBDIR` is a **directory on the device**, expanded by the\nhost shell. For this example, use the test app's logged `libdir`, such as\n`\u002Fdata\u002Fapp\u002F~~...\u002Fcom.kclf.apptest-...\u002Flib\u002Farm64`, and verify that it contains\n`libkclfapp_payload.so` installed by the test APK. Replace the full path when\ninjecting another SO.\n\n- The expanded path must be absolute on the device, at most 255 bytes, and\n  contain no commas, spaces, tabs, newlines or other argument separators.\n  Quoting the command does not make these characters valid within the path.\n- The SO must be a supported 64-bit little-endian AArch64 ELF shared object\n  (`ET_DYN`).\n- Preparation opens the file using **the target process's credentials**. The\n  target must be able to read the SO, traverse its parent directories and\n  satisfy SELinux policy. Root access for the controller does not grant file\n  access to the target app.\n- `manual` also accepts a target-readable path such as\n  `\u002Fdata\u002Fuser\u002F0\u002F\u003Cpackage>\u002Ffiles\u002F\u003Cmodule>.so`; dependencies must already be loaded\n  and mapping permissions remain subject to device policy. `linker` additionally\n  requires an allowed path in the target linker namespace and permission for\n  executable file mappings. This example uses the installed native library\n  directory. Do not assume `\u002Fdata\u002Flocal\u002Ftmp` is usable by an ordinary app.\n\nCommon control strings, passed as the last argument to `kpm ctl0 kclf`:\n\n| Command | Meaning |\n| --- | --- |\n| `inject,\u003Ctid>,\u003Cabsolute-path>[,manual\\|linker][,wake][,unload][,keepelf][,force]` | Defaults to manual; device path is at most 255 bytes and cannot contain commas or whitespace separators |\n| `status` \u002F `probe` \u002F `sym` | Requests \u002F compatibility \u002F kernel-symbol diagnostics |\n| `images[,cursor]` | List resident manual images; follow `next=N` with `images,N` |\n| `release,\u003Ctid>,\u003Cimage-id>[,wake][,force]` | Release one manual reference; the last release runs finalizers and unmaps |\n| `cancel,\u003Cslot>` \u002F `reap` | Cancel queued work before execution \u002F reclaim finished slots and dead-target records |\n| `quiesce` | Disable new loads and check drain status; reload the KPM to accept loads again |\n\n`wake` wakes interruptible waits; otherwise work waits for a natural return to EL0.\n`unload` requests a one-shot load: a new manual image runs finalizers after its\nconstructors return and is then unmapped. The linker backend calls `dlclose` to\nrelease this load's reference; actual unloading depends on linker reference\ncounts and other rules. Omitting `unload` keeps the SO resident. This option\ncontrols the injected SO's lifetime.\n\n**Side effects of `unload`: the framework does not automatically wait for SO-created\nthreads to exit or unregister asynchronous callbacks, timers or hooks.** These may\noutlive the constructors. Accessing unmapped code, data or function pointers can\ncrash, deadlock or freeze the app. Use `unload` only when all work has completed\nsynchronously and no later users remain. Keep SOs with background work or persistent\ncallbacks resident; stop their work and unregister callbacks through the payload's\nown mechanism, then confirm execution has ended before releasing them. Use\n`release` for existing resident manual references; repeating `inject,...,unload`\ndoes not release those references.\n\n`keepelf` retains in-memory ELF headers for manual images.\n`force` only bypasses safe-point heuristics. **The restore tail overwrites x16\u002FIP0:\nuse a cooperative boundary where x16 is dead.** The syscall allowlist cannot prove\nthis or the absence of held locks. Manual loading requires every dependency to\nalready be loaded and remain resident; ELF PT_TLS and full C++\u002FJNI loader\nintegration are unsupported. See [implementation and limits](IMPLEMENTATION.md).\n\nImages marked `nodelete=emutls` or `nodelete=elf` cannot be released while their\ntarget mm is alive. Let the target process exit, then `reap` and confirm\n`quiesce=idle` before unloading the module. Hidden emutls absent from dynsym\ncannot be detected automatically; callers still own payload lifetime safety.\n\nBefore unloading, issue `quiesce`. For resident manual images, drain every\nreference using `images` \u002F `release`, after stopping payload threads and callbacks.\nThen:\n\n```sh\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf reap\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm ctl0 kclf quiesce\n# Continue only after quiesce=idle:\nadb shell \u002Fdata\u002Flocal\u002Ftmp\u002Fkpatch \"$KEY\" kpm unload kclf\n```\n\nAutomated app regression installs\u002Frestarts this test app and loads\u002Fdrains the KPM:\n\n```powershell\n.\\test\\app\\device-test.ps1 -SuperKey (Read-Host 'KernelPatch superkey') -Serial '\u003CSERIAL>' -Backend manual -Repeat 10\n# Use -Backend linker for bionic; -Apk \u002F -Kpm select custom outputs.\n```\n","KCLF 是一个面向 Android ARM64 平台的内核级 SO 注入框架，用于在目标进程线程上下文中无痕加载和执行自定义共享库。其核心基于 Linux 内核 task_work 机制实现在用户态（EL0）安全触发 SO 构造\u002F析构函数，支持 manual（自主重定位映射）与 linker（调用 bionic loader）两种后端；具备符号名长度放宽、emutls 支持、BTF 兼容性回退等稳健特性。适用于安卓逆向分析、动态插桩、运行时行为观测及内核增强型调试等需要高隐蔽性与低侵入性的安全研究场景。","2026-11-24 04:33:26","CREATED_QUERY"]