How to extract source code from apk - General Topics

Hey guys heres a way to extract source code of an apk
I know many of u may know it but still no thread in this section
If its wrong or right or a question only then reply
NOW WHAT IS SOURCE CODE:
A text listing of commands to be compiled or assembled into an executable program
How to extract source code:
Requirements
1. Android-apktool
2. Dex2jar
3. JD-Gui
Procedure
Rename the .apk file you wish to retrieve and change the extension to .zip. Then extract the file that it creates.
Copy the contents of the dex2jar folder to the extracted folder to make it easier for yourself, and run:
dex2jar classes.dex
and copy the resulting “classes.dex.dex2jar.jar” into a new folder.
Open up the Java Decompiler and drag “classes.dex.dex2jar.jar” into the window and then go to File > Save and save the source in a .zip file.
Extract the saved .zip and copy the contents to a new folder somewhere. This will be where we keep your source code.
Now, copy “framework-res.apk” and “yourapk.apk” to the APKTool folder. Then open a command prompt or Terminal window and type:
apktool if framework-res.apk
apktool d
Now just copy the contents of the resulting folder to the same place you copied the contents of “classes.dex.dex2jar.jar” earlier and you have your source code.
Apk source code files
http://db.tt/oqdrcBpk
Now to import this project into eclipse
Go here
Enjoy modifying
Sent by typing by my fingers

Drop Box Link Not Working...please update it

Thanks for the small guide. I've been wondering if there was a way to do this.
Sent from ALCATEL One Touch Fierce

M not Able to Find dex2jar classes.dex

red de0392 said:
M not Able to Find dex2jar classes.dex
Click to expand...
Click to collapse
You have to run it in CMD that "dex2jar classes.dex" is not a file. its a command.

Related

[Q] dex2jar conversion

Hi every body i m new in ur forum. i don't know how to get the code from apk file. i have go through ur early posts now i m stuck that how can i run the dex2jar.bat. i m using win7 please guide me. Thanks alot
Please use the Q&A Forum for questions &
Read the Forum Rules Ref Posting
Moving to Q&A
Hello proudnation47 and welcome to XDA.
You'll need dex2jar and jd-gui in the process, so download them.
Extract classes.dex from apk:
-rename .apk to .zip
-open with archive manager like WinRar, 7zip or whatever
-copy the classes.dex file where you want (on desktop, for example)
Open command prompt:
-press "Windows" key and "R"
-type cmd
-press "Run"
In command prompt:
-type cd [location of dex2jar folder]
-for example "cd C:\dex2jar"
-type dex2jar.bat [location of classes.dex]
-for example "dex2jar.bat D:\Classes.dex"
And it will create .jar file in the folder of your Classes.dex (for example above, it will create "D:\classes-dex2jar.jar"
Then open jd-gui, navigate to newly created .jar file with "Open With" and it will display the content of .jar file.
Notice that this process isn't perfect, and that you cannot create workable .dex file, the sole purpose of this process is to make it easier to understand to code.
If you want to edit it and create a workable file, you'll need to use jesusfreke's smali/baksmali method, which is harder to understand, but you'll create a workable file at the end.

[Q] Unable to convert .dex to .jar in mac osx

Hi All,
I'm using Mac OSX(10.7) and trying to extract java file from a android apk. So i downloaded apk and then copied dex2jar zip file
After extracting dex file from apk(classes.dex), i had unzipped dex2jar and opened termial changed directory path to dex2jar and executed as below
my-MacBook-Pro:dex2jar-0.0.9.11 my$ **dex2jar.sh classes.dex**
but it says
*-bash: dex2jar.sh: command not found*
Click to expand...
Click to collapse
I checked in directory and dex2jar.sh is present. What is the mistake i'm doing
Most likely your directory where dex2jar.sh resides isn't listed in your PATH, so just type
Code:
./dex2jar.sh classes.dex
(dot and slash are important)

[GUIDE] [N00B] How to decompile/recompile .apk

GUIDE
What will you Need:
ApkTool
Java JDK/JRE 32 bit
Terminal knowledge
Brain
Instructions
Extract zip folder to anywhere you choose. E.g: C:/android/apktool extracting the files to 'apktool' folder.
3.Now copy the apk to your Apk Tool folder.
2. Open your terminal
Your terminal will look like this...
C:\users\yourname>
Code:
[COLOR="Black"]cd.. → go back
cd.. android → go to this folder[/COLOR]
(Yes, it contains "..")
So you must be in your folder apktool (E.q: C:/android/apktool>)
3. Installing Framework
Code:
apktool if framework-res.apk
(framework-res.apk is only example.. You can type "apktool if SystemUI.apk",...)
4. Decompiling
Code:
apktool d framework-res.apk framework1
(framework-res.apk is apk which you want to decompile and framework1.. You can type "apktool if SystemUI.apk",...)
Now you can enjoy it!
5. Recompiling/Finished Product
Code:
apktool b framework1 framework-res-new.apk
(framework1 is the folder with your edited files and framework-res-new.apk is your new apk file)
You can't use the new apk... You have to take what you did and add it back to the original apk file to proper signature.
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.
Congratulations! You modded .apk!​
you can help i know...
Mlopik said:
GUIDE
What will you Need:
ApkTool
Java JDK/JRE 32 bit
Terminal knowledge
Brain
Instructions
Extract zip folder to anywhere you choose. E.g: C:/android/apktool extracting the files to 'apktool' folder.
3.Now copy the apk to your Apk Tool folder.
2. Open your terminal
Your terminal will look like this...
C:\users\yourname>
Code:
[COLOR="Black"]cd.. → go back
cd.. android → go to this folder[/COLOR]
(Yes, it contains "..")
So you must be in your folder apktool (E.q: C:/android/apktool>)
3. Installing Framework
Code:
apktool if framework-res.apk
(framework-res.apk is only example.. You can type "apktool if SystemUI.apk",...)
4. Decompiling
Code:
apktool d framework-res.apk framework1
(framework-res.apk is apk which you want to decompile and framework1.. You can type "apktool if SystemUI.apk",...)
Now you can enjoy it!
5. Recompiling/Finished Product
Code:
apktool b framework1 framework-res-new.apk
(framework1 is the folder with your edited files and framework-res-new.apk is your new apk file)
You can't use the new apk... You have to take what you did and add it back to the original apk file to proper signature.
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.
Congratulations! You modded .apk!​
Click to expand...
Click to collapse
Hey boss... can you tell me how to rename a app... i need it badly.. please.and thanks in advance

[Guide/Tut] G2 DEODEXING APK IN 3 SIMPLE STEPS- ANY ROM- PERFECT DEODEXING

OF LATELY A LOT OF PEOPLE SEEM TO FACE DECOMPILING ISSUES POST DEODEXING, SOME DO NOT KNOW HOW TO DEODEX. SO I MADE THIS VERY SIMPLE YET 100% WORKING GUIDE. FOLLOW IT ANY ONE, I MEAN ANYONE CAN SUCCESSFULLY DEODEX ANY APK IN HIS G2 ROM [THIS METHOD WORKS PERFECTLY FOR OTHER PHONES AS WELL]
WHAT YOU NEED:-
1. TOOLS FOR DEODEXING:- DOWNLOAD HERE
2. FRAMEWORK FOLDER FROM YOUR PHONE [FOUND IN "/system" folder"]
3. APK AND ODEX FILE TO BE DEODEXED [eg. LGSystemUI.apk & LGSystemUI.odex]-Found either in [/system/app OR /system/priv-app]
LETS START:-
PREPARATION-
---Download and unzip the tools folder above to the folder c:\baksmali . Indtall 7zip utility from the tools as made available above.
---Place the entire "framework" folder in the c:\baksmali folder. Also place the apk and odex file to be deodexed in c:\baksmali folder.
---Open up a dos prompt in c:\baksmali folder ...
*STEP 1*
Type the following command:
HTML:
java -jar baksmali.jar -d c:\baksmali\framework -x nameofodexfile.odex
You will see that an out folder is created in the c:\baksmali folder
*STEP 2*
Type the following command:
HTML:
java -jar smali.jar -o classes.dex out
You will see that a file "classes.dex" is created in the c:\baksmali folder
*STEP 3*
-Open your apk file using 7zip utility.
-Simply Drag the classes.dex file and drop in the 7zip open window. Click YES.
-YOU HAVE SUCCESSFULLY CREATED THE DEODEXED APK FILE.
NOTE:
1. If during step 1 you get errors, it is likely that either the framework is different or apk & odex belongs to a different ROM.
2. Use 7zip as it is better and safe than winrar for handling apk files.
3. If above steps are followed, the chances of any errors are "0".
4. While decompiling apks use apktool 1.5.2. This handles smali files much better than 2.0.3 version.
I certainly hope this guide proves helpful to those intending to take up theming/modding... Best of Luck... If you have any concerns get in touch with me- I will gladly help....
Thank you XDA for this wonderful forum
Consider pressing thanks button if you find this tutorial helpful- It promotes development...
Hi, very good tutorial! Just what I needed. Thanks!
rastigo said:
OF LATELY A LOT OF PEOPLE SEEM TO FACE DECOMPILING ISSUES POST DEODEXING, SOME DO NOT KNOW HOW TO DEODEX. SO I MADE THIS VERY SIMPLE YET 100% WORKING GUIDE. FOLLOW IT ANY ONE, I MEAN ANYONE CAN SUCCESSFULLY DEODEX ANY APK IN HIS G2 ROM [THIS METHOD WORKS PERFECTLY FOR OTHER PHONES AS WELL]
WHAT YOU NEED:-
1. TOOLS FOR DEODEXING:- DOWNLOAD HERE
2. FRAMEWORK FOLDER FROM YOUR PHONE [FOUND IN "/system" folder"]
3. APK AND ODEX FILE TO BE DEODEXED [eg. LGSystemUI.apk & LGSystemUI.odex]-Found either in [/system/app OR /system/priv-app]
LETS START:-
PREPARATION-
---Download and unzip the tools folder above to the folder c:\baksmali . Indtall 7zip utility from the tools as made available above.
---Place the entire "framework" folder in the c:\baksmali folder. Also place the apk and odex file to be deodexed in c:\baksmali folder.
---Open up a dos prompt in c:\baksmali folder ...
*STEP 1*
Type the following command:
HTML:
java -jar baksmali.jar -d c:\baksmali\framework -x nameofodexfile.odex
You will see that an out folder is created in the c:\baksmali folder
*STEP 2*
Type the following command:
HTML:
java -jar smali.jar -o classes.dex out
You will see that a file "classes.dex" is created in the c:\baksmali folder
*STEP 3*
-Open your apk file using 7zip utility.
-Simply Drag the classes.dex file and drop in the 7zip open window. Click YES.
-YOU HAVE SUCCESSFULLY CREATED THE DEODEXED APK FILE.
NOTE:
1. If during step 1 you get errors, it is likely that either the framework is different or apk & odex belongs to a different ROM.
2. Use 7zip as it is better and safe than winrar for handling apk files.
3. If above steps are followed, the chances of any errors are "0".
4. While decompiling apks use apktool 1.5.2. This handles smali files much better than 2.0.3 version.
I certainly hope this guide proves helpful to those intending to take up theming/modding... Best of Luck... If you have any concerns get in touch with me- I will gladly help....
Thank you XDA for this wonderful forum
Consider pressing thanks button if you find this tutorial helpful- It promotes development...
Click to expand...
Click to collapse
when i unzip the tools zip the baksmali is a file not a folder so i cant add the framework to the file? not sure if you can help me further
jaymazz13 said:
when i unzip the tools zip the baksmali is a file not a folder so i cant add the framework to the file? not sure if you can help me further
Click to expand...
Click to collapse
you've to create a folder in c:\
then you rename this new folder baksmali
in this folder you have to unzip the file downloaded here
after unzipped
now you can put here your framework
It works great!
One question, how to odex again?

How can I look at the code that is running an app?

I have built a few web sites but now I'm learning how to build apps. Is there a way to look at the code that is running a particular app on my phone so I can get an idea of how it is put together?
Can I open an app from my phone with Android Studio?
Follow the steps given below.
Procedure to open the source code:
Step 1:
Make a new folder and copy over the .apk file that you want to decode.
Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.
Step 2:
Now extract this .zip file in the same folder (or NEW FOLDER).
Download dex2jar and extract it to the same folder (or NEW FOLDER).
Move the classes.dex file into the dex2jar folder.
Now open command prompt and change directory to that folder (or NEW FOLDER). Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex) and press enter. You now have the classes.dex.dex2jar file in the same folder.
Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.
Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.
Step 3:
Now open another new folder
Put in the .apk file which you want to decode
Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder
Download framework-res.apk and put it in the same folder (Not all apk file need this file, but it doesn't hurt)
Open a command window
Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)
now you get a file folder in that folder and can easily read the apk's xml files.

Categories

Resources