Skip to main content

Deoptfuscator

CI Latest release

Deoptfuscator removes a specific control-flow obfuscation technique from Android apps: opaque predicates driven by static counter fields (see How it works). It was selected for BlackHat Arsenal USA 2020 and is described in the IEEE Access paper "Deoptfuscator: Defeating Advanced Control-flow Obfuscation Using Android Runtime (ART)". Coding agents can use it too: an MCP server lets them deobfuscate an APK, read its code and record the names they work out. Everything is static, and no APK is installed or run.

The deoptfuscator command on the obfuscated 2buntu fixture: a method full of opaque predicates, the same method after deobfuscate, and a recorded class name

This is real output on the obfuscated test fixture. It shows one method with its opaque predicates (the counter field accesses are highlighted), the same method after deobfuscate, and a recorded name. The animation is made with scripts/make_demo.py.

Quick start

For agents in Claude Code, install the plugin: the MCP server and a skill that tells the agent how to use it (more clients and the tools):

/plugin install deoptfuscator --marketplace Gyoonus/deoptfuscator

To deobfuscate an APK from the command line, use the Docker image (linux/amd64), which has every tool:

docker run --rm -v "$PWD:/work" ghcr.io/gyoonus/deoptfuscator app.apk
# -> app_deobfuscated.apk, zipaligned and signed with a debug key

Or build it yourself with docker build -t deoptfuscator . and run deoptfuscator instead of ghcr.io/gyoonus/deoptfuscator. Without Docker, use the release tarball for Linux or macOS.

Options:

deoptfuscator.py APK [-o OUT.apk] [-c CONFIG] [-k KEEP_RULES]
                     [--keystore KS --ks-pass pass:...]
                     [--no-sign] [--report FILE] [--json]
                     [--keep-workdir] [-v]
  • config/default.json (default) removes the opaque predicates and cleans up method bodies only: constant propagation, dead code elimination, copy propagation, block deduplication and register allocation. Classes and methods stay as they are.
  • config/aggressive.json additionally runs the Redex optimizations the v1 pipeline used (inlining, CSE, peephole, ...), for smaller, easier-to-read code that is further from the original structure.

v2 is a re-implementation on top of Redex. It needs no AOSP checkout, no prebuilt ART libraries and no Git LFS, and it builds and runs on current Linux. The original ART-based implementation (v1) that the paper describes is kept at tag v1.

Use with agents (MCP)

deoptfuscator mcp serves Deoptfuscator to coding agents as an MCP server (stdio). An agent can deobfuscate an APK, then read its code: search classes and strings, show bytecode, follow cross-references, and record the names it works out for obfuscated classes, methods and fields. Everything is static: no APK is installed or run.

Claude Code, as a plugin with the server and a skill:

/plugin install deoptfuscator --marketplace Gyoonus/deoptfuscator

On Claude Code older than 2.1.275, add the marketplace first: /plugin marketplace add Gyoonus/deoptfuscator, then /plugin install deoptfuscator@deoptfuscator. Auto-update is off by default for marketplaces other than Anthropic's: turn it on in /plugin (Marketplaces), or update with claude plugin update deoptfuscator@deoptfuscator. The skill, analyze-apk, gives the agent the workflow below and the tool's limits, and tells it to treat text inside an app as data, not instructions. Without the plugin, copy it to ~/.claude/skills/analyze-apk/.

Claude Code, the server only (use either this or the plugin, not both):

claude mcp add deoptfuscator -- uvx deoptfuscator mcp

Other MCP clients:

{
  "mcpServers": {
    "deoptfuscator": {
      "command": "uvx",
      "args": ["deoptfuscator", "mcp"]
    }
  }
}
Tool What it does
overview Package, manifest components, permissions, largest packages, share of obfuscated-looking class names
deobfuscate Removes the counter-based opaque predicates; writes app_deobfuscated.apk and a JSON report next to the input (needs redex-all)
list_classes, search Classes; string constants (with the methods using them) and names
show A class or method as Dalvik bytecode, with access flags, overrides, and every reference to app code tagged with its id (# m345)
xrefs Callers of a method, readers and writers of a field, subclasses and users of a class
rename Records a name, with the evidence, for a class, method or field (see below)
export_names Writes the names as a ProGuard mapping

Classes, methods and fields are referred to by short ids (c12, m345, f6) that stay the same for a given file, or by descriptor or Java name. After deobfuscate, a method that was 34 instructions of opaque predicates in the 2buntu fixture reads:

class c75 public final Lo/ˎˎ; extends Landroid/database/sqlite/SQLiteOpenHelper;
  method m331 public final onCreate(Landroid/database/sqlite/SQLiteDatabase;)V  // overrides Landroid/database/sqlite/SQLiteOpenHelper;
      0000: const-string v0, "CREATE TABLE article (_id INTEGER PRIMARY KEY AUTOINCREMENT, ...);"
      0002: invoke-virtual v2, v0, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V
      0005: return-void

Names given with rename are kept in app.names.json next to the APK, shared by app.apk and app_deobfuscated.apk, and shown in place of the obfuscated ones from then on (Lo/ˎˎ; becomes Lcom/twobuntu/db/ArticleHelper;; inner classes follow their outer class's name). A method is renamed together with the methods it overrides or is overridden by; methods that override Android platform methods keep their names, and names that would clash are refused. The APK itself is never modified.

Requirements: Python 3.10 or later. uvx installs the deoptfuscator package from PyPI with androguard and mcp, and a newer Python if yours is older. If the first start takes longer than the client waits (/mcp shows the server failed or still reconnecting), run uvx deoptfuscator --version once in a terminal, then reconnect. deobfuscate also needs redex-all on PATH or in $REDEX, from the release tarball for Linux x86_64 or macOS (Apple silicon, macOS 15 or later), or built from source. The macOS binaries are not notarized: download the tarball with curl or gh, or after a browser download run xattr -dr com.apple.quarantine on the extracted directory. Platform overrides are recognized with the Android SDK's android.jar, found through ANDROID_HOME (without it, only java.lang.Object's methods are known).

Every tool is also a command, for agents that only have a shell (pip install deoptfuscator, or prefix each command with uvx):

deoptfuscator overview app.apk
deoptfuscator deobfuscate app.apk      # app_deobfuscated.apk, unsigned, and a report
deoptfuscator show app_deobfuscated.apk m331
deoptfuscator rename app.apk c75 com.twobuntu.db.ArticleHelper --note "SQLiteOpenHelper of the twobuntu database"

For scripts, deoptfuscator deobfuscate APK --json and deoptfuscator APK --json print the result as one JSON object: the output APK, the report's path, and the counts (opaque predicates resolved, counter fields removed, candidates kept, by reason). deoptfuscator APK --report FILE writes the pass's full report. The commands exit with 0 on success, 1 on an error (the message goes to stderr, and with --json also to stdout as {"error": ...}) and 2 on a usage error.

Example: an agent on the 2buntu fixture

An agent got only tests/fixtures/2buntu/obfuscated.apk, these tools and a one-paragraph task: find out what the app does, and recover the original names of its obfuscated classes, methods and fields. One session took 68 turns, 18 minutes and $9.63 of API use. In it, the agent did the following:

  • It called deobfuscate first and read only the deobfuscated APK after that.
  • It named all 82 obfuscated classes and all 182 obfuscated methods that do not override platform methods. It also named 301 of the 314 fields. The other 13 are synthetic this$0 fields, a name that the server refused at the time; it accepts them now.
  • It described the app correctly as a news reader for 2buntu.com, and named the bundled libraries: Universal Image Loader, parts of Apache Commons IO, and Android support code.

Checked against the original names, it got 172 of 178 right in the bundled image loader and 21 of 30 in the app's own code. Both are public open source, so some of this may be the model remembering them rather than reading the code. For code a model has never seen, take these numbers as an upper bound.

The same session without redex-all, where the agent read the obfuscated code throughout, was about as accurate but covered less: 153 methods and 265 fields. The opaque predicates make methods longer, so show cut 27 of its 145 listings at 400 lines, against 2 of 123 after deobfuscation. Sessions with other models and efforts cost from $0.19 to $23.97. Effort mattered: at medium effort, the two cheaper models named mostly classes and then stopped. Each of these results comes from a single session. The task, harness, transcripts and scoring are in the experiment's write-up.

How it works

The obfuscation technique Deoptfuscator targets drives opaque predicates with private static int counter fields. Counters are updated from each other with parity-preserving arithmetic, and the inserted branches test the parity of the result:

# <clinit>: a = 0 (even), b = 1 (odd)
sget v1, Lo/AuX;->ॱˎ:I        # a, always even
add-int/lit8 v1, v1, 0xf
rem-int/lit16 v2, v1, 0x80
sput v2, Lo/AuX;->ॱˋ:I        # b = (a + 15) % 128, always odd
rem-int/lit8 v1, v1, 0x2
if-nez v1, :cond_22           # (a + 15) is always odd: always taken

Only one side of each branch is the original code; the other side is junk (in the test app, for example, code that divides by zero). The parity invariant guarantees that the original side is always taken.

Deoptfuscator fixes each counter to the value its class initializer gives it and lets an optimizing compiler fold the predicates away. v1 used ART's optimizing compiler for this and assumed the rewrite was safe. v2 does it in one Redex pass, DeoptfuscatorPass (redex-pass/), and only rewrites a counter when it can prove that this preserves the app's behaviour:

  1. Candidates are non-final, non-volatile private static int fields.
  2. Values read from a candidate may only flow through parity-preserving integer arithmetic into if-eqz / if-nez tests of x % 2 or x & 1, or into writes to other candidates. Values written to it may only be computed from constants and candidates.
  3. Every write must keep the parity of the field's initial value. The pass checks this by evaluating each written expression over parities, and it checks that no read can happen before <clinit> stores the initial value.
  4. Then the parity is the same at every read, so every read is replaced by the initial value and every write is deleted, along with the field. Redex's ConstantPropagationPass and LocalDcePass fold the predicates and drop the junk branches.

Redex's IR type checker runs after every pass, so a broken transformation aborts the run instead of producing an invalid APK.

The pass writes a report of the fields it removed (and of the candidates it kept, with the reason). --report FILE saves it; the deobfuscate tool and subcommand write it next to the output APK.

Redex is run with config/keep-all.pro, which keeps every class and member, so nothing is removed or renamed just because Redex cannot see it used (pass your own rules with --keep-rules).

Results

On the obfuscated 2buntu app in tests/fixtures/2buntu, measured with tests/dexmetrics.py:

obfuscated v1 (2020) v2 default v2 aggressive
opaque branches 585 56 0 0
counter updates 585 577 0 0
switches 434 11 9 9
instructions 19,940 13,406 7,345 7,010
methods 437 437 437 380

opaque branches counts rem-int ..., 2 results that decide an if-eqz / if-nez, and counter updates counts rem-int ..., 128 counter updates. v2 proves all 585 predicates safe to fold and leaves one candidate field alone, a real program field.

On an app obfuscated with Obfuscapk's control-flow obfuscators (ArithmeticBranch, Goto, Reorder): ringdroid, in tests/fixtures/obfuscapk:

original obfuscated v2 on original v2 on obfuscated
conditional branches 394 592 388 388
instructions 9,424 32,231 9,062 9,064
mean method size 21.8 74.4 20.9 20.9

These predicates are not counter-based, so DeoptfuscatorPass resolves none of them. The rest of the default pipeline removes all 198 inserted branches: constant propagation, dead code elimination and the other cleanup passes. The obfuscated app ends with as many branches as the original one after the same cleanup.

Building without Docker

You need the Redex build dependencies (Ubuntu 22.04 or later):

sudo apt-get install cmake ninja-build g++ git python3 \
  binutils-dev libiberty-dev libjemalloc-dev libjsoncpp-dev liblz4-dev \
  liblzma-dev zlib1g-dev libprotobuf-dev protobuf-compiler \
  libboost-filesystem-dev libboost-iostreams-dev libboost-program-options-dev \
  libboost-regex-dev libboost-system-dev libboost-thread-dev \
  zipalign apksigner dexdump

scripts/build_redex.sh              # Redex at the commit in REDEX_COMMIT
export REDEX=$PWD/build/redex-build/redex-all
python3 deoptfuscator.py app.apk
python3 tests/test_golden.py        # golden test against v1's output

The first build compiles all of Redex (about an hour on 4 cores); after changing the pass, re-running the script only recompiles the pass.

Limitations

  • DeoptfuscatorPass handles the counter-based opaque predicates described above. Predicates that constant propagation can fold on its own, such as Obfuscapk's ArithmeticBranch, are removed by the rest of the pipeline (see Results). Other control-flow obfuscation (for example control-flow flattening), identifier renaming, string encryption, class encryption and layout obfuscation are not undone. The agent tools help recover names, but they do not undo renaming in the APK.
  • The safety argument covers bytecode only: code that reads the counter fields through reflection or JNI would see them gone.
  • The output is signed with the debug key in deoptfuscator.keystore (password 123456) and is meant for analysis.

Publication

@article{you2022deoptfuscator,
    title = "Deoptfuscator: Defeating Advanced Control-flow Obfuscation Using Android Runtime (ART)",
    journal = "IEEE Access",
    volume = "10",
    pages = "61426-61440",
    year = "2022",
    issn = "2169-3536",
    doi = "10.1109/ACCESS.2022.3181373",
    url = "https://ieeexplore.ieee.org/document/9791370",
    author = "You, Geunha and Kim, Gyoosik and Han, Sangchul and Park, Minkyu and Cho, Seong-je",
    keywords = "Android app, malicious app, obfuscation, deobfuscation, control-flow obfuscation"
}

Contact

  • E-mail: gyoonus at gmail dot com [Gyoosik Kim (김규식)]

Acknowledgement

This research was supported by Basic Science Research Program through the National Research Foundation of Korea (NRF) funded by the Ministry of Science and ICT (no. 2018R1A2B2004830).

NRF

Metadata

Release files for deoptfuscator 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deoptfuscator 2.1.1
File Size Uploaded Provenance Actions
deoptfuscator-2.1.1.tar.gz 43.7 kB With provenance Details for deoptfuscator-2.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deoptfuscator 2.1.1
File Interpreter ABI Platform Actions
deoptfuscator-2.1.1-py3-none-any.whl Python 3 none any Details for deoptfuscator-2.1.1-py3-none-any.whl

Total release size: 85.6 kB

Release files / deoptfuscator-2.1.1.tar.gz

Download URL deoptfuscator-2.1.1.tar.gz
Size 43.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2d126fc3a0e3f67b871dbcd2dc299143de07afe1846f31d251f7eeae57e1a24c
BLAKE2b-256 checksum
How to use checksums
303dbea3f3eefd1de3686245f0e9d250673bd2c272526b7087dc006375eb38eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Release files / deoptfuscator-2.1.1-py3-none-any.whl

Download URL deoptfuscator-2.1.1-py3-none-any.whl
Size 41.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
782b7dbc78f13345eeb5f115ede286895a5d9318cee673aa6e32ed2ec293fa54
BLAKE2b-256 checksum
How to use checksums
815b885d5199bd7be0e59127c7696b215b258e60844c75a9734077668a6cfd00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

Security for deoptfuscator 2.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for deoptfuscator-2.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page