skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.98k stars 4.9k forks source link

[feature] Documentation: explain conversion from Smali to Java #1485

Open eGit opened 2 years ago

eGit commented 2 years ago

Describe your idea:

It would be nice for people who want to understand it at a low level (maybe even use the jadx libraries directly), how .smali is converted to .java by jadx?

Is there an intermediate step where .class files are created? And if yes, is it possible to write out these .class files? Does jadx use its own code to do the smali to java conversion or is it some 3rd party library? What alternatives exist to use to go from smali to .class or .java files? Maybe do the first step with jadx to get smali and then the next step with some other tool, to compare the .java generated by jadx with some other output?

jpstotz commented 2 years ago

@eGit Jadx does not use smali or class files as intermediate for decompiling Android apps. It directly reads the DEX code (the classes*.dex files inside the APK file) by it's jadx-dex-input.

Jadx-gui is also capable of displaying the smali code but that happens independently of the decompilation. That part uses dexlib2 (the library that is developed as part of apktool).

skylot commented 2 years ago

It would be nice for people who want to understand it at a low level

Sure. I plan to write a short overview of how jadx works.

explain conversion from Smali to Java

Jadx input IR (intermediate representation) is very close to dex format, so dex is "native" for jadx. And smali input support implemented using internal conversion to dex. Next, actual decompilation consist of many steps of transforming from input IR to the "output" IR which is close to Java AST and ends with java code generation.

Is there an intermediate step where .class files are created? ... Is it possible to write out these .class files?

No. Conversion from dex to java code is direct.

Does jadx use its own code to do the smali to java conversion or is it some 3rd party library?

To compile smali files to dex format, smali library is used. Next used only own jadx code.

What alternatives exist to use to go from smali to .class or .java files?

To convert .dex to .class you can use dex2jar or enjarify To decompile .class to .java there are many java decompilers like: cfr, procyon, jd-gui, bytecode-viewer

Mino260806 commented 4 months ago

Sure. I plan to write a short overview of how jadx works.

I'm also interested! I'd like to contribute to jadx-core but I can't really grasp how it works. @skylot maybe you can point us in the right direction