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

Failure with Rebuild obfuscator using *.aab file #159

Closed alexgeta closed 9 months ago

alexgeta commented 1 year ago

Prerequisites

Before opening this issue, I tried the following steps:

Description

Steps to reproduce

Expected behavior:

Actual behavior:

(venv) alex@alex-Swift-SF314-42:~/Obfuscapk/src$ python3 -m obfuscapk.cli -o Rebuild -o NewAlignment -o NewSignature -p app-release.aab
04/03/2023 23:15:20> [DEBUG][obfuscapk.main][check_external_tool_dependencies()] Checking external tool dependencies
04/03/2023 23:15:20> [DEBUG][obfuscapk.main][check_external_tool_dependencies()] Checking external tool dependencies
04/03/2023 23:15:20> [DEBUG][obfuscapk.obfuscation][__init__()] Auto-generated random secret key for encryption: "BgKDO1qEuT4c3C4Ob8UFIscjAnnytEZI"
04/03/2023 23:15:20> [DEBUG][obfuscapk.obfuscation][__init__()] No working directory provided, the operations will take place in the same directory as the input file, in the directory "obfuscation_working_dir"
04/03/2023 23:15:20> [DEBUG][obfuscapk.obfuscation][__init__()] No obfuscated apk path provided, the result will be saved as "obfuscation_working_dir/app-release_obfuscated.aab"
Running obfuscators (Rebuild):   0%|                                                                                                                                              |[00:00<?, ?obfuscator/s]04/03/2023 23:15:20> [INFO][yapsy_loaded_plugin_Rebuild_1.rebuild.Rebuild][obfuscate()] Running "Rebuild" obfuscator
04/03/2023 23:15:20> [INFO][obfuscapk.toolbundledecompiler.BundleDecompiler][decode()] Running decode command "java -jar /usr/local/bin/BundleDecompiler.jar d --in=app-release.aab --out=obfuscation_working_dir/app-release"
04/03/2023 23:15:37> [INFO][obfuscapk.toolbundledecompiler.BundleDecompiler][build()] Running build command "java -jar /usr/local/bin/BundleDecompiler.jar b --in=obfuscation_working_dir/app-release --out=obfuscation_working_dir/app-release_obfuscated.aab"
04/03/2023 23:15:41> [ERROR][obfuscapk.toolbundledecompiler.BundleDecompiler][build()] Error during build command: obfuscation_working_dir/app-release
obfuscation_working_dir/app-release_obfuscated.aab
build bundle Resources...
build Decompiled Resources...
/home/alex/.tmp/BundleDecompiler//build-tools/30.0.3/linux/aapt2 compile  --dir obfuscation_working_dir/app-release/base/res -o obfuscation_working_dir/tmp/build/res
build bundle to proto.apk...
cd obfuscation_working_dir/tmp/build; /home/alex/.tmp/BundleDecompiler//build-tools/30.0.3/linux/aapt2 link --proto-format -o obfuscation_working_dir/tmp/proto.apk -I /home/alex/.tmp/BundleDecompiler//platforms/android-30/android.jar -R ./res/*.flat  --manifest obfuscation_working_dir/app-release/base/manifest/AndroidManifest.xml
obfuscation_working_dir/app-release/base/manifest/AndroidManifest.xml: error: failed to load XML file: No such file or directory.
Exception in thread "main" com.bundle.exception.EncodeDecodeException: 'BUILD_FAILED'
    at com.bundle.recompile.BuildManager.buildProtoFormatApk(BuildManager.java:354)
    at com.bundle.recompile.BuildManager.buildResourcesFiles(BuildManager.java:79)
    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)

04/03/2023 23:15:41> [ERROR][obfuscapk.obfuscation][build_obfuscated_apk()] Error during apk building: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=obfuscation_working_dir/app-release', '--out=obfuscation_working_dir/app-release_obfuscated.aab']' returned non-zero exit status 1.
04/03/2023 23:15:41> [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=obfuscation_working_dir/app-release', '--out=obfuscation_working_dir/app-release_obfuscated.aab']' returned non-zero exit status 1.
04/03/2023 23:15:41> [CRITICAL][obfuscapk.main][perform_obfuscation()] Error during obfuscation: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=obfuscation_working_dir/app-release', '--out=obfuscation_working_dir/app-release_obfuscated.aab']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/home/alex/Obfuscapk/src/obfuscapk/main.py", line 153, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/home/alex/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/home/alex/Obfuscapk/src/obfuscapk/obfuscation.py", line 553, in build_obfuscated_apk
    bundledecompiler.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/home/alex/Obfuscapk/src/obfuscapk/toolbundledecompiler.py", line 180, in build
    output = subprocess.check_output(
  File "/usr/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=obfuscation_working_dir/app-release', '--out=obfuscation_working_dir/app-release_obfuscated.aab']' returned non-zero exit status 1.
Running obfuscators (Rebuild):   0%|                                                                                                                                              |[00:20<?, ?obfuscator/s]
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/alex/Obfuscapk/src/obfuscapk/cli.py", line 189, in <module>
    main()
  File "/home/alex/Obfuscapk/src/obfuscapk/cli.py", line 171, in main
    perform_obfuscation(
  File "/home/alex/Obfuscapk/src/obfuscapk/main.py", line 153, in perform_obfuscation
    (obfuscator_name_to_function[obfuscator_name])(obfuscation)
  File "/home/alex/Obfuscapk/src/obfuscapk/obfuscators/rebuild/rebuild.py", line 20, in obfuscate
    obfuscation_info.build_obfuscated_apk()
  File "/home/alex/Obfuscapk/src/obfuscapk/obfuscation.py", line 553, in build_obfuscated_apk
    bundledecompiler.build(self._decoded_apk_path, self.obfuscated_apk_path)
  File "/home/alex/Obfuscapk/src/obfuscapk/toolbundledecompiler.py", line 180, in build
    output = subprocess.check_output(
  File "/usr/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-jar', '/usr/local/bin/BundleDecompiler.jar', 'b', '--in=obfuscation_working_dir/app-release', '--out=obfuscation_working_dir/app-release_obfuscated.aab']' returned non-zero exit status 1.

Versions

Additional information

Manifest file are located at /home/alex/Obfuscapk/src/obfuscation_working_dir/app-release/base/manifest/AndroidManifest.xml

Apk file(s):

https://we.tl/t-tRI8wGL7b7

Therahuls1n9h commented 1 year ago

any update regarding this issue?

Haoxiqiang commented 1 year ago

It could be the target version caused, BundleDecompiler only supports 30. support aab file need more extra work. BundleDecompiler last update at Sep 4, 2021

Haoxiqiang commented 1 year ago

I wrote a solution which not like BundleDecompiler's pr PR 121 Obfuscapk should only process the APK's file type and support the creation of the output of an AAB file type. @ClaudiuGeorgiu what do you think about this problem?

Therahuls1n9h commented 1 year ago

is it working? can you share the solution

Haoxiqiang commented 1 year ago

is it working? can you share the solution

yeah, I wrote a tool for converting files between APK and AAB types. It works well, I'm now writing a more friendly way of calling. There are some details that require more coding.

Haoxiqiang commented 1 year ago

simply put. The bundletool provides the basic conversion API. I use different combinations for different files. It's easy but needs some work.

Therahuls1n9h commented 1 year ago

if you can share it would be greatful

Therahuls1n9h commented 1 year ago

@Haoxiqiang if possible please share the tool

Haoxiqiang commented 1 year ago

u can refer to the repo: https://github.com/shapun963/Apk-AAB-Converter

It achieves a similar lib and only needs a small amount of modification.

I wrote a repo as our company library not as the open-source provided now.