December 23, 2011

Decompiling and Compiling Using baksmali and smali

Today its gonna be about modifying jar and apk files using baksmali and smali which i learnt over the internet.
First you need to download the necessary files.
Download and extract this zip to your pc. baksmali and smali
If you don't have notepad++ ,download it here.
If you don't have 7zip, download it here.

After this follow the below instructions.

Decompiling:


I am going to decompile an “android.policy.jar” of a custom rom.
But you can use this procedure to decompile apk files also by editing the smali code.
 
1.bat is the decompiler file. 
Now you need to open this file using notepad ++ and edit the file name inside.
You can edit this bat file and rename the jar/apk name to what jar/apk file your working with. 
  
In my case am gonna use anroid.policy.jar
Then rename 2.bat in the same way to classes.dex

 
Copy the anroid.policy.jar file that you want to edit to the folder
 
 
Now Double Click Command Prompt.bat. Its a windows batch file for this folder.
Then type 1 and press enter.
 

The displayed info might change but the result would be that you would get a folder called Classout in the folder.

Now double click your way through the folders until you reach the smali code.
Now open the required smali code file with notepad++ only and then edit the required code and save the file.
Compiling:
                
Now we will recompile the classout folder to get the new classes.dex” file
                      Back to command prompt type 2 then press enter.
 There would be a new classes.dex file created and ready in your folder. 
Now right click on the android.policy.jar and select 7zip -> Open archive.


You will have a open “android.policy.jar” (not unzipped) to drop “classes.dex” in.
Click on class.dex and while holding down button drag and drop into open “android.policy.jar” window.

                                         Click Yes to finish the copy.
Close window and copy “android.policy.jar” to your phone and replace the existing android.policy.jar file to test. Keep a back up of the original though in case something messes up :) 

A result of the above decompiling and compiling would be this following screen shot. I have added a footer line at the bottom of my Sony Ericsson W8. I use Ginger dx ROM and I removed Doixanh's signature at the bottom. Sorry Doixanh. No offense.



No comments: