138

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?

0

6 Answers 6

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

4
  • 1
    so how to pack the edited files(.java/.class/.smali/.jar) again into a apk file.. pls help.
    – Ashok Raj
    Apr 13, 2012 at 12:51
  • 8
    JD-GUI gets pretty close, but not close enough. Jun 5, 2012 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. Sep 11, 2012 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 3, 2017 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

5
  • 1
    This tool pops with Java exception on start
    – fnc12
    Sep 18, 2016 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, 2016 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." Jan 31, 2018 at 6:22
  • The correct link for classyshark is this one: github.com/google/android-classyshark May 30, 2019 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 7, 2021 at 3: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/

12
  • 1
    Explain,please, why my answer was downvoted?
    – Daryn
    Jan 31, 2014 at 5:15
  • 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 6, 2014 at 22:38
  • 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, 2015 at 11:55
  • 2
    this site has been considered malicious by firefox and norton/symantac for windows search.norton.com Oct 6, 2015 at 21:21
  • 4
    The download link is down.
    – Zirui Wang
    Sep 13, 2017 at 2: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.

8
  • Christoph, does Virtuous Ten Studio support in-smali method/class refactoring?
    – Dennis L
    May 25, 2015 at 14:00
  • 10
    Could you state your affiliation with Virtuous?
    – Allison
    Aug 16, 2015 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, 2015 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, 2015 at 19:02
  • @Dennis: Yes, it does. You can then create an updated APK with a push of a button.
    – Christoph
    Aug 21, 2015 at 19:10
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.

-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/

Not the answer you're looking for? Browse other questions tagged or ask your own question.