{"id":20064907,"url":"https://github.com/baidu/titan-dex","last_synced_at":"2025-04-13T09:37:20.973Z","repository":{"id":48287655,"uuid":"194606378","full_name":"baidu/titan-dex","owner":"baidu","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-11T13:18:54.000Z","size":882,"stargazers_count":205,"open_issues_count":4,"forks_count":34,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-27T01:09:52.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baidu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-01T05:37:03.000Z","updated_at":"2025-02-10T04:32:43.000Z","dependencies_parsed_at":"2024-11-13T13:48:16.987Z","dependency_job_id":"36e0e95e-b244-4b25-b3c6-99d2977eaaa5","html_url":"https://github.com/baidu/titan-dex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Ftitan-dex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Ftitan-dex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Ftitan-dex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Ftitan-dex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baidu","download_url":"https://codeload.github.com/baidu/titan-dex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248691567,"owners_count":21146390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:48:11.282Z","updated_at":"2025-04-13T09:37:20.939Z","avatar_url":"https://github.com/baidu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Titan-Dex字节码操作框架\n\n## 描述\nTitan-Dex是面向Android Dalvik(ART)字节码（bytecode）格式的操纵框架，可以在二进制格式下实现修改已有的类，或者动态生成新的类。  \n功能类似于著名的针对JVM字节码格式的[ASM](https://asm.ow2.io/)框架，在Android平台上从JVM Class格式到Dex格式要经过dx、d8等工具的转换，\n有些情况下会造成期望结果的失真，而Titan-Dex针对Dalvik(ART)字节码格式，可以所操纵就所得的效果，在有些场景下更加适合，比如在Titan-Hotfix,还有classes.dex体积分析与优化等项目中就使用了Titan-Dex。  \n基于Titan-Dex最基础的操纵框架能力，还包含了一系列的字节码转换、代码流图分析、multi-dex分包等工具集合。\n\n## 特性\n* 支持Dex最新格式，提供Node和Visitor两种模式，方便操纵Dex元素  \n* 支持读取和输出smali格式  \n* 支持字节码指令流图分析功能，可以校验字节码类型安全性，以及获取pc偏移出的寄存器类型集合  \n* 支持基于Titan-Dex的多种扩展，比如multi-dex分包能力等。\n\n## 快速开始\n使用上非常类似于[ASM框架](https://asm.ow2.io/asm4-guide.pdf)，如果需要修改或者新增Dalvki(ART)字节码，请同时参考[Android官方文档](https://source.android.com/devices/tech/dalvik/dalvik-bytecode)\n\n最新版本已经发布到jcenter上\n\n```\nimplementation(\"com.baidu.titan.dex:dex-core:1.0.9\")\nimplementation(\"com.baidu.titan.dex:dex-io:1.0.9\")\n```\n\n## 使用示例\n\n```java\nDexItemFactory dexFactory = new DexItemFactory();\n\nMultiDexFileBytes mdfb = MultiDexFileBytes.createFromZipFile(new File(\"test.apk\"));\n\n// dex reader\nMultiDexFileReader mdReader = new MultiDexFileReader(dexFactory);\nmdfb.forEach((dexId, dexBytes) -\u003e {\n    mdReader.addDexContent(dexId, dexBytes.getDexFileBytes());\n});\nmdReader.accept(new MultiDexFileVisitor() {\n\n    @Override\n    public DexFileVisitor visitDexFile(int dexId) {\n        return new DexFileVisitor() {\n            @Override\n            public DexClassVisitor visitClass(DexClassVisitorInfo classInfo) {\n                return new DexClassVisitor() {\n                    @Override\n                    public void visitBegin() {\n                    }\n\n                    @Override\n                    public void visitSourceFile(DexString sourceFile) {\n                    }\n                    @Override\n                    public DexAnnotationVisitor visitAnnotation(DexAnnotationVisitorInfo annotationInfo) {\n                        return super.visitAnnotation(annotationInfo);\n                    }\n\n                    @Override\n                    public DexFieldVisitor visitField(DexFieldVisitorInfo fieldInfo) {\n                        return super.visitField(fieldInfo);\n                    }\n\n                    @Override\n                    public DexMethodVisitor visitMethod(DexMethodVisitorInfo methodInfo) {\n                        return super.visitMethod(methodInfo);\n                    }\n\n                    @Override\n                    public void visitEnd() {\n                    }\n                };\n            }\n        };\n    }\n});\n\n\n// dex node\nMultiDexFileNode mdfn = new MultiDexFileNode();\nmdReader.accept(mdfn.asVisitor());\nMap\u003cInteger, DexFileNode\u003e dexFiles = mdfn.getDexNodes();\ndexFiles.forEach((dexId, dexFileNode) -\u003e {\n    List\u003cDexClassNode\u003e classes = dexFileNode.getClassesList();\n    // ...\n});\n\n```\n\n## 测试\n在dex-test/src/test目录下编写了多个测试用例，可以通过命令行，或者在android studio中执行测试\n\n## 如何贡献\n欢迎一起参与改进Titan-Dex！  \n提交的代码需通过code style检查，完成自测，有相应的单元测试用例。\n\n## License\nThis project is licensed under the Apache-2.0 license - see the LICENSE file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Ftitan-dex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaidu%2Ftitan-dex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Ftitan-dex/lists"}