<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sushil Bhojwani on Medium]]></title>
        <description><![CDATA[Stories by Sushil Bhojwani on Medium]]></description>
        <link>https://medium.com/@_sushil?source=rss-196b4b595a3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oDiG-bxW2obF2eM8FNwAKQ.jpeg</url>
            <title>Stories by Sushil Bhojwani on Medium</title>
            <link>https://medium.com/@_sushil?source=rss-196b4b595a3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:40:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_sushil/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Oat2Dex | Android Pentesting]]></title>
            <link>https://medium.com/@_sushil/oat2dex-android-pentesting-6f99e9c57198?source=rss-196b4b595a3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f99e9c57198</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[mobile-pentesting]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sushil Bhojwani]]></dc:creator>
            <pubDate>Fri, 16 Nov 2018 10:23:57 GMT</pubDate>
            <atom:updated>2018-11-16T10:23:57.121Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>DEX 2 OAT</strong></h3><p>While looking at the topic name itself a question arises what is dex and oat, this document will clear all your doubts on such questions and even has more to demonstrate.</p><p>· <strong>DEX (a.k.a. Dalvik Executable)</strong>: A Dex file contains code which is ultimately executed by the Android Runtime. Every APK has a single classes.dex file, which references any classes or methods used within an app. Essentially, any Activity, Object, or Fragment used within your codebase, will be transformed into bytes within a Dex file that can be run as an Android app.</p><p>o <strong>Dexing Process (How dex files are created?)</strong></p><p>All the Java source files in an Android project are first compiled to .class files, which consist of bytecode instructions. In a traditional Java application, these instructions would be executed on the JVM. However, Android apps are executed on the Android Runtime, which uses incompatible opcodes, and therefore an additional Dexing step is required, where .class files are converted into a single .dex file.</p><p>Because most mobile devices are severely constrained in the amount of memory, processing power, and battery life available, ART offers superior performance to the JVM. One key feature that helps achieve this is that ART performs both Ahead-of-Time (also known as OAT) and Just-in-Time compilation. This avoids some of the runtime overhead of JIT, while still allowing performance improvements over time as an app is profiled.</p><p>· <strong>OAT: </strong>An OAT file is created by the Android operating system in order to speed up the loading time of an Android app (.APK file). When an app is installed, Android automatically optimizes app data and creates a corresponding OAT file. Android uses this file to load the app more quickly, which creates a better experience for the user.</p><p>OAT files are typically saved to the following directory on the Android device:</p><p><strong>/data/dalvik-cache/</strong></p><p>Android performs these optimizations using a tool called dex2oat. When you install an application on a device running Android 5.0 or later, dex2oat converts the Dalvik code located in the .ODEX file to native code and stores it in an OAT file. Therefore, each app will have a corresponding OAT file. dex2oat is typically located in the following directory on the Android device:</p><p><strong>/system/bin/dex2oat/</strong></p><p><strong><em>NOTE:</em></strong><em> OAT files were introduced with Android 5.0, which is codenamed “Lollipop” or “L.” Previous versions of Android use .ODEX (Optimized DEX) files instead of OAT files for optimized executables. The new Android 5.0 runtime, called ART (Android Runtime), uses an ahead-of-time (AOT) compilation method, which improves upon its predecessor’s method of just-in-time compilation. ART replaces the previous runtime, which is called Dalvik.</em></p><p>Technically all the files when are optimised by <strong>dex2oat tool</strong> they are converted into <strong>ELF shared object file</strong> format but android calls it as an <strong>OAT format</strong>.</p><p>To prove the same we will pull one file from <strong>/data/dalvik-cache/</strong> directory and have a closer look to that file. For this, we need to boot up an Android device with version 5.0 or greater to our Geny Motion (in this I’m using Custom Phone with v5.1).</p><p><strong>Step: 1</strong> Pulling any file from /data/dalvik-cache/ directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*LZHvPk4jFRt7Hz_U4zXk6Q.png" /><figcaption>Pulling a file from android device</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*IZdNZcSmNvtvhK4Kjh6MtA.png" /></figure><p>Originally it is a dex file for an android device but if we open this file with a text editor, we will come to know that it is an ELF file.</p><p><strong>Step: 2</strong> Open that file with Notepad++ file editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*eqtSmi4pZ3p29DKqhugERA.png" /></figure><p>It has ELF as its magic numbers, so by this we can prove that it is an ELF file.</p><p>o <strong>ELF Format:</strong></p><p>The Executable and Linkable Format (ELF, formerly named Extensible Linking Format), is a common standard file format for executable files, object code, shared libraries, and core dumps.</p><p>By format design, the ELF is flexible, extensible, and cross-platform. For instance it supports different address sizes so it does not exclude any particular central processing unit (CPU) or instruction set architecture. This has allowed it to be adopted by many different operating systems on many different hardware platforms.</p><p>· <strong>OAT2DEX TOOL</strong></p><p>Oat2dex is a tool useful for converting AOT compiled files to dex files, which will be then helpful for us to analyze the source code.</p><p>Link for the tool: <a href="https://github.com/testwhat/SmaliEx">https://github.com/testwhat/SmaliEx</a></p><p>Some questions do come to mind that why we need this tool as we already have full apk and also the classes.dex for that specific apk. Below is answer according to my understanding.</p><p>o <strong>Why use this tool?</strong></p><p>Whenever a system app has to be tested, this tool plays a major role as we don’t have the apk for system apps &amp; also when we don’t have classes.dex for any application.</p><p>o <strong>What is boot.oat?</strong></p><p>This file is created whenever a device’s system is upgraded or when the app is booted up for the first time after being purchased. The boot.oat file is referenced by an app when the app calls a framework application programming interface (API) method.</p><p><strong>Steps for using oat2dex tool</strong></p><p><strong>Step 1:</strong> Download zip from this link and extract it:</p><p><a href="https://github.com/testwhat/SmaliEx">https://github.com/testwhat/SmaliEx</a></p><p>After extracting it will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*Qq_aEgicYhw39WmMTLVnCA.png" /></figure><p><strong>Step 2:</strong> Now, open command prompt and traverse to the directory where you have extracted this tool &amp; after we need to build up the tool to use it, command to build is</p><p><strong>gradlew -b smaliex/build.gradle dist</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*pD6hXm8INTct65l33dghpQ.png" /></figure><p>This will create some more directories in SmaliEx folder.</p><p><strong>Step 3:</strong> Inside smaliex-bin folder there is a jar file called <strong>“oat2dex.jar”</strong>. You can copy this jar to your main SmaliEx folder, but its user’s choice.</p><p>Now, we will go back to android device and search for a file called boot.oat in <strong>/data/dalvik-cache/x86/</strong> directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*x9dNnfZ2y0bFUrDgBK4Jvg.png" /></figure><p>Pull this file to your system, for pulling come out of the adb shell and directly pull the file by using command:</p><p><strong>adb pull /data/dalvik-cache/x86/system@framework@boot.oat</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ObRKqUt7gaRL4dyLkGCVxQ.png" /></figure><p><strong>Step 4:</strong> Using <strong>oat2dex.jar </strong>we will run the boot function to de-optimize boot classes of the device from boot.oat by using command:</p><p><strong>java -jar oat2dex.jar boot C:\platform-tools\oat\system@framework@boot.oat</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*M4izjc3-Tr1JfRC0IRlDKA.png" /></figure><p>Output for this command will create a folder in the same directory with all de-optimized dex files of boot classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*EJ6BrItm_v8rPYKGA2hE1g.png" /></figure><p><strong>Step 5: </strong>Now, these de-optimized boot dex files will be useful in de-optimizing any optimized dex from /data/dalvik-cache/x86/ directory.</p><p>For performing this task, we will need an optimized dex file from the device by command (In this case I’m pulling Calculator app’s optimized dex file):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*Szh2ReT6R-UUT65bJrdRJw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*f1pNi_PwsesH1JnlsO60BA.png" /></figure><p>Using <strong>oat2dex.jar </strong>we will de-optimize Calculator app using command:</p><p><strong>java -jar oat2dex.jar &lt;app.odex&gt; &lt;boot-class-folder output from previous step&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*aI0vk_spPEK5Za-IEjZD_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*4FnFFth-LtwWFPdDOT88HQ.png" /></figure><p>Above obtained dex file is completely de-optimized version of dex for Calculator app &amp; can be further converted to smali, jar, etc. according to your need.</p><p><strong>Step 6:</strong> Converting <strong>“Calculator.dex”</strong> to jar, using dex2jar tool</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*pdzquJOkO_ZmbBVHS9qGKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*8jqhXc31NAyXoEylojhJeA.png" /></figure><p>Using this jar file we can obtain all the class files through <a href="http://jd.benow.ca/"><strong>JD-GUI</strong></a><strong> </strong>utility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*82d2JFORngCUn18ASGhkQA.png" /></figure><p>We can also convert <strong>“Calculator.dex” </strong>to smali files, for that using command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*E6eNa7rZtpWYfJePFOKjbw.png" /></figure><p>Output of this will be a folder named Calculator with all the smali files in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*rwGtzYWwh9bNDIpcVtLfOA.png" /></figure><p><em>By performing above steps we have come to a conclusion that all the optimized dex files present in the dalvik-cache folder of any device can be reversed and a proper de-optimized dex file for that particular application can be achieved, it can be a system app also. And furthermore those dex files can be converted to jar, smali, etc.</em></p><p>Oat2dex tool has few more functionalities which are demonstrated below.</p><p>· Creating smali files from odex/oat files directly (with optimized opcode) by using oat2dex tool.</p><p><strong>Step: 1</strong> Optimized dex files (.odex) of system apps are located under <strong>/system/app/&lt;app_name&gt;/&lt;architecture&gt;/</strong> in an android device. As I’m performing activities for Calculator app, path is <strong>/system/app/Calculator/x86/Calculator.odex</strong></p><p>Pulling <strong>Calculator.odex </strong>to our system by command:</p><p><strong>adb pull /system/app/Calculator/x86/Calculator.odex</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*f6n1Fdvf7CMUKeAsKLp5tA.png" /></figure><p><strong>Step 2: </strong>Now, using this odex file we will generate smali files by command:</p><p><strong>java -jar oat2dex.jar smali &lt;oat/odex file&gt;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*BhQaEc_01Arq7WpWBKaeow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*-wyUbyW9JD-Sf_955f8xPg.png" /></figure><p>Output of this command will create a folder containing all the smali files for the given odex/oat file.</p><p><em>There are few more commands in this tool which can be used, but I have not yet completed working on it completely. I’m still trying to understand those commands to the core. I’ll come up with something good soon. Thanks for reading.</em></p><p><em>Follow me on linked in : </em><a href="https://in.linkedin.com/in/sushil-bhojwani-06255566"><em>Sushil Bhojwani</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f99e9c57198" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>