ClaudiuGeorgiu / Obfuscapk

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
MIT License
1.09k stars 285 forks source link

Error obfuscapk BundleDecompiler #151

Closed DaniilKobitskoy closed 9 months ago

DaniilKobitskoy commented 1 year ago

Hello dear developers. I've run into a problem that I can't fix. I do everything as written in your instructions, but nothing works out for me. Here is the bug report. Please tell me what am I doing wrong? I really need your product and really want to make it myself.

I would be extremely grateful for help.

Sincerely, Daniil Kobitskoy.

daniil@daniil-VirtualBox:~/Obfuscapk/src$ sudo docker run -v "/home/daniil/eviljocker/app/release/":"/workdir" obfuscapk -w /workdir/obfuscation_dir/ -o ConstStringEncryption -o Rebuild -o NewAlignment -o NewSignature -d /workdir/app-release-obf.aab /workdir/app-release.aab 22/01/2023 22:07:54> [ERROR][obfuscapk.toolbundledecompiler.BundleDecompiler][decode()] Error during decode command: Input AppBundle path: /workdir/app-release.aab tools installing..,/root/.tmp/BundleDecompiler/ /workdir/app-release.aab /workdir/obfuscation_dir/app-release /tmp/temp.sh: 1: unzip: not found Exception in thread "main" java.lang.NullPointerException at com.bundle.main.BundleAnalyze.getBaseApkFile(BundleAnalyze.java:260) at com.bundle.main.BundleAnalyze.UnpackAppBundle(BundleAnalyze.java:248) at com.bundle.main.BundleAnalyze.analyze(BundleAnalyze.java:103) at com.bundle.main.BundleDecompiler.doRunBundleDecompiler(BundleDecompiler.java:90) at com.bundle.main.BundleDecompiler.main(BundleDecompiler.java:35)

22/01/2023 22:07:54> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. 22/01/2023 22:07:54> [ERROR][yapsy_loaded_plugin_ConstStringEncryption_1.const_string_encryption.ConstStringEncryption][obfuscate()] Error during execution of "ConstStringEncryption" obfuscator: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. 22/01/2023 22:07:54> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. Traceback (most recent call last): File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/const_string_encryption/const_string_encryption.py", line 66, in obfuscate obfuscation_info.get_smali_files(), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Obfuscapk/obfuscapk/obfuscation.py", line 642, in get_smali_files self.decode_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 356, in decode_apk bundledecompiler.decode( File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 121, in decode output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/Obfuscapk/obfuscapk/cli.py", line 189, in main() File "/Obfuscapk/obfuscapk/cli.py", line 171, in main perform_obfuscation( File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/const_string_encryption/const_string_encryption.py", line 66, in obfuscate obfuscation_info.get_smali_files(), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Obfuscapk/obfuscapk/obfuscation.py", line 642, in get_smali_files self.decode_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 356, in decode_apk bundledecompiler.decode( File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 121, in decode output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1.

Prerequisites

Before opening this issue, I tried the following steps:

Description

Steps to reproduce

Expected behavior:

Actual behavior:

paste here the complete error message, including the command that generated the error

Versions

Additional information

Apk file(s):

ClaudiuGeorgiu commented 1 year ago

Hi, I think the error might be related to this message: /tmp/temp.sh: 1: unzip: not found, so maybe installing unzip inside the Docker image could help (I'll update the image when I have time). However, bundle support is still experimental, so even with this fix there might still be other problems.

DaniilKobitskoy commented 1 year ago

Hi, I think the error might be related to this message: /tmp/temp.sh: 1: unzip: not found, so maybe installing unzip inside the Docker image could help (I'll update the image when I have time). However, bundle support is still experimental, so even with this fix there might still be other problems.

Hello. Thank you very much for your feedback. I'll wait for the image update. Or is it possible for me to install unzip into the Docker image myself?

ClaudiuGeorgiu commented 1 year ago

I updated the Docker image, if it still doesn't work you should at least get a different error.

DaniilKobitskoy commented 1 year ago

I updated the Docker image, if it still doesn't work you should at least get a different error.

Good evening. Yes, the error has changed, but the error still crashes. This time it's like this: daniil@daniil-VirtualBox:~/Obfuscapk/src$ sudo docker run -v "/home/daniil/eviljocker/app/release/":"/workdir" obfuscapk -w /workdir/obfuscation_dir/ -o ConstStringEncryption -o Rebuild -o NewAlignment -o NewSignature -d /workdir/app-release-obf.aab /workdir/app-release.aab 23/01/2023 10:06:24> [ERROR][obfuscapk.toolbundledecompiler.BundleDecompiler][decode()] Error during decode command: Input AppBundle path: /workdir/app-release.aab tools installing..,/root/.tmp/BundleDecompiler/ /workdir/app-release.aab /workdir/obfuscation_dir/app-release /tmp/temp.sh: 1: zip: not found Failed...,/root/.tmp/BundleDecompiler//build-tools/30.0.3/linux/aapt2 dump badging /workdir/obfuscation_dir/app-release/tmp/base.apk decompile sources... decompile classes2.dex... Exception in thread "main" java.lang.Exception: java.lang.Exception: org.jf.dexlib2.DexFileFactory$DexFileNotFoundException: base.apk does not exist at com.bundle.smaliConversion.SmaliManager.decodeSourcesSmali(SmaliManager.java:29) at com.bundle.decompile.DecompileManger.decompileSmali(DecompileManger.java:34) at com.bundle.decompile.DecompileManger.decompile(DecompileManger.java:17) at com.bundle.main.BundleDecompiler.doRunBundleDecompiler(BundleDecompiler.java:92) at com.bundle.main.BundleDecompiler.main(BundleDecompiler.java:35) Caused by: java.lang.Exception: org.jf.dexlib2.DexFileFactory$DexFileNotFoundException: base.apk does not exist at com.bundle.smaliConversion.SmaliDecoder.decode(SmaliDecoder.java:100) at com.bundle.smaliConversion.SmaliDecoder.decode(SmaliDecoder.java:36) at com.bundle.smaliConversion.SmaliManager.decodeSourcesSmali(SmaliManager.java:27) ... 4 more Caused by: org.jf.dexlib2.DexFileFactory$DexFileNotFoundException: base.apk does not exist at org.jf.dexlib2.DexFileFactory.loadDexContainer(DexFileFactory.java:237) at com.bundle.smaliConversion.SmaliDecoder.decode(SmaliDecoder.java:70) ... 6 more

23/01/2023 10:06:24> [ERROR][obfuscapk.obfuscation][decode_apk()] Error during apk decoding: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. 23/01/2023 10:06:24> [ERROR][yapsy_loaded_plugin_ConstStringEncryption_1.const_string_encryption.ConstStringEncryption][obfuscate()] Error during execution of "ConstStringEncryption" obfuscator: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. 23/01/2023 10:06:24> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. Traceback (most recent call last): File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/const_string_encryption/const_string_encryption.py", line 66, in obfuscate obfuscation_info.get_smali_files(), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Obfuscapk/obfuscapk/obfuscation.py", line 642, in get_smali_files self.decode_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 356, in decode_apk bundledecompiler.decode( File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 121, in decode output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1. Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/Obfuscapk/obfuscapk/cli.py", line 189, in main() File "/Obfuscapk/obfuscapk/cli.py", line 171, in main perform_obfuscation( File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/const_string_encryption/const_string_encryption.py", line 66, in obfuscate obfuscation_info.get_smali_files(), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Obfuscapk/obfuscapk/obfuscation.py", line 642, in get_smali_files self.decode_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 356, in decode_apk bundledecompiler.decode( File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 121, in decode output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'd', '--in=/workdir/app-release.aab', '--out=/workdir/obfuscation_dir/app-release']' returned non-zero exit status 1.

Now obfuscapk requires this: /tmp/temp.sh: 1: zip: not found

ClaudiuGeorgiu commented 1 year ago

I should definitely add some test cases for bundle files... I updated the image (again), if you still get similar errors, you can edit the Dockerfile and then build the Docker image.

DaniilKobitskoy commented 1 year ago

Я определенно должен добавить несколько тестовых случаев для файлов пакетов... Я обновил образ (снова), если вы все еще получаете подобные ошибки, вы можете отредактировать файл Docker, а затем собрать образ Docker .

Thanks, I'll try it right now!

DaniilKobitskoy commented 1 year ago

I should definitely add some test cases for bundle files... I updated the image (again), if you still get similar errors, you can edit the Dockerfile and then build the Docker image. Hello, we are slowly moving in victory! The mistakes that were there are gone. Now this error pops up. How to fix it?

dannil@dannil-VirtualBox:~/Obfuscapk/src$ sudo docker run -v "/home/dannil/eviljocker/app/release":"/workdir" obfuscapk -w /workdir/obfuscation_dir/ -o Rebuild -d /workdir/app-release-obf.aab /workdir/app-release.aab 26/01/2023 15:05:11> [ERROR][obfuscapk.toolbundledecompiler.BundleDecompiler][build()] Error during build command: /workdir/obfuscation_dir/app-release /workdir/app-release-obf.aab build bundle Resources... build Decompiled Resources... /root/.tmp/BundleDecompiler//build-tools/30.0.3/linux/aapt2 compile --dir /workdir/obfuscation_dir/app-release/base/res -o /workdir/tmp/build/res /workdir/obfuscation_dir/app-release/base/res/color-night-v8/material_timepicker_modebutton_tint.xml:2: error: not well-formed (invalid token). /workdir/obfuscation_dir/app-release/base/res/color-night-v8/material_timepicker_modebutton_tint.xml: error: file failed to compile. Exception in thread "main" com.bundle.exception.EncodeDecodeException: 'BUILD_FAILED' at com.bundle.recompile.BuildManager.compileResources(BuildManager.java:300) at com.bundle.recompile.BuildManager.buildResourcesFiles(BuildManager.java:78) at com.bundle.recompile.BuildManager.buildResources(BuildManager.java:70) at com.bundle.recompile.BuildManager.buildAppBundle(BuildManager.java:37) at com.bundle.main.BundleDecompiler.doRunBundleDecompiler(BundleDecompiler.java:113) at com.bundle.main.BundleDecompiler.main(BundleDecompiler.java:35)

26/01/2023 15:05:11> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=/workdir/obfuscation_dir/app-release', '--out=/workdir/app-release-obf.aab']' returned non-zero exit status 1. 26/01/2023 15:05:11> [ERROR][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Error during execution of "Rebuild" obfuscator: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=/workdir/obfuscation_dir/app-release', '--out=/workdir/app-release-obf.aab']' returned non-zero exit status 1. 26/01/2023 15:05:11> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=/workdir/obfuscation_dir/app-release', '--out=/workdir/app-release-obf.aab']' returned non-zero exit status 1. Traceback (most recent call last): File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate obfuscation_info.build_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 553, in build_obfuscated_apk bundledecompiler.build(self._decoded_apk_path, self.obfuscated_apk_path) File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 180, in build output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=/workdir/obfuscation_dir/app-release', '--out=/workdir/app-release-obf.aab']' returned non-zero exit status 1. Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/Obfuscapk/obfuscapk/cli.py", line 189, in main() File "/Obfuscapk/obfuscapk/cli.py", line 171, in main perform_obfuscation( File "/Obfuscapk/obfuscapk/main.py", line 153, in perform_obfuscation (obfuscator_name_to_function[obfuscator_name])(obfuscation) File "/Obfuscapk/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate obfuscation_info.build_obfuscated_apk() File "/Obfuscapk/obfuscapk/obfuscation.py", line 553, in build_obfuscated_apk bundledecompiler.build(self._decoded_apk_path, self.obfuscated_apk_path) File "/Obfuscapk/obfuscapk/toolbundledecompiler.py", line 180, in build output = subprocess.check_output( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 466, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=/workdir/obfuscation_dir/app-release', '--out=/workdir/app-release-obf.aab']' returned non-zero exit status 1.

ClaudiuGeorgiu commented 1 year ago

So you get the error even when using only Rebuild obfuscator, this means that the problem is not caused by some obfuscation, but BundleDecompiler is not able to rebuild the bundle after decompiling it (even without modifications to the code).

DaniilKobitskoy commented 1 year ago

So you get the error even when using only Rebuild obfuscator, this means that the problem is not caused by some obfuscation, but BundleDecompiler is not able to rebuild the bundle after decompiling it (even without modifications to the code).

What should I do in this case?

khanbaba commented 1 year ago

So you get the error even when using only Rebuild obfuscator, this means that the problem is not caused by some obfuscation, but BundleDecompiler is not able to rebuild the bundle after decompiling it (even without modifications to the code).

What should I do in this case?

use absolute path for destination directory and app path

DaniilKobitskoy commented 1 year ago

Таким образом, вы получаете ошибку даже при использовании только обфускатора Rebuild, это означает, что проблема не вызвана какой-то обфускацией, но BundleDecompiler не может пересобрать пакет после его декомпиляции (даже без изменений в коде).

Что мне делать в этом случае?

используйте абсолютный путь для каталога назначения и пути к приложению

Hello, I just noticed your reply. Could you contact me via telegram, I really need this tool and I still can't get anything(

DaniilKobitskoy commented 1 year ago

Hello dear @ClaudiuGeorgiu. I faced such a problem that after obfscation my apk is not installed on the device, why is this happening?