Repository navigation
fix(apktool): reduce runtime memory pressure - #1038
Closed
3316891527 wants to merge 1 commit into
Closed
3316891527 wants to merge 1 commit into
3316891527 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
背景与动机
当前 APKTool/JADX 等逆向工具与宿主应用运行在同一进程。在 Android 进程的 Java 堆上限固定(通常为 512MB)的前提下,主应用需要为 UI、聊天数据、模型等核心功能预留内存。逆向工具作为同进程内的附加任务,仅能使用堆中的剩余空间,可用余量有限。与此同时:
这些因素叠加后,即使 APK 体积不大,也可能触发 OOM。
本 PR 聚焦于降低当前同进程实现下的内存峰值和长期累积压力。
本 PR 不涉及独立
:apk_reverse进程或 IPC 架构,进程隔离属于后续独立改动。改动范围
复用 ClassLoader 缓存
将 helper runtime 的输出文件名从“每次调用递增”改为“稳定的后端槽位”:APKTool decode/build 共用槽位,JADX 使用独立槽位,其他 helper 调用使用通用槽位,以命中宿主
JsExternalJavaCodeLoader的路径缓存,避免每次调用都创建新的DexClassLoader实例。限制并行度与结果集
将 APKTool 默认
jobs限制为 1,避免多线程解码带来的内存峰值。同时,在 JavaScript 与 helper Java 边界将搜索结果限制为最多 1000 条,防止超大结果集撑爆内存。资源导出改为流式复制
将 ToolPkg JAR 资源从
readBytes()+ 一次性写入改为流式复制,避免复制 JADX 等大资源时产生额外的完整字节数组。native 搜索改为流式扫描
将 helper 的目录 native 字符串搜索改为
InputStream流式扫描,避免将整个.so文件一次性载入堆内存。裁剪 JADX Android runtime
从 Android JADX runtime 中移除当前 APK-only 工具不需要的
apkm、smali、xapk等输入插件,并重新生成 APKTool、JADX 和 helper 三份 dex-JAR。同步构建产物
同步修改
examples/apktool/src/packages/apk_reverse.ts与实际运行的dist/packages/apk_reverse.js。兼容性与风险
JsExternalJavaCodeLoader的路径缓存行为;若缓存未命中,可能退化为新建 ClassLoader,但不会影响功能,只会略微增加内存压力。需要在 Android 设备上确认实际 classloader 兼容性。native symbol、offset和hex bytes等解析路径仍保留现有的完整二进制解析逻辑,后续可进一步优化。验证方式
git diff --check target/development...HEAD:PASS。node --check examples/apktool/dist/packages/apk_reverse.js:PASS。runtime_helperGradletest:PASS。runtime_helperGradleruntimeFatJar:PASS。.class条目:PASS。:app:assembleDebug当前被环境问题阻塞:SDKaidl在当前 Linux/proot 环境无法启动;资源任务还依赖当前环境缺失的 STT 下载、liboperit_ripgrep.so和ffmpeg-kit-local.aar。这些阻塞未被标记为通过。检查清单
development。apk_reverse.js已同步。:apk_reverse进程与 IPC 不属于本 PR。