How to deodex firmware using jbart. What is odex and deodex in Android. Unpacking and analysis of the original file

If you are not just an ordinary user of an Android-based device, but like to install various firmware, then you have probably heard or read on various forums and sites about “odexed” and “deodexed” firmware. What's the difference? In short, Deodex firmware is better suited for modification. The developer of deodexed firmware can independently change the appearance of icons, configure various menus, and so on. Let's tell you about everything in more detail.

What is Deodex?

Android firmware, like any other application, has a special “executive” part that is designed to perform pre-programmed actions. As you can see for yourself, these commands are placed in a separate file classes.DEX, which is present in the firmware.

Often, in official firmware, the manufacturer moves this file outside the firmware to speed up work and reduce the amount of memory occupied by the firmware. The transition to Android 5.0 with the ART runtime environment significantly changed the process of launching and installing applications, but the very concept of odex and deodex was retained.

Advantages and disadvantages of Odex and Deodex firmware


- More complex firmware modification process
+ Small increase in firmware performance
+ Save space when installing programs


+ Simplified firmware customization
- Need more space to install applications

How to get Deodex firmware?

Before starting the process of deodexing the firmware, a number of conditions must be met. The first step is to install and configure it on your computer. Next, we need to obtain Root rights on our mobile device, install any file manager with access to the system partition and copy the following folders to the device’s memory or to a microSD card.

/app
/priv-app
/framework


Deodex using JoelDroid Batch Deodexer

This utility will only work with devices based on Android 5.0 and later. You also need to install and download the application itself.


  • Unpack the archive with the utility ]JoelDroid Lollipop Batch Deodexer V 2.5.

  • Previously saved folders app, priv-app, framework

  • Launch the JoelDroid Lollipop Batch Deodexer utility, click on the "Browse" button and indicate the directory on your computer where you copied app, priv-app, framework

  • Click on the button "Start Process"

Deodex using Deodexer for Android Runtime

First of all, download the archive and unpack it. The further process is no different from the previous utility:


  • Previously saved folders app, priv-app, framework you need to place a separate directory on your computer.

  • Run the Deodexer for Android Runtime utility, specify the directory on your computer where you copied app, priv-app, framework

  • Click on the button "Execute" and wait for the deodexation process to complete.

Deodex using Jbart

Unlike previous utilities, which can only work with devices based on Android 5.0 and higher, this utility is not tied to the OS. You can make Deodex for any device from Android 2.3.x Ginerbread to Android 6.0 Marshmallow.



Each of you has heard the words “deodex” or “odex” more than once. Usually, they are found where various firmware for your device are posted, for example, on XDA-Developers or 4pda. So what does it mean, DEODEX or ODEX? What are their differences? How to make DEODEX? You will find answers to these and other questions in the next issue of the digest “What is...”.
Odex (Optimized Dalvik Executable File) is a file located in the same folder with system applications, which stores the code of the program itself. As you know, every program needs instructions, thanks to which it (the program) will perform one or another function or work. This is exactly the program code that I described earlier. If you want to modify any system file, you will need to dig into both the odex file itself and the .apk when installing the odex firmware. From this it becomes clear that this process will not be very easy. It is for this reason that the possibility of deodex firmware was implemented.

As you already know, in odex firmware the files are stored “randomly”. However, with deodex there is no such disorder, so to speak. All files in deodex are stored like a .zip archive, but in our case they are “packed” into .apk. For this reason, disassembling the application for further modifications becomes easier, and due to the fact that everything is packed in one place, the deodex firmware will perhaps take up less space.

However, deodex cannot be praised endlessly. The main disadvantage of deodex is that applications take a little longer to load than on odex. Most likely, the user will not notice this. But I can’t help but note that both the advantage of odex and the disadvantage of deodex is that all system applications in odex are optimized for a specific device by the manufacturer itself. And this is undoubtedly a plus of odex firmware.

I almost forgot to mention that when installing various ready-made modifications to the system for your device, you need to have deodex firmware.

Probably, in this situation, the meaning of the terms is clear. And I'm willing to bet that some people already want to try deodex. There are a huge number of instructions for deodex firmware on the World Wide Web. However, I won’t dare send you to search for them on Google, but I will simply silently write down this whole process, trying to highlight all the little things.

The instructions for different versions of Android are not the same. Due to the fact that Android 5.0 Lollipop is installed on my device, I will write instructions for deodex specifically for this version.

  1. First, we need to download a special utility, JoelDroid Lollipop Batch Deodexer, to our PC. This utility requires a Java program to operate. I note that in frequent cases, a Java application writes its path incorrectly and incorrectly. For this reason, you need to manually register this path according to these instructions.
  • After this, we need to install on our device running on Android 5.0 Lollipop any file manager through which we need to copy the three main system folders - APP, PRIV-APP, FRAEMWORK - to a separate folder on the SD card. They are located in the root folder System.


  • Next, we need to create the MyROM folder in the root of any internal drive on your PC. Then we create another folder in this folder, but with the name System. In theory, you should get the following path - E:\MyROM\system. Where "E" is your internal storage (hard drive)
  • Those system folders that we copied in the second step need to be moved to the E:\MyROM\system folder.
  • Now, in theory, we have prepared everything, and we can already proceed to the DEODEXATION point.
  • Launch the previously installed JoelDroid Lollipop Batch Deodexer utility.
  • By clicking the “Browse” button in the utility, we need to show the path to E:\MyROM\system
  • The path is indicated, everything is ready. All we have to do is press the “Start Prosecc” key, after which deodexation will begin. This procedure takes about 10-15 minutes.
  • After deodexation is complete, we need to copy the resulting files, which are located along the path E:\MyROM\system, to a MicroSD flash drive on your device.
  • Next, we need to download AROMA FileManager and install it via custom recovery on your device. But before installing, we need to select System in the Mount section if it is not selected.
  • After all this, we must go to the root of the file system and delete the APP, PRIV-APP and FRAEMWORK folders from the System folder, just delete them, since when copying the ARM folders will remain, and the whole process, consider it, has gone down the drain.
  • Next, copy the deodex folders previously transferred in step 9 to the System folder in the root of the entire file system.
  • After this, we need to flash a script that sets permissions for folders (RWXRX-RX), .apk files and .xml files (RW-R-R)
  • Next we need to make wipe cache and wipe dalvik/art. Reboot the device and enjoy the deodex firmware you received.

  • Make sure that you have DEODEX installed - you can update the firmware using the following short instructions: D


    I fully believe that I have talked about the most basic things about the terms ODEX and DEODEX, and this article can be completed. Thank you all for your attention, please rate the article, have a good day and a successful SUMMER!

    Android users can be divided into two groups. The first is those for whom it is important to have stable work and for the phone to simply work. The second are those who can’t wait to try new functions and check other firmware for their phone, who really love tinkering with their phone. This is where the main difference between ODEX and DEODEX firmware lies.

    ODEX (odexed) firmware– these are official, branded or factory Android firmware. DEODEX (deoxified) are firmwares modified by users.

    Why such a distinction?

    “Odexed” firmware will immediately reveal itself by the presence of files with the .odex extension in the /system/app folder. The abbreviation odex means “Optimized Dalvik Executable File”. This kind of file is very necessary for a clear system structure that contains all the information about the application. Android receives the data immediately directly without unzipping the apk files. .odex files are usually loaded into Dalvik-cache, which stores information about programs that the user frequently uses. The speed of the system increases significantly.

    The advantages of ODEX firmware can be written down the fact that applications open faster and apk files take up little space. The disadvantages are the difficulty of hacking and changing programs. But most users don’t need this; they value the speed and stability of the system.

    For example, such firmware is an ideal solution for those who just want to download games to an Android tablet (http://vipsmart.org/all-genres/tablet/).

    DEODEX



    In “deodexed” firmware, application information is contained in the apk file. The code usually inserted into an odex file is included in an apk called classex.dex.

    The main advantages of such firmware are that they are much easier to modify (all data is in one place), and system programs are easier to remove.

    One of the disadvantages is that programs take longer to launch. But this drawback is not very significant. Dalvic-cache stores all data about applications that the user frequently uses. And programs take a long time to load only after clearing the Dalvic cache. For example, after installing a firmware update or in other cases.

    To summarize, we can say with confidence that “odexed” (factory) firmware is recommended for those who value speed and stability. “Deoxed” (custom) ones are more suitable for those for whom it is important to customize the firmware completely to suit their needs, try new functions and “dig deeper” into the Android system.

    Hello Habr!

    Several years ago, when I was first introduced to Android, I heard from a work colleague that Android provides the ability to install modified or homemade firmware. Frankly, I was far from it then. And even half a year ago I was barely interested in such things. Deep in my heart, I was sure that what the manufacturer was doing was already intended for normal use.

    Imagine my disappointment when I purchased a phone from China, where the factory settings prohibited the use of Google, Skype, Facebook and other applications. In principle, it was possible to turn a blind eye to some things, but when my phone did not require the use of a Google account, I made promises to definitely figure it out no matter what happened to me.

    Half a year has passed and my custom firmware is being successfully used all over the world.

    This series of articles will discuss how to do reverse programming for Android, implement patches, tweaks and mods.

    Preamble

    So! Let's first define the concepts that will be used in given article. Your usual understanding, however, may be very different.

    Patch- changing or replacing existing program code in order to modify the program algorithm.
    Maud- as a rule, adding additional functionality to existing program code without changing the algorithm.
    Tweak- improvement of the program functionality in order to facilitate access to system parameters.

    I also want to note that all examples will be taken for an HTC phone, but this does not mean that this information cannot be used on other phones.

    Preparing the environment

    I can do without detailed instructions on how to use this or that software. If you are interested in this article and have read this far, then I hope that you are already an experienced user and have experience using, or at least experimenting in, this area. There are plenty of instructions, articles and test results in the public domain, just like on Habré. I will also do without describing some terms, otherwise the article will turn out to be very long and tedious. We will write only to the point. I'm sure you've been on Wednesday for a long time. If not, then I suggest downloading and installing it.

    1 . Android SDK. This is an application development environment for Android. In order to make modifications, we will definitely have to check our program code. The development environment is the best we can use.
    2 . Android Kitchen. This utility will allow you to work with images of system partitions of official or unofficial firmware.
    3 . JD-GUI. Java code decompiler. I would like to note right away that this is the best decompiler in terms of ease of use.
    4 . DJ Java Decompiler. Another decompiler, or disassembler, as some like to call it, of Java language program code. It is not convenient to use, but it parses code that JD-GUI sometimes does not understand.
    5 . smali. Another disassembler, but this time dalvik code. smali is needed for disassembling, and backsmali is needed for assembling code.
    6 . dex2jar. A utility for converting Dalvik code executable files.

    Firmware conversion

    Of course, the firmware that you have on your phone from the manufacturer is optimized to reduce power consumption. In order for the firmware to be modified, it must be converted into a format that allows the code to be modified. Android Kitchen is used for this. Of course, you can do it with your hands, as I did before until I found this very “kitchen”. You can read on the Internet how to remove the system area from the phone, install the environment, and make DEODEX firmware. If you don't understand anything already, I think it's worth holding off on reading this article until you gain enough experience.

    After the firmware has changed from an optimized version (ODEX - optimized dalvik executable code, if my memory serves me correctly) to DEODEX (that is, NOT optimized), all executable files are ready for modification.

    Direct modifications

    Creating patches
    As I already said, my phone was initially banned from using Google. Well, no matter what, you can’t go to the Playstore, you can’t set up an account, the phone book doesn’t really sync. Why do you need such an Android? After digging for a long time into the logcat of the device itself, I found entries that said that the use of Google is prohibited. The most inconvenient thing about Android is that you see the log, but you don’t know which system application is producing it. To find where my legs were coming from, I had to gut all system applications to disassembled Java code. It took a lot of time, but I still use the work I did when analyzing and finding the right code. The steps to obtain such tools are as follows:
    1 . Make DEODEX of all firmware
    2 . Your new DEODEX firmware will need to be assembled and flashed onto your phone. How this is done is the topic of another article.
    3 . From each file located in /system/framework, extract the classes.dex file and convert it to JAR using dex2jar.
    4 . Open each resulting JAR in JD-GUI and re-save it into source code
    5 . Unpack the source code from the archive.

    In the end, I ended up with as many folders as there were JAR files in /system/framework, and each folder had a Java source code structure.
    Through simple manipulations, I quickly found the place that generated entries in logcat.

    We will not consider the entire logic of the ban, since each case is a separate story. I had to spend a couple of hours before I found where the checks were made, built a block diagram of the algorithm in my head and understood where to go in order to “spoil” the algorithm a little.

    It turned out to be simple. There is a subroutine that, based on pre-established constants, when contacted, answered whether the phone belongs to China or not.

    The code was in the file HTCExtension.jar, and the class that contained this subroutine was in

    Unpacking and analysis of the original file
    1 . First, we need to take the original DEODEX JAR file, which is responsible for the part of the code we need. In our case HTCExtension.jar.
    2 . Open with any archiver and pull out classes.dex from there
    3 . Use the dex2jar converter to convert it to a JAR file. Command: dex2jar.bat classes.dex
    4 . Open the resulting classes_dex2jar.jar file in JD-GUI.
    5 . Yes, most often JD-GUI decompiles the code not as it looks in the original, it is understandable, but it is quite readable. In the source code we see that the subroutine checks the project parameters and the firmware language flag. In our unfortunate case, TRUE is returned.
    public static boolean isChina() ( if ((HtcBuildFlag.Htc_PROJECT_flag == 216) || (HtcBuildFlag.Htc_PROJECT_flag == 218) || (HtcBuildFlag.Htc_PROJECT_flag == 23)); while (((HtcBuildFlag.Htc_PROJECT_flag == 1) && (2 == HtcBuildFlag.Htc_LANGUAGE_flag)) || (HtcBuildFlag.Htc_PROJECT_flag == 27)) return true; return false; )
    6 . To make a patch, we need to disassemble the Dalvik code itself. For this we use baksmali. The most convenient way is to create a separate folder and put three files there together: HTCExtension.jar, smali.jar And baksmali.jar. Give the command java -Xmx512m -jar baksmali.jar -a -d -o HTCExtension -x HTCExtension.jar

    This is the API for your version of Android. For JB it's 16
    - the folder where all the firmware frameworks are located.

    In my case it was the command
    java -Xmx512m -jar baksmali.jar -a 16 -d S:\dev\Android\Android-Kitchen\WORKING_JB_15\system\framework -o HTCExtension -x HTCExtension.jar
    7 . In our newly created folder, the HTCExtension folder appeared, and in it our files with Dalvik code.
    8 . Finding the file along the path \com\htc\util\contacts\BuildUtils$Customization.java and look at the code:
    .method public static isChina()Z .registers 3 .prologue const/4 v0, 0x1 .line 276 sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_PROJECT_flag:S const/16 v2, 0xd8 if-eq v1 , v2, :cond_13 sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_PROJECT_flag:S const/16 v2, 0xda if-eq v1, v2, :cond_13 sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag ;->Htc_PROJECT_flag:S const/16 v2, 0x17 if-ne v1, v2, :cond_14 .line 297:cond_13:goto_13 return v0 .line 283:cond_14 sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;-> Htc_PROJECT_flag:S if-ne v1, v0, :cond_1d .line 285 const/4 v1, 0x2 sget-short v2, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_LANGUAGE_flag:S if-eq v1, v2, :cond_13 .line 291:cond_1d sget-short v1, Lcom/htc/htcjavaflag/HtcBuildFlag;->Htc_PROJECT_flag:S const/16 v2, 0x1b if-eq v1, v2, :cond_13 .line 297 const/4 v0, 0x0 goto:goto_13 .end method
    9 . Scary, isn't it? Nothing is clear. But this is a fixable issue. Having created a few of your own patches and thus gained experience, you can easily modify the code without third-party tools. In our case, in this code
    .prologue const/4 v0, 0x1 assigns the variable v0 the value 1, that is, TRUE. Then there are all sorts of checks, and if the phone is not Chinese, then the value of the variable changes:
    .line 297 const/4 v0, 0x0 goto:goto_13
    10 . The easiest way to save the father of Russian democracy is to change the code to the following:
    .prologue const/4 v0, 0x0 , that is, change the value of the variable from 1 to 0. That is, no matter what, the value FALSE would always be returned and in the JD-GUI the code would look like public static boolean isChina() ( if (( HtcBuildFlag.Htc_PROJECT_flag == 216) || (HtcBuildFlag.Htc_PROJECT_flag == 218) || (HtcBuildFlag.Htc_PROJECT_flag == 23)); while (((HtcBuildFlag.Htc_PROJECT_flag == 1) && (2 == HtcBuildFlag.Htc _LANGUAGE_flag)) || (HtcBuildFlag.Htc_PROJECT_flag == 27)) return false; return false; )
    11 . Yes, the method will work. But we are not looking for easy ways - this time. Secondly, it’s not exactly beautiful. I would like code something like
    public static boolean isChina() ( return false; )
    12 . How can we get the Dalvik code for this source code? For beginners we will do a little trick.

    Creating Dalvik code
    1 . Open Android SDK.
    2 . We create a new project, and write the following code in our only test class
    package ru.habrahabr.test; public class test ( public static boolean isChina() ( return false; ) )
    3 . We compile our project and then take the assembled application from the workspace.
    4 . We put the assembled application in the folder where we gutted the JAR file.
    5 . Give the command java -Xmx512m -jar baksmali.jar -a -d -o test -x test .apk
    6 . We disassembled the newly built application into Dalvik code.
    7 . Open our test.smali file and see the code there
    .method public static isChina()Z .registers 1 .prologue .line 7 const/4 v0, 0x0 return v0 .end method
    8 . That's it, the patching code is ready.
    Rolling a patch
    1 . Dalvik code is littered with markers indicating a line of code in the original source file. This is necessary when displaying errors, if any, in your program. The code also works fine without specifying lines.
    2 . We delete the lines with line numbering, copy and replace the method (subroutine) in our \com\htc\util\contacts\BuildUtils$Customization.java file.
    .method public static isChina()Z .registers 1 .prologue const/4 v0, 0x0 return v0 .end method
    3 . Save the file. Yes, I forgot to say, you need a normal editor, for example Notepad++ or EditPlus. Who likes which one?
    Compiling and building a patched JAR file
    1 . Using backsmali, we gutted our JAR file, and now we need to put it back together.
    2 . Give the command java -Xmx512m -jar smali.jar -a 16 HTCExtension -o classes.dex
    3 . The classes.dex file appears in our folder
    4 . Opening again HTCExtension.jar file with an archiver and replace the existing one in it classes.dex to our just created one.
    5 . That's it, ours HTCExtension.jar contains modified program code.
    Replacing the original file with a patched one
    Usually, special scripts are created for ordinary users, which are replaced via recovery. But we are not interested in this. Firstly, it’s long and tedious, and secondly, we are experienced users and can afford some subtleties.

    1 . You can replace the current working file with the following commands if you already have DEODEX firmware and have root access:

    Adb push HTCExtension.jar /sdcard/HTCExtension.jar adb shell su mount -o remount -rw /system dd if=/system/framework/HTCExtension.jar of=/system/framework/HTCExtension.jar.back dd if=/sdcard /HTCExtension.jar of=/system/framework/HTCExtension.jar chmod 644 /system/framework/HTCExtension.jar rm /data/dalvik-cache/system@ [email protected]@classes.dex reboot

    The first command uploads the patched file to the flash drive
    2nd command opens shell
    3rd command gives root access
    The 4th command mounts the system in read/write mode
    5th command makes a backup copy of the file
    The 6th command overwrites the existing file with the new patched one.
    7th command configures permissions
    8th command deletes cache
    The 9th command reboots the device.

    2 . Thank you for reading to this point, there is little left.
    3 . After a reboot, your new patched code will take effect.
    4 . If the code does not work or an error occurs, then using simple combinations you can return the backup copy.
    adb shell su mount -o remount -rw /system dd if=/system/framework/HTCExtension.jar.back of=/system/framework/HTCExtension.jar rm /data/dalvik-cache/system@ [email protected]@classes.dex reboot

    Epilogue

    Yes, some thought this article was too specific, some found it difficult to understand, and some found it useless. I deliberately avoided in-depth detail and illustrations of how it all looks live and in practice. Firstly, this work will be thankless and will only give rise to even more questions. Secondly, I don’t want to see an army of users on forums complaining that they killed their phone.

    For the next article I will tell you how to make Tweeks. There will be an example of using automatic recording of phone calls using native phone tools. Thank you for your attention.

    P.S. If something is not clear or confusing, ask questions - I will always be happy to answer and explain.

    While using different Android firmware, you have probably come across such concepts as “odexed” and “deodexed”. And often, when performing any manipulations with the firmware, you need to know whether it is “odexed” or “deodexed” so as not to do anything stupid. So what's behind these two terms?

    Odexed ROM

    If the firmware is marked odexed, then in the system applications folder /system/app you will find files with the extension .odex. This extension stands for ""Optimized Dalvik Executable File"". In addition to the normal APK file, you will find an .odex copy of it. For example, Browser.apk and browser.odex.

    What is an .odex file?

    This file primarily serves to organize the structure of any application, contains application instructions, and allows Android to quickly access them without unnecessary searching and extracting from the .apk file. Odex files are directly loaded into the cache of the Java virtual machine “dalvik”, this allows the system to work much faster.

    Advantages of Odexed firmware

    Applications launch much faster because their code is pre-loaded into the dalvik cache. The size of .apk files is small, so they take up less space.

    Disadvantages of Odexed firmware

    The modding/themes/hacking application becomes much more complex since the code is now in two different places. If you delete any application, the .odex file must also be deleted. If you do not remove it, errors may occur.

    Deodexed ROM

    As for this type of firmware, all instructions and code for applications are located in .apk files. The code that was stored in the .odex file is now embedded in the .apk called classes.dex.

    Advantages of Deodexed firmware

    Deodexed is much easier for modding/themes/hacking since all the code is now in one .apk file. System apps are easier to remove because you only need to remove one APK file.

    Disadvantages of Deodexed firmware

    Applications start slower. But not only applications, but also the system itself takes longer to load, since application content is loaded from the system, and not directly.

    Android firmware, which comes directly from manufacturers of various devices, is mostly odexed. Custom firmware, in 9 cases out of 10, is deodexed. What we get is that odexed firmware has better operating speed, Deodexed is more suitable for hacks, modding and other manipulations. That's it, briefly about the main thing.