FORUMS

[GUIDE] How to Decompile APKs with ODEX files [Noob Friendly]

107 posts
Thanks Meter: 22
 
By dnnz, Senior Member on 29th February 2016, 12:12 AM
Post Reply Email Thread
THIS GUIDE HAS BEEN TESTED ON KITKAT, MARSHMALLOW AND NOUGAT

When you have a system app with an odex file like bluetooth.apk and bluetooth.odex you can't use apktool for decompile and there is no need for deodex the whole ROM, follow this guide to decompile and mod one of these apps and nothing else.


REQUIREMENTS

- Be root
- platform-tools folder : lastest version download
- Java installed
- Files: baksmali.jar, smali.jar and zipalign.exe.


SET UP

- Make a folder named "Baksmali" and place these files: baksmali.jar, smali.jar, zipaling.exe, the apk and it's odex file
- Place the platform-tools folder in Baksmali folder and rename it to framework.
- Make sure the files are named baksmali.jar and smali.jar for simplicity , not baksmali-somenumber.jar. This is optional but keep in mind that in the commands i will assume these files are named like that so if you don't you'll have to replace with their real names like baksmali-2.0.0.jar

I i attached a zip with the complete Baksmali folder, but keep in mind this folder was created in feb 2016, you may need download manually the latest files to make sure if you got any errors it's not because of outdated versions


DECOMPILE

- Conect your device to the PC
- Go to Backsmali/framework
- Right click + SHIFT on an empty space of the folder and select "open command window here" and write:

adb pull /system/framework/arm/boot.oat boot.oat

For kitkat: adb pull /system/framework


- Go to Baksmali folder
- Right click + SHIFT on an empty space of the folder and select "open command window here" and write this command (replace NAME with the name of your odex file):

java -jar baksmali.jar -x -c boot.oat -d framework NAME.odex -o out

For Kitkat = java -jar baksmali.jar -d framework -x NAME.odex

- The files should be in the "out" folder now created


COMPILE

This way you can create a classes.dex so then you can place it in an apk so the apk is not more dependent of the odex file.

- Again in Baksmali folder Right click + SHIFT and select "open command window here":

java -jar smali.jar -o classes.dex out

Now open the APK file with 7zip/winrar and drag the file classes.dex, confirm and exit.

write this command:

zipalign -v 4 apk.apk new_apk.apk

apk: name of the apk we just added classes.dex file
new_apk: apk generated by zipaling, ready to use in the device

PLACE APP IN THE DEVICE

Rename the new_apk to the original name, and with a root explorer place it in system/app with permisions rw-r-r, remember deleting the odex file in that folder.
Update Marhsmallow: Delete the folder APKNAME in system/app and paste the apk in with permisions rw-r-r
If when you open the app crashes always try rebooting

Attached Files
File Type: zip Baksmali.zip - [Click for QR Code] (3.16 MB, 4104 views)
The Following 14 Users Say Thank You to dnnz For This Useful Post: [ View ] Gift dnnz Ad-Free
1st March 2016, 11:59 AM |#2  
Junior Member
Thanks Meter: 0
 
More
Hello

Thank you for your guide.
I am trying to decompile the Settings.apk in order to solve some translations issues in a flash-able ROM.
In the priv-app/Settings folder there is a Settings.odex file, so i tried to follow your guide to decompile the whole thing.
The following command gives me an error, i think there is some version mismatch here:

java -jar baksmali-2.1.0.jar -d framework -x Settings.odex
Exception in thread "main" org.jf.dexlib2.DexFileFactory$UnsupportedOatVersio nException: Unsupported oat version: 39
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:147)
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:78)
at org.jf.baksmali.main.main(main.java:266)

I am copying the needed files (framework, Settings.odex/apk) from the Zip ROM, not from the phone, i guess this isnt an issue right?
1st March 2016, 03:40 PM |#3  
OP Senior Member
Thanks Meter: 22
 
More
Quote:
Originally Posted by luismpc

Hello

Thank you for your guide.
I am trying to decompile the Settings.apk in order to solve some translations issues in a flash-able ROM.
In the priv-app/Settings folder there is a Settings.odex file, so i tried to follow your guide to decompile the whole thing.
The following command gives me an error, i think there is some version mismatch here:

java -jar baksmali-2.1.0.jar -d framework -x Settings.odex
Exception in thread "main" org.jf.dexlib2.DexFileFactory$UnsupportedOatVersio nException: Unsupported oat version: 39
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:147)
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:78)
at org.jf.baksmali.main.main(main.java:266)

I am copying the needed files (framework, Settings.odex/apk) from the Zip ROM, not from the phone, i guess this isnt an issue right?


Idk maybe you should try adb pull to extract the framework from the phone, also the last versión of baksmali is 2.1.1 you got them all here.
The folder i share has the lastest versión of both.
Note Im not a dev, i made this step by step guide because i dind't find in google something clear about it and took me a long time to make it work.
1st March 2016, 03:49 PM |#4  
Junior Member
Thanks Meter: 0
 
More
I followed this guide here and i was able to decompile my file, thanks
29th April 2016, 07:12 AM |#5  
OP Senior Member
Thanks Meter: 22
 
More
Quote:
Originally Posted by luismpc

Hello

Thank you for your guide.
I am trying to decompile the Settings.apk in order to solve some translations issues in a flash-able ROM.
In the priv-app/Settings folder there is a Settings.odex file, so i tried to follow your guide to decompile the whole thing.
The following command gives me an error, i think there is some version mismatch here:

java -jar baksmali-2.1.0.jar -d framework -x Settings.odex
Exception in thread "main" org.jf.dexlib2.DexFileFactory$UnsupportedOatVersio nException: Unsupported oat version: 39
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:147)
at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileF actory.java:78)
at org.jf.baksmali.main.main(main.java:266)

I am copying the needed files (framework, Settings.odex/apk) from the Zip ROM, not from the phone, i guess this isnt an issue right?

The guide worked on KitKat, now is updated to work on Marhsmallow, you can use the new method maybe also works on Lollipop...
28th August 2016, 03:37 AM |#6  
Senior Member
Flag 大阪府
Thanks Meter: 79
 
Donate to Me
More
This guide worked wonderfully for me. I was able to decompile and recompile a system apk for Marshmallow. Thank you!

Is there a way to convert the smali files to java for Marshmallow apks (dex2jar)?
19th September 2016, 03:43 AM |#7  
Pain-N-Panic's Avatar
Senior Member
Flag Droid
Thanks Meter: 530
 
More
Everything worked great up until the compile part. I got an error saying "mismatched d input '' expecting END_METHOD_DIRECTIVE"

See photo attached. Anyone have any idea how to fix this so I can compile a classes.dex for my SystemUI?

Also, I just upgraded to Android N if that makes a difference...
Attached Thumbnails
Click image for larger version

Name:	_20160918_223957.jpg
Views:	474
Size:	157.0 KB
ID:	3879565  
5th December 2016, 05:59 PM |#8  
neo4uo's Avatar
Senior Member
Flag Alabama
Thanks Meter: 281
 
More
I tried for a Marshmallow file and get this error, also I did update smali and baksmali to the latest files;
Code:
C:\Baksmali>java -jar baksmali.jar -x -c boot.oat -d framework LGSystemUI.odex -o out
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -x
        at com.beust.jcommander.JCommander.parseValues(JCommander.java:742)
        at com.beust.jcommander.JCommander.parse(JCommander.java:282)
        at com.beust.jcommander.JCommander.parse(JCommander.java:265)
        at org.jf.baksmali.Main.main(Main.java:90)
Thanks
4th May 2017, 04:05 AM |#10  
Senior Member
Thanks Meter: 10
 
More
Quote:
Originally Posted by neo4uo

I tried for a Marshmallow file and get this error, also I did update smali and baksmali to the latest files;

Code:
C:\Baksmali>java -jar baksmali.jar -x -c boot.oat -d framework LGSystemUI.odex -o out
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -x
        at com.beust.jcommander.JCommander.parseValues(JCommander.java:742)
        at com.beust.jcommander.JCommander.parse(JCommander.java:282)
        at com.beust.jcommander.JCommander.parse(JCommander.java:265)
        at org.jf.baksmali.Main.main(Main.java:90)
Thanks

you don't need the "-x" for baksmail, just "x"

Code:
java -jar baksmali.jar x -c boot.oat -d framework LGSystemUI.odex -o out
The Following User Says Thank You to a.vandelay For This Useful Post: [ View ] Gift a.vandelay Ad-Free
5th May 2017, 06:24 PM |#11  
San.Dip's Avatar
Member
Thanks Meter: 46
 
More
Quote:

you don't need the "-x" for baksmail, just "x"

Thanks a lot, it worked for me. I am using version 2.2.0.
However, while executing "java -jar smali.jar -o classes.dex out" command I get following error. Please suggest the necessary correction.

C:\Users\Sandip\Desktop\New folder\Baksmali>java -jar smali.jar -o classes.dex out
Exception in thread "main" com.beust.jcommander.MissingCommandException: Expected a command, got -o
at com.beust.jcommander.JCommander.parseValues(JComma nder.java:725)
at com.beust.jcommander.JCommander.parse(JCommander.j ava:304)
at com.beust.jcommander.JCommander.parse(JCommander.j ava:287)
at org.jf.smali.Main.main(Main.java:87)
C:\Users\Sandip\Desktop\New folder\Baksmali>
Post Reply Subscribe to Thread

Tags
apk, app, decompile, odex, system

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes