### 重编后检查动态依赖和未定义符号 Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md 重编后使用 readelf 检查 NEEDED 和 UND 符号,确认只剩 libc/loader 的符号,且 STT_FILE 包含 root.c 和 io_daemon.c。 ```bash $ readelf -dW libbaseline_6_1.so | grep NEEDED (NEEDED) Shared library: [libdl.so] (NEEDED) Shared library: [libc.so] $ readelf -sW libbaseline_6_1.so | awk '$7=="UND"' # 只剩 libc/loader 的符号 ``` -------------------------------- ### 载荷构建流程 ASCII 图 Source: https://github.com/hmascs/ksuroot/blob/main/MODULE.md ASCII 流程图,展示从 boot.img 到打好补丁的 .so 的五个阶段:boot.img 解析、内核镜像、kallsyms、偏移解析、打补丁。 ```text boot.img ──► 内核镜像 ──► 内核符号表(kallsyms) ──► 这条链需要的偏移 ──► 打好补丁的 .so ① ② ③ ④ ⑤ ``` -------------------------------- ### 查看旧产物动态符号表中的 FILE 符号 Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md 使用 readelf 和 awk 列出旧产物中所有 FILE 类型的符号,发现缺少 root.c 和 io_daemon.c。 ```bash $ readelf -sW libbaseline_6_1.so | awk '$4=="FILE"' ... aarch64.c fops.c main.c pipe.c posture.c preload.c slide.c util.c ``` -------------------------------- ### 运行载荷模块单测命令 Source: https://github.com/hmascs/ksuroot/blob/main/MODULE.md 运行载荷模块的单测,不需要连接设备。 ```bash # 只跑载荷模块的单测(不需要连设备) ./gradlew :app:testDebugUnitTest --tests 'com.kernelpack.*' ``` -------------------------------- ### Copy preload.so into jniLibs Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md Copy built preload.so files into the app's jniLibs directory. After copying, you must run 'bash ksu-toolchain/compile_check.sh ' to verify the payloads carry the required marker. ```bash cp /root/vrbuild/build/baseline-6.1-tokay/bin/preload.so \ app/src/main/jniLibs/arm64-v8a/libbaseline_6_1.so cp /root/vrbuild/build/baseline-6.12-gki/bin/preload.so \ app/src/main/jniLibs/arm64-v8a/libbaseline_6_12.so ``` -------------------------------- ### Run build_baselines.sh in Ubuntu chroot Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md Runs the baseline build recipe inside an Ubuntu chroot. Requires the missing exploit source tree at bsrc/exploit/src; without it the script stops at '找不到载荷源码'. ```bash bash build_baselines.sh # 在 Ubuntu chroot 里跑 ``` -------------------------------- ### 检查旧产物中 vr detag 标记数量 Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md 使用 strings 和 grep 统计旧产物中 'vr detag' 出现的次数,结果为 0,表明标记未抹除。 ```bash $ strings -a libbaseline_6_1.so | grep -c "vr detag" # 旧产物 0 ``` -------------------------------- ### Run compile_check.sh Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md Run the compile check script after copying the preload.so files. The BundledPayloadVrKoAuditTest uses real bytes to verify the payloads carry the marker; without this, the test fails. ```bash bash ksu-toolchain/compile_check.sh ``` -------------------------------- ### 查看旧产物 .comment 段中的编译器版本 Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md 使用 readelf 查看旧产物 .comment 段,包含 clang 22.0.1、clang 21.0.0 和 LLD 21.0.0,用于确定 NDK 版本。 ```bash clang version 22.0.1 ... clang version 21.0.0 ... LLD 21.0.0 ``` -------------------------------- ### com.kernelpack 模块目录结构 Source: https://github.com/hmascs/ksuroot/blob/main/MODULE.md 目录树展示 com.kernelpack 模块的源码结构,包括主源码、测试、jniLibs 和 assets 目录。 ```text app/src/main/java/com/kernelpack/ ├── KernelPack.kt 总入口:pack(PackRequest) → PackResult ├── SymbolAlignment.kt ★ 双向符号对齐闸门 ├── Hex.kt ├── boot/ boot.img 头解析 + 压缩格式 ├── kallsyms/ kallsyms 扫描(两种排布) ├── elf/ ELF 只读解析 ├── patch/ SharedObjectPatcher + PatchSpec + PatchReport ├── resolve/ KernelImage + OffsetResolver ├── model/ KernelImageAnalysis / TargetProfile / OffsetEntry / ResolveSource ├── policy/ ★ BuildGate(硬闸门)· KernelSchemeSelector(选线) ├── profile/ ★ BaselineRegistry(107 档)· GhostLockKernelOffsets │ · GhostLockKernelCatalog · Profiles / AbiProfile ├── offsets/ ★ GhostLock offsets.json 互通 │ (schema / IO / 合并 / 键映射 / 统一解析) ├── offset/ OffsetProvenance(逐条偏移的来源与可信度)· PselectFeasibility ├── vivo/ VrKoBypass(vr.ko 判定)· VrKoPayloadCheck(字节判据) │ · VrKoPayloadGate(蓝厂方案专属闸门) ├── ota/ ★ 「解析完整包链接」:HTTP Range 只取需要的块 │ HttpRangeReader · ZipCentralDirectory · PayloadBinUtils │ · XzDecoder · OtaPayloadExtractor └── export/ target.h / offsets.json 导出 app/src/test/java/com/kernelpack/ 对应的单测(40 个文件) app/src/main/jniLibs/arm64-v8a/ ├── libbaseline_6_1.so ★ 自编 6.1 族基线(带 vr.ko 抹标记,配方见 载荷构建/) ├── libbaseline_6_12.so ★ 自编 6.12 族基线(同上) ├── libionstack.so 通用方案 6.6 基线(**不带** vr.ko,本就不该带) └── libbs.so 蓝厂方案 6.6 基线(all-in-one,自带 vr.ko 抹标记) app/src/main/assets/ └── GL_LICENSE_Apache2.txt GhostLock 上游许可证(Apache-2.0) ``` -------------------------------- ### Run build_baselines.sh in Termux chroot Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md Run the build_baselines.sh script inside an Ubuntu chroot on Termux. The script copies exploit sources, builds with make, and self-verifies the 'vr detag' marker. Overridable variables: WS, BUILD_ROOT (default /root/vrbuild), NDK_ROOT, API, SRC_ROOT. ```bash chroot-distro login ubuntu -- bash -lc \ 'bash /data/data/com.dsharnessmobile.shell/files/home/.dsh/workspaces/incoming/载荷构建/build_baselines.sh' ``` -------------------------------- ### 构建 Release APK Source: https://github.com/hmascs/ksuroot/blob/main/README.md 使用 Gradle 构建 release 版本 APK。需要 JDK 21、Android Gradle Plugin 9.2、compileSdk 37、NDK 30.0.16248370 和 CMake 3.22.1。产物位于 app/build/outputs/apk/release/,签名参数从 GRADLE_USER_HOME/gradle.properties 读取。 ```bash ./gradlew assembleRelease ``` -------------------------------- ### CMake build configuration for ksu_native shared library Source: https://github.com/hmascs/ksuroot/blob/main/app/src/main/cpp/CMakeLists.txt CMake configuration for building a shared library named ksu_native from native_probe.c. Requires CMake 3.22.1 or later, compiles with -O2 -Wall -Wextra -Werror, and links against the log library. ```cmake cmake_minimum_required(VERSION 3.22.1) project(ksu_native LANGUAGES C) add_library(ksu_native SHARED native_probe.c) target_compile_options(ksu_native PRIVATE -O2 -Wall -Wextra -Werror) target_link_libraries(ksu_native PRIVATE log) ``` -------------------------------- ### Upstream Makefile key variables Source: https://github.com/hmascs/ksuroot/blob/main/载荷构建/README.md Key Makefile variables from the upstream build. pick_src selects per-file overrides from src/targets/$(PROJECT)/. TARGET_CONFIG_H is a string used in #include. PRELOAD_SRCS includes src/ prefix while CORE_SRCS does not; missing source files silently leave undefined symbols. ```make pick_src = $(if $(wildcard src/targets/$(PROJECT)/$(1)),src/targets/$(PROJECT)/$(1),src/$(1)) TARGET_CFLAGS := -DTARGET_CONFIG_H=\"targets/$(PROJECT)/target.h\" COMMON_CFLAGS := -O2 -g0 -Wall -Wextra -Isrc CORE_SRCS := main.c util.c slide.c fops.c pipe.c root.c posture.c PRELOAD_SRCS := $(CORE_SRCS) src/preload.c src/io_daemon.c src/su_blob.S src/wallpaper_blob.S ```