deoptfuscator 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deopt/__init__.py +4 -0
- deopt/__main__.py +5 -0
- deopt/cli.py +147 -0
- deopt/config/aggressive.json +51 -0
- deopt/config/default.json +26 -0
- deopt/config/keep-all.pro +5 -0
- deopt/deoptfuscator.keystore +0 -0
- deopt/driver.py +326 -0
- deopt/names.py +253 -0
- deopt/platform.py +122 -0
- deopt/program.py +347 -0
- deopt/render.py +130 -0
- deopt/server.py +181 -0
- deopt/tools.py +484 -0
- deoptfuscator-2.1.0.dist-info/METADATA +379 -0
- deoptfuscator-2.1.0.dist-info/RECORD +19 -0
- deoptfuscator-2.1.0.dist-info/WHEEL +4 -0
- deoptfuscator-2.1.0.dist-info/entry_points.txt +2 -0
- deoptfuscator-2.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: deoptfuscator
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: Undo counter-based control-flow obfuscation in Android apps and read their code: a CLI and an MCP server for agents
|
|
5
|
+
Project-URL: Homepage, https://github.com/Gyoonus/deoptfuscator
|
|
6
|
+
Project-URL: Issues, https://github.com/Gyoonus/deoptfuscator/issues
|
|
7
|
+
Author: Gyoosik Kim
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: android,apk,deobfuscation,dex,mcp,redex,reverse-engineering
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Information Technology
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Security
|
|
17
|
+
Classifier: Topic :: Software Development :: Disassemblers
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: androguard>=4.1
|
|
20
|
+
Requires-Dist: mcp>=1.21.2
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Deoptfuscator
|
|
24
|
+
|
|
25
|
+
[](https://github.com/Gyoonus/deoptfuscator/actions/workflows/ci.yml)
|
|
26
|
+
[](https://github.com/Gyoonus/deoptfuscator/releases/latest)
|
|
27
|
+
|
|
28
|
+
Deoptfuscator removes a specific control-flow obfuscation technique from
|
|
29
|
+
Android apps: opaque predicates driven by static counter fields (see
|
|
30
|
+
[How it works](https://github.com/Gyoonus/deoptfuscator#how-it-works)). It was selected for
|
|
31
|
+
[BlackHat Arsenal USA 2020](https://www.blackhat.com/us-20/arsenal/schedule/#deoptfuscator-automated-deobfuscation-of-android-bytecode-using-compilation-optimization-19958)
|
|
32
|
+
and is described in the IEEE Access paper
|
|
33
|
+
"[Deoptfuscator: Defeating Advanced Control-flow Obfuscation Using Android Runtime (ART)](https://ieeexplore.ieee.org/document/9791370)".
|
|
34
|
+
Coding agents can use it too: an MCP server lets them deobfuscate an APK,
|
|
35
|
+
read its code and record the names they work out. Everything is static,
|
|
36
|
+
and no APK is installed or run.
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
<sub>This is real output on the obfuscated test fixture. It shows one method with its opaque predicates (the
|
|
41
|
+
counter field accesses are highlighted), the same method after
|
|
42
|
+
`deobfuscate`, and a recorded name. The animation is made with
|
|
43
|
+
[scripts/make_demo.py](https://github.com/Gyoonus/deoptfuscator/blob/main/scripts/make_demo.py).</sub>
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
For agents in Claude Code, install the plugin: the MCP server and a skill
|
|
48
|
+
that tells the agent how to use it ([more clients and the tools](https://github.com/Gyoonus/deoptfuscator#use-with-agents-mcp)):
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
/plugin install deoptfuscator --marketplace Gyoonus/deoptfuscator
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To deobfuscate an APK from the command line, use Docker:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
docker build -t deoptfuscator .
|
|
58
|
+
docker run --rm -v "$PWD:/work" deoptfuscator app.apk
|
|
59
|
+
# -> app_deobfuscated.apk, zipaligned and signed with a debug key
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
deoptfuscator.py APK [-o OUT.apk] [-c CONFIG] [-k KEEP_RULES]
|
|
66
|
+
[--keystore KS --ks-pass pass:...]
|
|
67
|
+
[--no-sign] [--report FILE] [--json]
|
|
68
|
+
[--keep-workdir] [-v]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
* `config/default.json` (default) removes the opaque predicates and cleans up
|
|
72
|
+
method bodies only: constant propagation, dead code elimination, copy
|
|
73
|
+
propagation, block deduplication and register allocation. Classes and
|
|
74
|
+
methods stay as they are.
|
|
75
|
+
* `config/aggressive.json` additionally runs the Redex optimizations the v1
|
|
76
|
+
pipeline used (inlining, CSE, peephole, ...), for smaller, easier-to-read
|
|
77
|
+
code that is further from the original structure.
|
|
78
|
+
|
|
79
|
+
> **v2** is a re-implementation on top of [Redex](https://github.com/facebook/redex).
|
|
80
|
+
> It needs no AOSP checkout, no prebuilt ART libraries and no Git LFS, and it
|
|
81
|
+
> builds and runs on current Linux. The original ART-based implementation (v1)
|
|
82
|
+
> that the paper describes is kept at tag
|
|
83
|
+
> [`v1`](https://github.com/Gyoonus/deoptfuscator/tree/v1).
|
|
84
|
+
|
|
85
|
+
## Use with agents (MCP)
|
|
86
|
+
|
|
87
|
+
`deoptfuscator mcp` serves Deoptfuscator to coding agents as an MCP server
|
|
88
|
+
(stdio). An agent can deobfuscate an APK, then read its code: search
|
|
89
|
+
classes and strings, show bytecode, follow cross-references, and record the
|
|
90
|
+
names it works out for obfuscated classes, methods and fields. Everything is
|
|
91
|
+
static: no APK is installed or run.
|
|
92
|
+
|
|
93
|
+
Claude Code, as a plugin with the server and a skill:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
/plugin install deoptfuscator --marketplace Gyoonus/deoptfuscator
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
On Claude Code older than 2.1.275, add the marketplace first:
|
|
100
|
+
`/plugin marketplace add Gyoonus/deoptfuscator`, then
|
|
101
|
+
`/plugin install deoptfuscator@deoptfuscator`. Auto-update is off by
|
|
102
|
+
default for marketplaces other than Anthropic's: turn it on in `/plugin`
|
|
103
|
+
(Marketplaces), or update with
|
|
104
|
+
`claude plugin update deoptfuscator@deoptfuscator`. The skill,
|
|
105
|
+
[analyze-apk](https://github.com/Gyoonus/deoptfuscator/blob/main/plugin/skills/analyze-apk/SKILL.md), gives the agent the
|
|
106
|
+
workflow below and the tool's limits, and tells it to treat text inside an
|
|
107
|
+
app as data, not instructions. Without the plugin, copy it to
|
|
108
|
+
`~/.claude/skills/analyze-apk/`.
|
|
109
|
+
|
|
110
|
+
Claude Code, the server only (use either this or the plugin, not both):
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
claude mcp add deoptfuscator -- uvx --from git+https://github.com/Gyoonus/deoptfuscator deoptfuscator mcp
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Other MCP clients:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"deoptfuscator": {
|
|
122
|
+
"command": "uvx",
|
|
123
|
+
"args": ["--from", "git+https://github.com/Gyoonus/deoptfuscator",
|
|
124
|
+
"deoptfuscator", "mcp"]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Tool | What it does |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `overview` | Package, manifest components, permissions, largest packages, share of obfuscated-looking class names |
|
|
133
|
+
| `deobfuscate` | Removes the counter-based opaque predicates; writes `app_deobfuscated.apk` and a JSON report next to the input (needs `redex-all`) |
|
|
134
|
+
| `list_classes`, `search` | Classes; string constants (with the methods using them) and names |
|
|
135
|
+
| `show` | A class or method as Dalvik bytecode, with access flags, overrides, and every reference to app code tagged with its id (`# m345`) |
|
|
136
|
+
| `xrefs` | Callers of a method, readers and writers of a field, subclasses and users of a class |
|
|
137
|
+
| `rename` | Records a name, with the evidence, for a class, method or field (see below) |
|
|
138
|
+
| `export_names` | Writes the names as a ProGuard mapping |
|
|
139
|
+
|
|
140
|
+
Classes, methods and fields are referred to by short ids (`c12`, `m345`,
|
|
141
|
+
`f6`) that stay the same for a given file, or by descriptor or Java name.
|
|
142
|
+
After `deobfuscate`, a method that was 34 instructions of opaque predicates
|
|
143
|
+
in the 2buntu fixture reads:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
class c75 public final Lo/ˎˎ; extends Landroid/database/sqlite/SQLiteOpenHelper;
|
|
147
|
+
method m331 public final onCreate(Landroid/database/sqlite/SQLiteDatabase;)V // overrides Landroid/database/sqlite/SQLiteOpenHelper;
|
|
148
|
+
0000: const-string v0, "CREATE TABLE article (_id INTEGER PRIMARY KEY AUTOINCREMENT, ...);"
|
|
149
|
+
0002: invoke-virtual v2, v0, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V
|
|
150
|
+
0005: return-void
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Names given with `rename` are kept in `app.names.json` next to the APK,
|
|
154
|
+
shared by `app.apk` and `app_deobfuscated.apk`, and shown in place of the
|
|
155
|
+
obfuscated ones from then on (`Lo/ˎˎ;` becomes
|
|
156
|
+
`Lcom/twobuntu/db/ArticleHelper;`; inner classes follow their outer class's
|
|
157
|
+
name). A method
|
|
158
|
+
is renamed together with the methods it overrides or is overridden by;
|
|
159
|
+
methods that override Android platform methods keep their names, and names
|
|
160
|
+
that would clash are refused. The APK itself is never modified.
|
|
161
|
+
|
|
162
|
+
Requirements: Python 3.10 or later (`uvx` installs `androguard` and `mcp`).
|
|
163
|
+
On first start, `uvx` downloads the package and its dependencies, and
|
|
164
|
+
Python too if yours is older, which can take longer than the client waits:
|
|
165
|
+
if `/mcp` shows the server failed or still reconnecting, run
|
|
166
|
+
`uvx --from git+https://github.com/Gyoonus/deoptfuscator deoptfuscator --version`
|
|
167
|
+
once in a terminal, then reconnect.
|
|
168
|
+
`deobfuscate` also needs `redex-all` on `PATH` or in `$REDEX`, from the
|
|
169
|
+
[release tarball](https://github.com/Gyoonus/deoptfuscator/releases/latest)
|
|
170
|
+
for Linux x86_64 or macOS (Apple silicon, macOS 15 or later), or
|
|
171
|
+
[built from source](https://github.com/Gyoonus/deoptfuscator#building-without-docker). The macOS binaries are not
|
|
172
|
+
notarized: download the tarball with `curl` or `gh`, or after a browser
|
|
173
|
+
download run `xattr -dr com.apple.quarantine` on the extracted directory.
|
|
174
|
+
Platform overrides are recognized with the Android SDK's `android.jar`,
|
|
175
|
+
found through `ANDROID_HOME` (without it, only `java.lang.Object`'s
|
|
176
|
+
methods are known).
|
|
177
|
+
|
|
178
|
+
Every tool is also a command, for agents that only have a shell:
|
|
179
|
+
|
|
180
|
+
```sh
|
|
181
|
+
deoptfuscator overview app.apk
|
|
182
|
+
deoptfuscator deobfuscate app.apk # app_deobfuscated.apk, unsigned, and a report
|
|
183
|
+
deoptfuscator show app_deobfuscated.apk m331
|
|
184
|
+
deoptfuscator rename app.apk c75 com.twobuntu.db.ArticleHelper --note "SQLiteOpenHelper of the twobuntu database"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For scripts, `deoptfuscator deobfuscate APK --json` and
|
|
188
|
+
`deoptfuscator APK --json` print the result as one JSON object: the output
|
|
189
|
+
APK, the report's path, and the counts (opaque predicates resolved,
|
|
190
|
+
counter fields removed, candidates kept, by reason).
|
|
191
|
+
`deoptfuscator APK --report FILE` writes the pass's full report. The
|
|
192
|
+
commands exit with 0 on success, 1 on an error (the message goes to
|
|
193
|
+
stderr, and with `--json` also to stdout as `{"error": ...}`) and 2 on a
|
|
194
|
+
usage error.
|
|
195
|
+
|
|
196
|
+
### Example: an agent on the 2buntu fixture
|
|
197
|
+
|
|
198
|
+
An agent got only `tests/fixtures/2buntu/obfuscated.apk`, these tools and
|
|
199
|
+
a one-paragraph task: find out what the app does, and recover the
|
|
200
|
+
original names of its obfuscated classes, methods and fields. One session
|
|
201
|
+
took 68 turns, 18 minutes and $9.63 of API use. In it, the agent did the
|
|
202
|
+
following:
|
|
203
|
+
|
|
204
|
+
- It called `deobfuscate` first and read only the deobfuscated APK after
|
|
205
|
+
that.
|
|
206
|
+
- It named all 82 obfuscated classes and all 182 obfuscated methods that
|
|
207
|
+
do not override platform methods. It also named 301 of the 314 fields.
|
|
208
|
+
The other 13 are synthetic `this$0` fields, a name that the server
|
|
209
|
+
refused at the time; it accepts them now.
|
|
210
|
+
- It described the app correctly as a news reader for 2buntu.com, and
|
|
211
|
+
named the bundled libraries: Universal Image Loader, parts of Apache
|
|
212
|
+
Commons IO, and Android support code.
|
|
213
|
+
|
|
214
|
+
Checked against the original names, it got 172 of 178 right in the
|
|
215
|
+
bundled image loader and 21 of 30 in the app's own code. Both are public
|
|
216
|
+
open source, so some of this may be the model remembering them rather
|
|
217
|
+
than reading the code. For code a model has never seen, take these
|
|
218
|
+
numbers as an upper bound.
|
|
219
|
+
|
|
220
|
+
The same session without `redex-all`, where the agent read the
|
|
221
|
+
obfuscated code throughout, was about as accurate but covered less: 153
|
|
222
|
+
methods and 265 fields. The opaque predicates make methods longer, so
|
|
223
|
+
`show` cut 27 of its 145 listings at 400 lines, against 2 of 123 after
|
|
224
|
+
deobfuscation. Sessions with other models and efforts cost from $0.19 to
|
|
225
|
+
$23.97. Effort mattered: at medium effort, the two cheaper models named
|
|
226
|
+
mostly classes and then stopped. Each of these results comes from a
|
|
227
|
+
single session.
|
|
228
|
+
The task, harness, transcripts and scoring are in the experiment's
|
|
229
|
+
[write-up](https://github.com/Gyoonus/deoptfuscator/blob/research/experiments/experiments/symbol_recovery/README.md#step-5-an-agent-with-the-mcp-server-agentnamespy).
|
|
230
|
+
|
|
231
|
+
## How it works
|
|
232
|
+
|
|
233
|
+
The obfuscation technique Deoptfuscator targets drives opaque predicates with
|
|
234
|
+
`private static int` counter fields. Counters are updated from each other with
|
|
235
|
+
parity-preserving arithmetic, and the inserted branches test the parity of the
|
|
236
|
+
result:
|
|
237
|
+
|
|
238
|
+
```smali
|
|
239
|
+
# <clinit>: a = 0 (even), b = 1 (odd)
|
|
240
|
+
sget v1, Lo/AuX;->ॱˎ:I # a, always even
|
|
241
|
+
add-int/lit8 v1, v1, 0xf
|
|
242
|
+
rem-int/lit16 v2, v1, 0x80
|
|
243
|
+
sput v2, Lo/AuX;->ॱˋ:I # b = (a + 15) % 128, always odd
|
|
244
|
+
rem-int/lit8 v1, v1, 0x2
|
|
245
|
+
if-nez v1, :cond_22 # (a + 15) is always odd: always taken
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Only one side of each branch is the original code; the other side is junk
|
|
249
|
+
(in the test app, for example, code that divides by zero). The parity
|
|
250
|
+
invariant guarantees that the original side is always taken.
|
|
251
|
+
|
|
252
|
+
Deoptfuscator fixes each counter to the value its class initializer gives it
|
|
253
|
+
and lets an optimizing compiler fold the predicates away. v1 used ART's
|
|
254
|
+
optimizing compiler for this and assumed the rewrite was safe. v2 does it in
|
|
255
|
+
one Redex pass, `DeoptfuscatorPass` ([redex-pass/](https://github.com/Gyoonus/deoptfuscator/blob/main/redex-pass/)), and only
|
|
256
|
+
rewrites a counter when it can prove that this preserves the app's behaviour:
|
|
257
|
+
|
|
258
|
+
1. Candidates are non-final, non-volatile `private static int` fields.
|
|
259
|
+
2. Values read from a candidate may only flow through parity-preserving
|
|
260
|
+
integer arithmetic into `if-eqz` / `if-nez` tests of `x % 2` or `x & 1`, or
|
|
261
|
+
into writes to other candidates. Values written to it may only be computed
|
|
262
|
+
from constants and candidates.
|
|
263
|
+
3. Every write must keep the parity of the field's initial value. The pass
|
|
264
|
+
checks this by evaluating each written expression over parities, and it
|
|
265
|
+
checks that no read can happen before `<clinit>` stores the initial value.
|
|
266
|
+
4. Then the parity is the same at every read, so every read is replaced by the
|
|
267
|
+
initial value and every write is deleted, along with the field. Redex's
|
|
268
|
+
`ConstantPropagationPass` and `LocalDcePass` fold the predicates and drop
|
|
269
|
+
the junk branches.
|
|
270
|
+
|
|
271
|
+
Redex's IR type checker runs after every pass, so a broken transformation
|
|
272
|
+
aborts the run instead of producing an invalid APK.
|
|
273
|
+
|
|
274
|
+
The pass writes a report of the fields it removed (and of the candidates it
|
|
275
|
+
kept, with the reason). `--report FILE` saves it; the `deobfuscate` tool
|
|
276
|
+
and subcommand write it next to the output APK.
|
|
277
|
+
|
|
278
|
+
Redex is run with [config/keep-all.pro](https://github.com/Gyoonus/deoptfuscator/blob/main/config/keep-all.pro), which keeps
|
|
279
|
+
every class and member, so nothing is removed or renamed just because Redex
|
|
280
|
+
cannot see it used (pass your own rules with `--keep-rules`).
|
|
281
|
+
|
|
282
|
+
## Results
|
|
283
|
+
|
|
284
|
+
On the obfuscated 2buntu app in
|
|
285
|
+
[tests/fixtures/2buntu](https://github.com/Gyoonus/deoptfuscator/blob/main/tests/fixtures/2buntu), measured with
|
|
286
|
+
[tests/dexmetrics.py](https://github.com/Gyoonus/deoptfuscator/blob/main/tests/dexmetrics.py):
|
|
287
|
+
|
|
288
|
+
| | obfuscated | v1 (2020) | v2 default | v2 aggressive |
|
|
289
|
+
|-----------------|-----------:|----------:|-----------:|--------------:|
|
|
290
|
+
| opaque branches | 585 | 56 | **0** | **0** |
|
|
291
|
+
| counter updates | 585 | 577 | **0** | **0** |
|
|
292
|
+
| switches | 434 | 11 | 9 | 9 |
|
|
293
|
+
| instructions | 19,940 | 13,406 | 7,345 | 7,010 |
|
|
294
|
+
| methods | 437 | 437 | 437 | 380 |
|
|
295
|
+
|
|
296
|
+
`opaque branches` counts `rem-int ..., 2` results that decide an `if-eqz` /
|
|
297
|
+
`if-nez`, and `counter updates` counts `rem-int ..., 128` counter updates.
|
|
298
|
+
v2 proves all 585 predicates safe to fold and leaves one candidate field
|
|
299
|
+
alone, a real program field.
|
|
300
|
+
|
|
301
|
+
On an app obfuscated with [Obfuscapk](https://github.com/ClaudiuGeorgiu/Obfuscapk)'s
|
|
302
|
+
control-flow obfuscators (`ArithmeticBranch`, `Goto`, `Reorder`):
|
|
303
|
+
ringdroid, in [tests/fixtures/obfuscapk](https://github.com/Gyoonus/deoptfuscator/blob/main/tests/fixtures/obfuscapk/RESULTS.md):
|
|
304
|
+
|
|
305
|
+
| | original | obfuscated | v2 on original | v2 on obfuscated |
|
|
306
|
+
|-----------------------|---------:|-----------:|---------------:|-----------------:|
|
|
307
|
+
| conditional branches | 394 | 592 | 388 | **388** |
|
|
308
|
+
| instructions | 9,424 | 32,231 | 9,062 | 9,064 |
|
|
309
|
+
| mean method size | 21.8 | 74.4 | 20.9 | 20.9 |
|
|
310
|
+
|
|
311
|
+
These predicates are not counter-based, so DeoptfuscatorPass resolves none
|
|
312
|
+
of them. The rest of the default pipeline removes all 198 inserted
|
|
313
|
+
branches: constant propagation, dead code elimination and the other
|
|
314
|
+
cleanup passes. The obfuscated app ends with as many branches as
|
|
315
|
+
the original one after the same cleanup.
|
|
316
|
+
|
|
317
|
+
## Building without Docker
|
|
318
|
+
|
|
319
|
+
You need the Redex build dependencies (Ubuntu 22.04 or later):
|
|
320
|
+
|
|
321
|
+
```sh
|
|
322
|
+
sudo apt-get install cmake ninja-build g++ git python3 \
|
|
323
|
+
binutils-dev libiberty-dev libjemalloc-dev libjsoncpp-dev liblz4-dev \
|
|
324
|
+
liblzma-dev zlib1g-dev libprotobuf-dev protobuf-compiler \
|
|
325
|
+
libboost-filesystem-dev libboost-iostreams-dev libboost-program-options-dev \
|
|
326
|
+
libboost-regex-dev libboost-system-dev libboost-thread-dev \
|
|
327
|
+
zipalign apksigner dexdump
|
|
328
|
+
|
|
329
|
+
scripts/build_redex.sh # Redex at the commit in REDEX_COMMIT
|
|
330
|
+
export REDEX=$PWD/build/redex-build/redex-all
|
|
331
|
+
python3 deoptfuscator.py app.apk
|
|
332
|
+
python3 tests/test_golden.py # golden test against v1's output
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
The first build compiles all of Redex (about an hour on 4 cores); after
|
|
336
|
+
changing the pass, re-running the script only recompiles the pass.
|
|
337
|
+
|
|
338
|
+
## Limitations
|
|
339
|
+
|
|
340
|
+
* DeoptfuscatorPass handles the counter-based opaque predicates described
|
|
341
|
+
above. Predicates that constant propagation can fold on its own, such as
|
|
342
|
+
Obfuscapk's `ArithmeticBranch`, are removed by the rest of the pipeline
|
|
343
|
+
(see [Results](https://github.com/Gyoonus/deoptfuscator#results)). Other control-flow obfuscation (for example
|
|
344
|
+
control-flow flattening), identifier renaming, string encryption, class
|
|
345
|
+
encryption and layout obfuscation are not undone. The agent tools help
|
|
346
|
+
recover names, but they do not undo renaming in the APK.
|
|
347
|
+
* The safety argument covers bytecode only: code that reads the counter fields
|
|
348
|
+
through reflection or JNI would see them gone.
|
|
349
|
+
* The output is signed with the debug key in `deoptfuscator.keystore`
|
|
350
|
+
(password `123456`) and is meant for analysis.
|
|
351
|
+
|
|
352
|
+
## Publication
|
|
353
|
+
|
|
354
|
+
```bibtex
|
|
355
|
+
@article{you2022deoptfuscator,
|
|
356
|
+
title = "Deoptfuscator: Defeating Advanced Control-flow Obfuscation Using Android Runtime (ART)",
|
|
357
|
+
journal = "IEEE Access",
|
|
358
|
+
volume = "10",
|
|
359
|
+
pages = "61426-61440",
|
|
360
|
+
year = "2022",
|
|
361
|
+
issn = "2169-3536",
|
|
362
|
+
doi = "10.1109/ACCESS.2022.3181373",
|
|
363
|
+
url = "https://ieeexplore.ieee.org/document/9791370",
|
|
364
|
+
author = "You, Geunha and Kim, Gyoosik and Han, Sangchul and Park, Minkyu and Cho, Seong-je",
|
|
365
|
+
keywords = "Android app, malicious app, obfuscation, deobfuscation, control-flow obfuscation"
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Contact
|
|
370
|
+
|
|
371
|
+
* E-mail: gyoonus at gmail dot com [Gyoosik Kim (김규식)]
|
|
372
|
+
|
|
373
|
+
## Acknowledgement
|
|
374
|
+
|
|
375
|
+
This research was supported by Basic Science Research Program through the
|
|
376
|
+
National Research Foundation of Korea (NRF) funded by the Ministry of Science
|
|
377
|
+
and ICT (no. 2018R1A2B2004830).
|
|
378
|
+
|
|
379
|
+

|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
deopt/__init__.py,sha256=DydJm-fi9TToz6bUdGtLjLaxSwwavfMwf77VeiVGmBk,164
|
|
2
|
+
deopt/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
deopt/cli.py,sha256=DxqSpWm4Sz4OL5O7pRt_3Vv9FnyOKgR1ErbFOc4IkUc,5695
|
|
4
|
+
deopt/names.py,sha256=TgVx_weQzhMsIXf2Lk57EmXUQk0LC7vHdFIT-FScNyQ,11037
|
|
5
|
+
deopt/platform.py,sha256=jy7A8Xq7vvnCcQM0qazELhul6rc_1JVn2IzLBFutP-E,4322
|
|
6
|
+
deopt/program.py,sha256=NKWB7FgYsS8Vy7968B7zaXqEfFw-XArvzzJbDu2slSc,12814
|
|
7
|
+
deopt/render.py,sha256=ybzgsfq4RcW0G-qB_N6l_5JulWU7ZUBk_JVjQmXuXqc,5138
|
|
8
|
+
deopt/server.py,sha256=z-iC0-bH-mqEtt9Dlw13O2WEaczNQ4KhgQui9OBoQcs,7973
|
|
9
|
+
deopt/tools.py,sha256=S3RtEVljz1UEekGz0-FN9RHDTRLLWFkPu22a9o2c1NQ,20149
|
|
10
|
+
deopt/config/aggressive.json,sha256=ZsbMc1K4jnK_CgP7xAJIDEDuIHnyX_0dixBE8hT6TJY,1153
|
|
11
|
+
deopt/config/default.json,sha256=ejVofCcoGrL6PzXaOKfZI5gdg-5eLHaGRWf3EM_2uis,543
|
|
12
|
+
deopt/config/keep-all.pro,sha256=9jrBk6Jw1w8c-KlSZDeIqEUZi0LKrsbg5Edm-bZPt6A,254
|
|
13
|
+
deopt/deoptfuscator.keystore,sha256=otB5KhLP3SNqXm2Wi40c2-tf4fdqfshemz1PvnP1QAE,2613
|
|
14
|
+
deopt/driver.py,sha256=vy6UDZS1ynC5ye2iZ_agqv0oB9oMnhlv7hy--ZRBLUw,13071
|
|
15
|
+
deoptfuscator-2.1.0.dist-info/METADATA,sha256=XEP7jEg21jYDJ4xRwQhP8fQj9DgfAKIXtAnK-EXXQAM,18710
|
|
16
|
+
deoptfuscator-2.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
17
|
+
deoptfuscator-2.1.0.dist-info/entry_points.txt,sha256=i-SY_JZDsRW0749SJgCpZVqMRrySPpE53i880ufOiNs,49
|
|
18
|
+
deoptfuscator-2.1.0.dist-info/licenses/LICENSE,sha256=qtSC0tUWTgcDE27IO25N8QdB8wwIonhEbPix8hWKgZk,1068
|
|
19
|
+
deoptfuscator-2.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Gyoosik Kim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|