Git Product home page Git Product logo

dexrewrite's Introduction

介绍

DexRewrite 是一个针对Android dex文件分析、解析、重构的 C++ 库

如何使用

  1. 使用 Android Studio 和 Cmake编译
  2. 使用 Jetbrains Clion 和 Cmake编译

核心功能

  • 解析整个dex文件。
  • 统计字符串、函数、字段引用。
  • 反编译指定函数
  • Android隐藏API调用扫描

待发布功能

  • Dex文件合并(已完成,测试中,待开源)
  • Dex ASM汇编支持(已经完成、测试中,待开源)

待修复BUG

  • Dex文件合并后,各个索引值排序问题
  • ASM 框架插入代码 goto、goto/16、goto/32 跳转存在问题

参考代码

相关使用可以参考 main.cpp repairdex.cpp文件

参考代码一

遍历整个dex文件中的所有类

for (const auto &class_data : mHeader->ClassDatas()) {
    const char *class_name = class_data->GetClassDef()->ClassType()->GetStringId()->Data();
    for (auto &direct_method : *class_data.get()->DirectMethods()) {
        repairNopCode(direct_method->GetCodeItem());
    }   
    for (auto &virtual_method: *class_data.get()->VirtualMethods()) {
        repairNopCode(virtual_method->GetCodeItem());
    }
}

参考代码二

遍历dex文件中所有函数实体

for (const auto &class_data : mHeader->ClassDatas()) {
    for (auto &direct_method : *class_data.get()->DirectMethods()) {
        repairNopCode(direct_method->GetCodeItem());
    }
    for (auto &virtual_method: *class_data.get()->VirtualMethods()) {
        repairNopCode(virtual_method->GetCodeItem());
    }
}

或者

for (const auto &methodItem : mHeader->MethodItems()) {
    auto index = methodItem.first;
    auto method_item = methodItem.second;
}

参考代码三

遍历所有Dex文件中的Codeitem实体

for (const auto &codeItem : mHeader->CodeItems()) {

}

参考代码四

将dex文件输出到文件

dex_ir::DexWriter::Output(mHeader.get(), "out.dex");

关于代码仓库

致力于脱离Java环境,实现一套可以对Dex文件反编译、字节码编译的框架。开源版本目前仅限于重写Dex文件、反编译Dex文件。

至于DexASM 和 DexMerger 相关代码已经实现,正在测试中,目前用于公司产品上,稳定后将会开源。

引用

https://android.googlesource.com/platform/art/+/master/dexlayout/

https://android.googlesource.com/platform/art/+/refs/heads/master/libdexfile/

dexrewrite's People

Contributors

xiaobaiyey avatar fengjixuchui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.