My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 10, 2009 by JesusFr...@JesusFreke.com
Labels: Featured
DeodexInstructions  
Instructions on using baksmali and deodexerant to deodex an .odex file

Introduction

baksmali now has the ability to disassemble odex files, and optionally to deodex them.

Details

It requires the help of deodexerant, which is a small binary that runs on the phone and links to the dalvik libraries. It's purpose is to provide info to baksmali that can only be obtained from a running instance of dalvik (things like vtable indexes, field byte offsets, etc.).

The syntax for deodexerant is:

deodexerant <odex_file> <port>

And then baksmali has a new -x option to tell it to deodex the file. The syntax is

baksmali -x <host>:<port> <odex_file>

You can also use -x :<port> as a shortcut for -x localhost:<port>

The main thing you have to keep in mind when deodexing something is that you must use the same "bootclasspath" jars that were used when the odex was created. The easiest way to satisfy this is to actually be running the firmware that you are trying to deodex. It's also possible to setup a chroot environment if you need to deodex something from a different firmware, but I'll leave that as an exercise for the reader. Feel free to ping me on #smali on irc.freenode.com if you need any help with that.

So let's say you are running a rom based on an official t-mobile US image, and the apps in /system/app are odexed. A deodex session would go something like this:

adb push deodexerant /data/local
adb shell chmod 755 /data/local/deodexerant
adb forward tcp:1234 tcp:1234
adb pull /system/app/Calculator.odex .
adb shell /data/local/deodexerant /system/app/Calculator.odex 1234 &
java -jar baksmali.jar -x :1234 Calculator.odex

You will then have the usual set of .smali files in the out directory, ready to be re-assembled back into a classes.dex file with smali.

Note how I use adb forward so that the communication happens over usb. If you try to do this over wifi it is slow. The latency of the usb link is much less than the latency over wifi, and since baksmali makes a large number of smallish, synchronous requests to deodexerent, latency kills its performance.


Comment by DrakeDrizzyRogers, Oct 01, 2009

Hey JF Im following you example on how to deodex and i get stuck here

adb push deodexerant /data/local adb shell chmod 755 /data/local/deodexerant adb forward tcp:1234 tcp:1234 adb pull /system/app/Calculator.odex <<---- HERE

I enter the command and all the options of adb come out, is there anything im doing wrong, im using the your example as a start"I tried pulling the calculator"

Kind regards Drizzy

Comment by isaacwal...@gmail.com, Oct 01, 2009

@Drizzy you forgot the period (.)

Comment by bradomirov, Oct 08, 2009

I get stuck on the next line where the deodexerant is fetching the data...

adb shell /data/local/deodexerant /system/app/Calculator.odex 1234 &

It just sits there. How long does it take??? I waited 10-15 min and terminated the process... Everything else up to that point went smooth...

Comment by JesusFr...@JesusFreke.com, Oct 17, 2009

branomirov: that command is supposed to just sit there. Or rather, it should go back immediately to your prompt. Don't forget the & at the end. After you run the command, it's just sitting there, waiting for baksmali to connect to it. It doesn't do anything until baksmali connects to it and starts requesting information from it.

Comment by Dr.Daniel.Hall, Oct 17, 2009

JF, What do you mean, "supposed to just sit there" and then you say, "it should go back immediately to your prompt"? Say, i've got a 130kb odex, should it take minutes or seconds?

Comment by Dr.Daniel.Hall, Oct 17, 2009

Also, after &, do I hit enter or do I type "& java etc......."?

Comment by Dr.Daniel.Hall, Oct 17, 2009

N/m, I figured that part out. Now i'm sitting here scratching my head at the output files.....

Comment by saykalik, Oct 19, 2009

JF,

I tried your example and was able to get a dex file out of the calculator odex. What i would like to do is try to get the etc.odex and core.odex files into dex. When I try to do that it says that its a read only file system.

What would be the best approach to grab these files and convert them to dex?

Thanks, terr

Comment by Dr.Daniel.Hall, Oct 19, 2009

Well, created classes.dex and added them to the .apks, but they don't seem to work.

Comment by laurent.dinclaux, Oct 20, 2009

Ok I can deodex and get the our folder. To be sure, to recreate a valid classes.dex file, is that the right command to run:

java -jar smali.jar out

?

Comment by afirejar, Oct 20, 2009

java -jar smali.jar -o classes.dex

Comment by ruben.sethi, Oct 23, 2009

You can just copy the system .odex files to the sdcard, and then use deodexerant on the sdcard copy. Works fine for me.

Comment by h.a.gamdi, Oct 25, 2009

Hey,

Every time I try to smali the out folder I got this message:

UNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError??: Java heap space

at org.antlr.runtime.DFA.unpackEncodedString(DFA.java:191) at org.jf.smali.smaliLexer.<clinit>(smaliLexer.java:20013) at org.jf.smali.main.assembleSmaliFile(main.java:206) at org.jf.smali.main.main(main.java:138)

The command I used to smali the out folder is: java -jar smali.jar -o classed.dex out

Any help will be appreciated, and many thanks and kind regards to you JF.

Comment by h.a.gamdi, Oct 26, 2009

Hi everyone,

I just found this post in XDD explaining many things.

http://forum.xda-developers.com/showthread.php?t=537779

Hope u will find it helpful.

Comment by laurent.dinclaux, Oct 27, 2009

Hi,

I really need to deodex a file and I get:

UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.RuntimeException?: bad magic value

at org.jf.dexlib.DexFile?.<init>(DexFile?.java:309) at org.jf.baksmali.main.main(main.java:161)

Comment by h.a.gamdi, Oct 27, 2009

Hi laurent.dinclaux:

what command did u use for smali ?

Comment by JittUppal, Oct 30, 2009

I have deodexterant working but I can't get smali to compile the files back - any ideas on what is going wrong? Thanks.

C:\android\adb>java -Xmx512M -jar smali.jar out/ -o newclasses.dex C:\android\adb\out\com\android\server\WindowManagerService?.smali25760,4? The of fset/label is out of range. The offset is -133 and the range for this opcode is 127?.

Comment by mongdlove, Nov 24, 2009

Can I do this with HTC Hero device? I've followed the instruction, but I got exception. =(

Comment by brentnesbit, Dec 05, 2009

I just posted this on JF's blog but I figured I would post here too in hopes of getting help with the error. :)

I am working on smali/baksmali’ing framework.odex on my cdma hero to change a couple of things. The baksmali goes perfectly fine but when I try to smali I get bombarded with errors in every single .smali file:

c:\test\framework\out\android\app\ActivityManagerProxy?.smali4364,32? no viable alternative at character ‘}’

c:\test\framework\out\android\accounts\AccountMonitor?$AccountUpdater?.smali73,4? no viable alternative at character ‘:’

My syntax that I used was: c:\test\framework>java -Xmx512m -jar c:\android\sdk\tools\smali.jar out

I also tried with -o test.dex and got the same thing. I tried without the memory switch but got a memory error (it’s a huge odex). I also tried 0.96 and got the same errors. Any help that you can give is appreciated. :) I am using v1.0. Thanks.

Comment by sohyuanchin, Dec 06, 2009

Hi, thanks for this! I'm unable to deodex framework.odex, and am able to deodex services.odex but unable to compile it back using smali:

java -Xmx512M -jar smali.jar -o classes.dex out /home/wysie/Desktop/tempfiles/out/com/android/server/WindowManagerService?.smali25760,4? The offset/label is out of range. The offset is -133 and the range for this opcode is 127?.

Any ideas? Thanks!

Comment by n8schicht, Dec 15, 2009

When I try to use baksmali.jar on "com.google.android.maps.odex", "core.odex", "ext.odex" and "framework.odex" I get error messages (all other files in /system/framework/ work fine though):

UNEXPECTED TOP-LEVEL ERROR: java.lang.StackOverflowError??

at java.util.LinkedList??.listIterator(LinkedList??.java:667)

at java.util.AbstractList??.listIterator(AbstractList??.java:284)

at java.util.AbstractSequentialList??.iterator(AbstractSequentialList??.java:222)

at org.jf.dexlib.Util.DeodexUtil??$insn.propogateRegisters(DeodexUtil??.java:1414)

at org.jf.dexlib.Util.DeodexUtil??$insn.propogateRegisters(DeodexUtil??.java:1484)

at org.jf.dexlib.Util.DeodexUtil??$insn.propogateRegisters(DeodexUtil??.java:1484)

at org.jf.dexlib.Util.DeodexUtil??$insn.propogateRegisters(DeodexUtil??.java:1484)

...

Can I do something about this?

I envoked the command with: java -Xmx512M -jar /opt/android-sdk/tools/baksmali.jar -x :1234 com.google.android.maps.odex

Thank you :)

Comment by JesusFr...@JesusFreke.com, Dec 15, 2009

n8schicht: I'm not sure if you're running into a bug into baksmali, or if you just have a small stack size. The logic that analyzes the code to determine the types for registers is highly recursive, so it's not unusual to have a large call stack. But I've never had any issues with the stack not being large enough.

Try adding a -Xmss1m to increase the stack size to 1mb. If that doesn't work maybe try going up to... 10m? If that doesn't work, there's something else wrong here.

Also, would you (and everyone :p) mind submitting things like this as issues. It seems silly to report issues as comments on a wiki page :p. That just gets messy after a while.

Comment by n8schicht, Dec 16, 2009

JF: Thanks for your quick reply, "java -Xss1m" did the trick :) And sorry for me posting this as a comment, I will do better next time ;) Thanks again!

Comment by tiran133, Dec 18, 2009

Hi, one questeion its not exactly one abiut smali/baksmali but i hope u can help me.

If I baksmali some files(odex) in the framework folder using the helper "deotexerant", it all goes well. Then I smali it back to .dex (No errors) put the file into the .jar file. Delete the old .odex file an and push the new .jar file back to phone. I get an error like. "Mismatche dep name..." If I make an odex file out of it. Using dexopt-wrapper put it in the framework folder, delete the .dex from the .jar. I get an "Mismatch dep signature..." error. The same if I copy the odex form dalvik-cache to the frameworkk folder. Some how smali destroyes the signature of these files and make the system inconsisten. Can i do somthing about it?

Appriciate your help thanks

Comment by JesusFr...@JesusFreke.com, Dec 18, 2009

tiran133: correct. Every odex on the phone stores the name and a checksum of the odex files that it is dependent on. This generally consists of the odexes for the jar files mentioned in the BOOTCLASSPATH, but a few jars have extra dependencies as well (i.e. the maps apk depends on the maps jar). If you change any of these odexes that other odexes depend on, it breaks the dependency and they no longer work.

So if you want to make a change to any of the odexed framework jars in the bootclasspath, you basically need to deodex every single apk and jar on the phone.

Comment by Rivera5783, Dec 28, 2009

ok so can someone plz explain to me what's the real difference between disassembling an odex file and de-odexing an odex file?? when i disassemble an odex i get the output .smali files, but unable to re-dex them; and still kinda confused on how to do the whole tcp:1234 method.. doesn't seem to work out for me.. my odex files are from the nexus dump not on my phone so i'm kinda confused

Comment by me95131, Dec 30 (6 days ago)

Hi JF, Would you please take a look? I am trying to deodex ADP2/Sapphire's /system/framework/com.google.android.maps.odex, but got the error below when I ran this command:

C:\android-sdk_r04\smali>java -Xss1m -Xmx512M -jar baksmali.jar -x :1234 com.google.android.maps.odex

Errors:


UNEXPECTED TOP-LEVEL ERROR: java.lang.StackOverflowError?
at java.util.LinkedList?.listIterator(Unknown Source) at java.util.AbstractList?.listIterator(Unknown Source) at java.util.AbstractSequentialList?.iterator(Unknown Source) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1396) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466) at org.jf.dexlib.Util.DeodexUtil?$insn.propagateRegisters(DeodexUtil?.java:1466)

Comment by JesusFr...@JesusFreke.com, Dec 30 (6 days ago)

me95131: see 5 comments up from yours ;)

Comment by me95131, Dec 30 (6 days ago)

Hi JF, I have tried the following commands based on the comments regarding "adding a -Xmss1m":

"java -Xss1m -Xmx512M" "java -Xss10m -Xmx512M" "java -Xss16m -Xmx512M" "java -Xss64m -Xmx512M" "java -Xss32m -Xmx1024M" "java -Xss64m -Xmx1024M"

However, the errors are the same.

The "/system/framework/com.google.android.gtalkservice.odex" has no problem with "java -Xss1m -Xmx512M". Just that "/system/framework/com.google.android.maps.odex" had probelms at 2/3 of work done.

This is from a Sapphire/ADP2 phone. I am running the smali from Windows Vista 32bit. Please take a second look at it. Thank you so much!

Comment by JesusFr...@JesusFreke.com, Dec 30 (6 days ago)

Ack, I just noticed that you included the -Xss1m param in your original report. I had totally missed it. Sorry about that :).

Can you create an issue, and we'll continue this discussion there? This really isn't the place for that :p

Comment by me95131, Dec 30 (6 days ago)

Thanks JF! I just created an issue here: http://code.google.com/p/smali/issues/detail?id=11

Hosted by Google Code