136

I downloaded APK Manager that lets me unpack APK files.

But it only unpacks it and doesn't decompile the .smali file to .java.

Is it possible to decompile the .smali to .java?

Smi
  • 13,850
  • 9
  • 56
  • 64
BimoZX
  • 1,611
  • 2
  • 12
  • 15

6 Answers6

118

No, APK Manager decompiles the .dex file into .smali and binary .xml to human readable xml.

The sequence (based on APK Manager 4.9) is 22 to select the package, and then 9 to decompile it. If you press 1 instead of 9, then you will just unpack it (useful only if you want to exchange .png images).

There is no tool available to decompile back to .java files and most probably it won't be any. There is an alternative, which is using dex2jar to transform the dex file in to a .class file, and then use a jar decompiler (such as the free jd-gui) to plain text java. The process is far from optimal, though, and it won't generate working code, but it's decent enough to be able to read it.

dex2jar: https://github.com/pxb1988/dex2jar

jd-gui: http://jd.benow.ca/

Edit: I knew there was somewhere here in SO a question with very similar answers... decompiling DEX into Java sourcecode

Luc
  • 5,339
  • 2
  • 48
  • 48
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 1
    so how to pack the edited files(.java/.class/.smali/.jar) again into a apk file.. pls help. – Ashok Raj Apr 13 '12 at 12:51
  • 8
    JD-GUI gets pretty close, but not close enough. – Kevin Parker Jun 05 '12 at 19:21
  • 4
    @Aleadam Do you mean APK Manager or APKTool? I did not find an installation page anywhere for APK manager. However, APKTool "decompiles the .dex file into .smali and binary .xml to human readable xml" - like you said. – IgorGanapolsky Sep 11 '12 at 18:10
  • JD-GUI is a bit outdated now. Try some command line tools like CFR or Krakatau for newer versions of java. – toster-cx Oct 03 '17 at 21:38
36

There is a new cross plateform (java) and open source tool, that enable you to do that, just checkout https://bytecodeviewer.com

enter image description here

=========

EDIT: As of April 2017, there is a new open source tool developed by google, that is meant to do just what we have been looking for => https://github.com/google/android-classyshark

Nothing4You
  • 146
  • 2
  • 10
Gomino
  • 12,127
  • 4
  • 40
  • 49
  • 1
    This tool pops with `Java exception` on start – fnc12 Sep 18 '16 at 10:27
  • A simple workaround for `Java exception` on start would be running with jdk7 in commandline: `java -jar BytecodeViewer x.y.z.jar `. To ensure that you are working with jdk7, check for the output of `java -version` – denolk Oct 20 '16 at 13:18
  • 4
    Classyshark does not output Java code. Quoting the description: "It can reliably browse any Android executable and show important info such as class interfaces and members, dex counts and dependencies." – Jack Miller Jan 31 '18 at 06:22
  • The correct link for classyshark is this one: https://github.com/google/android-classyshark – Mr Washington May 30 '19 at 11:10
  • 1
    Classyshark does not work at all. It shows me all functions without body. All functions appear as function Name() { ... } Quite uesless. And BytecodeViewer is extremely slow and has lots of problems decompiling several functions saying "Couldn't be decompiled" I have better experience with JADX. It is very fast, has a great colored text editor, a good search functionality and although it also cannot decompile some functions, it works much better. – Elmue Dec 07 '21 at 03:48
28

dex2jar helps to decompile your apk but not 100%. You will have some problems with .smali files. Dex2jar cannot convert it to java. I know one application that can decompile your apk source files and no problems with .smali files. Here is a link http://www.hensence.com/en/smali2java/

Daryn
  • 770
  • 9
  • 19
  • 1
    Explain,please, why my answer was downvoted? – Daryn Jan 31 '14 at 05:15
  • I wish i would double vote this to counter the down voter. The linked app works like a charm. This must be the easiest option than dex2jar. – chedine Mar 14 '14 at 18:42
  • I can't save the decompiled files – Ilya Gazman Mar 18 '14 at 12:17
  • 8
    I don't know why others are downvoting, but it could be because the link is for a download of a windows .exe file with no source. It would be pretty irresponsible for anyone to execute this file. – Sky Kelsey Apr 06 '14 at 22:38
  • Why did they do it only for Windows? Damn. – tasomaniac Sep 26 '14 at 07:09
  • This worked well to convert to Java. However, I am unable to save all the Java files at once. I can save them one by one (but this would take quite a while). There also was no find in files. JD-GUI has a nice feature where you can click on a class name in a file and it will take you to that class. This feature was not available in smali2java. – Jonathan Hult Dec 27 '14 at 18:00
  • smali2java seems to work in wine without obvious difficulty, so add Linux to the OS list :-) – Mark May 17 '15 at 15:42
  • 1
    Thanks, this has just saved me, after my comp crashed during a save, and lost 2 classes!!, got the build apk and saved me rewriting – RuAware Jun 14 '15 at 11:55
  • 2
    this site has been considered malicious by firefox and norton/symantac for windows http://search.norton.com/ – Ravi Parekh Oct 06 '15 at 21:21
  • http://safeweb.norton.com/report/show?product=ask.com&action=info&source=&version=&ulang=eng&url=www.hensence.com – Ravi Parekh Oct 06 '15 at 21:23
  • hmm, on decompiling it says that my java runtime Environment version is to high, version is 1.8 and 1.7 is required. – CularBytes Oct 12 '15 at 13:31
  • 4
    The download link is down. – Zirui Wang Sep 13 '17 at 02:21
3

My recommendation is Virtuous Ten Studio. The tool is free but they suggest a donation. It combines all the necessary steps (unpacking APK, baksmaliing, decompiling, etc.) into one easy-to-use UI-based import process. Within five minutes you should have Java source code, less than it takes to figure out the command line options of one of the above mentioned tools.

Decompiling smali to Java is an inexact process, especially if the smali artifacts went through an obfuscator. You can find several decompilers on the web but only some of them are still maintained. Some will give you better decompiled code than others. Read "better" as in "more understandable" than others. Don't expect that the reverse-engineered Java code will compile out of the box. Virtuous Ten Studio comes with multiple free Java decompilers built-in so you can easily try out different decompilers (the "Generate Java source" step) to see which one gives you the best results, saving you the time to find those decompilers yourself and figure out how to use them. Amongst them is CFR, which is one of the few free and still maintained decompilers.

As output you receive, amongst other things, a folder structure that contains all the decompiled Java source code. You can then import this into IntelliJ IDEA or Eclipse for further editing, analysis (e.g. Go to definition, Find usages), etc.

Christoph
  • 2,211
  • 1
  • 16
  • 28
  • Christoph, does Virtuous Ten Studio support in-smali method/class refactoring? – Dennis L May 25 '15 at 14:00
  • 10
    Could you state your affiliation with Virtuous? – Allison Aug 16 '15 at 16:50
  • 1
    Virtous doesn't convert smali to java properly. Gives errors stating that .java file is not found where it should generate by itself. Waste of time – Buddy Aug 18 '15 at 13:50
  • @Sirens: I am not affiliated with Virtuous in any way. I just happened to use their tool and found it very useful. I also updated my answer with some more information on decompiling. – Christoph Aug 21 '15 at 19:02
  • @Dennis: Yes, it does. You can then create an updated APK with a push of a button. – Christoph Aug 21 '15 at 19:10
  • No Mac OS version! Funny because they just could have created the whole thing in Java :P – rraallvv Oct 28 '16 at 11:52
  • The website is now parked. Maybe the tool died? – Sam Feb 08 '20 at 06:38
  • Looks like it. After all, this question and answer is 6 years old. Probably there are much better tools and methods nowadays. – Christoph Feb 11 '20 at 14:06
1

I second that.

Dex2jar will generate a WORKING jar, which you can add as your project source, with the xmls you got from apktool.

However, JDGUI generates .java files which have ,more often than not, errors.

It has got something to do with code obfuscation I guess.

Avijit
  • 391
  • 2
  • 21
-1

For getting the practical view of converting .apk file into .java files just check out https://www.youtube.com/watch?v=-AX4NYE-9V8 video . you will get more benefited and understand clearly. It clearly demonstrates the steps you required if you are using mac OS.

The basic requirement for getting this done. 1. http://code.google.com/p/dex2jar/
2. http://jd.benow.ca/

Param
  • 268
  • 1
  • 3
  • 12