text
stringlengths
0
1.99k
tools and techniques will need to be adjusted specifically for it.
(Shoutout to Androguard development picking up after a dry spell!)
To avoid maintaining special Dalvik tooling, some tools opt to transpile
Dalvik bytecode into a form usable by tools with a larger audience, such as
dex2jar used by SootUP [8]. Its predecessor, Soot, is used by SimiDroid.
Unfortunately, Dalvik is not Java. It has a hard limitation on the number
of identifiers in a single DEX file, so tools need to be able to merge
those. It's no big deal nowadays. However, Dalvik does not impose an upper
limit on the number of instructions in a method, so if it is lifted to Java
bytecode, certain functions must be split because they contain more than
65536 bytes, which Java bytecode forbids. This was an open issue that
crashes Soot (and thus SimiDroid) and, for a while, caused SootUP to skip
analyzing a method. While the upstream dex2jar has fixed the issue [17],
SootUP removed this dependency and integration is left as an exercise to
the reader. Also, there might still be a way to break analysis with large
methods `:)`.
---[ 2.4 - Summary and Back to Binary
To summarize, tools to compute similarity don't work well with modern
Android apps. Optimizations are having an overly obfuscating effect, and
Dalvik-based tools have trouble keeping up to date. So what are our
options? What do other fields do to meet their similarity needs? Turns out:
Rop Gadgets^W^W BinDiff is forever [9] (and now open source!). Let's leave
Dalvik be and compile apps to their binary OAT version using the ARTs
ahead-of-time compilation. Since these binaries are valid ELF files, we can
feed them to a disassembler, create a BinExport [13] file, and then feed it
further to halvarflake's friendly neighborhood diffing tool based on
graph-isomorphism [10].
--[ 3 - A Bit of Examples
> What is a function? A miserable little pile of bytes.
Let's go over some questions you might have by now. We've tried all this on
a Pixel 8 hardware phone running Android 15 (BP1A.250305.019) just to show
off this works on real devices, but an emulator works just as well. Since
the system owns the system-generated OAT files, we need root to access
them. Our test app will be Organic Maps [11] (version 2025.05.20-5-FDroid)
because we just think it's neat and more people should know about it.
---[ 3.1 - How Does the ART Compile an App's Code Ahead-of-Time?
The ART is supposed to run AOT compilation during installation, and dex2oat
is part of the art, so let's start logcat with `adb logcat artd:I *:S` and
install an app.
```console
$ adb install app.organicmaps.apk
Performing Streamed Install
Success
```
In the logcat output, we see the complete invocation of dex2oat:
```console
$ adb logcat artd:I *:S # formatted for convenience
[...]
02-29 13:37:42.123 6074 6074 I artd : Running dex2oat:
/apex/com.android.art/bin/art_exec --drop-capabilities
--set-task-profile=Dex2OatBootComplete --set-priority=background
--keep-fds=6:7:8:9:10:11 --
/apex/com.android.art/bin/dex2oat64
--zip-fd=6 --zip-location=/data/app/[...]/base.apk
--oat-fd=7 --oat-location=/data/app/[...]/oat/arm64/base.odex
--output-vdex-fd=8 --swap-fd=9 --class-loader-context-fds=10:11
--class-loader-context=PCL[]{PCL[...]}
--classpath-dir=/data/app/[...] --instruction-set=arm64
--instruction-set-features=default
--instruction-set-variant=cortex-a55
--compiler-filter=verify
--compilation-reason=install --compact-dex-level=none
--max-image-block-size=524288 --resolve-startup-const-strings=true
--generate-mini-debug-info --runtime-arg -Xtarget-sdk-version:35
--runtime-arg -Xhidden-api-policy:enabled --cpu-set=0,1,2,3,4,5,6,7,8
-j8 --runtime-arg -Xms64m --runtime-arg -Xmx512m
--comments=app-name:app.organicmaps,[...]
```
There's a lot in there, and `dex2oat --help` makes for a lovely afternoon
read. But we'd like to point out some interesting things. The obvious one
is that it's just a binary that we can call ourselves. Sure, there is some
trickery with file descriptors, but the flag `--dex-file` accepts a DEX,
JAR, or APK. Second, the flag `--compiler-filter` is used to verify the
code, creating the .vdex file. It also accepts 'everything', which is
nothing more than the full-AOT mode of Android 7 and 8.
Because the system didn't use a profile for this compilation, the resulting
odex is quite small:
```console
$ adb shell pm path app.organicmaps
package:/data/app/~~ICLdeF7FOXIe1b9MxToZGQ==/app.organicmaps-2xFay0QEb95pHRC
_k_T1gA==/base.apk
$ adb shell ls -lah
/data/app/~~ICLdeF7FOXIe1b9MxToZGQ==/app.organicmaps-2xFay0QEb95pHRC_k_T1gA=
=/oat/arm64/base.odex
-rw-r--r-- 1 system all_a306 65K 2025-02-29 13:37