Skip to content
This repository was archived by the owner on Jul 27, 2024. It is now read-only.

Commit 5826d47

Browse files
Merge pull request #121 from mirsamantajbakhsh/AndroidBundle
Android App Bundle Support Added
2 parents f56d7f8 + 9e8a53b commit 5826d47

File tree

7 files changed

+406
-60
lines changed

7 files changed

+406
-60
lines changed

.github/workflows/macos.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
sudo chmod a+x /usr/local/bin/apktool
4040
sudo wget -q "https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_${APKTOOL_VERSION}.jar" -O /usr/local/bin/apktool.jar
4141
sudo chmod a+x /usr/local/bin/apktool.jar
42+
# Install BundleDecompiler.
43+
sudo wget -q https://github.com/TamilanPeriyasamy/BundleDecompiler/raw/master/build/libs/BundleDecompiler-0.0.2.jar -O /usr/local/bin/BundleDecompiler.jar
44+
sudo chmod a+x /usr/local/bin/BundleDecompiler.jar
4245
4346
- name: Run tests
4447
run: |

.github/workflows/ubuntu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
sudo chmod a+x /usr/local/bin/apktool
4040
sudo wget -q "https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_${APKTOOL_VERSION}.jar" -O /usr/local/bin/apktool.jar
4141
sudo chmod a+x /usr/local/bin/apktool.jar
42+
sudo wget -q https://github.com/TamilanPeriyasamy/BundleDecompiler/raw/master/build/libs/BundleDecompiler-0.0.2.jar -O /usr/local/bin/BundleDecompiler.jar
43+
sudo chmod a+x /usr/local/bin/BundleDecompiler.jar
4244
4345
- name: Run tests
4446
run: |

README.md

100644100755
Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Windows Build Status](https://github.com/ClaudiuGeorgiu/Obfuscapk/workflows/Windows/badge.svg)](https://github.com/ClaudiuGeorgiu/Obfuscapk/actions?query=workflow%3AWindows)
88
[![MacOS Build Status](https://github.com/ClaudiuGeorgiu/Obfuscapk/workflows/MacOS/badge.svg)](https://github.com/ClaudiuGeorgiu/Obfuscapk/actions?query=workflow%3AMacOS)
99
[![Docker Hub](https://img.shields.io/docker/cloud/build/claudiugeorgiu/obfuscapk)](https://hub.docker.com/r/claudiugeorgiu/obfuscapk)
10-
[![Python Version](https://img.shields.io/badge/Python-3.6%2B-green.svg?logo=python&logoColor=white)](https://www.python.org/downloads/)
10+
[![Python Version](https://img.shields.io/badge/Python-3.7%2B-green.svg?logo=python&logoColor=white)](https://www.python.org/downloads/)
1111
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ClaudiuGeorgiu/Obfuscapk/blob/master/LICENSE)
1212

1313

@@ -20,6 +20,22 @@ obfuscated app retains the same functionality as the original one, but the diffe
2020
under the hood sometimes make the new application very different from the original
2121
(e.g., to signature-based antivirus software).
2222

23+
### :new: Android App Bundle support :new:
24+
25+
Obfuscapk is adding support for
26+
[Android App Bundles](https://developer.android.com/guide/app-bundle) (aab files) by
27+
using [BundleDecompiler](https://github.com/TamilanPeriyasamy/BundleDecompiler) (see
28+
[#121](https://github.com/ClaudiuGeorgiu/Obfuscapk/pull/121)). In order to use this new
29+
feature, download the latest version of BundleDecompiler available from
30+
[here](https://github.com/TamilanPeriyasamy/BundleDecompiler/tree/master/build/libs) and
31+
save it as `BundleDecompiler.jar` in a directory included in `PATH` (e.g., in Ubuntu,
32+
`/usr/local/bin` or `/usr/bin`).
33+
34+
`NOTE:` BundleDecompiler doesn't work on Windows yet, so app bundle obfuscation is not
35+
supported by Obfuscapk on Windows platform. Also, app bundle support is still in early
36+
development, so if you faced any problems or if you want to help us improve, please see
37+
[contributing](#-contributing).
38+
2339

2440

2541
## ❱ Publication
@@ -109,7 +125,7 @@ Docker version 19.03.0, build aeac949
109125
#### Official Docker Hub image
110126

111127
The [official Obfuscapk Docker image](https://hub.docker.com/r/claudiugeorgiu/obfuscapk)
112-
is available on Docker Hub (automatically built from this repository):
128+
is available on Docker Hub:
113129

114130
```Shell
115131
$ # Download the Docker image.
@@ -136,7 +152,7 @@ installed correctly:
136152

137153
```Shell
138154
$ docker run --rm -it obfuscapk --help
139-
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK]
155+
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB]
140156
...
141157
```
142158

@@ -174,15 +190,22 @@ Copyright (C) 2009 The Android Open Source Project
174190
...
175191
```
176192

177-
To install and use `apktool` you need a recent version of Java.
193+
To support app bundles obfuscation you need
194+
[BundleDecompiler](https://github.com/TamilanPeriyasamy/BundleDecompiler), so download
195+
the latest available version from
196+
[here](https://github.com/TamilanPeriyasamy/BundleDecompiler/tree/master/build/libs) and
197+
save it as `BundleDecompiler.jar` in a directory included in `PATH` (e.g., in Ubuntu,
198+
`/usr/local/bin` or `/usr/bin`).
199+
200+
To use BundleDecompiler and `apktool` you also need a recent version of Java.
178201
`zipalign` and `apksigner` are included in the Android SDK. The location of the
179202
executables can also be specified through the following environment variables:
180-
`APKTOOL_PATH`, `APKSIGNER_PATH` and `ZIPALIGN_PATH` (e.g., in Ubuntu, run
181-
`export APKTOOL_PATH=/custom/location/apktool` before running Obfuscapk in the same
182-
terminal).
203+
`APKTOOL_PATH`, `BUNDLE_DECOMPILER_PATH`, `APKSIGNER_PATH` and `ZIPALIGN_PATH` (e.g.,
204+
in Ubuntu, run `export APKTOOL_PATH=/custom/location/apktool` before running Obfuscapk
205+
in the same terminal).
183206

184207
Apart from the above tools, the only requirement of this project is a working
185-
`Python 3` (at least `3.6`) installation (along with its package manager `pip`).
208+
`Python 3` (at least `3.7`) installation (along with its package manager `pip`).
186209

187210
#### Install
188211

@@ -209,7 +232,7 @@ $ cd src/
209232
$ # The following command has to be executed always from Obfuscapk/src/ directory
210233
$ # or by adding Obfuscapk/src/ directory to PYTHONPATH environment variable.
211234
$ python3 -m obfuscapk.cli --help
212-
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK]
235+
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB]
213236
...
214237
```
215238

@@ -249,28 +272,29 @@ Let's start by looking at the help message:
249272

250273
```Shell
251274
$ obfuscapk --help
252-
obfuscapk [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK] [-i] [-p] [-k VT_API_KEY]
275+
obfuscapk [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB] [-i] [-p] [-k VT_API_KEY]
253276
[--keystore-file KEYSTORE_FILE] [--keystore-password KEYSTORE_PASSWORD]
254277
[--key-alias KEY_ALIAS] [--key-password KEY_PASSWORD] [--use-aapt2]
255-
<APK_FILE>
278+
<APK_OR_BUNDLE_FILE>
256279
```
257280

258-
There are two mandatory parameters: `<APK_FILE>`, the path (relative or absolute) to
259-
the apk file to obfuscate and the list with the names of the obfuscation techniques to
260-
apply (specified with a `-o` option that can be used multiple times, e.g.,
261-
`-o Rebuild -o NewAlignment -o NewSignature`). The other optional arguments are as
262-
follows:
281+
There are two mandatory parameters: `<APK_OR_BUNDLE_FILE>`, the path (relative or
282+
absolute) to the apk or app bundle file to obfuscate and the list with the names of the
283+
obfuscation techniques to apply (specified with a `-o` option that can be used multiple
284+
times, e.g., `-o Rebuild -o NewAlignment -o NewSignature`). The other optional arguments
285+
are as follows:
263286

264287
* `-w DIR` is used to set the working directory where to save the intermediate files
265288
(generated by `apktool`). If not specified, a directory named `obfuscation_working_dir`
266289
is created in the same directory as the input application. This can be useful for
267290
debugging purposes, but if it's not needed it can be set to a temporary directory
268291
(e.g., `-w /tmp/`).
269292

270-
* `-d OUT_APK` is used to set the path of the destination file: the apk file generated
271-
by the obfuscation process (e.g., `-d /home/user/Desktop/obfuscated.apk`). If not
272-
specified, the final obfuscated file will be saved inside the working directory.
273-
Note: existing files will be overwritten without any warning.
293+
* `-d OUT_APK_OR_AAB` is used to set the path of the destination file: the apk file
294+
generated by the obfuscation process (e.g., `-d /home/user/Desktop/obfuscated.apk` or
295+
`-d /home/user/Desktop/obfuscated.aab`). If not specified, the final obfuscated file
296+
will be saved inside the working directory. Note: existing files will be overwritten
297+
without any warning.
274298

275299
* `-i` is a flag for ignoring known third party libraries during the obfuscation
276300
process, to use fewer resources, to increase performances and to reduce the risk of
@@ -302,8 +326,8 @@ shown in the example below:
302326
com.mycompany.dontobfuscate
303327
com.mycompany.ignore
304328
...
305-
```
306-
* `--use-aapt2` is a flag for use aapt2 option to rebuild app when using apktool.
329+
```
330+
* `--use-aapt2` is a flag for using aapt2 option when rebuilding an app with `apktool`.
307331

308332
Let's consider now a simple working example to see how Obfuscapk works:
309333

src/obfuscapk/cli.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ def get_cmd_args(args: list = None):
2121

2222
parser = argparse.ArgumentParser(
2323
prog="python3 -m obfuscapk.cli",
24-
description="Obfuscate an application (.apk) without needing its source code.",
24+
description="Obfuscate an application (.apk/.aab) without needing its "
25+
"source code.",
2526
)
2627
parser.add_argument(
2728
"apk_file",
2829
type=str,
29-
metavar="<APK_FILE>",
30-
help="The path to the application (.apk) to obfuscate",
30+
metavar="<APK_OR_BUNDLE_FILE>",
31+
help="The path to the application (.apk/.aab) to obfuscate",
3132
)
3233
parser.add_argument(
3334
"-o",
@@ -54,9 +55,9 @@ def get_cmd_args(args: list = None):
5455
"-d",
5556
"--destination",
5657
type=str,
57-
metavar="OUT_APK",
58-
help="The path where to save the obfuscated .apk file. By default the file "
59-
"will be saved in the working directory",
58+
metavar="OUT_APK_OR_AAB",
59+
help="The path where to save the obfuscated .apk/.aab file. By default the "
60+
"file will be saved in the working directory",
6061
)
6162
parser.add_argument(
6263
"-i",

src/obfuscapk/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from obfuscapk.obfuscation import Obfuscation
99
from obfuscapk.obfuscator_manager import ObfuscatorManager
1010
from obfuscapk.tool import Apktool, Zipalign, ApkSigner
11+
from obfuscapk.toolbundledecompiler import BundleDecompiler
1112

1213
if "LOG_LEVEL" in os.environ:
1314
log_level = os.environ["LOG_LEVEL"]
@@ -38,6 +39,7 @@ def check_external_tool_dependencies():
3839
# an exception will be thrown by the corresponding constructor.
3940
logger.debug("Checking external tool dependencies")
4041
Apktool()
42+
BundleDecompiler()
4143
ApkSigner()
4244
Zipalign()
4345

0 commit comments

Comments
 (0)