One, foreword

Today we introduce a very useful decompiler tool, JADx. Jadx is very powerful and, for me, pretty much meets my daily decompilation needs.

Jadx advantages:

  1. Graphical interface.
  2. Drag-and-drop operation.
  3. Decompile the output Java code.
  4. Export the Gradle project.

These advantages make JADX my first choice for decompilation. It handles most decompilation needs and is basically my first choice for decompilation tools.

Let’s take a look at how JADX works.

Use jADX

2.1 installation jadx

Jadx itself is an open source project, and the source code is available on Github.

Jadx lot:

github.com/skylot/jadx

You can clone the source code directly if you are interested, and then compile it locally. But most of the time, we need a compiled version. The compiled version can be downloaded from SourceForge.

Sourceforge downloads JADx.

Sourceforge.net/projects/ja…

Just download the latest version, which is currently jADX-0.6.1. After downloading and unpacking, you get this directory structure:

jadx-path

For Mac or Linux, use jadX-GUI. For Windows, you need to use jadx-gui.bat. Double-click on jadx-gui.bat to run directly. (The rest of this article will focus on the Mac environment. Most of the operations on Windows are similar.)

2.2 use jadx

As mentioned earlier, just double-click jADX-GUI to run it directly. When you run it, it starts up a terminal, where you can see the output of all your operations, and the error log will be printed here.

After you open it, you can select an APK, dex, JAR, zip, class, or AAR file. You can see that JADX supports a variety of formats. Basically, it is compiled into bytecode recognized by the Java virtual machine, and it can be decompiled. In addition to selecting a file, you can also drag and drop apK files directly into it, which is very useful.

I picked up an Apk I had handy, threw it in, and saw how it would look decompiled.

jadx-run

This is the decompiled code, for APK, some XML resources, also have been decompiled back, very convenient.

Three, jADX advantages

Jadx is very convenient to use, and the GUI program provided is also very easy to use. Let’s start with some handy tips for jADX-GUI programs.

3.1 Powerful search function

The search function provided by JADX is very powerful and not slow.

You can activate it by clicking Navigation -> Text Search or Navigation -> Class Search. The more convenient shortcut is Control + Shift + F, which varies from person to person.

text-search

The search of JADX supports four dimensions, Class, Method, Field and Code. We can check the boxes according to the content we search. The largest range is Code, which is basically text matching search. The decompiled Apk here integrates Alipay payment, so you can search alipay content.

3.2 The referenced code is directly searched

Sometimes you find the key code and you want to see where it is called or referenced.

Jadx also provides support for this. To Find the class or method we want to look at, right-click and select Find Usage.

find-Usage

And then it will find out for you where it’s referenced in the project.

usage-search

Click can jump directly in the past, very convenient.

3.3 deobfuscation

Apk in general before the release out, will be confused, this is basically the standard domestic App. Such a class would end up being confused as A.B.C, and the method would end up A.B.C.A (), which would be very difficult to read. It’s hard to look at an A.java file and decide which one it is, depending on the package name.

The deobfusation function can give them a special name, so that it is unique in this project, which is convenient for us to identify and search.

This feature can be activated in Tools -> Deobfusation.

Here’s how it works.

deo-before

This is what happens when deobfusation is enabled:

deo-after

And you can see that a becomes p003a. I don’t know if that makes it easier for you?

3.4 Export Gradle project with one click

Although, jADX-GUI can read the code directly, it is still very convenient. But after all, it is not as convenient as our common editor. Jadx also supports the ability to export decompiled projects directly into a Gradle compiled project.

You can activate this function by using File -> Save as Gradle project.

save-gradle

The final output directory can be opened directly through Android Studio.

gradle-project

Although AS can open it directly, in most cases you won’t be able to compile it. However, this functionality is mainly designed to make reading easier by taking advantage of the powerful IDE features of AS, such AS method jumps, reference searches, and so on.

Error handling for JADx

Jadx also has some error situations, but here are some of the more common ones.

4.1 the inconsistent code

Sometimes there are codes that are not fully decompiled, and you’ll see an error with the JADX WARNING: Inconsistent Code flag.

incon-before

This section of code, it is not Java code, not conducive to our reading. In this case, JADX can try turning on the Show Inconsistent Code switch. You can find it in File -> Preferences.

show-pre

After the State Code is enabled, let’s take a look at this code and see how cozy it feels.

code2

Most of the code that you do this with is pseudocode, and there may be some errors, so let’s look at it on a case-by-case basis.

There are many more switches in Preferences that you can explore for yourself.

4.2 Decompilation error or lag

Jadx decompilates small APKs with no pressure at all, but for heavier APKs, usually larger than 50MB, you may encounter problems with jADX decompilation.

If you look at the Log output in Terminal, you should see that it’s actually caused by OOM.

oom

Officials also provide some solutions to the problem caused by insufficient memory.

1. Reduce the number of threads processed.

Jadx uses multiple threads to speed up compilation, and multiple threads consume a lot of memory. Therefore, reducing the number of threads during decompilation is an effective method.

If you use the command line, you can set the number of threads to 1 by using the -j 1 parameter. If you do not set the number of threads to 4 by default.

Using JadX-GUI, you can configure the number of threads in Preferences by configuring the Processing Threads Count.

2. Modify the Jadx script

Directly edit the jadx script in the./bin directory, find DEFAULT_JVM_OPTS, and set it to DEFAULT_JVM_OPTS=” -xmx2500m “to configure the current memory size.

For Windows, you need to edit the jadx.bat file.

3. Run commands

If none of the above works, you can use the command line and put the compiler through the jadx command in the absence of a better option. Set the number of threads to 1, which is slower, but in most cases, can output decompiled code normally.

Here’s an example:

jadx -d out -j 1 classes.dex

You can run the jadx -h command to view other commands.

jadx-help

Take a closer look at the parameters configured by the Jadx command. Basically, you can find the corresponding configuration items in Preferences, and it should not be difficult to see how it is used.

Five, the summary

Jadx is really very easy to use, to the use of its basically here, are explained clearly.

Have you had any problems with jadx during decompilation? What better tool to recommend, you can leave me a message in the message area, we discuss together.

Today in the background of the official account of Chengxiang ink shadow, reply “growth”. I will send you some learning materials I collated, including: Android decompilation, algorithms, design patterns, Kotlin, virtual machines, Linux, Web project source code.

Recommended Reading:

  • Really talk about the shadows
  • Use StateListAnimator to animate your clicks!
  • Good code can speak for itself
  • Six simple tips on how to write Clean Code
  • Hand write your first Dalvik version of HelloWorld!