cmd cannot recognize dex2jar- Android Apk - android

i want to get source code from apk and use this solution Is there a way to get the source code from an APK file?
i try to dex file to jar and i used dex2jar; but cmd cannot recognize this command.
dex2jar classes.dex
"dex2jar is not recognized as an internal or external command"
is dex2jar deprecated?
what can i use to convert dex to jar?

None of the above answers worked for me, I was able to get it working in the following way,
There is no need of the classes.dex file.
So follow the following instructions carefully:
Download the latest version of dex2jar i was able to google it and get the latest one from sourceforge.
just in case if you didnt get it http://sourceforge.net/projects/dex2jar/
drop your apk file inside the dex2jar folder.
open command prompt[win user] and navigate to that folder where you dropped the apk file.
enter this command d2j-dex2jar.bat someApk.apk and you will get the jar file[read the jar file using jd-ui tool]
for mac users refer this[point 4 in the link] for suitable terminal command http://sourceforge.net/p/dex2jar/wiki/UserGuide/

Use the command
d2j-dex2jar classes.dex
instead of
dex2jar classes.dex
Also make sure that u extracted the dex2jar file in the same folder as your apk source files kept in step 1 of given example.

If you are using dex2jar-2.x jar file than it is creating problem. Try to download dex2jar-0.0.9.15 jar file and then try that command.

Here are the steps I used:
unzipped both apk folder & dex2jar folder
Created a New Folder
Combined all apk & dex2jar files into the new folder
Opened command prompt & changed my directory pointing to the new folder name
in command prompt, I typed d2j-dex2jar classes.dex, Hit Enter
....this created a new file in my new folder named classes-dex2jar.jar

I had the same problem and I have solved it, the file which you download from the GitHub isn't actually compiled so you would have to compile it first, rather than compiling, download this zip file from https://sourceforge.net/projects/dex2jar/files/dex2jar-2.0.zip/download and do the exact same process told(in the answer you are referring in your question) and you will get a jar file as your output. This file has already compiled all the resources for you so you wouldn't have to do this work manually!

I had extracted both apk and dex in different folders. On copying the extracted files in the same folder and running
dex2jar classex.dex
it worked.

Even after all those answers if some people having problem go to folder
dex2jar-0.0.9.15\dex-tools\src\main\bin
here you have both the dex2jar.bat/sh and d2j-dex2jar.bat/sh files are present there.
move your classes.dex and use the any of those command.

For me problem with the path, the correct path is C:\Users\username\Desktop\foldername\dex2jar>d2j-dex2jar classes.dex

I solved it by first downloading dex2jar-0.0.9.1 jar file and not the latest one. Then i used the following command
d2j-dex2jar.bat classes.dex and make sure that you open the command window in the dex2jar-0.0.9.15 directory. A shortcut to open the cmd there is to open the directory and then press shift and right click anywhere inside the directory window. Then go to open command window here.

1) Download dex2jar from this link and extract in your working directory.
2) In the extracted folder open command prompt and enter d2j-dex2jar ..\classes.dex.
You will get classes-dex2jar.jar in the current folder.

Related

Converted dex2jar to .jar file. However results are empty in JD GUI

I have converted my dex file from apk to to a jar file
Steps:
Change xyz.apk to xyz.zip
Extract xyz.zip
Copy classes.dex to my dex2jar folder
Drag and release clases.dex onto dex2jar.abat
Classes_dex2jar.jar is created
Open clases_dex2jar.jar in JD Gui
Empty screen for JD Gui
Can someone please advise what I have done wrong?
I have also tried doing step 4 using the terminal, but it yields the same result. I am running on Windows 7.
I have never renamed it to zip and extract the file. Normally I copy the apk file to the same folder with dex2jar folder and run:
d2j-dex2jar.bat file.apk
It will generate the jar file: file.jar and you can open it normally in JD GUI.
I suggest using cfr decompiler or procyon as they're much better than JD GUI and produce better results when combined with dex2jar.

How to get change the package name without using eclips

I was lose my android project and i was just only the apk file which is only on publish on google play store.my quation is that any kinde of formula or trick is available to get my source code and i was change the package name and uploade it again..
Try these free programs...
http://www.xda-developers.com/android/easily-decompile-and-recompile-apks-with-android-apktool/
Dex2jar
Android .apk file is a compressed form of a file which contains only Java classes (in .dex form), xml files.
To get the source code from apk file, you can use tools like
dex2jar
apktool
You can look into this link for a detailed explanation.
Of course you can do reverse engineering, but you will not get the exact source code. Because as google announce that whenever you upload apk to market google play runs a proguard on it so whenever anybody try to reverse engineering no body can exact code. It makes your class name Like class A, class B and for loop converts to while loop and and change the variable name to unreadable form.
Please go through it, it gives you all the resources and source code of application. Now you are free to change the package name and so on..
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.apk.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 de-compiler from
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
put .apk file which you want to decode
download Apktool for windows v1.x And Apktool
install window using google and put in the same folder
download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
Open a command window
Navigate to the root directory of APKtool and type the following command:
apktool if framework-res.apk.
Above command should result in Framework installed ....
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.
Enjoy and happy coding

Using apktool to decompile apk file

I tried extracting apk file using apktool. I followed steps mentioned below.
Is there a way to get the source code from an APK file?
but i am not able to get it completely.I am not sure about where to put the apktool and how to decompile apk file.
i got following error while running apktool command
C:\Windows\System32>apktool.bat
Unable to access jarfile C:\Windows\System32\apktool.jar
Please help me to sort this out.
Thanks in advance
I faced the same problem. I my case i discovered that the jar file is present in a separate package and i had to download apktool1.5.2.tar.bz2 in addition to apktool-install-windows-r05-ibot.tar.bz2 .
Then i extracted the jar file and placed it in the same directory as apktool.
Hope it helps.
I also had this problem, then i noticed this in apktool.After done that,apktool gone well.
Rename downloaded jar to apktool.jar
I would create a folder called "apktool" somewhere where it won't be deleted ( a safe spot ).
Download the wrapper file & the apktool file itself via the Google code page (linked below). This is 2 files. One is a wrapper, OS specific, along with aapt ( which is needed for rebuild), and the other is simply apktool.jar which is the main application.
Once that is done, go into Environment Variables (PATH) for Windows, and add that current directory to it. So you can access apktool / aapt anywhere via command prompt.
http://code.google.com/p/android-apktool/
ApkTool + Dex2Jar + any java decompiler? Comon! This is old style :0)
Try NEW open-source APK and DEX decompiler called Jadx: https://sourceforge.net/projects/jadx/files/
It has also online version here: http://www.javadecompilers.com/apk/
I have followed https://ibotpeaches.github.io/Apktool/install/ link for windows and renamed jar file as "apktool.jar" with extra jar extension (ie.apktool.jar.jar) so I was getting "Error: Unable to access jarfile C:\APKtool\apktool.jar".
After renaming properly (removing extra .jar extension) , I am able to use "apktool.jar" properly.
I know it is silly mistake, but some time it happens :)
Those who are still facing same issue, follow below steps:
Download "https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/windows/apktool.bat"
download latest apktool from https://bitbucket.org/iBotPeaches/apktool/downloads/
Rename apktool_version.jar to apktool.jar
Put .bat and .jar in same folder.
Run apktool.bar d "path of apkfile/example.apk"

Reverse engineering from an APK file to a project

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?
There are two useful tools which will generate Java code (rough but good enough) from an unknown APK file.
Download dex2jar tool from dex2jar.
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
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:
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
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
put .apk file which you want to decode
download Apktool for windows v1.x And Apktool
install window using google and put in the same folder
download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
Open a command window
Navigate to the root directory of APKtool and type the following command:
apktool if framework-res.apk.
Above command should result in Framework installed ....
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
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
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.
2: Here you can see an option "Profile or debug APK" click on it and select your apk file and press ok.
3:
It will open all your manifest and java classes with in a minute depending upon size of apk.
That's it.
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.
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
Try this tool: https://decompile.io, it runs on iPhone/iPad/Mac
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.
Below are some of the tools which you can use to perform reverse engineering from an APK file to source code :
Dex2jar
Java decompiler
Apktool
Apk Analyser
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.
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
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.
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.

How to extract code of .apk file which is not working? [duplicate]

This question already has answers here:
Is there a way to get the source code from an APK file?
(32 answers)
Closed 5 years ago.
Actually I was trying to extract code of a .apk file called cloudfilz.apk and wanted to manipulate in its source code so I followed the steps given below:-
make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg: rename from filename.apk to filename.apk.zip) and save it..now you get classes.dex files etc...at this stage you are able to see drawable but not XML and java file...so continue...
Step 2:
now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now download dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (in this case NEW FOLDER).....now open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write "dex2jar classes.dex" and press enter.....now you get classes.dex.dex2jar file in the same folder......
=>Question:-I was successful to achieve step 1 but in step2 when I am executing dex2jar classes.dex I am getting an error on command prompt java.lang.UnsupportedClassVersionError ,I know this is due to incompatibility between my installed JDK version and classes.dex JDK version number so stuck here and don't have way out...
Note: All of the following instructions apply universally (aka to all OSes) unless otherwise specified.
Prerequsites
You will need:
A working Java installation
A working terminal/command prompt
A computer
An APK file
Steps
Step 1: Changing the file extension of the APK file
Change the file extension of the .apk file by either adding a .zip extension to the filename, or to change .apk to .zip.
For example, com.example.apk becomes com.example.zip, or com.example.apk.zip. Note that on Windows and macOS, it may prompt you whether you are sure you want to change the file extension. Click OK or Add if you're using macOS:
Step 2: Extracting Java files from APK
Extract the renamed APK file in a specific folder. For example, let that folder be demofolder.
If it didn't work, try opening the file in another application such as WinZip or 7-Zip.
For macOS, you can try running unzip in Terminal (available at /Applications/Terminal.app), where it takes one or more arguments: the file to unzip + optional arguments. See man unzip for documentation and arguments.
Download dex2jar (see all releases on GitHub) and extract that zip file in the same folder as stated in the previous point.
Open command prompt (or a terminal) and change your current directory to the folder created in the previous point and type the command d2j-dex2jar.bat classes.dex and press enter. This will generate classes-dex2jar.jar file in the same folder.
macOS/Linux users: Replace d2j-dex2jar.bat with d2j-dex2jar.sh. In other words, run d2j-jar2dex.sh classes.dex in the terminal and press enter.
Download Java Decompiler (see all releases on Github) and extract it and start (aka double click) the executable/application.
From the JD-GUI window, either drag and drop the generated classes-dex2jar.jar file into it, or go to File > Open File... and browse for the jar.
Next, in the menu, go to File > Save All Sources (Windows: Ctrl+Alt+S, macOS: ⌘+⌥+S). This should open a dialog asking you where to save a zip file named `classes-dex2jar.jar.src.zip" consisting of all packages and java files. (You can rename the zip file to be saved)
Extract that zip file (classes-dex2jar.jar.src.zip) and you should get all java files of the application.
Step 3: Getting xml files from APK
For more info, see the apktool website for installation instructions and more
Windows:
Download the wrapper script (optional) and the apktool jar (required) and place it in the same folder (for example, myxmlfolder).
Change your current directory to the myxmlfolder folder and rename the apktool jar file to apktool.jar.
Place the .apk file in the same folder (i.e myxmlfolder).
Open the command prompt (or terminal) and change your current directory to the folder where apktool is stored (in this case, myxmlfolder). Next, type the command apktool if framework-res.apk.
What we're doing here is that we are installing a framework. For more info, see the docs.
The above command should result in "Framework installed ..."
In the command prompt, type the command apktool d filename.apk (where filename is the name of apk file). This should decode the file. For more info, see the docs.
This should result in a folder filename.out being outputted, where filename is the original name of the apk file without the .apk file extension. In this folder are all the XML files such as layout, drawables etc.
Source: How to get source code from APK file - Comptech Blogspot
Any .apk file from market or unsigned
If you apk is downloaded from market and hence signed Install Astro File Manager from market. Open Astro > Tools > Application Manager/Backup and select the application to backup on to the SD card .
Mount phone as USB drive and access 'backupsapps' folder to find the apk of target app (lets call it app.apk) . Copy it to your local drive same is the case of unsigned .apk.
Download Dex2Jar zip from this link: SourceForge
Unzip the downloaded zip file.
Open command prompt & write the following command on reaching to directory where dex2jar exe is there and also copy the apk in same directory.
dex2jar targetapp.apk file(./dex2jar app.apk on terminal)
http://jd.benow.ca/ download decompiler from this link.
Open ‘targetapp.apk.dex2jar.jar’ with jd-gui
File > Save All Sources to sava the class files in jar to java files.
step 1:
Download dex2jar here. Create a java project and paste (dex2jar-0.0.7.11-SNAPSHOT/lib ) jar files .
Copy apk file into java project
Run it and after refresh the project ,you get jar file .Using java decompiler you can view all java class files
step 2: Download java decompiler here
Click here this is a good tutorial for both window/ubuntu.
apktool1.5.1.jar download from here.
apktool-install-linux-r05-ibot download from here.
dex2jar-0.0.9.15.zip download from here.
jd-gui-0.3.3.linux.i686.tar.gz (java de-complier) download from here.
framework-res.apk ( Located at your android device /system/framework/)
Procedure:
Rename the .apk file and change the extension to .zip ,
it will become .zip.
Then extract .zip.
Unzip downloaded dex2jar-0.0.9.15.zip file , copy the contents and paste it to unzip folder.
Open terminal and change directory to unzip “dex2jar-0.0.9.15 “
– cd
– sh dex2jar.sh classes.dex (result of this command “classes.dex.dex2jar.jar” will be in your extracted folder itself).
Now, create new folder and copy “classes.dex.dex2jar.jar” into it.
Unzip “jd-gui-0.3.3.linux.i686.zip“ and open up the “Java Decompiler” in full screen mode.
Click on open file and select “classes.dex.dex2jar.jar” into the window.
“Java Decompiler” and go to file > save and save the source in a .zip file.
Create “source_code” folder.
Extract the saved .zip and copy the contents to “source_code” folder.
This will be where we keep your source code.
Extract apktool1.5.1.tar.bz2 , you get apktool.jar
Now, unzip “apktool-install-linux-r05-ibot.zip”
Copy “framework-res.apk” , “.apk” and apktool.jar
Paste it to the unzip “apktool-install-linux-r05-ibot” folder (line no 13).
Then open terminal and type:
– cd
– chown -R : ‘apktool.jar’
– chown -R : ‘apktool’
– chown -R : ‘aapt’
– sudo chmod +x ‘apktool.jar’
– sudo chmod +x ‘apktool’
– sudo chmod +x ‘aapt’
– sudo mv apktool.jar /usr/local/bin
– sudo mv apktool /usr/local/bin
– sudo mv aapt /usr/local/bin
– apktool if framework-res.apk
– apktool d .apk

Categories

Resources