enjarify是由Google官方新出品的基于Python3开发,类似dex2jar的一个将Dalvik字节码转换成相对应的Java字节码开源工具,官方宣称有比dex2jar更优秀的兼容性,准确性及更高的效率。

Introduction

Enjarifyis a tool for translating Dalvik bytecode to equivalent Java bytecode. This allows Java analysis tools to analyze Android applications.

Usage And Installation

Enjarify is a pure python 3 application, so you can just git clone and run it. To run it directly, assuming you are in the top directory of the repository, you can just do

1 2 python3 - O - m enjarify . main yourapp . apk

For normal use, you’ll probably want to use the wrapper scripts and set it up on your path.

Linux

For convenience, a wrapper shell script is provided, enjarify.sh. This will try to use Pypy if available, since it is faster than CPython. If you want to be able to call Enjarify from anywhere, you can create a symlink from somewhere on your PATH, such as ~/bin. To do this, assuming you are inside the top level of the repository,

1 2 ln - s "$PWD/enjarify.sh" ~ / bin / enjarify

Windows

A wrapper batch script, enjarify.bat, is provided. To be able to call it from anywhere, just add the root directory of the repository to your PATH. The batch script will always invoke python3 as interperter. If you want to use pypy, just edit the script.

Usage

Assuming you set up the script on your path correctly, you can call it from anywhere by just typing enjarify, e.g.

1 2 enjarify yourapp . apk

The most basic form of usage is to just specify an apk file or dex file as input. If you specify a multidex apk, Enjarify will automatically translate all of the dex files and output the results in a single combined jar. If you specify a dex file, only that dex file will be translated. E.g. assuming you manually extracted the dex files you could do

1 2 enjarify classes2 . dex

The default output file is [inputname]-enjarify.jar in the current directory. To specify the filename for the output explicitly, pass the -o or –output option.

1 2 enjarify yourapp . apk - o yourapp . jar

By default, Enjarify will refuse to overwrite the output file if it already exists. To overwrite the output, pass the -f or –force option.

Why Not Dex2jar?

Dex2jar is an older tool that also tries to translate Dalvik to Java bytecode. It works reasonable well most of the time, but a lot of obscure features or edge cases will cause it to fail or even silently produce incorrect results. By contrast, Enjarify is designed to work in as many cases as possible, even for code where Dex2jar would fail. Among other things, Enjarify correctly handles unicode class names, constants used as multiple types, implicit casts, exception handlers jumping into normal control flow, classes that reference too many constants, very long methods, exception handlers after a catchall handler, and static initial values of the wrong type.

Limitations

Enjarify does not currently translate optional metadata such as sourcefile attributes, line numbers, and annotations.

Enjarify tries hard to successfully translate as many classes as possible, but there are some potential cases where it is simply not possible due to limitations in Android, Java, or both. Luckily, this only happens in contrived circumstances, so it shouldn’t be a problem in practice.

Performance Tips

PyPy is much faster than CPython. To install PyPy, seehttp://pypy.org/. Make sure you get PyPy3 rather than regular PyPy. The Linux wrapper script will automatically use the command pypy3 if available. On Windows, you’ll need to edit the wrapper script yourself.

By default, Enjarify runs optimizations on the bytecode which make it more readable for humans (copy propagation, unused value removal, etc.). If you don’t need this, you can speed things up by disabling the optimizations with the –fast option. Note that in the very rare case where a class is too big to fit in a classfile without optimization, Enjarify will automatically retry it with all optimizations enabled, so this option does not affect the number of classes that are successfully translated.

Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

工具下载及源代码见:https://github.com/google/enjarify

更多相关文章

  1. android 主流浏览器对 scheme 打开本地 APP 功能的兼容性
  2. Android(安卓)MVP模式 谷歌官方代码解读
  3. Android官方新推的DI库 Hilt
  4. Android官方开发语音--Kotlin
  5. Android中的Menu的简介(翻译自官方文档)——————个人笔记
  6. 字节跳动Android面经:3面+职业规划
  7. Android(安卓)NDK 下的宽字符编码转换及icu库的使用
  8. itools官方下载2015 v3.1.7.0 中文版
  9. Android(安卓)HIDL官方文档(十)—— Converting Modules

随机推荐

  1. 仿苹果音量调节柱
  2. Android(安卓)开机优化
  3. Android 笔记 01
  4. Android 系统用户态启动过程
  5. Android Relative Layout 安卓相对布局详
  6. JDK与adb/android环境变量配置完整教程
  7. android——退出程序的功能,关闭所有本程
  8. 重新审视 Android
  9. android语音识别接科大讯飞sdk
  10. Android异步消息处理机制详解及源码分析