how to decompile a .apk without errors? - java

I tried the apktool, and even the online version, http://www.decompileandroid.com/
But still can't get something that works in eclipse.
I want to decompile an app called bucket drops, which was made as part of an android course. I want to look at the source code and tweak it.
When I tried decompiling the .apk file it lacked the .classpath and .project files, so I made a new project in eclipse and copied the source code into it, but for some reason eclipse shows that the app is buggy!
What do I do?

How-To: Decompile/Recompile apk's with ApkTool
Requirements:
ApkTool
Java JDK/JRE 32 bit
Basic Cmd/terminal knowledge
Download ApkTool here
ApkTool.zip
first you need to extract that zip folder to anywhere you choose, preferably on root of c/drive ie: C:/android/apktool extracting the files to 'apktool' folder
Now place the STOCK framework-res.apk & whatever other apk's you would like to modify into the 'apktool' folder
Getting to CMD directory
Open up a Cmd Prompt (terminal) and get to the 'apktool' directory ie:
Your cmd will probly look like this..
C:\users\yourname>
so type in
cd.. (yes include the '..' and press enter after you type each command)
this will get you to back directory so now you will see
C:\users>
so type again
cd..
you should now see this:
C:>
now type in:
cd 'apktoo'l/'directory'
for me it looks like:
cd android/apktool
now you should see:
C:/android/apktool>
and you are in the apktool directory :D
Click to expand...
Installing Framework
Now that you are in directory we need to install the device's framework to your system for it to compile correctly so type this:
apktool if framework-res.apk
this will install the devices framework to your system (need to do this)
Decompiling
now to decompile the apk you want to edit.. type this:
apktool d framework-res.apk framework1
or
apktool d music.apk music
music.apk is the apk your decompiling
music is the folder you're creating for the decompiled apk
now make your edits :D DO NOT Change/Edit ANY PNG's
Recompiling/Finished Product
now to recompile your new apk type this:
apktool b music music-new.apk
or
apktool b framework1 framework-res-new.apk
framework1 is the folder with your edited files
framework-res-new.apk is your new apk file :D
Now we are NOT done... we cannot use the new apk's... we have to take what we did and add it back to the original apk file to keep proper signature :D
use something like 7zip, take the 'resources.arcs' file and any other xml files you edited out of the "-new" apk and copy them into Original apk
now the apk is ready to flash with your new changes :D :D
Hope this helped some of you new themers out there!!!
Source: AndroidForums

One of my colleague has written a ruby Gem to address this problem, It can decompile an Apk and open it's code in a friendly GUI.
apkToJava is the gem name. you should try it once.
It's an easy to use tool which just take two to three commands to get an Apk decompiled.
gem install apkToJava
apkToJava setup
apkToJava /path/to/apk/file.apk
As of now its support only two operating systems Mac OS and Linux.

Related

Unable to compile app using apktool: "Asset package include not found"

I'm trying to compile an application but I'm having no luck.
I can't even compile an untouched app, i.e., if I decompile mms.apk (no errors at all) and I tried to compile right on, it doesn't work!
I have done this before when I still used windows 7 so idk why it isn't working.
One thing I noticed is that the frameworks get installed to C:\Windows\system32\config\systemprofile\apktool\framework\1.apk
is that okay? I'm using windows 8 now if that makes any difference.
anyway, here is the output I get:
Thank you!
install the framework of your phone like this
apktool if framework-res.apk
The file that is located at C:\Windows\system32\config\systemprofile\apktool\framework\1.apk could not be read properly.
It may be due to the fact that you didn't have permission to write the file initially during the apktool if framework-res.apk command. As you can see, during decompile apktool must load the frameworks so it can properly resolve resources during decompile. The first few lines of that error indicate apktool couldn't pull that file correctly.
I would do what Cristi said above, except make sure your in a admin launched command prompt window, so that you'll have permission to read/write to all portions of the C drive.
I think you should use the updated version of APKTtool:
Download APKTool
Put all three files (aapt.exe, apktool.jar and apktool.bat) in one folder.
Then goto that folder directory using cmd and type apktool d apkname.apk.

Decompile an APK, modify it and then recompile it

I need to modify an existing APK, modify the sources and then recompile it.
I can decompile it using dex2jar or apktool, it's working great
From the jar file I can obtain the java sources (using jd-gui)
Then I can modify the java files
But now I would like to know how to recompile the java files and put them back into a jar file! (the jar part should be easy, the main problem seems to be how to recompile the java files for android)
I know that an other solution is to use apktool and then modify the smali files, but it seems to be really complicated when we want to add a lot of code!
My application is a basic a HelloWorld whitout obfuscation.
Thanks to Chris Jester-Young I managed to make it work!
I think the way I managed to do it will work only on really simple projects:
With Dex2jar I obtained the Jar.
With jd-gui I convert my Jar back to Java files.
With apktool i got the android manifest and the resources files.
In Eclipse I create a new project with the same settings as the old one (checking all the information in the manifest file)
When the project is created I'm replacing all the resources and the manifest with the ones I obtained with apktool
I paste the java files I extracted from the Jar in the src folder (respecting the packages)
I modify those files with what I need
Everything is compiling!
/!\ be sure you removed the old apk from the device an error will be thrown stating that the apk signature is not the same as the old one!
I know this question is answered still, I would like to pass an information how to get source code from apk with out dexjar.
There is an online decompiler for android apks
Upload apk from local machine
Wait some moments
Download source code in zip format
I don't know how reliable is this.
#darkheir Answer is the manual way to do decompile apk. It helps us to understand different phases in Apk creation.
Once you have source code , follow the step mentioned in the accepted answer
Report so many ads on this links
Another online Apk De-compiler #Andrew Rukin : http://www.javadecompilers.com/apk
Still worth. Hats Off to creators.
The answers are already kind of outdated or not complete. This maybe works for non-protected apks (no Proguard), but nowadays nobody deploys an unprotected apk. The way I was able to modify a (my) well-protected apk (Proguard, security check which checks for "hacking tools", security check, which checks if the app is repackaged with debug mode,...) is via apktool as already mentioned by other ones here. But nobody explained, that you have to sign the app again.
apktool d app.apk
//generates a folder with smali bytecode files.
//Do something with it.
apktool b [folder name] -o modified.apk
//generates the modified apk.
//and then
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore modified.apk androiddebugkey
//signs the app the the debug key (the password is android)
//this apk can be installed on a device.
In my test, the original release apk had no logging. After I decompiled with apktool I exchanged a full byte code file without logging by a full byte code file with logging, re-compiled and signed it and I was able to install it on my device.
Afterwards I was able to see the logs in Android Studio as I connected the app to it.
In my opinion, decompiling with dex2jar and JD-GUI is only helpful to get a better understanding what the classes are doing, just for reading purposes. But since everything is proguarded, I'm not sure that you can ever re-compile this half-baked Java code to a working apk. If so, please let me know. I think, the only way is to manipulate the byte code itself as mentioned in this example.
First download the dex2jar tool from Following link
http://code.google.com/p/dex2jar/downloads/list
Extract the file it create dex2jar folder
Now you pick your apk file and change its extension .apk to .zip after changing extension it seems to be zip file then extract this zip file you found classes.dex file
Now pick classes.dex file and put it into dex2jar folder
Now open cmd window and type the path of dex2jar folder
Now type the command dex2jar.bat classes.dex and press Enter
Now Open the dex2jar folder you found classes_dex2jar.jar file
Next you download the java decompiler tool from the following link
http://java.decompiler.free.fr/?q=jdgui
Last Step Open the file classes_dex2jar.jar in java decompiler tool now you can see apk code
I know this question has been answered and I am not trying to give better answer here. I'll just share my experience in this topic.
Once I lost my code and I had the apk file only. I decompiled it using the tool below and it made my day.
These tools MUST be used in such situation, otherwise, it is unethical and even sometimes it is illegal, (stealing somebody else's effort). So please use it wisely.
Those are my favorite tools for doing that:
javadecompilers.com
and to get the apk from google play you can google it or check out those sites:
apk-dl.com
apkpure.com
On the date of posting this answer I tested all the links and it worked perfect for me.
NOTE: Apk Decompiling is not effective in case of proguarded code. Because Proguard shrink and obfuscates the code and rename classes to nonsense names which make it fairly hard to understand the code.
Bonus:
Basic tutorial of Using Proguard:
dex2jar with jd-gui will give all the java source files but they are not exactly the same. They are almost equivalent .class files (not 100%).
So if you want to change the code for an apk file:
decompile using apktool
apktool will generate smali(Assembly version of dex) file for every java file with same name.
smali is human understandable, make changes in the relevant file,
recompile using same apktool(apktool b Nw.apk <Folder Containing Modified Files>)
I know this question is answered still and I am not trying to be smart here. I'll just want to share another method on this topic.
Download applications with apk grail
APK Grail providing the free zip file of the application.
This is a way:
Using apktool to decode:
$ apktool d -f {apkfile} -o {output folder}
Next, using JADX (at github.com/skylot/jadx)
$ jadx -d {output folder} {apkfile}
2 tools extract and decompiler to same output folder.
Easy way: Using Online APK Decompiler
https://apk.tools/tools/apk-decompiler/ (recommended)
http://www.javadecompilers.com/apk
https://www.apkdecompilers.com

How to decompile Java class files which jd-gui decompiler is unable to decompile?

We accidently got some JAVA source files deleted from the system.
This happened when We checked out a folder from repository directly as an eclipse project and then tried to copy a folder from another eclipse project into this one.Strangely all those folder files have vanished from local system (and obviously they never made it to SVN repository).
Somehow We have obtained .svn-base files for some CLASS files.Now We are trying to decompile class files to obtain the source code back. However some of the class files are giving error "invalid input file" when jd compiler is trying to process them.
Is there any other solution to this ?
From what I can tell, "jd-gui" is closed source, so you may need to contact the developer to find out what that message means. (If it was open source, we could just look at the source code to figure out what the likely problem was!)
However, one thing is clear from various questions that Google shows up, and that is that "jd-gui" doesn't understand how to decompile archives (JAR, EAR, etc). So maybe you just need to un-JAR something to make it work.
The other thing you could try (first) is to see what "javap" makes of the class files that "jd-gui" doesn't like.
Try using JAD to decompile your files.
www.varaneckas.com/jad/
You may need to unzip your jar files and then run something like the following to decompile them all
find <srcdirectory> -name *.class -exec jad -s .java -r -ff -clear -debug -d <dest directory> {} \;
I havent tested the above command but hopefully it is almost there...
I also had the error "invalid input file" with a certain class file. I was using version 0.3.6 of jd-gui. After downloading the newest version of jd-gui (which was 1.6.6 at the moment of writing this) I could decompile the class file which previously failed.
So if someone still has this problem it makes sense to check the version and upgrade if it is an older one. Here is a link to the "Latest-Release"-download page:
http://java-decompiler.github.io/

Extract source code from .jar file

Is there a way to extract the source code from an executable .jar file (Java ME)?
Use JD GUI. Open the application, drag and drop your JAR file into it.
You can extract a jar file with the command :
jar xf filename.jar
References : Oracle's JAR documentation
I believe this can be done very easily. You can always extract the source files (Java files) of a jar file into a zip.
Steps to get sources of a jar file as a zip :
Download JAD from http://techieme.in/resources-needed/ and save it at any
location on your system.
Drag and drop the jar for which you want the sources on the JAD.
3 JAD UI will open with all the package structure in a tree format.
Click on File menu and select save jar sources.
It will save the sources as a zip with the same name as the jar.
Hope this helps.
The link is dead due to some reason so adding the link from where you can download the JDGUI
Your JAR may contain source and javadoc, in which case you can simply use jar xf my.jar to extract them.
Otherwise you can use a decompiler as mentioned in adarshr's answer:
Use JD GUI. Open the application, drag
and drop your JAR file into it.
I know it's an old question Still thought it would help someone
1) Go to your jar file's folder.
2) change it's extension to .zip.
3) You are good to go and can easily extract it by just double clicking it.
Note: I tested this in MAC, it works. Hopefully it will work on windows too.
Do the following on your linux box where java works (if u like the terminal way of doing things)
cd ~
mkdir decompiled_code && cd decompiled_code
// download jar procyon from https://drive.google.com/file/d/1yC2gJhmLoyE8royCph5dLEncgkNZXj58/view?usp=sharing
java -jar procyon-decompiler-0.5.36.jar /Path/to/your/jar -o .
NOTE : as #Richard commented "this may be illegal depending on whether you own the copyright to the jar, the country you live in and your purpose for doing it."
Steps to get sources of a jar file as a zip :
Download JD-GUI from http://java-decompiler.github.io/ and save it
at any location on your system.
Drag and drop the jar or open .jar file for which you want the
sources on the JD.
Java Decompiler will open with all the package structure in a tree
format.
Click on File menu and select save jar sources. It will save
the sources as a zip with the same name as the jar.
Example:-
We can use Eclipse IDE for Java EE Developers as well for update/extract code if require.
From eclipse chose Import Jar and then select jar which you need. Follow instruction as per image below
AndroChef Java Decompiler produces very good code that you can use directly in your projects...
Above tools extract the jar. Also there are certain other tools and commands to extract the jar.
But AFAIK you cant get the java code in case code has been obfuscated.
suppose your JAR file is in C:\Documents and Settings\mmeher\Desktop\jar and the JAR file name is xx.jar, then write the below two commands in command prompt:
1> cd C:\Documents and Settings\mmeher\Desktop\jar
2> jar xf xx.jar
-Covert .jar file to .zip (In windows just change the extension)
-Unzip the .zip folder
-You will get complete .java files

how to open an .apk file

hi i am a new developer, i created an app of my own. I created the .apk file and get it signed and aligned it. When i was running it on my device i thought of doing some changes in it, but i missed the original source code. Can i get back my source code using the aligned.apk file... I am using eclipse
The apk is just a zip file so you can unzip it. Your code will be in a classes.dex file in the dalvik format. There are some tools you can use to convert it back from dex2jar, and then decompile the class files using jad but your source code will most likely be imcomplete.

Categories

Resources