Reverse engineering from an APK file to a project
Asked Answered
B

12

294

I accidently erased my project from Eclipse, and all I have left is the APK file which I transferred to my phone. Is there a way to reverse the process of exporting an application to the .apk file, so I can get my project back?

Burbank answered 4/10, 2012 at 17:50 Comment(6)
https://mcmap.net/q/46176/-decompling-an-android-apk-duplicateHereinafter
you do know that eclipse has a version history of its own?Artillery
possible duplicate of Is there a way to get the source code from an APK file?Tiffaneytiffani
if you are writing something important to you, you should use a VCS. Bitbucket has free private repositories.Montiel
github.com/skylot/jadxMatchwood
Thats the standard story :)Manaker
R
338

There are two useful tools which will generate Java code (rough but good enough) from an unknown APK file.

  1. Download dex2jar tool from dex2jar.

  2. Use the tool to convert the APK file to JAR: Windows:

     $ d2j-dex2jar.bat demo.apk
     dex2jar demo.apk -> ./demo-dex2jar.jar
    

    MacOS / Linux:

     $ d2j-dex2jar.sh -f demo.apk -o demo.jar
    
  3. Once the JAR file is generated, use JD-GUI to open the JAR file. You will see the Java files.

The output will be similar to:

JD GUI

Then you can use other tools to retrieve the AndroidManifest.xml and resource files (like images, translations, etc...) from the APK file.

  • Apktool

     $ java -jar apktool.jar -q decode -f demo.apk -o outputDir
    
  • AXMLParser

     $ apkinfo demo.apk
    
  • NinjaDroid

     $ ninjadroid demo.apk --all --extract
    
Rinarinaldi answered 4/10, 2012 at 18:29 Comment(15)
how to get the resource filesConsociate
cmd is deprecated, use d2j-dex2jar instead (v0.0.9.15).Heronry
@HoangHuynh you will have an res folder with unreadable xml filesHibbitts
But this is not Editable... how to edit file and make once again APK with editable change.??Predict
@GautamVasoya To edit you'll need to use something like baksmali to convert the apk to assembly and edit the assembly. I don't think there's any way to get it to Java source for editing at this time.Ministry
Why the classes names are like a, b, c ?Moneywort
Use link for command.Kirakiran
this is a fact that you will able to generate only java file's or the res layout files and values , but not 100% , instead of layout or values includes the particular Id will be given so we need R (reference) file for that. we need python,meven cmd also.Kendo
why my output jar file size is 0?Pastel
In Mac if you Cannot use dex2jar : permission denied then do this $sudo chmod +x d2j-dex2jar.shOquinn
@FredrickGauss your comment is probably deprecated — I have 2.0 version, and the command is dex2jar.Colpin
@Rinarinaldi your answer is a bit confusing, because dex2jar does not convert apk to jar. See: $ file ru.mail.calendar-1.apkru.mail.calendar-1.apk: Java archive data (JAR). Thus, apk is a jar archive. What the command does, is converts .dex files (inside the archive) to .class files.Colpin
it deosn't give resources.Lorin
sudo: d2j-dex2jar.bat: command not found what should i doIncumbency
is it still useful if app has proguard implemented ?Electrodynamometer
S
87

First of all I recommend this video may this is clears all yours doubts

If not please go through it

Procedure for decoding .apk files, step-by-step method:

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apk file to .zip (eg.: rename from filename.apk to filename.zip) and save it.

If problems in the converting into .zip please refers link

After getting .zip now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue. If you don’t see the extensions go through check the configuration

Step 2:

Now extract this zip apk file in the same folder. Now download dex2jar from this link

and extract it to the same folder. Now open command prompt and change directory to that folder.

Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder.

Then download java decompiler

And now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. Extract that zip file (classes_dex2jar.src.zip) and you will get all java files of the application.

At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

Now open another new folder and put these files

  1. put .apk file which you want to decode

  2. download Apktool for windows v1.x And Apktool

install window using google and put in the same folder

  1. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)

  2. Open a command window

  3. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk.

Above command should result in Framework installed ....

  1. apktool d "appName".apk ("appName" denotes application which you want to decode) now you get a file folder in that folder and now you can easily read xml files also.

Step 4: Finally we got the res/ as well as java code of project which is our target at starting.

P.S. If you are not able to get res folder by above steps please do install new apktool

  • Is Java 1.7 installed? Install Apktool 2.x
  • Is Java 1.6 or higher installed? Install Apktool 1.x

Enjoy and happy coding

Siskin answered 4/10, 2012 at 17:50 Comment(8)
really usefull. Just something you haven't mentioned : the apktool.jar is not in the same package, i got it from a former package and pasted it in the same dir as apktool.Hibbitts
i reversed engineer the code but why is the name of class, variable are like aa, bc, e.t.c and also many errorsMagnetoelectricity
unable to do that in cmdHensley
any other way to do that ?Hensley
unable to get res folder . .please helpHensley
@MeghalAgrawal try my answerMc
@Magnetoelectricity This means that the code has been obfuscated using ProGuard.Goodall
how to download dex2jar from the given link, please helpCelebrated
M
68

No software & No too much steps..

Just upload your APK & get your all resources from this site..

https://www.apkdecompilers.com/

This website will decompile the code embedded in APK files and extract all the other assets in the file.

note: I decompile my APK file & get code within one miniute from this website

Update 1:

I found another online decompiler site,

http://www.javadecompilers.com/apk/ - Not working continuously asking for popup blocking

Update 2:

I found apk decompiler app in play store,

https://play.google.com/store/apps/details?id=com.njlabs.showjava

We can decompile the apk files in our android phone. and also we can able to view the java & xml files in this application

Update 3:

We can use another option Analyze APK feature from Android studio 2.2 version

Build -> Analyze APK -> Select your APK -> it give results

enter image description here

Mc answered 16/1, 2015 at 10:5 Comment(6)
in last method we can't open java class, only shows method namesQuijano
@Quijano are you try the ShowJava? if no try & update meMc
@RanjithKumar its limited to 50 MB APK size.. i have a 85 MB APK to decompile.Epithelioma
@RaviSharma try this play.google.com/store/apps/details?id=in.pounkumar.apkextractorMc
How to run that decompiled project in android studio? can anyone please write about this.Leuko
Strange! Android Studio allows reverse-engineering its own App :DKatinka
B
10

In Android Studio 3.5, It's soo easy that you can just achieve it in a minute. following is a step wise process.

1: Open Android Studio, Press window button -> Type Android Studio -> click on icon to open android studio splash screen which will look like this.

enter image description here

2: Here you can see an option "Profile or debug APK" click on it and select your apk file and press ok.

enter image description here

3: It will open all your manifest and java classes with in a minute depending upon size of apk.

enter image description here

That's it.

Bathymetry answered 13/11, 2019 at 8:2 Comment(2)
this solution not giving me any type of java fileKetron
You can find a video tutorial on this approach here: youtu.be/CWI0edpXXWkAdjoin
F
5

Not really. There are a number of dex disassembler/decompiler suites out there such as smali, or dex2jar that will generate semi-humanreadable output (in the case of dex2jar, you can get java code through the use of something like JD-GUI but the process is not perfect and it is very unlikely that you'll be able to 100% recreate your source code. However, it could potentially give you a place to start rebuilding your source tree.

Fado answered 4/10, 2012 at 17:54 Comment(0)
F
5

There is a new way to do this.

Android Studio 2.2 has APK Analyzer it will give lot of info about apk, checkout it here :- http://android-developers.blogspot.in/2016/05/android-studio-22-preview-new-ui.html

Ap

Foremost answered 14/6, 2016 at 6:38 Comment(0)
D
3

Yes, you can get your project back. Just rename the yourproject.apk file to yourproject.zip, and you will get all the files inside that ZIP file. We are changing the file extension from .apk to .zip. From that ZIP file, extract the classes.dex file and decompile it by following way.

First, you need a tool to extract all the (compiled) classes on the DEX to a JAR. There's one called dex2jar, which is made by a Chinese student.

Then, you can use JD-GUI to decompile the classes in the JAR to source code. The resulting source code should be quite readable, as dex2jar applies some optimizations.

Diphenylhydantoin answered 4/10, 2012 at 18:3 Comment(0)
I
3

Below are some of the tools which you can use to perform reverse engineering from an APK file to source code :

  1. Dex2jar
  2. Java decompiler
  3. Apktool
  4. Apk Analyser
Ingulf answered 20/7, 2017 at 9:28 Comment(0)
C
3

For the Android platform, you can try ShowJava, available on the Play Store.

You can consult the generated code through the app interface and the generated java files and folders structure are stored in ShowJava folder in /sdcard, alongside the resulting .jar file from the conversion.

The app is free with an ad banner at the bottom of the main view, but there is an in-app purchase option (3,99$) to remove it. In-app purchase does not add any functionality beside removing the ad banner.

Disclosure : I'm not the developer of the app neither I'm affiliated with him in any way.

Cadmann answered 24/4, 2018 at 11:12 Comment(0)
L
2

Follow below steps to do this or simply use apkToJava gem for this process, it even takes care of installing the required tools for it to work.

  • convert apk file to zip
  • unzip the file
  • extract classes.dex from it
  • use dex to jar to convert classes.dex into jar file
  • use jadx gui to open the jar file as java source code
Lucillelucina answered 31/1, 2016 at 6:24 Comment(0)
B
2

If you are looking for a professional alternative, have a look at JEB Decompiler from PNF Software.

There is a demo version that will let you decompile most code.

Berlinda answered 6/5, 2017 at 16:25 Comment(0)
C
2

Another tool that you may want to use is APK Studio It relies howewer on third party tools: Apktool, jadx, ADB and Uber APK signer that you need to download separately.

Classroom answered 1/8, 2020 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.