Giter Club home page Giter Club logo

obfuscapk's Introduction

Important

From 17/01/2024, the Obfuscapk project is maintained by the other co-authors at https://github.com/Mobile-IoT-Security-Lab/Obfuscapk. Consider it as the new official Obfuscapk repository.

This repository is archived. Please don't contact me for support.

Some of the most common questions are answered in FAQ and troubleshooting.

Logo

A black-box obfuscation tool for Android apps.

Codacy Code Coverage Python Version License

Obfuscapk is a modular Python tool for obfuscating Android apps without needing their source code, since apktool is used to decompile the original apk file and to build a new application, after applying some obfuscation techniques on the decompiled smali code, resources and manifest. The obfuscated app retains the same functionality as the original one, but the differences under the hood sometimes make the new application very different from the original (e.g., to signature-based antivirus software).

๐Ÿ†• Android App Bundle support ๐Ÿ†•

Obfuscapk is adding support for Android App Bundles (aab files) by using BundleDecompiler (see #121). In order to use this new feature, download the latest version of BundleDecompiler available from here, save it as BundleDecompiler.jar in a directory included in PATH (e.g., in Ubuntu, /usr/local/bin or /usr/bin) and make sure it has the executable flag set.

Important

BundleDecompiler doesn't work on Windows yet, so app bundle obfuscation is not supported by Obfuscapk on Windows platform. Also, app bundle support is still in early development, so if you faced any problems or if you want to help us improve, please see contributing.

โฑ Publication

More details about Obfuscapk can be found in the paper "Obfuscapk: An open-source black-box obfuscation tool for Android apps". You can cite the paper as follows:

@article{aonzo2020obfuscapk,
    title = "Obfuscapk: An open-source black-box obfuscation tool for Android apps",
    journal = "SoftwareX",
    volume = "11",
    pages = "100403",
    year = "2020",
    issn = "2352-7110",
    doi = "https://doi.org/10.1016/j.softx.2020.100403",
    url = "https://www.sciencedirect.com/science/article/pii/S2352711019302791",
    author = "Simone Aonzo and Gabriel Claudiu Georgiu and Luca Verderame and Alessio Merlo",
    keywords = "Android, Obfuscation, Program analysis"
}

โฑ Demo

Demo

โฑ Architecture

Architecture

Obfuscapk is designed to be modular and easy to extend, so it's built using a plugin system. Consequently, every obfuscator is a plugin that inherits from an abstract base class and needs to implement the method obfuscate. When the tool starts processing a new Android application file, it creates an obfuscation object to store all the needed information (e.g., the location of the decompiled smali code) and the internal state of the operations (e.g., the list of already used obfuscators). Then the obfuscation object is passed, as a parameter to the obfuscate method, to all the active plugins/obfuscators (in sequence) to be processed and modified. The list and the order of the active plugins is specified through command line options.

The tool is easily extensible with new obfuscators: it's enough to add the source code implementing the obfuscation technique and the plugin metadata (a <obfuscator-name>.obfuscator file) in the src/obfuscapk/obfuscators directory (take a simple existing obfuscator like Nop as a starting example). The tool will detect automatically the new plugin, so no further configuration is needed (the new plugin will be treated like all the other plugins bundled with the tool).

โฑ Installation

There are two ways of getting a working copy of Obfuscapk on your own computer: either by using Docker or by using directly the source code in a Python 3 environment. In both cases, the first thing to do is to get a local copy of this repository, so open up a terminal in the directory where you want to save the project and clone the repository:

$ git clone https://github.com/ClaudiuGeorgiu/Obfuscapk.git

Docker image


Prerequisites

This is the suggested way of installing Obfuscapk, since the only requirement is to have a recent version of Docker installed:

$ docker --version
Docker version 20.10.21, build baeda1f

Official Docker Hub image

The official Obfuscapk Docker image is available on Docker Hub (automatically built from this repository):

$ # Download the Docker image.
$ docker pull claudiugeorgiu/obfuscapk
$ # Give it a shorter name.
$ docker tag claudiugeorgiu/obfuscapk obfuscapk

Install

If you downloaded the official image from Docker Hub, you are ready to use the tool so go ahead and check the usage instructions, otherwise execute the following command in the previously created Obfuscapk/src/ directory (the folder containing the Dockerfile) to build the Docker image:

$ # Make sure to run the command in Obfuscapk/src/ directory.
$ # It will take some time to download and install all the dependencies.
$ docker build -t obfuscapk .

When the Docker image is ready, make a quick test to check that everything was installed correctly:

$ docker run --rm -it obfuscapk --help
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB]
...

Obfuscapk is now ready to be used, see the usage instructions for more information.

From source


Prerequisites

Make sure to have a recent version of apktool, apksigner and zipalign installed and available from the command line:

$ apktool
Apktool v2.9.0 - a tool for reengineering Android apk files
...
$ apksigner
Usage:  apksigner <command> [options]
        apksigner --version
        apksigner --help
...
$ zipalign
Zip alignment utility
Copyright (C) 2009 The Android Open Source Project
...

To support app bundles obfuscation you also need BundleDecompiler, so download the latest available version from here, save it as BundleDecompiler.jar in a directory included in PATH (e.g., in Ubuntu, /usr/local/bin or /usr/bin) and make sure it has the executable flag set.

To use BundleDecompiler and apktool you also need a recent version of Java. zipalign and apksigner are included in the Android SDK. The location of the executables can also be specified through the following environment variables: APKTOOL_PATH, BUNDLE_DECOMPILER_PATH, APKSIGNER_PATH and ZIPALIGN_PATH (e.g., in Ubuntu, run export APKTOOL_PATH=/custom/location/apktool before running Obfuscapk in the same terminal).

Apart from the above tools, the only requirement of this project is a working Python 3 (at least 3.7) installation (along with its package manager pip).

Install

Run the following commands in the main directory of the project (Obfuscapk/) to install the needed dependencies:

$ # Make sure to run the commands in Obfuscapk/ directory.

$ # The usage of a virtual environment is highly recommended.
$ python3 -m venv venv
$ source venv/bin/activate

$ # Install Obfuscapk's requirements.
$ python3 -m pip install -r src/requirements.txt

After the requirements are installed, make a quick test to check that everything works correctly:

$ cd src/
$ # The following command has to be executed always from Obfuscapk/src/ directory
$ # or by adding Obfuscapk/src/ directory to PYTHONPATH environment variable.
$ python3 -m obfuscapk.cli --help
usage: python3 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB]
...

Obfuscapk is now ready to be used, see the usage instructions for more information.

โฑ Usage

From now on, Obfuscapk will be considered as an executable available as obfuscapk, so you need to adapt the commands according to how you installed the tool:

  • Docker image: a local directory containing the application to obfuscate has to be mounted to /workdir in the container (e.g., the current directory "${PWD}"), so the command:

    $ obfuscapk [params...]

    becomes:

    $ docker run --rm -it -u $(id -u):$(id -g) -v "${PWD}":"/workdir" obfuscapk [params...]
  • From source: every instruction has to be executed from the Obfuscapk/src/ directory (or by adding Obfuscapk/src/ directory to PYTHONPATH environment variable) and the command:

    $ obfuscapk [params...]

    becomes:

    $ python3 -m obfuscapk.cli [params...]

Let's start by looking at the help message:

$ obfuscapk --help
obfuscapk [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK_OR_AAB] [-i] [-p] [-k VT_API_KEY]
          [--keystore-file KEYSTORE_FILE] [--keystore-password KEYSTORE_PASSWORD]
          [--key-alias KEY_ALIAS] [--key-password KEY_PASSWORD] [--use-aapt2]
          <APK_OR_BUNDLE_FILE>

There are two mandatory parameters: <APK_OR_BUNDLE_FILE>, the path (relative or absolute) to the apk or app bundle file to obfuscate and the list with the names of the obfuscation techniques to apply (specified with a -o option that can be used multiple times, e.g., -o Rebuild -o NewAlignment -o NewSignature). The other optional arguments are as follows:

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

  • -d OUT_APK_OR_AAB is used to set the path of the destination file: the apk file generated by the obfuscation process (e.g., -d /home/user/Desktop/obfuscated.apk or -d /home/user/Desktop/obfuscated.aab). If not specified, the final obfuscated file will be saved inside the working directory. Note: existing files will be overwritten without any warning.

  • -i is a flag for ignoring known third party libraries during the obfuscation process, to use fewer resources, to increase performances and to reduce the risk of errors. The list of libraries to ignore is adapted from LiteRadar project.

  • -p is a flag for showing progress bars during the obfuscation operations. When using the tool in batch operations/automatic builds it's convenient to have progress bars disabled, otherwise this flag should be enabled to see the obfuscation progress.

  • -k VT_API_KEY is needed only when using VirusTotal obfuscator, to set the API key to be used when communicating with Virus Total.

  • --keystore-file KEYSTORE_FILE, --keystore-password KEYSTORE_PASSWORD, --key-alias KEY_ALIAS and --key-password KEY_PASSWORD can be used to specify a custom keystore (needed for the apk signing). If --keystore-file is used, --keystore-password and --key-alias must be specified too, while --key-password is needed only if the chosen key has a different password from the keystore password. By default (when --keystore-file is not specified), a keystore bundled with Obfuscapk is used for the signing operations.

  • --ignore-packages-file IGNORE_PACKAGES_FILE is a path to a file which includes package names to be ignored. All the classes inside those packages will not be obfuscated when this option is used. The file should have one package name per line as shown in the example below:

    com.mycompany.dontobfuscate
    com.mycompany.ignore
    ...
    
  • --use-aapt2 is a flag for using aapt2 option when rebuilding an app with apktool.

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

$ # original.apk is a valid Android apk file.
$ obfuscapk -o RandomManifest -o Rebuild -o NewAlignment -o NewSignature original.apk

When running the above command, this is what happens behind the scenes:

  • since no working directory was specified, a new working directory (obfuscation_working_dir) is created in the same location as original.apk (this can be useful to inspect the smali files/manifest/resources in case of errors)

  • some checks are performed to make sure that all the needed files/executables are available and ready to be used

  • the actual obfuscation process begins: the specified obfuscators are executed (in order) one by one until there's no obfuscator left or until an error is encountered

    • when running the first obfuscator, original.apk is decompiled with apktool and the results are stored into the working directory

    • since the first obfuscator is RandomManifest, the entries in the decompiled Android manifest are reordered randomly (without breaking the xml structures)

    • Rebuild obfuscator simply rebuilds the application (now with the modified manifest) using apktool, and since no output file was specified, the resulting apk file is saved in the working directory created before

    • NewAlignment obfuscator uses zipalign tool to align the resulting apk file

    • NewSignature obfuscator signs the newly created apk file with a custom certificate contained in a keystore bundled with Obfuscapk (though a different keystore can be specified with the --keystore-file parameter)

  • when all the obfuscators have been executed without errors, the resulting obfuscated apk file can be found in obfuscation_working_dir/original_obfuscated.apk, signed, aligned and ready to be installed into a device/emulator

As seen in the previous example, Rebuild, NewAlignment and NewSignature obfuscators are always needed to complete an obfuscation operation, to build the final obfuscated apk. They are not actual obfuscation techniques, but they are needed in the build process, so they are included in the list of obfuscators to keep the overall architecture modular.

Not working as expected? See FAQ and troubleshooting.

โฑ Obfuscators

The obfuscators included in Obfuscapk can be divided into different categories, depending on the operations they perform:

  • Trivial: as the name suggests, this category includes simple operations (that do not modify much the original application), like signing the apk file with a new signature.

  • Rename: operations that change the names of the used identifiers (classes, fields, methods).

  • Encryption: packaging encrypted code/resources and decrypting them during the app execution. When Obfuscapk starts, it automatically generates a random secret key (32 characters long, using ASCII letters and digits) that will be used for encryption.

  • Code: all the operations that involve the modification of the decompiled source code.

  • Resources: operations on the resource files (like modifying the manifest).

  • Other

The obfuscators currently bundled with Obfuscapk are briefly presented below (in alphabetical order). Please refer to the source code of the project for more details.

Tip

Not all the obfuscators below correspond to real obfuscation techniques (e.g., Rebuild, NewAlignment, NewSignature and VirusTotal), but they are implemented as obfuscators to keep the architecture modular and easy to extend with new functionality.

AdvancedReflection [Code]

Uses reflection to invoke dangerous APIs of the Android Framework. To find out if a method belongs to the Android Framework, Obfuscapk refers to the mapping discovered by Backes et al.
๐Ÿ“„ AdvancedReflection source code

ArithmeticBranch [Code]

Insert junk code. In this case, the junk code is composed by arithmetic computations and a branch instruction depending on the result of these computations, crafted in such a way that the branch is never taken.
๐Ÿ“„ ArithmeticBranch source code

AssetEncryption [Encryption]

Encrypt asset files.
๐Ÿ“„ AssetEncryption source code

CallIndirection [Code]

This technique modifies the control-flow graph without impacting the code semantics: it adds new methods that invoke the original ones. For example, an invocation to the method m1 will be substituted by a new wrapper method m2, that, when invoked, it calls the original method m1.
๐Ÿ“„ CallIndirection source code

ClassRename [Rename]

Change the package name and rename classes (even in the manifest file).
๐Ÿ“„ ClassRename source code

ConstStringEncryption [Encryption]

Encrypt constant strings in code.
๐Ÿ“„ ConstStringEncryption source code

DebugRemoval [Code]

Remove debug information.
๐Ÿ“„ DebugRemoval source code

FieldRename [Rename]

Rename fields.
๐Ÿ“„ FieldRename source code

Goto [Code]

Given a method, it inserts a goto instruction pointing to the end of the method and another goto pointing to the instruction after the first goto; it modifies the control-flow graph by adding two new nodes.
๐Ÿ“„ Goto source code

LibEncryption [Encryption]

Encrypt native libs.
๐Ÿ“„ LibEncryption source code

MethodOverload [Code]

It exploits the overloading feature of the Java programming language to assign the same name to different methods but using different arguments. Given an already existing method, this technique creates a new void method with the same name and arguments, but it also adds new random arguments. Then, the body of the new method is filled with random arithmetic instructions.
๐Ÿ“„ MethodOverload source code

MethodRename [Rename]

Rename methods.
๐Ÿ“„ MethodRename source code

NewAlignment [Trivial]

Realign the application.
๐Ÿ“„ NewAlignment source code

NewSignature [Trivial]

Re-sign the application with a new custom signature.
๐Ÿ“„ NewSignature source code

Nop [Code]

Insert junk code. Nop, short for no-operation, is a dedicated instruction that does nothing. This technique just inserts random nop instructions within every method implementation.
๐Ÿ“„ Nop source code

RandomManifest [Resource]

Randomly reorder entries in the manifest file.
๐Ÿ“„ RandomManifest source code

Rebuild [Trivial]

Rebuild the application.
๐Ÿ“„ Rebuild source code

Reflection [Code]

This technique analyzes the existing code looking for method invocations of the app, ignoring the calls to the Android framework (see AdvancedReflection). If it finds an instruction with a suitable method invocation (i.e., no constructor methods, public visibility, enough free registers etc.) such invocation is redirected to a custom method that will invoke the original method using the Reflection APIs.
๐Ÿ“„ Reflection source code

Reorder [Code]

This technique consists of changing the order of basic blocks in the code. When a branch instruction is found, the condition is inverted (e.g., branch if lower than, becomes branch if greater or equal than) and the target basic blocks are reordered accordingly. Furthermore, it also randomly re-arranges the code abusing goto instructions.
๐Ÿ“„ Reorder source code

ResStringEncryption [Encryption]

Encrypt strings in resources (only those called inside code).
๐Ÿ“„ ResStringEncryption source code

VirusTotal [Other]

Send the original and the obfuscated application to Virus Total. You must provide the VT API key (see -k option).
๐Ÿ“„ VirusTotal source code

โฑ License

You are free to use this code under the MIT License.

โฑ Credits

Unige Dibris

This software was developed for research purposes at the Computer Security Lab (CSecLab), hosted at DIBRIS, University of Genoa.

โฑ Team

obfuscapk's People

Contributors

ardalanforoughipour avatar claudiugeorgiu avatar dado1513 avatar elyorbe avatar kiber-io avatar liujiangshan avatar mirsamantajbakhsh avatar packmad avatar techee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obfuscapk's Issues

Problem with a "NewAlignment"

Hello there! I tryed use your obfuscator, but I receive some problem. I run configuration
"python -m obfuscapk.cli -i -p -o RandomManifest -o ArithmeticBranch -o AdvancedReflection -o Reflection -o FieldRename -o ConstStringEncryption -o ResStringEncryption -o DebugRemoval -o Goto -o Rebuild -o Reorder -o NewSignature -o NewAlignment 1.apk"
After some minutes i look at process and I found that the process is frozen! Just at the moment "NewAlignment".W
problem
aiting didn't help me :(
What might be the problem?

Can't use print method to show debug log.

Hi,
I have modify some part of code, and i try to add some print to debug somethings, but it did't show anything. Did you add any code to prevent show print log to console?

Example:

  • On class_rename.py
  • I try to add print method to this:
 def encrypt_identifier(self, identifier: str) -> str:
        identifier_md5 = util.get_string_md5(identifier)
        result = 'p{0}'.format(identifier_md5.lower()[:16])
        print("Class name: " + result)
        return result
  • But it did't show anything on console.

Bundle Support

Will it support Android Application Bundle (.aab) in the following ?

AdvancedReflection Does Not Seem to Work

Hi Obfuscapk team - you have a nice obfuscation and I am glad for the documentation. It was easy to get to run.

I tried a bunch of different obfuscation configs and most work. However, I ran around 20 apps through using the AdvancedReflection arg only and not one of them created a new obfuscated app (but it did for other config options so I know Obfuscapk can handle the apps).

Any thoughts?

Obfuscate ClassName not change name class on another script under another packagename by Ignore Option

Hi, i have quick modified Ignore option. Now it will only obfuscate some list on resources\libs_to_ignore.txt instead of ignore it. I think it is better include than ignore, so i only add package i need to obfuscate.

Code:

# Get only the smali files that are part of known thirdparty libraries.
if any(
	relative_smali_file.startswith(lib)
	for lib in libs_to_ignore
):
	filtered_smali_files.append(smali_file)

Steps:

1/ My goal is obfuscate all class under this package name: "com.myclass.ads"

2/ Use Obfuscapk success.

3/ But after success obfuscate and rebuild, my app crash. When i decompile code and check it i saw:

  • It is obfuscated all class under my package "com.myclass.ads".
  • "com.myclass.ads" name have been change to "p4d236d9a.pf0f21d36.pa102906f"
  • It trigger error when crash: Didn't find class "com.myclass.ads.Models.AdConfigs" on path: DexPathList.

Reason:

On another script, my "com.myclass.ads" classes is not change. On my MainActivity, under another package, it is still remaining package:
"com.myclass.ads"

So did i miss something? Did i need to modify anything to make it work? To Include than Ignore
Thanks!

Error during decode command

root@localhost:/home/kali/Obfuscapk/src# python3.7 -m obfuscapk.cli -o RandomManifest -o Rebuild -o NewSignature -o NewAlignment fud.apk
04/04/2020 11:36:41> [ERROR][obfuscapk.tool.Apktool][decode()] Error during decode command: I: Using Apktool 2.2.3 on fud.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /root/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':1.0' as the value of the DISPLAY variable.
at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:102)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:61)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:101)
at java.desktop/java.awt.GraphicsEnvironment$LocalGE.(GraphicsEnvironment.java:83)
at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:129)
at java.desktop/java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1181)
at brut.androlib.res.decoder.Res9patchStreamDecoder.decode(Res9patchStreamDecoder.java:60)
at brut.androlib.res.decoder.ResStreamDecoderContainer.decode(ResStreamDecoderContainer.java:33)
at brut.androlib.res.decoder.ResFileDecoder.decode(ResFileDecoder.java:120)
at brut.androlib.res.decoder.ResFileDecoder.decode(ResFileDecoder.java:87)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:263)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:132)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:115)
at brut.apktool.Main.cmdDecode(Main.java:166)
at brut.apktool.Main.main(Main.java:81)

04/04/2020 11:36:41> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: Command '['apktool', 'd', '--force', 'fud.apk', '-o', 'obfuscation_working_dir/fud']' returned non-zero exit status 1.
04/04/2020 11:36:41> [ERROR][yapsy_loaded_plugin_RandomManifest_1.random_manifest.RandomManifest][obfuscate()] Error during execution of "RandomManifest" obfuscator: Command '['apktool', 'd', '--force', 'fud.apk', '-o', 'obfuscation_working_dir/fud']' returned non-zero exit status 1.
04/04/2020 11:36:41> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['apktool', 'd', '--force', 'fud.apk', '-o', 'obfuscation_working_dir/fud']' returned non-zero exit status 1.
Traceback (most recent call last):
File "/home/kali/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscators/random_manifest/random_manifest.py", line 108, in obfuscate
manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscation.py", line 439, in get_manifest_file
self.decode_apk()
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscation.py", line 276, in decode_apk
apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
File "/home/kali/Obfuscapk/src/obfuscapk/tool.py", line 61, in decode
output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
File "/usr/local/lib/python3.7/subprocess.py", line 376, in check_output
**kwargs).stdout
File "/usr/local/lib/python3.7/subprocess.py", line 468, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'd', '--force', 'fud.apk', '-o', 'obfuscation_working_dir/fud']' returned non-zero exit status 1.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/kali/Obfuscapk/src/obfuscapk/cli.py", line 81, in
arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
File "/home/kali/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscators/random_manifest/random_manifest.py", line 108, in obfuscate
manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscation.py", line 439, in get_manifest_file
self.decode_apk()
File "/home/kali/Obfuscapk/src/obfuscapk/obfuscation.py", line 276, in decode_apk
apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
File "/home/kali/Obfuscapk/src/obfuscapk/tool.py", line 61, in decode
output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
File "/usr/local/lib/python3.7/subprocess.py", line 376, in check_output
**kwargs).stdout
File "/usr/local/lib/python3.7/subprocess.py", line 468, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'd', '--force', 'fud.apk', '-o', 'obfuscation_working_dir/fud'

Request more Resource Obfuscate

Hi,
Nowadays, i saw many app have steal resources like drawables, animations, layout from another app then modify and make it for themself. I think Resource Obfuscate is very best to prevent this situation.
Currently Obfusapk have only 1 Resource Obfuscate type "RandomManifest", i think it will need more type to make stronger obfuscate like:

  • XML Layouts
  • XML Values
  • Drawables
  • Animations
  • Menus

Every type above can use tech like Encrypt - Rename - ReOrder - Insert Junk to make it unique and obfuscated.

Obfuscator Rename generate same name everytime

Hi,
After use ClassRename, i have found some bugs(maybe not):

Steps:

  • Try to Obfuscate use RenameClass
  • Result 1 : p4d236d9a.pc5e83bf4
  • Result 2: p4d236d9a.pc5e83bf4
  • Result 3: p4d236d9a.pc5e83bf4

Class renamed always be the same as many times i try to obfuscate. If it is not a bug, how can i have different results every time?

Use Obfusapk but i still can open with JarDx and look inside dex file

Hi,
I'm using Obfusapk to obfuscate my apk, but after use all of this commands:
python -m obfuscapk.cli -o LibEncryption -o ResStringEncryption -o AssetEncryption -o ConstStringEncryption -o Rebuild -o NewAlignment -o NewSignature input.apk

New APK is still open and view code like normal with JarDX tools. Is this normal?
Because i thought encryption is encrypt dex file, so nobody can normaly open it and view anycode of mine.

i am getting this error

usage: python3.7 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR]
[-d OUT_APK] [-i] [-p] [-k VT_API_KEY]
<APK_FILE>
python3.7 -m obfuscapk.cli: error: argument -p/--show-progress: ignored explicit argument '-w'

Obfuscate Ionic apk

Hi, I trying used this tool for obfuscate ionic app (.apk) in multiple attempts with differences Obfuscator but the result its the same, apk never is installed.

I using docker mode.

any recommendation for my case?

MethodRename not working?

Hello, i wrote a simple code to see how renaming works
photo_2020-08-18_16-13-56
Collected apk file and launched obfuscation with the following parameters
photo_2020-08-18_16-16-49
as for renaming fields, it worked well. But with renaming methods, something is wrong
photo_2020-08-18_16-18-12

Add option for "--use-aapt2" when build with apktool

Is this feature request related to a problem?

Yes, I was facing an error when build the new apk. And I found this:
iBotPeaches/Apktool#1978

Proposed solution

I manually change the code in tool.py
build_cmd: List[str] = [self.apktool_path, "b", "--force-all", source_dir_path]
to
build_cmd: List[str] = [self.apktool_path, "b", "--force-all", "--use-aapt2", source_dir_path]

However, I think it will be better to add an option to toggle.

Additional context

Noooo

Would you like to submit a pull request for this feature?

I am lazy :P

Btw, Nice work! Hope more people can enjoy this in future. Star is a must!

Not working in Windows (getting the system cannot find the file specified)

# python -m obfuscapk.cli -o RandomManifest -o Rebuild -o NewSignature -o NewAlignment H:\PROJECTS\Android\MemoApp\app\release\app-release.apk
04/01/2020 21:49:20> [ERROR][obfuscapk.tool.Apktool][decode()] Error during decoding: [WinError 2] The system cannot find the file specified
04/01/2020 21:49:20> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: [WinError 2] The system cannot find the file specified
04/01/2020 21:49:20> [ERROR][yapsy_loaded_plugin_RandomManifest_1.random_manifest.RandomManifest][obfuscate()] Error during execution of "RandomManifest" obfuscator: [WinError 2] The system cannot find the file specified
04/01/2020 21:49:20> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Opt\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscators\random_manifest\random_manifest.py", line 108, in obfuscate
    manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscation.py", line 439, in get_manifest_file
    self.decode_apk()
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "C:\Opt\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 488, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Opt\Obfuscapk\src\obfuscapk\cli.py", line 81, in <module>
    arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
  File "C:\Opt\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscators\random_manifest\random_manifest.py", line 108, in obfuscate
    manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscation.py", line 439, in get_manifest_file
    self.decode_apk()
  File "C:\Opt\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "C:\Opt\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 488, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

GoTo Implementation

This is a general question about the GoTo obfuscation. I understand what it does, adding the two new nodes at the beginning and end of methods. I have a couple questions:

  1. Have you considered a more complex application of goto? That is, adding gotos within the body of the methods themselves. My guess is you would need to understand the control flow of the method from beginning to end and then calculate where and how an acceptable goto may be introduced. Which would require a complex algorithm and really
    difficult to introduce in looping constructs.

  2. Second, the goto introduced is at the byte code level. So, I just wanted to verify that its not problematic to introduce a goto into the method body as part of the obfuscation process. I would think there is no reason it would be a problem but wanted to double check.

Thanks!

Justin

Play store and Stacktrace ?

This looks like a terrific project.

My questions relate to the Play Store submission and also obtaining a Stacktrace from users.

a)
will the resulting APK be accepted by Google / Play ?

b)
is it still possible after applying this to the APK to obtain the usual Stacktrace back if an app crashes ?

For both the above, particularly though b) is there any documentation explaining how to do so.

Thanks

ResStringEncryption improvement

Hi,
I tested sample apk with ResStringEncryption option. It works with only resource strings which are read using String type. If StringBuilder or StringBuffer type used for reading, resource string is ignored.

Proposed solution

Add StringBuilder and StringBuffer checking for ResStringEncryption obfuscator

Additional context

Ljava/lang/StringBuilder and Ljava/lang/StringBuffer options can be added for regex pattern checking

load_string_res_pattern = re.compile(
r"\s+invoke-virtual\s"
r"{[vp0-9]+,\s(?P<param_register>[vp0-9]+)},\s"
r"(Landroid/content/res/Resources;->getString\(I\)Ljava/lang/String;"
r"|Landroid/content/Context;->getString\(I\)Ljava/lang/String;)"
)
load_string_array_res_pattern = re.compile(
r"\s+invoke-virtual\s"
r"{[vp0-9]+,\s(?P<param_register>[vp0-9]+)},\s"
r"Landroid/content/res/Resources;->"
r"getStringArray\(I\)\[Ljava/lang/String;"
)

Would you like to submit a pull request for this feature?

Yes

does it support kotlin?

I know it tries to obfuscate smali code and probably it doesn't matter if the source code is in java or kotlin but i get this error after obfuscating kotlin which leads to crashing!

java.lang.VerifyError: Verifier rejected class kotlin.text.StringsKt__StringsKt: kotlin.sequences.Sequence kotlin.text.StringsKt__StringsKt.lineSequence(java.lang.CharSequence) failed to verify: kotlin.sequences.Sequence kotlin.text.StringsKt__StringsKt.lineSequence(java.lang.CharSequence): [0x17] copyRes1 v4<- result0 type=Undefined (declaration of 'kotlin.text.StringsKt__StringsKt' appears in /data/app/com.willowdev.jniexample-y8XwLqPySLWXJYecEY6H0A==/base.apk)
at kotlin.text.StringsKt__StringsKt.removePrefix(Unknown Source:0)

ResStringEncryption plugin has not worked correctly

Prerequisites

Before opening this issue, I tried the following steps:

Description

I have tried "ResStringEncryption" plugin and checked the resource string. The tool did not encrypted the content.

Steps to Reproduce

  1. python3.7 -m obfuscapk.cli -i -o ResStringEncryption -o Rebuild
  2. Decompile APK and check string resource
  3. The content is not encrypted as expected

Expected behavior:
The resource string/string atrray should be encrpted

Actual behavior:
They are still plain text

if applicable, paste here the complete error message

Versions

  • Installation mode Source
  • Obufscapk version Lastest
  • OS (e.g., Ubuntu 16.04): Mac 10.14
  • Python version (e.g., Python 3.7.4): 3.7.4

Additional Information

Apk file(s):

APK won't load

Couple of obfuscated APKs that I tried installing on a phone fail to install.
Install just silently quits w/o any message.
I tried looking at the Manifest files created in working directory, and get a parsing error:
XML Parsing Error: not well-formed
Both in the build and original directories; they both are created by APKTool, right?
Any ideas how to trace the problem?
Thanks

more detail:
Manifest won't show in Explorer at all, and opening withNotepad shows it's full of binary chars along with normal entries.
Here is first few lines:
๏ฟฝ ๏ฟฝ รœ
๏ฟฝ ๏ฟฝ รฌ๏ฟฝ 2 รค ๏ฟฝ 4 Z ๏ฟฝ ยฎ ร’ รž รถ ๏ฟฝ๏ฟฝ ๏ฟฝ๏ฟฝ (๏ฟฝ <๏ฟฝ P๏ฟฝ ^๏ฟฝ p๏ฟฝ รˆ๏ฟฝ รŒ๏ฟฝ รž๏ฟฝ ๏ฟฝ๏ฟฝ F๏ฟฝ Z๏ฟฝ ลพ๏ฟฝ ยฆ๏ฟฝ ร‚๏ฟฝ ร”๏ฟฝ รฎ๏ฟฝ ๏ฟฝ๏ฟฝ $๏ฟฝ ^๏ฟฝ x๏ฟฝ ยฐ๏ฟฝ ร‚๏ฟฝ รผ๏ฟฝ *๏ฟฝ p๏ฟฝ ลฝ๏ฟฝ ลพ๏ฟฝ รถ๏ฟฝ ๏ฟฝ B๏ฟฝ V๏ฟฝ ลฝ๏ฟฝ ร€๏ฟฝ รฌ๏ฟฝ ๏ฟฝ๏ฟฝ R๏ฟฝ f๏ฟฝ ยช๏ฟฝ ร†๏ฟฝ ๏ฟฝ v e r s i o n C o d e ๏ฟฝ v e r s i o n N a m e ๏ฟฝ c o m p i l e S d k V e r s i o n ๏ฟฝ c o m p i l e S d k V e r s i o n C o d e n a m e
m i n S d k V e r s i o n ๏ฟฝ t a r g e t S d k V e r s i o n ๏ฟฝ n a m e
d e b u g g a b l e

No module named 'tqdm' on Ubuntu 18.04

Hello,
I am trying to install this on my machine following the instructions provided on this repository. All installation from src/requirements.txt succeed

But when trying to execute python3.7 -m obfuscapk.cli --help, it threw the error below

secret@secret:~/penetration_testing/android/Obfuscapk/src$ python3.7 -m obfuscapk.cli --help
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/cli.py", line 7, in
from .main import perform_obfuscation, check_external_tool_dependencies
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/main.py", line 9, in
from . import util
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/util.py", line 14, in
from tqdm import tqdm
ModuleNotFoundError: No module named 'tqdm'

is Android JNI supported?

I have a native code app that calls methods by reflection, It is supported or it will crash in some cases?
Thank you for your efforts

Error during apk decoding

Steps to Reproduce

  1. git clone https://github.com/ClaudiuGeorgiu/Obfuscapk.git
  2. python3.7 -m pip install -r src/requirements.txt
  3. cd src/
  4. python3.7 -m obfuscapk.cli --help (shows help as expected)
  5. obfuscapk -o RandomManifest -o Rebuild -o NewSignature -o NewAlignment original.apk

Expected behavior:

The obsfuscation should decompile and obfuscate code and then it should compile and sign the apk

Actual behavior:

After running the command it starts to decompile apk and then throws an error, working directory is empty with just folder name

if applicable, paste here the complete error message

root@kali:~/Obfuscapk/src# python3.7 -m obfuscapk.cli -o Rebuild -o NewAlignment --ignore-libs  original.apk 
01/04/2020 15:17:24> [ERROR][obfuscapk.tool.Apktool][decode()] Error during decode command: I: Using Apktool 2.4.0 on original.apk
Exception in thread "main" brut.androlib.AndrolibException: brut.directory.DirectoryException: java.util.zip.ZipException: zip file is empty
	at brut.androlib.ApkDecoder.hasResources(ApkDecoder.java:307)
	at brut.androlib.ApkDecoder.decode(ApkDecoder.java:103)
	at brut.apktool.Main.cmdDecode(Main.java:167)
	at brut.apktool.Main.main(Main.java:76)
Caused by: brut.directory.DirectoryException: java.util.zip.ZipException: zip file is empty
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:55)
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:38)
	at brut.directory.ExtFile.getDirectory(ExtFile.java:52)
	at brut.androlib.ApkDecoder.hasResources(ApkDecoder.java:305)
	... 3 more
Caused by: java.util.zip.ZipException: zip file is empty
	at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1529)
	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1343)
	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1437)
	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1268)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1231)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:726)
	at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:843)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:246)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:176)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:190)
	at brut.directory.ZipRODirectory.<init>(ZipRODirectory.java:53)
	... 6 more

01/04/2020 15:17:24> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: Command '['apktool', 'd', '--force', 'original.apk', '-o', 'obfuscation_working_dir/original']' returned non-zero exit status 1.
01/04/2020 15:17:24> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['apktool', 'd', '--force', 'original.apk', '-o', 'obfuscation_working_dir/original']' returned non-zero exit status 1.
01/04/2020 15:17:24> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['apktool', 'd', '--force', 'original.apk', '-o', 'obfuscation_working_dir/original']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/root/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/root/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 390, in build_obfuscated_apk
    self.decode_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "/root/Obfuscapk/src/obfuscapk/tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "/usr/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'd', '--force', 'original.apk', '-o', 'obfuscation_working_dir/original']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/Obfuscapk/src/obfuscapk/cli.py", line 81, in <module>
    arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
  File "/root/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/root/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 390, in build_obfuscated_apk
    self.decode_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "/root/Obfuscapk/src/obfuscapk/tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "/usr/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'd', '--force', 'original.apk', '-o', 'obfuscation_working_dir/original']' returned non-zero exit status 1.

Versions

  • Installation mode (from source code):
  • Obufscapk version (commit 3adbf7b):
  • OS (Kali linux 2019-1):
  • Python version (Python 3.7.7):

Additional Information

i also used apktool_fix_kali_2019 script to make sure its not apktool problem
i also tried to decompile the same apk directly with apktool d original.apk, it works as expected
i also tried with different apk, the problem persist
its a metasploit payload with local ip for testing in LAN

apk file
original.zip

Error during build command

Prerequisites

Before opening this issue, I tried the following steps:

  • Installed the tool in a way described in the readme and ran python3 -m obfuscapk.cli --help without any errors

  • Ran the tool using only Rebuild, NewSignature and NewAlignment obfuscators to verify that the app is not using anti-repackaging techniques

  • Ran the tool using --ignore-libs flag to exclude third party libraries from the obfuscation

  • Checked FAQ and troubleshooting

  • Checked for existing similar issues on GitHub

Steps to reproduce

(env) root@kali:~/Obfuscapk/src# python3 -m obfuscapk.cli \
> -p \
> -w ~/Desktop/working-dir/ \
> -d ~/Desktop/obfuscated.apk \
> -o ConstStringEncryption -o Nop -o Goto -o RandomManifest -o Rebuild -o NewSignature -o NewAlignment \
> ~/Desktop/olya.apk
Encrypting constant strings: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[00:00<00:00, 420.48file/s]
Inserting "nop" instructions in smali files: 100%|โ–ˆโ–ˆโ–ˆโ–ˆ|[00:00<00:00, 321.92file/s]
Inserting "goto" instructions in smali files: 100%|โ–ˆโ–ˆโ–ˆ|[00:00<00:00, 576.21file/s]
Running obfuscators (Rebuild):  14%|โ–ˆโ–Š           |[00:13<01:23, 13.89s/obfuscator]21/05/2020 02:03:23> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
I: Using Apktool 2.2.3
I: Smaling smali folder into classes.dex...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 2): [aapt, p, --forced-package-id, 127, --min-sdk-version, 10, --target-sdk-version, 17, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, /tmp/APKTOOL4273073544497306388.tmp, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /root/Desktop/working-dir/olya/res, -M, /root/Desktop/working-dir/olya/AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:493)
        at brut.androlib.Androlib.buildResources(Androlib.java:427)
        at brut.androlib.Androlib.build(Androlib.java:326)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:231)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 2): [aapt, p, --forced-package-id, 127, --min-sdk-version, 10, --target-sdk-version, 17, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, /tmp/APKTOOL4273073544497306388.tmp, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /root/Desktop/working-dir/olya/res, -M, /root/Desktop/working-dir/olya/AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:441)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:479)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 2): [aapt, p, --forced-package-id, 127, --min-sdk-version, 10, --target-sdk-version, 17, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, /tmp/APKTOOL4273073544497306388.tmp, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /root/Desktop/working-dir/olya/res, -M, /root/Desktop/working-dir/olya/AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:435)
        ... 6 more
W: ERROR: Unknown option '--forced-package-id'
W: Android Asset Packaging Tool
W: 
W: Usage:
W:  aapt l[ist] [-v] [-a] file.{zip,jar,apk}
W:    List contents of Zip-compatible archive.
W: 
W:  aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]]
W:    strings          Print the contents of the resource table string pool in the APK.
W:    badging          Print the label and icon for the app declared in APK.
W:    permissions      Print the permissions from the APK.
W:    resources        Print the resource table from the APK.
W:    configurations   Print the configurations in the APK.
W:    xmltree          Print the compiled xmls in the given assets.
W:    xmlstrings       Print the strings of the given compiled xml assets.
W: 
W:  aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \
W:         [-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \
W:         [--debug-mode] [--min-sdk-version VAL] [--target-sdk-version VAL] \
W:         [--app-version VAL] [--app-version-name TEXT] [--custom-package VAL] \
W:         [--rename-manifest-package PACKAGE] \
W:         [--rename-instrumentation-target-package PACKAGE] \
W:         [--utf16] [--auto-add-overlay] \
W:         [--max-res-version VAL] \
W:         [-I base-package [-I base-package ...]] \
W:         [-A asset-source-dir]  [-G class-list-file] [-P public-definitions-file] \
W:         [-D main-dex-class-list-file] \
W:         [-S resource-sources [-S resource-sources ...]] \
W:         [-F apk-file] [-J R-file-dir] \
W:         [--product product1,product2,...] \
W:         [-c CONFIGS] [--preferred-density DENSITY] \
W:         [--split CONFIGS [--split CONFIGS]] \
W:         [--feature-of package [--feature-after package]] \
W:         [raw-files-dir [raw-files-dir] ...] \
W:         [--output-text-symbols DIR]
W: 
W:    Package the android resources.  It will read assets and resources that are
W:    supplied with the -M -A -S or raw-files-dir arguments.  The -J -P -F and -R
W:    options control which files are output.
W: 
W:  aapt r[emove] [-v] file.{zip,jar,apk} file1 [file2 ...]
W:    Delete specified files from Zip-compatible archive.
W: 
W:  aapt a[dd] [-v] file.{zip,jar,apk} file1 [file2 ...]
W:    Add specified files to Zip-compatible archive.
W: 
W:  aapt c[runch] [-v] -S resource-sources ... -C output-folder ...
W:    Do PNG preprocessing on one or several resource folders
W:    and store the results in the output folder.
W: 
W:  aapt s[ingleCrunch] [-v] -i input-file -o outputfile
W:    Do PNG preprocessing on a single file.
W: 
W:  aapt v[ersion]
W:    Print program version.
W: 
W:  Modifiers:
W:    -a  print Android-specific data (resources, manifest) when listing
W:    -c  specify which configurations to include.  The default is all
W:        configurations.  The value of the parameter should be a comma
W:        separated list of configuration values.  Locales should be specified
W:        as either a language or language-region pair.  Some examples:
W:             en
W:             port,en
W:             port,land,en_US
W:    -d  one or more device assets to include, separated by commas
W:    -f  force overwrite of existing files
W:    -g  specify a pixel tolerance to force images to grayscale, default 0
W:    -j  specify a jar or zip file containing classes to include
W:    -k  junk path of file(s) added
W:    -m  make package directories under location specified by -J
W:    -u  update existing packages (add new, replace older, remove deleted files)
W:    -v  verbose output
W:    -x  create extending (non-application) resource IDs
W:    -z  require localization of resource attributes marked with
W:        localization="suggested"
W:    -A  additional directory in which to find raw asset files
W:    -G  A file to output proguard options into.
W:    -D  A file to output proguard options for the main dex into.
W:    -F  specify the apk file to output
W:    -I  add an existing package to base include set
W:    -J  specify where to output R.java resource constant definitions
W:    -M  specify full path to AndroidManifest.xml to include in zip
W:    -P  specify where to output public resource definitions
W:    -S  directory in which to find resources.  Multiple directories will be scanned
W:        and the first match found (left to right) will take precedence.
W:    -0  specifies an additional extension for which such files will not
W:        be stored compressed in the .apk.  An empty string means to not
W:        compress any files at all.
W:    --debug-mode
W:        inserts android:debuggable="true" in to the application node of the
W:        manifest, making the application debuggable even on production devices.
W:    --include-meta-data
W:        when used with "dump badging" also includes meta-data tags.
W:    --pseudo-localize
W:        generate resources for pseudo-locales (en-XA and ar-XB).
W:    --min-sdk-version
W:        inserts android:minSdkVersion in to manifest.  If the version is 7 or
W:        higher, the default encoding for resources will be in UTF-8.
W:    --target-sdk-version
W:        inserts android:targetSdkVersion in to manifest.
W:    --max-res-version
W:        ignores versioned resource directories above the given value.
W:    --values
W:        when used with "dump resources" also includes resource values.
W:    --version-code
W:        inserts android:versionCode in to manifest.
W:    --version-name
W:        inserts android:versionName in to manifest.
W:    --replace-version
W:        If --version-code and/or --version-name are specified, these
W:        values will replace any value already in the manifest. By
W:        default, nothing is changed if the manifest already defines
W:        these attributes.
W:    --custom-package
W:        generates R.java into a different package.
W:    --extra-packages
W:        generate R.java for libraries. Separate libraries with ':'.
W:    --generate-dependencies
W:        generate dependency files in the same directories for R.java and resource package
W:    --auto-add-overlay
W:        Automatically add resources that are only in overlays.
W:    --preferred-density
W:        Specifies a preference for a particular density. Resources that do not
W:        match this density and have variants that are a closer match are removed.
W:    --split
W:        Builds a separate split APK for the configurations listed. This can
W:        be loaded alongside the base APK at runtime.
W:    --feature-of
W:        Builds a split APK that is a feature of the apk specified here. Resources
W:        in the base APK can be referenced from the the feature APK.
W:    --feature-after
W:        An app can have multiple Feature Split APKs which must be totally ordered.
W:        If --feature-of is specified, this flag specifies which Feature Split APK
W:        comes before this one. The first Feature Split APK should not define
W:        anything here.
W:    --rename-manifest-package
W:        Rewrite the manifest so that its package name is the package name
W:        given here.  Relative class names (for example .Foo) will be
W:        changed to absolute names with the old package so that the code
W:        does not need to change.
W:    --rename-instrumentation-target-package
W:        Rewrite the manifest so that all of its instrumentation
W:        components target the given package.  Useful when used in
W:        conjunction with --rename-manifest-package to fix tests against
W:        a package that has been renamed.
W:    --product
W:        Specifies which variant to choose for strings that have
W:        product variants
W:    --utf16
W:        changes default encoding for resources to UTF-16.  Only useful when API
W:        level is set to 7 or higher where the default encoding is UTF-8.
W:    --non-constant-id
W:        Make the resources ID non constant. This is required to make an R java class
W:        that does not contain the final value but is used to make reusable compiled
W:        libraries that need to access resources.
W:    --shared-lib
W:        Make a shared library resource package that can be loaded by an application
W:        at runtime to access the libraries resources. Implies --non-constant-id.
W:    --app-as-shared-lib
W:        Make an app resource package that also can be loaded as shared library at runtime.
W:        Implies --non-constant-id.
W:    --error-on-failed-insert
W:        Forces aapt to return an error if it fails to insert values into the manifest
W:        with --debug-mode, --min-sdk-version, --target-sdk-version --version-code
W:        and --version-name.
W:        Insertion typically fails if the manifest already defines the attribute.
W:    --error-on-missing-config-entry
W:        Forces aapt to return an error if it fails to find an entry for a configuration.
W:    --output-text-symbols
W:        Generates a text file containing the resource symbols of the R class in the
W:        specified folder.
W:    --ignore-assets
W:        Assets to be ignored. Default pattern is:
W:        !.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~
W:    --skip-symbols-without-default-localization
W:        Prevents symbols from being generated for strings that do not have a default
W:        localization
W:    --no-version-vectors
W:        Do not automatically generate versioned copies of vector XML resources.
W:    --no-version-transitions
W:        Do not automatically generate versioned copies of transition XML resources.
W:    --private-symbols
W:        Java package name to use when generating R.java for private resources.

21/05/2020 02:03:23> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/root/Desktop/working-dir/olya', '-o', '/root/Desktop/obfuscated.apk']' returned non-zero exit status 1.
21/05/2020 02:03:23> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/root/Desktop/working-dir/olya', '-o', '/root/Desktop/obfuscated.apk']' returned non-zero exit status 1.
21/05/2020 02:03:23> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/root/Desktop/working-dir/olya', '-o', '/root/Desktop/obfuscated.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/root/Obfuscapk/src/obfuscapk/main.py", line 119, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/root/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 494, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/root/Obfuscapk/src/obfuscapk/tool.py", line 153, in build
    output = subprocess.check_output(
  File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/root/Desktop/working-dir/olya', '-o', '/root/Desktop/obfuscated.apk']' returned non-zero exit status 1.
Running obfuscators (Rebuild):  57%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–     |[00:14<00:11,  3.74s/obfuscator]
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/root/Obfuscapk/src/obfuscapk/cli.py", line 133, in <module>
    main()
  File "/root/Obfuscapk/src/obfuscapk/cli.py", line 121, in main
    perform_obfuscation(
  File "/root/Obfuscapk/src/obfuscapk/main.py", line 119, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/root/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/root/Obfuscapk/src/obfuscapk/obfuscation.py", line 494, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/root/Obfuscapk/src/obfuscapk/tool.py", line 153, in build
    output = subprocess.check_output(
  File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/root/Desktop/working-dir/olya', '-o', '/root/Desktop/obfuscated.apk']' returned non-zero exit status 1.

Expected behavior:

I'm using Kali Linux 2019.4, running obfuscapk in a virtual environment.

Versions

  • Installation mode (e.g., from source ):
  • Obufscapk version (e.g., commit 0676488):
  • OS (e.g., Kali Linux 2019.4):
  • Python version (e.g., 3.8.2):
  • Apktool version (e.g., v2.4.1):

NewSignature error

I been trying to sign the rebuilt APK with my sig;
For that I replaced the keystore file with mine, however I am getting an Error at signing stage, saying:

jarsigner.exe returned non-zero exit status 1

Any experience with those?

The Obfuscation process halted on 43%

Encrypting constant strings: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[00:09<00:00, 772.12file/s]
Inserting "nop" instructions in smali files: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[00:06<00:00, 1224.65file/s]
Inserting "goto" instructions in smali files: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[00:06<00:00, 1258.33file/s]
Running obfuscators (Rebuild): 43%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– |[00:30<00:47, 11.93s/obfuscator]27/03/2020 14:07:35> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: I: Using Apktool 2.4.1
I: Smaling smali folder into classes.dex...
I: Building resources...
W: invalid resource directory name: /home/secret/Desktop/testedapks/kaloka/res navigation
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_8524507960092424740.tmp, p, --forced-package-id, 127, --min-sdk-version, 22, --target-sdk-version, 29, --version-code, 1, --version-name, 1.0.17, --no-version-vectors, -F, /tmp/APKTOOL991550281430554690.tmp, -e, /tmp/APKTOOL21718041769775050.tmp, -0, arsc, -I, /home/secret/.local/share/apktool/framework/1.apk, -S, /home/secret/Desktop/testedapks/kaloka/res, -M, /home/secret/Desktop/testedapks/kaloka/AndroidManifest.xml]

27/03/2020 14:07:35> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['apktool', 'b', '--force-all', '/home/secret/Desktop/testedapks/kaloka', '-o', '/home/secret/Desktop/kaloka.apk']' returned non-zero exit status 1.
27/03/2020 14:07:35> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['apktool', 'b', '--force-all', '/home/secret/Desktop/testedapks/kaloka', '-o', '/home/secret/Desktop/kaloka.apk']' returned non-zero exit status 1.
27/03/2020 14:07:35> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['apktool', 'b', '--force-all', '/home/secret/Desktop/testedapks/kaloka', '-o', '/home/secret/Desktop/kaloka.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
obfuscation_info.build_obfuscated_apk()
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/obfuscation.py", line 396, in build_obfuscated_apk
apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/tool.py", line 93, in build
output = subprocess.check_output(build_cmd, stderr=subprocess.STDOUT).strip()
File "/usr/lib/python3.7/subprocess.py", line 411, in check_output
**kwargs).stdout
File "/usr/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'b', '--force-all', '/home/secret/Desktop/testedapks/kaloka', '-o', '/home/secret/Desktop/kaloka.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/cli.py", line 81, in
arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
obfuscation_info.build_obfuscated_apk()
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/obfuscation.py", line 396, in build_obfuscated_apk
apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
File "/home/secret/penetration_testing/android/Obfuscapk/src/obfuscapk/tool.py", line 93, in build
output = subprocess.check_output(build_cmd, stderr=subprocess.STDOUT).strip()
File "/usr/lib/python3.7/subprocess.py", line 411, in check_output
**kwargs).stdout
File "/usr/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'b', '--force-all', '/home/secret/Desktop/testedapks/kaloka', '-o', '/home/secret/Desktop/kaloka.apk']' returned non-zero exit status 1.
Running obfuscators (Rebuild): 43%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ– |[00:45<01:00, 15.04s/obfuscator]

Apktool build fail

I was trying Obfuscapk on a sample application and I got this error.

subprocess.CalledProcessError: Command '['/usr/bin/apktool', 'b', '--force-all', '/home/ardalan/obfuscation_working_dir/app-release', '-o', '/home/ardalan/result.apk']' returned non-zero exit status 1.
Running obfuscators (Rebuild):  50%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ                         |[00:03<00:03,  3.89s/obfuscator]
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/ardalan/Obfuscapk/src/obfuscapk/cli.py", line 177, in <module>
    main()
  File "/home/ardalan/Obfuscapk/src/obfuscapk/cli.py", line 172, in main
    arguments.key_password,
  File "/home/ardalan/Obfuscapk/src/obfuscapk/main.py", line 144, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/home/ardalan/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/home/ardalan/Obfuscapk/src/obfuscapk/obfuscation.py", line 502, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/home/ardalan/Obfuscapk/src/obfuscapk/tool.py", line 158, in build
    build_cmd, stderr=subprocess.STDOUT, input=b"\n"
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/usr/bin/apktool', 'b', '--force-all', '/home/ardalan/obfuscation_working_dir/app-release', '-o', '/home/ardalan/result.apk']' returned non-zero exit status 1.

after some debugging I found out this is because of Apktool trying to reconstruct resourses from the decoded files of an app which have not been successfully decoded. I fixed this issue by modifying tool.py file and adding the "-r" to the "decode_cmd" list when calling Apktool.

I was wondering if in the new version there would flag that would automatically add "-r" in apktook command.
Although Obfuscapk does resource obfuscation and adding "-r" may cause problems for them, for other types of obfuscation this flag will mitigate some crashes.

Error

Hi I have Unbynty 16.04 32 bit

After the command python3.7-m obfuscapk.cli --help error

ggg@ubuntu:~/Downloads/Obfuscapk-master$ cd src/
ggg@ubuntu:~/Downloads/Obfuscapk-master/src$ python3.7 -m obfuscapk.cli --help
07/09/2019 23:10:23> [ERROR][yapsy][loadPlugins()] Unable to import plugin: /home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/res_string_encryption
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 518, in loadPlugins
    candidate_module = PluginManager._importModule(plugin_module_name, candidate_filepath)
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 581, in _importModule
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.7/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.7/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/res_string_encryption/__init__.py", line 4, in <module>
    from .res_string_encryption import ResStringEncryption
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/res_string_encryption/res_string_encryption.py", line 11, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
07/09/2019 23:10:23> [ERROR][yapsy][loadPlugins()] Unable to import plugin: /home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/virus_total
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 518, in loadPlugins
    candidate_module = PluginManager._importModule(plugin_module_name, candidate_filepath)
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 581, in _importModule
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.7/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.7/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/virus_total/__init__.py", line 4, in <module>
    from .virus_total import VirusTotal
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/virus_total/virus_total.py", line 12, in <module>
    from virus_total_apis import PublicApi as VirusTotalPublicApi
ModuleNotFoundError: No module named 'virus_total_apis'
07/09/2019 23:10:23> [ERROR][yapsy][loadPlugins()] Unable to import plugin: /home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/asset_encryption
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 518, in loadPlugins
    candidate_module = PluginManager._importModule(plugin_module_name, candidate_filepath)
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 581, in _importModule
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.7/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.7/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/asset_encryption/__init__.py", line 4, in <module>
    from .asset_encryption import AssetEncryption
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/asset_encryption/asset_encryption.py", line 9, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
07/09/2019 23:10:23> [ERROR][yapsy][loadPlugins()] Unable to import plugin: /home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/lib_encryption
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 518, in loadPlugins
    candidate_module = PluginManager._importModule(plugin_module_name, candidate_filepath)
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 581, in _importModule
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.7/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.7/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/lib_encryption/__init__.py", line 4, in <module>
    from .lib_encryption import LibEncryption
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/lib_encryption/lib_encryption.py", line 9, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
07/09/2019 23:10:23> [ERROR][yapsy][loadPlugins()] Unable to import plugin: /home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/const_string_encryption
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 518, in loadPlugins
    candidate_module = PluginManager._importModule(plugin_module_name, candidate_filepath)
  File "/usr/local/lib/python3.7/dist-packages/yapsy/PluginManager.py", line 581, in _importModule
    candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
  File "/usr/lib/python3.7/imp.py", line 244, in load_module
    return load_package(name, filename)
  File "/usr/lib/python3.7/imp.py", line 216, in load_package
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/const_string_encryption/__init__.py", line 4, in <module>
    from .const_string_encryption import ConstStringEncryption
  File "/home/ggg/Downloads/Obfuscapk-master/src/obfuscapk/obfuscators/const_string_encryption/const_string_encryption.py", line 10, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
usage: python3.7 -m obfuscapk.cli [-h] -o OBFUSCATOR [-w DIR] [-d OUT_APK]
                                  [-i] [-p] [-k VT_API_KEY]
                                  <APK_FILE>

Obfuscate an application (.apk) without needing its source code.

positional arguments:
  <APK_FILE>            The path to the application (.apk) to obfuscate

optional arguments:
  -h, --help            show this help message and exit
  -o OBFUSCATOR, --obfuscator OBFUSCATOR
                        The name of the obfuscator to use. Can be specified
                        multiple times to use more obfuscators (in sequence).
                        Allowed values are: AdvancedReflection,
                        ArithmeticBranch, CallIndirection, DebugRemoval, Goto,
                        MethodOverload, Nop, Reflection, Reorder, ClassRename,
                        FieldRename, MethodRename, RandomManifest,
                        NewAlignment, NewSignature, Rebuild
  -w DIR, --working-dir DIR
                        The working directory that will contain the
                        intermediate files. By default a directory will be
                        created in the same directory as the input
                        application. If the specified directory doesn't exist,
                        it will be created
  -d OUT_APK, --destination OUT_APK
                        The path where to save the obfuscated .apk file. By
                        default the file will be saved in the working
                        directory
  -i, --ignore-libs     Ignore known third party libraries during the
                        obfuscation operations
  -p, --show-progress   Show obfuscation progress (as a progress bar)
  -k VT_API_KEY, --virus-total-key VT_API_KEY
                        When using Virus Total obfuscator, a valid API key has
                        to be provided. Can be specified multiple times to use
                        a different API key for each request (cycling through
                        the API keys)
ggg@ubuntu:~/Downloads/Obfuscapk-master/src$ `

ofuscar los .xml

Hola, bueno antes que nada agradezco su gran trabajo en esta herramienta...
Bueno mi pregunta es si puedo ofuscar los archivos .xml ya que probรฉ varios mรฉtodos y en ninguno cambio el cรณdigo (hacerlo incomprensible)

Saludos

No output of obfuscated APK?

Prerequisites

Before opening this issue, I tried the following steps:

  • Installed the tool in a way described in the readme and ran python3 -m obfuscapk.cli --help without any errors

  • Ran the tool using only Rebuild, NewSignature and NewAlignment obfuscators to verify that the app is not using anti-repackaging techniques

  • Ran the tool using --ignore-libs flag to exclude third party libraries from the obfuscation

  • Checked FAQ and troubleshooting

  • Checked for existing similar issues on GitHub

Description

No output when running the script

Steps to reproduce

  1. Obfuscapk\src>py -m obfuscapk.cli -p -o Rebuild test.apk

Expected behavior:

output apk should be shown in obfuscation_working_dir

Actual behavior:
only files such as assets, res, manifest etc can be found. no sign of apk

No error. everything is successful.
Running obfuscators (Rebuild): 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[01:22<00:00, 82.57s/obfuscator]

Versions

  • Installation mode (e.g., from source or with Docker):
    source
  • Obufscapk version (e.g., commit 0676488):
    commit 75cbc4e
  • OS (e.g., Ubuntu 16.04):
    Windows 10
  • Python version (e.g., 3.7.4):
    3.7.3
  • Apktool version (e.g., v2.4.0):
    2.4.1

Additional information

Apk file(s):

Keep package name intact

I realize now that it's changing package name in the output APK;
How can I revert it back? or never change it in a first place

My Errors in Ofuscapk

python -m obfuscapk.cli -p -d C:\Users\GAMER\Downloads\apk\obfuscation_working_dir\OUT\obfuscated.apk -o Rebuild -o NewAlignment -o NewSignature Sopa.apk
Running obfuscators (NewSignature):  67%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž              |[03:47<02:39, 159.05s/obfuscator]10/08/2020 23:07:10> [ERROR][obfuscapk.tool.Jarsigner][sign()] Error during sign command: jarsigner: unable to sign jar: java.net.UnknownHostException: timestamp.comodoca.com

10/08/2020 23:07:10> [ERROR][obfuscapk.obfuscation][sign_obfuscated_apk()] Error during apk signing: Command '['C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\jarsigner.exe', '-tsa', 'http://timestamp.comodoca.com/rfc3161', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1', '-keystore', 'C:\\Users\\GAMER\\Obfuscapk\\src\\obfuscapk\\resources\\obfuscation_keystore.jks', '-storepass', 'obfuscation_password', 'C:\\Users\\GAMER\\Downloads\\apk\\obfuscation_working_dir\\OUT\\obfuscated.apk', 'obfuscation_key']' returned non-zero exit status 1.
10/08/2020 23:07:10> [ERROR][yapsy_loaded_plugin_NewSignature_1.new_signature.NewSignature][obfuscate()] Error during execution of "NewSignature" obfuscator: Command '['C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\jarsigner.exe', '-tsa', 'http://timestamp.comodoca.com/rfc3161', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1', '-keystore', 'C:\\Users\\GAMER\\Obfuscapk\\src\\obfuscapk\\resources\\obfuscation_keystore.jks', '-storepass', 'obfuscation_password', 'C:\\Users\\GAMER\\Downloads\\apk\\obfuscation_working_dir\\OUT\\obfuscated.apk', 'obfuscation_key']' returned non-zero exit status 1.
10/08/2020 23:07:10> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\jarsigner.exe', '-tsa', 'http://timestamp.comodoca.com/rfc3161', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1', '-keystore', 'C:\\Users\\GAMER\\Obfuscapk\\src\\obfuscapk\\resources\\obfuscation_keystore.jks', '-storepass', 'obfuscation_password', 'C:\\Users\\GAMER\\Downloads\\apk\\obfuscation_working_dir\\OUT\\obfuscated.apk', 'obfuscation_key']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\main.py", line 144, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\obfuscators\new_signature\new_signature.py", line 20, in obfuscate
    obfuscation_info.sign_obfuscated_apk()
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\obfuscation.py", line 538, in sign_obfuscated_apk
    jarsigner.resign(
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\tool.py", line 305, in resign
    return self.sign(
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\tool.py", line 244, in sign
    output = subprocess.check_output(sign_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\jarsigner.exe', '-tsa', 'http://timestamp.comodoca.com/rfc3161', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1', '-keystore', 'C:\\Users\\GAMER\\Obfuscapk\\src\\obfuscapk\\resources\\obfuscation_keystore.jks', '-storepass', 'obfuscation_password', 'C:\\Users\\GAMER\\Downloads\\apk\\obfuscation_working_dir\\OUT\\obfuscated.apk', 'obfuscation_key']' returned non-zero exit status 1.
Running obfuscators (NewSignature):  67%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Ž              |[04:01<02:00, 120.92s/obfuscator]
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\cli.py", line 177, in <module>
    main()
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\cli.py", line 161, in main
    perform_obfuscation(
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\main.py", line 144, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\obfuscators\new_signature\new_signature.py", line 20, in obfuscate
    obfuscation_info.sign_obfuscated_apk()
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\obfuscation.py", line 538, in sign_obfuscated_apk
    jarsigner.resign(
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\tool.py", line 305, in resign
    return self.sign(
  File "C:\Users\GAMER\Obfuscapk\src\obfuscapk\tool.py", line 244, in sign
    output = subprocess.check_output(sign_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\jarsigner.exe', '-tsa', 'http://timestamp.comodoca.com/rfc3161', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1', '-keystore', 'C:\\Users\\GAMER\\Obfuscapk\\src\\obfuscapk\\resources\\obfuscation_keystore.jks', '-storepass', 'obfuscation_password', 'C:\\Users\\GAMER\\Downloads\\apk\\obfuscation_working_dir\\OUT\\obfuscated.apk', 'obfuscation_key']' returned non-zero exit status 1.

FieldRename causes error when inheritance is used

Prerequisites

Before opening this issue, I tried the following steps:

  • Installed the tool in a way described in the readme and ran python3 -m obfuscapk.cli --help without any errors

  • Ran the tool using only Rebuild, NewSignature and NewAlignment obfuscators to verify that the app is not using anti-repackaging techniques

  • Ran the tool using --ignore-libs flag to exclude third party libraries from the obfuscation

  • Checked FAQ and troubleshooting

  • Checked for existing similar issues on GitHub

Description

I tested sample apk with FieldRename option. It works for trivial cases. But it doesn't seem to work for inheritance cases. Resulting smali file is corrupted after subclass inherits from super class. Subclass can't access field of it's super class after obfuscation. I tested with inheritance from Android libraries.

Steps to reproduce

  1. AppCacheInfo class inherits from android.content.pm.ApplicationInfo class. AppCacheInfo now has packagename field inherited from super class
  2. Access fields
    AppCacheInfoinfo = new AppCacheInfo();
    info.packagename = "testpackagename";
  3. Build the application and obfuscate using Obfuscapk

Expected behavior:
Normal running app

Actual behavior:

Obfuscation completes without errors. But apk file can't be run. Error message is like this:

java.lang.NoSuchFieldError: No instance field โ„ฑโ–”โ–“โ–โ–’โ–งโ–’โ–‰โ–ฎโ–’โ–†โ–ฉโ–ฉโ–žโ–“โ–‰โ–—โ–งโ–“โ–โ–†โ–€โ–งโ–€โ–‰โ–€โ–ฎโ–งโ–™โ–€โ–ฎโ–งโ–ง of type Ljava/lang/String; in class Lmobikit/android/util/AppCacheInfo; or its superclasses (declaration of 'mobikit.android.util.AppCacheInfo' appears in /data/app/com.gaia.mobikit.android-wELqJWIgraxLKWjGx9J7EQ==/base.apk)
        at mobikit.android.util.AppCacheDao.createAppCacheInfo(AppCacheDao.java:88)

Versions

  • Installation mode : from source
  • Obufscapk version : commit c9e493b
  • OS : Windows 10
  • Python version : 3.8.5
  • Apktool version: v2.4.1

Additional information

Apk file(s):

Using ClassRename

How can I not fully use ClassRename, for example I want to change the name of the classes, but not change the name of the package

Use AAPT2 in apktool

Hello, I'm trying to obfuscate an APK but I got the following error:

30/04/2020 16:38:03> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: I: Using Apktool 2.4.1
I: Smaling smali folder into classes.dex...
I: Building resources...
W: invalid resource directory name: /Users/alvaro.salcedo.local/Desktop/input/res navigation
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/5g/hjj3jgm50237mbgxn41lypbr0000gp/T/brut_util_Jar_7411735407958661890.tmp, p, --forced-package-id, 127, --min-sdk-version, 21, --target-sdk-version, 29, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, /var/folders/5g/hjj3jgm50237mbgxn41lypbr0000gp/T/APKTOOL1299611481270535293.tmp, -e, /var/folders/5g/hjj3jgm50237mbgxn41lypbr0000gp/T/APKTOOL3454279392600081360.tmp, -0, arsc, -I, /Users/alvaro.salcedo.local/Library/apktool/framework/1.apk, -S, /Users/alvaro.salcedo.local/Desktop/input/res, -M, /Users/alvaro.salcedo.local/Desktop/input/AndroidManifest.xml]

30/04/2020 16:48:03> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/Users/alvaro.salcedo.local/Desktop/input', '-o', '/Users/alvaro.salcedo.local/Desktop/gd.apk']' returned non-zero exit status 1.
30/04/2020 16:48:03> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/Users/alvaro.salcedo.local/Desktop/input', '-o', '/Users/alvaro.salcedo.local/Desktop/gd.apk']' returned non-zero exit status 1.
30/04/2020 16:48:03> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/Users/alvaro.salcedo.local/Desktop/input', '-o', '/Users/alvaro.salcedo.local/Desktop/gd.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/obfuscation.py", line 396, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/tool.py", line 106, in build
    output = subprocess.check_output(build_cmd, stderr=subprocess.STDOUT, input=b"\n").strip()
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/Users/alvaro.salcedo.local/Desktop/input', '-o', '/Users/alvaro.salcedo.local/Desktop/gd.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/cli.py", line 81, in <module>
    arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/obfuscation.py", line 396, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/Users/alvaro.salcedo.local/Desktop/Obfuscapk/src/obfuscapk/tool.py", line 106, in build
    output = subprocess.check_output(build_cmd, stderr=subprocess.STDOUT, input=b"\n").strip()
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/usr/local/bin/apktool', 'b', '--force-all', '/Users/alvaro.salcedo.local/Desktop/input', '-o', '/Users/alvaro.salcedo.local/Desktop/gd.apk']' returned non-zero exit status 1.

The problem is that I'm using the navigation component and is only compatible using --use-aapt2 in apktool. (iBotPeaches/Apktool#1978 (comment))

The command I used is python3.7 -m obfuscapk.cli -i -p -w ~/Desktop -d ~/Desktop/gd.apk -o Rebuild -o NewSignature -o NewAlignment ~/Desktop/input.apk

Thanks.

MethodRename not working

Steps:

  • I use simple commands:
    python -m obfuscapk.cli -o FieldRename -o MethodRename -o Rebuild -o NewAlignment -o NewSignature -i -p input.apk
  • Success build and install, app running good.

Results:

  • Only Fields renamed, Methods not rename at all.
  • Bellow is my screenshot from decompile tool

PicPick_058

CalledProcessError

hello,myfriend
when i use -o OBFUSCATOR
they often report this error๏ผš

Command '['G:\android tool\ApkToolBox_v1.6.4\tool\apktool\apktool.BAT', 'd', '--force', '1.apk', '-o', 'obfuscation_working_dir\1']' returned non-zero exit status 1.

is there anything wrong with my apktool๏ผŸ

Thank you very much

This is a powerfull obfuscator and works as expected it helped me alot .
This is actually not an issue its Appreciation to you.
Please keep the project running .

Love you

Rebuild error

Prerequisites

Description

Before opening this issue, I tried the following steps:
We have tried many obfuscate options but all failed on similar error "Unsigned short value out of range: 65548"

Steps to Reproduce

Expected behavior:

As expected, "ClassRename" option only rename class name.

Actual behavior:

But somehow, It has added more methods to dex file.

if applicable, paste here the complete error message

[(venv) ThanhNgenMacPro:src thanhnguyen.truong$ python3.7 -m obfuscapk.cli -i -p -o ClassRename -o Rebuild uat-release-noObfuscate.apk
Class name to smali file mapping: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[01:24<00:00, 541.59file/s]
Renaming class declarations: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[03:50<00:00, 198.40file/s]
Renaming class usages in smali files: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[03:59<00:00, 190.73file/s]
Renaming class usages in xml files: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[03:44<00:00, 7.66file/s]
10/04/2020 17:17:32> [ERROR][yapsy_loaded_plugin_ClassRename_1.class_rename.ClassRename][obfuscate()] remain "[53548, 49759, 11340, 2297, -1275, 4169, 34762, 53573]"โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ|[03:44<00:00, 10.20file/s]
Running obfuscators (Rebuild): 50%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œ |[16:48<16:48, 1008.00s/obfuscator]10/04/2020 17:21:53> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: I: Using Apktool 2.4.1
I: Smaling smali folder into classes.dex...
I: Smaling smali_classes7 folder into classes7.dex...
I: Smaling smali_classes6 folder into classes6.dex...
I: Smaling smali_classes8 folder into classes8.dex...
I: Smaling smali_classes3 folder into classes3.dex...
I: Smaling smali_classes4 folder into classes4.dex...
I: Smaling smali_classes5 folder into classes5.dex...
I: Smaling smali_classes2 folder into classes2.dex...
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Lcom/google/android/gms/internal/vision/zzjq;->zzhs()Lcom/google/android/gms/internal/vision/zzjq;
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:917)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:341)
at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:297)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:61)
at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:36)
at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:418)
at brut.androlib.Androlib.buildNonDefaultSources(Androlib.java:364)
at brut.androlib.Androlib.build(Androlib.java:302)
at brut.androlib.Androlib.build(Androlib.java:268)
at brut.apktool.Main.cmdBuild(Main.java:251)
at brut.apktool.Main.main(Main.java:79)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x6c
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1190)
at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:913)
... 10 more
Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65548
at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:356)
at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1150)
... 11 more
]

Versions

  • Installation mode (e.g., from source or with Docker): source
  • Obufscapk version (e.g., commit 0676488): lastest version
  • OS (e.g., Ubuntu 16.04): MacOS 10.14.6
  • Python version (e.g., Python 3.7.4): 3.7.4

Additional Information

Apk file(s):

Subprocess calls fail on Windows

Team Obfuscapk:
I receive numerous errors on subprocess.py invocations when trying to run your software on Windows 8. The errors are all of a [WinError 2] The system cannot find the file specified variety,
output capture provided below. Everything is fresh installs.

I believe the error has to do with specifics of Python syntax on Windows platform: Googling for this Error brings a number of links where people discuss how particular Windows syntax needs to be when using subprocess calls.

Just couple of this:
https://stackoverflow.com/questions/53619765/python-subprocess-filenotfounderror?noredirect=1&lq=1

note that writing path with backslashes may be dangerous as you can create escape sequence that way which will be interpreted in different way. You can write windows paths with forward slashes and then call os.path.normpath on them

.. This was it! Just discovered that my "\bin" was becoming a special character (backspace?) in the final string. Escaping the backslash like so: "\\bin" throughout the command string fixed the issue

.

https://stackoverflow.com/questions/3022013/windows-cant-find-the-file-on-subprocess-call/32799942#32799942

On Windows, I believe the subprocess module doesn't look in the PATH unless you pass shell=True because it use CreateProcess() behind the scenes

Hopefully these can provide some clues to hep fix it.
Unfortunately my experience with debugging Python is exactly zero, as I lack practical knowledge about how to set up breakpoints/printout arguments on those calls, which would help identify the problem.
Totally open to help if you can guide me on that.

Appreciate you looking into this. Right now I got a feel any Windows user will run into the same issue.

Output capture

02/05/2020 20:31:08> [ERROR][obfuscapk.tool.Apktool][decode()] Error during decoding: [WinError 2] The system cannot find the file specified
02/05/2020 20:31:08> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: [WinError 2] The system cannot find the file specified
02/05/2020 20:31:08> [ERROR][yapsy_loaded_plugin_Goto_1.goto.Goto][obfuscate()] Error during execution of "Goto" obfuscator: [WinError 2] The system cannot find the file specified
02/05/2020 20:31:08> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscators\goto\goto.py", line 21, in obfuscate
    for smali_file in util.show_list_progress(obfuscation_info.get_smali_files(),
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscation.py", line 446, in get_smali_files
    self.decode_apk()
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\cli.py", line 80, in <module>
    perform_obfuscation(arguments.apk_file, arguments.obfuscator, arguments.working_dir, arguments.destination,
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscators\goto\goto.py", line 21, in obfuscate
    for smali_file in util.show_list_progress(obfuscation_info.get_smali_files(),
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscation.py", line 446, in get_smali_files
    self.decode_apk()
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
    apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
  File "C:\Users\myHome\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
    output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\rusty\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified



Can i use NonAsii characters for rename?

Hi,
I tried to use NonAsii character for rename to use some chinese character like "ๅ…ถ้“่ƒฝ้ขๅฐ†ๆ–น้ƒฝ็”Ÿ็”จ", but it always trigger error on print method:
UnicodeEncodeError: 'charmap' codec can't encode characters
Then i tried to uncoment all print method, it is build success, but check on decompile tool, it's not Nonasii characters i'm looking for.
Did i miss somethings?

Here is simple code to generate non asii chars, i have test on simple project, it's print success, but on Obfuscator src, it always trigger "UnicodeEncodeError" .

nonasiiChars = "ๅฏนๅœจๅŽๅˆ†ๅญไธญ็š„ๅชๆ— ่ฟ™ๅŒไนˆๆœ‰ไนŸๅฅฝๆญคๅ…ฌๅˆๅฎšไธ่€Œๆ‰€ไบบๅนดๅ…ถ้“่ƒฝ้ขๅฐ†ๆ–น้ƒฝ็”Ÿ็”จ็งๅฟƒไฝ "
asiiChars ="abcdefghijklmnopqrstuvwxyz0123456789"
dictChars = {}


def HandleDictChars():
    for id, item in enumerate(asiiChars):
        dictChars[item] = nonasiiChars[id]
    print(dictChars)
	
def GenerateRandomNameNonasii():
    input_string = "akjfadslfjsadlj234234"
    md5String = md5(input_string.encode()).hexdigest()
    result = md5String
    for key, value in dictChars.items():
        result = result.replace(key, value)

    print("md5String: " + md5String)
    print("Result: " + result)

HandleDictChars()
GenerateRandomNameNonasii()

Here is decompile code after use NonAsii characters:
PicPick_060

error executing obfuscated command in windows 10

executed this command python -m obfuscapk.cli -o RandomManifest 1.apk

I returned this error:

26/02/2020 15:20:35> [ERROR][obfuscapk.tool.Apktool][decode()] Error during decoding: [WinError 2] El sistema no puede encontrar el archivo especificado
26/02/2020 15:20:35> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: [WinError 2] El sistema no puede encontrar el archivo especificado
26/02/2020 15:20:35> [ERROR][yapsy_loaded_plugin_RandomManifest_1.random_manifest.RandomManifest][obfuscate()] Error during execution of "RandomManifest" obfuscator: [WinError 2] El sistema no puede encontrar el archivo especificado
26/02/2020 15:20:35> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: [WinError 2] El sistema no puede encontrar el archivo especificado
Traceback (most recent call last):
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscators\random_manifest\random_manifest.py", line 108, in obfuscate
manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscation.py", line 439, in get_manifest_file
self.decode_apk()
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
File "C:\Python37\lib\subprocess.py", line 376, in check_output
**kwargs).stdout
File "C:\Python37\lib\subprocess.py", line 453, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Python37\lib\subprocess.py", line 756, in init
restore_signals, start_new_session)
File "C:\Python37\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado
Traceback (most recent call last):
File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\cli.py", line 81, in
arguments.interactive, arguments.ignore_libs, arguments.virus_total_key)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\main.py", line 88, in perform_obfuscation
(obfuscator_name_to_function[obfuscator_name])(obfuscation)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscators\random_manifest\random_manifest.py", line 108, in obfuscate
manifest_tree = Xml.parse(obfuscation_info.get_manifest_file(), parser=xml_parser)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscation.py", line 439, in get_manifest_file
self.decode_apk()
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\obfuscation.py", line 276, in decode_apk
apktool.decode(self.apk_path, self._decoded_apk_path, force=True)
File "E:\Android\Github\Obfuscade\Obfuscapk\src\obfuscapk\tool.py", line 61, in decode
output = subprocess.check_output(decode_cmd, stderr=subprocess.STDOUT).strip()
File "C:\Python37\lib\subprocess.py", line 376, in check_output
**kwargs).stdout
File "C:\Python37\lib\subprocess.py", line 453, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Python37\lib\subprocess.py", line 756, in init
restore_signals, start_new_session)
File "C:\Python37\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado

Windows 10, 64 Bit.

How to set path for tools

I've downloaded apktool.jar it's inside src folder also i've jarsinger inside JRE folder but Obfuscapk
does not recognize them, what i have missed ?

Question on Multiple Obfuscation Runs

Hi Obfuscapk Team,

I have a question about multiple obfuscations of the same APK. Here goes:

  1. I have an APK and I obfuscate it using one obfuscator - Reflection.
  2. It works fine and I end up with an obfuscated APK.
  3. I then take that obfuscated APK and run it again through Obfuscapk - using the Reflection obfuscator. My goal is to understand if more reflection will be added - or if you get the most possible via the first run.
  4. What happens is that it fails with the error below. Seems like its main issue is:

Could not smali file: com/apireflectionmanager/ApiReflection.smali

I get that it introduces com.apireflectionmanager.ApiReflection.java as part of the first pass. Looks like a second pass would not be possible. Just confirming. Also - if it were possible - do you think more reflection would be introduced?

ERROR OUPUT

import 'yapsy_loaded_plugin_ConstStringEncryption_1.const_string_encryption' # <_frozen_importlib_external.SourceFileLoader object at 0x7fe300ac5950>
import 'yapsy_loaded_plugin_ConstStringEncryption_1' # <_frozen_importlib_external.SourceFileLoader object at 0x7fe300ac5650>
# /projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/__pycache__/__init__.cpython-37.pyc matches /projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/__init__.py
# code object from '/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/__pycache__/__init__.cpython-37.pyc'
# /projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/__pycache__/debug_removal.cpython-37.pyc matches /projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/debug_removal.py
# code object from '/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/debug_removal/__pycache__/debug_removal.cpython-37.pyc'
import 'yapsy_loaded_plugin_DebugRemoval_1.debug_removal' # <_frozen_importlib_external.SourceFileLoader object at 0x7fe300ac5ed0>
import 'yapsy_loaded_plugin_DebugRemoval_1' # <_frozen_importlib_external.SourceFileLoader object at 0x7fe300ac5b90>
04/06/2020 14:22:08> [ERROR][obfuscapk.tool.Apktool][build()] Error during build command: I: Using Apktool 2.4.0
I: Smaling smali folder into classes.dex...
../../../../../../../../gpfs/scratch/jmdv/junk4/StockTicker_obfuscated/smali/com/apireflectionmanager/ApiReflection.smali[11,12] Class Lcom/apireflectionmanager/ApiReflection; has already been interned
Could not smali file: com/apireflectionmanager/ApiReflection.smali

04/06/2020 14:22:08> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['apktool', 'b', '--force-all', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated', '-o', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated_obfuscated.apk']' returned non-zero exit status 1.
04/06/2020 14:22:08> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['apktool', 'b', '--force-all', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated', '-o', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated_obfuscated.apk']' returned non-zero exit status 1.
04/06/2020 14:22:08> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['apktool', 'b', '--force-all', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated', '-o', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated_obfuscated.apk']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/main.py", line 88, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/obfuscation.py", line 396, in build_obfuscated_apk
    apktool.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/projects/academic/stevko/delvecchio/obfuscation/obfuscapk/Obfuscapk/src/obfuscapk/tool.py", line 93, in build
    output = subprocess.check_output(build_cmd, stderr=subprocess.STDOUT).strip()
  File "/util/common/python/py37/anaconda-2020.02/lib/python3.7/subprocess.py", line 411, in check_output
    **kwargs).stdout
  File "/util/common/python/py37/anaconda-2020.02/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['apktool', 'b', '--force-all', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated', '-o', '/gpfs/scratch/jmdv/junk4/StockTicker_obfuscated_obfuscated.apk']' returned non-zero exit status 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.