Git Product home page Git Product logo

claudiugeorgiu / obfuscapk Goto Github PK

View Code? Open in Web Editor NEW
1.1K 46.0 277.0 7.25 MB

An automatic obfuscation tool for Android apps that works in a black-box fashion, supports advanced obfuscation features and has a modular architecture easily extensible with new techniques

License: MIT License

Python 99.30% Dockerfile 0.70%
android application app apk obfuscation black-box apktool smali obfuscapk

obfuscapk's People

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

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

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

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.

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)

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?

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):

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?

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?

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?

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$ `

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

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 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):

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):

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]

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

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 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'

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



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

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!

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.

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.

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

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.

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

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!

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):

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 ?

Bundle Support

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

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

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'

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.

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?

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

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.

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):

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'

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?

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.

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

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

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.

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

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.