[Android] alteredlikeness:
WHAT IS THIS, AND WHAT IS IT FOR?

This is a guide for creating a new odex file from a deodexed file, one at a time – manually, or with the tool provided. There are tools/methods for doing the entire system at once, but I have not had any luck with those. Plus, typically, one does not need the entire system re-odexed. This is more for those who want to personally mod their stock odexed systems, or create an odexed ROM maybe.

For starters, you can get away with modding a lot on an odexed system, without needing to deodex. You really only need to deodex in order to edit the smali files within the classes.dex (which is required to achieve the cooler mods). See cogeary’s great guide for deodexing tips.

-------------------------

MANUAL METHOD:

I will use the services.jar in this example. Just change the file name and path to existing .odex accordingly for other files. (thanks! to jhotmann for helping me to nail down this method)

Requirements:

odexed system

root

adb

busybox installed

dexopt-wrapper

Put this dexopt-wrapper file in /system/bin with 775 permissions:

X X X

X....X

X....X

Put the deodexed services.jar (or other jar/apk file you want to make a new odex of) on the root your /sdcard (on some phones that means internal storage).

Make sure USB Debugging is enabled.

Put your USB connection to MTP or PTP mode.

The bootclasspath is located in the /init.rc file at the root of your phone. Just make sure that all jars listed in init.rc are actually in your /system/framework folder and only include those in your bootclasspath in the command below. The one from Moto A2/Razr/other ICS is used below (minus the extra jar paths). To replace it with that of a different device, change the word bootclasspath with yours, using the path style as shown in the example below: dexopt-wrapper services.jar new.odex bootclasspath...

Connect with adb (do a adb devices check to make sure you're all good).

To create the new odex, enter the following one line at a time:

adb shell
su
cd /sdcard/
dexopt-wrapper services.jar new.odex /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

To copy the signature from the existing odex (change path to /system/app/.. if necessary):

busybox dd if=/system/framework/services.odex of=new.odex bs=1 count=20 skip=52 seek=52 conv=notrunc

Done! Rename new.odex (created on your /sdcard) to services.odex since that is your new signed odex file... and move to your phone using the method of your choice.

---------------------

SCRIPT METHOD (using the 1by1_ReOdexer):

I made this script to speed up the process a little bit (thanks! to jimbridgman and cogeary for their input). Note: This will not hurt your phone if you are on an odexed system and just want to play around with it…

Requirements:

Windows OS (for now – Linux coming soon)

odexed system

root

busybox installed

DOWNLOAD the 1by1_ReOdexer_v1.0.zip for Windows

Unzip it on your desktop or other convenient place (with no spaces in the file path)

Place the DEODEXED file you wish to make an odex out of on your /sdcard

Make sure you have busybox installed (in /system/bin or /xbin)

MAJOR NOTE:

The script is currently set up based on the SystemUI.apk/.odex and Motorola’s ICS bootclasspath.

To change the file name/path and/or the bootclasspath, right-click on the .bat file and open with a text editor (preferably something like Notepad++) and edit accordingly for the proper path to the apk/jar and odex. The bootclasspath was taken from /init.rc minus the jars that are not in /system/framework.

Connect to PC in MTP or PTP usb mode

Make sure usb debugging is enabled

Double-click 1by1_ReOdexer.bat to begin.

Here’s a successful screenshot (look for the bytes transferred to confirm it worked):

When finished you should have a new.odex file on your /sdcard.

CHANGE LOG:

8/25/12 (v1.0)

-initial release

Thanks to the following for testing!:

-DX2Trip on the A2 ICS

-RETIEF on the RAZR Maxx ICS

-iwabashu on the RAZR ICS

(I tested it on GB - but I am not high-fiving myself :D)

-----------------

Some vague notes on what to do next:

Depending on what you are after by re-odexing, there are different routes. For example, if you only edited or copied smali files, then you only need the new.odex file. Meaning that all of the smali code was inside of that classes.dex of the deodexed file on your sdcard, and you just made that into a new odex file (and copied the signatures from the existing .odex in /system).

If you have a deodexed apk with more edits than just smali (you could really just copy those edits over to your existing odexed apk with 7-zip or similar), but – if you want to, you will need to remove the classes.dex from the deodexed apk, and make sure that the signatures (/META-INF folder) and AndroidManifest.xml are the same as your existing apk (check, and or copy with 7-zip or similar).

.

.

.