Author Topic: HOW TO: deodex an .odex file  (Read 26872 times)

Offline DSM_

  • Saiyan Moderator™
  • Madteam Developer
  • Hero Member
  • ******
  • Posts: 938
  • Reputation: +1085/-9
    • View Profile
HOW TO: deodex an .odex file
« on: September 03, 2011, 09:24:42 AM »
    General information about odex files:
    Quote
    In short, an odex file is an optimized version of a classes.dex file that has optimizations that are device specific. In particular, an odex file has dependencies on every "BOOTCLASSPATH" file that is loaded when it is generated. The odex file is only valid when used with these exact BOOTCLASSPATH files. dalvik enforces this by storing a checksum of each file that the odex file is dependent on, and ensuring that the checksum for each file matches when the odex file is loaded.

    The BOOTCLASSPATH is simply a list of the jars/apk from which classes can be loaded, in addition to the main apk/jar that is loaded. A normal android system has 5 jars in it's base BOOTCLASSPATH - core.jar, ext.jar, framework.jar, android.policy.jar and services.jar. These can all be found in /system/framework. However, some apks have dependencies on additional jar or apks files beyond that of the base 5 jars. For example, for applications that use google maps, com.google.android.maps.jar will be appended to the BOOTCLASSPATH for that application's apk.

    These odex dependencies make life a bit difficult for a couple of reasons. For one - you can't take an apk+odex file from one system image and run it on another system image (unless the other system image uses the exact same framework files). Another problem is that if you make any changes to any of the BOOTCLASSPATH files, it will invalidate every odex that depends on that file - basically every apk/jar on the device.

    Requirements:

    Installation:
    Download smali-*.*.*.jar and baksmali-*.*.*.jar and rename them to smali.jar and baksmali.jar and place them to any directory that you remember.

    I placed them in C:\smali\

    I also copied the *.odex file to C:\smali folder.
    And i place \framework folder to C:\

    How to deodex an .odex file:
    Open Run>cmd.

    Note: to Recall the directory "C:\smali" you need to type first
    Quote
    cd C:\smali

    Now type the deodex command:
    Quote
    java -jar baksmali.jar -d C:\framework -x TouchWiz30Launcher.odex
    where -d is for Framework directory
    and -x option to tell baksmali that it should deodex the input.

    you will find and new folder "out" in the current directory - C:\smali

    Example : Image Link Broken

    Sometimes, we do all things right but still gives errors like in the image below, I tried BuddiesNow.odex but gives these error:
    Image Link Broken

    As we can see error is related to TouchWiz so I copy twframework-res.odex from framework folder to C:\smali

    we need to add one more option -c with :<BOOTCLASSPATH files>. Type like this:
    Quote
    java -jar baksmali.jar -c :twframework-res.odex -d C:\framework -x TouchWiz30Launcher.odex

    Example:
    Image Link Broken

    Now you got "out" folder with with decoded classess files.

    You can encode back to *.odex files after editing or you use this with apktool. If you use this folder with apktool it will merge *.odex file into the *.apk file.

    Use this command to smali back to *.odex
    Quote
    java -jar smali.jar -o <your-new-file-name>.odex <deodexed-folder>

    Example :
    Image Link Broken

    If you want to use it with apktool and want to emerge into .apk file:

    Read first the APKtool Tutorial - http://www.madteam.co/forum/tutorials/how-to-use-apktool-apk-re-engineering/

    •   Rename the deodexed folder (i.e. "out") to "smali" and move it to the decoded apk folder where "AndroidManifiest.xml" lies.
    •   Now use the APKtool build command to build the new APKtool.
    •   Don't forget to sign it.
    [/list]

    More information about DeodexInstructions here : http://code.google.com/p/smali/wiki/DeodexInstructions
    « Last Edit: October 05, 2011, 03:42:54 AM by DSM_ »


    Samsung Galaxy 5

    MAD Manager | TouchWiz Port

    Offline deck1994

    • Full Member
    • ***
    • Posts: 233
    • Reputation: +266/-0
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #1 on: September 03, 2011, 01:10:21 PM »
    thanks you so much :)))

    Offline suchin2505

    • Jr. Member
    • **
    • Posts: 86
    • Reputation: +21/-1
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #2 on: September 04, 2011, 09:54:42 PM »
    Thank U very much ....  :)
    If i Helped please click on the thankyou and the applaud button :)

    Offline fox not fire

    • Global Moderator
    • Hero Member
    • *****
    • Posts: 1411
    • Reputation: +1142/-2
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #3 on: September 05, 2011, 01:28:56 AM »
    Nice tutorial.. ;)
    About the performance, G5 is beyond the size...

    Offline komiks0916

    • Full Member
    • ***
    • Posts: 149
    • Reputation: +155/-0
    • www.pinoyhaven.com
      • View Profile
      • Pinoy Haven -  Ang Bagong Tambayan ng Pinoy!
    Re: HOW TO: deodex an .odex file
    « Reply #4 on: October 10, 2011, 06:32:23 AM »
    what happened to the images? :( can i request for a file to be converted and be deodexed? i have no PC at my home.. please help..

    Browser.apk
    Browser.odex

    Offline DSM_

    • Saiyan Moderator™
    • Madteam Developer
    • Hero Member
    • ******
    • Posts: 938
    • Reputation: +1085/-9
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #5 on: October 10, 2011, 08:17:51 AM »
    what happened to the images? :( can i request for a file to be converted and be deodexed? i have no PC at my home.. please help..

    Browser.apk
    Browser.odex

    it require correct framework to deodex, framework of ROM from you get these files


    Samsung Galaxy 5

    MAD Manager | TouchWiz Port

    Offline chintan

    • Global Moderator
    • Hero Member
    • *****
    • Posts: 670
    • Reputation: +515/-30
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #6 on: November 16, 2011, 05:08:01 AM »
    can't deodex stock camera :(
    CM7.2 v20130613 by psyke83,
    All settings defaults by rom
    S2E for moving data to sd-ext
    no mods :D
    I'm on freenode madteam irc chennal #gti5500 & #PhilZ-Touch.

    Offline DSM_

    • Saiyan Moderator™
    • Madteam Developer
    • Hero Member
    • ******
    • Posts: 938
    • Reputation: +1085/-9
      • View Profile
    Re: Re: HOW TO: deodex an .odex file
    « Reply #7 on: November 16, 2011, 05:42:59 AM »
    can't deodex stock camera :(
    Try
    java -jar baksmali.jar -c :twframework.jar:secfeature.jar -d C:\framework -x Camera.odex

    Sent from my GT-I5500 using Tapatalk


    Samsung Galaxy 5

    MAD Manager | TouchWiz Port

    Offline chintan

    • Global Moderator
    • Hero Member
    • *****
    • Posts: 670
    • Reputation: +515/-30
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #8 on: November 16, 2011, 08:57:42 AM »
    i got this

    E:\SamsungFirmwareTools\reeng>java -jar baksmali.jar -c :framework\twframework.jar:framework\sec_feature.jar -d framework -x ap
    p\Camera.odex


    Error occured while loading boot class path files. Aborting.
    org.jf.dexlib.Code.Analysis.ClassPath$ClassNotFoundException: Could not find interface Lcom/sec/android/seccamera/SecCamera$OnA
    ctionShotEventListener;
            at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.loadAllImplementedInterfaces(ClassPath.java:823)
            at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.<init>(ClassPath.java:683)
            at org.jf.dexlib.Code.Analysis.ClassPath.loadClassDef(ClassPath.java:280)
            at org.jf.dexlib.Code.Analysis.ClassPath.initClassPath(ClassPath.java:163)
            at org.jf.dexlib.Code.Analysis.ClassPath.InitializeClassPathFromOdex(ClassPath.java:110)
            at org.jf.baksmali.baksmali.disassembleDexFile(baksmali.java:104)
            at org.jf.baksmali.main.main(main.java:282)
    Error while loading class Lcom/sec/android/app/camera/Camera; from file app\Camera.odex
    Error while loading ClassPath class Lcom/sec/android/app/camera/Camera;


    E:\SamsungFirmwareTools\reeng>
    CM7.2 v20130613 by psyke83,
    All settings defaults by rom
    S2E for moving data to sd-ext
    no mods :D
    I'm on freenode madteam irc chennal #gti5500 & #PhilZ-Touch.

    Offline DSM_

    • Saiyan Moderator™
    • Madteam Developer
    • Hero Member
    • ******
    • Posts: 938
    • Reputation: +1085/-9
      • View Profile
    Re: Re: HOW TO: deodex an .odex file
    « Reply #9 on: November 16, 2011, 10:13:10 AM »
    i got this

    E:\SamsungFirmwareTools\reeng>java -jar baksmali.jar -c :framework\twframework.jar:framework\sec_feature.jar -d framework -x ap
    p\Camera.odex


    Error occured while loading boot class path files. Aborting.
    org.jf.dexlib.Code.Analysis.ClassPath$ClassNotFoundException: Could not find interface Lcom/sec/android/seccamera/SecCamera$OnA
    ctionShotEventListener;
            at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.loadAllImplementedInterfaces(ClassPath.java:823)
            at org.jf.dexlib.Code.Analysis.ClassPath$ClassDef.<init>(ClassPath.java:683)
            at org.jf.dexlib.Code.Analysis.ClassPath.loadClassDef(ClassPath.java:280)
            at org.jf.dexlib.Code.Analysis.ClassPath.initClassPath(ClassPath.java:163)
            at org.jf.dexlib.Code.Analysis.ClassPath.InitializeClassPathFromOdex(ClassPath.java:110)
            at org.jf.baksmali.baksmali.disassembleDexFile(baksmali.java:104)
            at org.jf.baksmali.main.main(main.java:282)
    Error while loading class Lcom/sec/android/app/camera/Camera; from file app\Camera.odex
    Error while loading ClassPath class Lcom/sec/android/app/camera/Camera;


    E:\SamsungFirmwareTools\reeng>

    Type extactly same command-
    cd E:\Samsun~1\reeng
    java -jar baksmali.jar -c :twframework.jar:sec_feature.jar:seccamera.jar -d framework -x app\Camera.odex

    Sent from my GT-I5500 using Tapatalk


    Samsung Galaxy 5

    MAD Manager | TouchWiz Port

    Offline aiah

    • Newbie
    • *
    • Posts: 1
    • Reputation: +6/-0
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #10 on: April 03, 2012, 08:42:31 AM »
    I'm arriving a bit late here.......  :)

    Im getting errors:
    java -jar baksmali.jar -d c:\framework -x memo.odex

    UNEXPECTED TOP-LEVEL EXCEPTION:
    org.jf.dexlib.Util.ExceptionWithContext: regCount does not match the number of arguments of the method
       at org.jf.dexlib.Util.ExceptionWithContext.withContext(ExceptionWithContext.java:54)
       at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(InstructionIterator.java:92)
       at org.jf.dexlib.CodeItem.readItem(CodeItem.java:154)
       at org.jf.dexlib.Item.readFrom(Item.java:76)
       at org.jf.dexlib.OffsettedSection.readItems(OffsettedSection.java:48)
       at org.jf.dexlib.Section.readFrom(Section.java:143)
       at org.jf.dexlib.DexFile.<init>(DexFile.java:431)
       at org.jf.baksmali.main.main(main.java:265)
    Caused by: java.lang.RuntimeException: regCount does not match the number of arguments of the method
       at org.jf.dexlib.Code.Format.Instruction3rc.checkItem(Instruction3rc.java:129)
       at org.jf.dexlib.Code.Format.Instruction3rc.<init>(Instruction3rc.java:79)
       at org.jf.dexlib.Code.Format.Instruction3rc.<init>(Instruction3rc.java:44)
       at org.jf.dexlib.Code.Format.Instruction3rc$Factory.makeInstruction(Instruction3rc.java:145)
       at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(InstructionIterator.java:84)
       ... 6 more
    Error occured at code address 0
    code_item @0x8bc0


    Any tips on how to solv?

    Offline armega

    • Newbie
    • *
    • Posts: 1
    • Reputation: +0/-0
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #11 on: May 29, 2012, 12:38:00 PM »
    DSM_, I'm confused...  are you saying that if I have an apk that does not contain a classes.dex file then I can still DeOdex my Mail.apk and Mail.odex files?

    Currently this is what I get...

    Quote
    C:\deodex>java -jar baksmali.jar -x Mail.apk
    UNEXPECTED TOP-LEVEL EXCEPTION:
    org.jf.dexlib.DexFile$NoClassesDexException: zip file Mail.apk does not contain a classes.dex file
            at org.jf.dexlib.DexFile.<init>(DexFile.java:298)
            at org.jf.baksmali.main.main(main.java:265)

    Offline DSM_

    • Saiyan Moderator™
    • Madteam Developer
    • Hero Member
    • ******
    • Posts: 938
    • Reputation: +1085/-9
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #12 on: May 29, 2012, 12:42:44 PM »
    Why are deodexing apk file?
    Do only Mail.odex :)
    You will get smali sources.


    Samsung Galaxy 5

    MAD Manager | TouchWiz Port

    Offline GTAGAME

    • Newbie
    • *
    • Posts: 1
    • Reputation: +0/-0
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #13 on: September 08, 2012, 11:22:30 AM »
    Hmm it doesn't work for me. I tried to export odex from the Galaxy S Launcher, yes... for testing, but it doesn't work.
    I always get this error: Error occured at code 8 code_item @0xf674

    Offline chintan

    • Global Moderator
    • Hero Member
    • *****
    • Posts: 670
    • Reputation: +515/-30
      • View Profile
    Re: HOW TO: deodex an .odex file
    « Reply #14 on: September 25, 2012, 07:07:12 AM »
    hey buddy
    i'm having problem compiling as i don't know much about the framework

    but i tried to port this for port cm7.2 by psyke for g5
    http://forum.xda-developers.com/showthread.php?t=1837060

    here is the error that i got
    Code: [Select]
    C:\apk>apktool b frame framework.apk
    W: Could not find sources
    I: Checking whether resources has changed...
    I: Building resources...
    C:\apk\frame\res\layout\recent_apps_dialog.xml:8: error: Error: No resource found that matches the given name (at 'id' with value '@id/zzz_button_job_manager').
    C:\apk\frame\res\layout\recent_apps_dialog.xml:8: error: Error: No resource found that matches the given name (at 'text' with value '@string/job_manager').
    C:\apk\frame\res\layout\recent_apps_dialog.xml:11: error: Error: No resource found that matches the given name (at 'id' with value '@id/zzz_recent_app_icon_row').
    C:\apk\frame\res\layout\recent_apps_dialog.xml:12: error: Error: No resource found that matches the given name (at 'id' with value '@id/zzz_recent_app_icon_row').
    C:\apk\frame\res\layout\recent_apps_dialog.xml:33: error: Error: No resource found that matches the given name (at 'id' with value '@id/zzz_button_job_manager_second ').
    C:\apk\frame\res\layout\recent_apps_dialog.xml:33: error: Error: No resource found that matches the given name (at 'text' with value '@string/job_manager').
    Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, -F, C:\Users\chintan\AppData\Local\Temp\APKTOOL7518713257217700692.tmp, -x, -S, C:\apk\frame\res, -M, C:\apk\frame\AndroidManifest
    xml]
            at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:193)
            at brut.androlib.Androlib.buildResourcesFull(Androlib.java:301)
            at brut.androlib.Androlib.buildResources(Androlib.java:248)
            at brut.androlib.Androlib.build(Androlib.java:171)
            at brut.androlib.Androlib.build(Androlib.java:154)
            at brut.apktool.Main.cmdBuild(Main.java:182)
            at brut.apktool.Main.main(Main.java:67)
    Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, C:\Users\chintan\AppData\Local\Temp\APKTOOL7518713257217700692.tmp, -x, -S, C:\apk\frame\res, -M, C:\apk\frame\AndroidManifest.xml]
            at brut.util.OS.exec(OS.java:83)
            at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:191)
            ... 6 more
    CM7.2 v20130613 by psyke83,
    All settings defaults by rom
    S2E for moving data to sd-ext
    no mods :D
    I'm on freenode madteam irc chennal #gti5500 & #PhilZ-Touch.