[Motorola Atrix 2] cogeary:
Manually Deodexing (Windows/Linux/OSX)

Let's start first with deodexing manually in order to learn about how the whole process works. Deodexing manually can be very useful if you only want to deodex a couple apks, or if some apks are giving tools such as xUltimate trouble. So here's what you'll need:

Basic knowledge of odex vs. deodex... READ THIS

Smali/baksmali installed correctly (if you are on Linux/OSX you can get the wrapper script as well, otherwise just use the .jars)

Java JRE installed correctly

The apks you want to deodex

ALL of the files in /system/framework from your ROM

This is also an excellent read for understanding the process of deodexing an apk

The first thing we want to do is find the bootclasspath for the ROM you are using. You will have to get the file /init.rc from your phone in some way; if you prefer using root explorer then use root explorer to copy it to your sd card, I prefer using adb. Once you have init.rc on your computer, open it up in a text editor. Search for the line that begins with "export BOOTCLASSPATH" and copy the rest of the line. It should look like this:

/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework-ext.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar:/system/framework/com.motorola.android.frameworks.jar:/system/framework/com.motorola.android.widget.jar:/system/framework/com.motorola.frameworks.core.addon.jar:/system/framework/kafdex.jar:/system/framework/com.motorola.orange.simauth.jar

The bootclasspath is simply a list of dependencies that the system apps need to run - i.e. jars/apks that contain code that the system apps use. It is necessary to have the correct bootclasspath when deodexing.

Now that we have the bootclasspath we can start to set up for the actual deodexing. All the files listed in the bootclasspath are found in /system/framework, so grab all the jars/apks in /system/framework from your ROM (adb pull them or take them from the flashable zip if available) and put them in a folder named "framework" somewhere that you can remember, such as your desktop or at the root of your hard drive (i.e. C:\framework). We will use the bootclasspath to find all the files in this folder that are needed to deodex the apps properly.

Now we have to modify the bootclasspath in order to get the baksmali command to work correctly. The current bootclasspath that we have is saying that all the frameworks are in the /system/framework folder of your computer, but most of you have the frameworks somewhere like C:\framework or /home/me/framework. So open your text editor again and paste the current bootclasspath. Hopefully your editor will have a find/replace function; if so, just keep replacing all instances of "/system/framework" with the path to your frameworks. For example, this is what it would look like if your frameworks are in C:\framework:

C:\framework\core.jar:C:\framework\core-junit.jar:C:\framework\bouncycastle.jar:C:\framework\ext.jar:C:\framework\framework.jar:C:\framework\framework-ext.jar:C:\framework\android.policy.jar:C:\framework\services.jar:C:\framework\apache-xml.jar:C:\framework\filterfw.jar:C:\framework\com.motorola.android.frameworks.jar:C:\framework\com.motorola.android.widget.jar:C:\framework\com.motorola.frameworks.core.addon.jar:C:\framework\kafdex.jar:C:\framework\com.motorola.orange.simauth.jar

Finally we are ready to actually deodex the apks. Place the apks and odex's (odexes?) you want to deodex anywhere... your desktop, a folder somewhere, the root of your hard drive... it does not matter. Place the smali/baksmali .jar's in the same directory as the apps you wish to deodex. Open up a command prompt/terminal/etc and "cd" to the directory that the .apk's are in. For example if they are in C:\apps_to_deodex then I would type

cd C:\apps_to_deodex

The process for deodexing is a little dance like this:

Use baksmali to decompile the .odex file to smali

Use smali to compile the .smali files to a .dex

Use an archive manager (ex. 7zip) to put the newly created .dex file into the original .apk

Delete the old .odex file and all the decompiled smali.

So, let's begin.

BAKSMALI

Since baksmali/smali are .jar's, we will be using java to execute them. The syntax for the baksmali command is something like this:

java -jar baksmali.jar -a [COLOR="Red"]api_level[/COLOR] -c [COLOR="red"]bootclasspath[/COLOR] -x [COLOR="red"]file.odex[/COLOR]

The -a argument is not necessary with ICS. If you are on GB then you must use "-a 10" in order for it to deodex properly.

The bootclasspath is the bootclasspath that we determined earlier

The file.odex is, of course, the name of the odex file you want to decompile.

So let's say I want to decompile abc.odex, which was built for ICS. The command would be:

java -jar baksmali.jar -c C:\framework\core.jar:C:\framework\core-junit.jar:C:\framework\bouncycastle.jar:C:\framework\ext.jar:C:\framework\framework.jar:C:\framework\framework-ext.jar:C:\framework\android.policy.jar:C:\framework\services.jar:C:\framework\apache-xml.jar:C:\framework\filterfw.jar:C:\framework\com.motorola.android.frameworks.jar:C:\framework\com.motorola.android.widget.jar:C:\framework\com.motorola.frameworks.core.addon.jar:C:\framework\kafdex.jar:C:\framework\com.motorola.orange.simauth.jar -x abc.odex

This command creates a directory called "out" containing the decompiled odex file.

SMALI

Now that we have "baksmalid" the odex file, we now need to "smali" it to turn the .smali code into the .dex format. The syntax for this command is something like this:

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

We are calling the newly generated file "classes.dex" because that is the file that Android looks for in deodexed apks.

When the command completes you will have a file called "classes.dex" sitting in the directory holding all the deodexed apps.

ARCHIVE MANAGER

Hopefully by now you understand the difference between an odexed app and a deodexed app...

Odexed -> abc.apk AND abc.odex

Deodexed -> abc.apk ONLY which contains classes.dex

So, since we have the classes.dex, all we have to do is drag-n-drop it into the respective.apk using an archive manager such as 7zip (Windows). The result is an .apk which contains all the files necessary for it to install and run... it is deodexed.

CLEANUP

If you are going to repeat the process multiple times you will begin to get confused with filenames and everything. Since you now have a fully funtional abc.apk, you can delete:

-The abc.odex file as it is no longe necessary

-The "out" folder created in step 1

-The classes.dex because it is already copied into abc.apk

TROUBLESHOOTING

Sometimes, no matter what you try, you just can not get an app to deodex because it just isn't finding the right dependencies to load. If you come across some troublesome apps, you can use the "-I" argument when baksmaling to force it to decompile:

java -jar baksmali.jar -a [COLOR="Red"]api_level[/COLOR] -c [COLOR="red"]bootclasspath[/COLOR] -x -I [COLOR="red"]file.odex[/COLOR]

A warning... if you use the -I option on an app that is normally able to deodex fine, you will most likely get force closes and other random errors. Only use -I as a last resort.

For some reason our BOOTCLASSPATH on the ICS leak seems to list some files that don't exist in /system/framework. This means that when you try to baksmali you will get an error about not being able to load class files. If you get this error, look for the .jar that it references, and delete it from the BOOTCLASSPATH and try again. In the end it should look something like this in Windows:

C:\path_to_frameworks\core.jar:C:\path_to_frameworks\core-junit.jar:C:\path_to_frameworks\bouncycastle.jar:C:\path_to_frameworks\ext.jar:C:\path_to_frameworks\framework.jar:C:\path_to_frameworks\framework-ext.jar:C:\path_to_frameworks\android.policy.jar:C:\path_to_frameworks\services.jar:C:\path_to_frameworks\apache-xml.jar:C:\path_to_frameworks\filterfw.jar:C:\path_to_frameworks\com.motorola.android.frameworks.jar:C:\path_to_frameworks\com.motorola.android.widget.jar:C:\path_to_frameworks\com.motorola.frameworks.core.addon.jar

Thanks alteredlikeness for the tip!

Deodexing Automatically with xUltimate (Windows)

Coming soon...

Hope this helps clear up some questions that you've had... enjoy!