From 96a30328031dcc33bfd4c81e4161441388a2187a Mon Sep 17 00:00:00 2001 From: Auto Black Formatter Date: Fri, 24 Dec 2021 13:26:30 +0000 Subject: [PATCH] Format code with Black [auto] --- src/obfuscapk/obfuscation.py | 49 ++++++++++++++++----------- src/obfuscapk/toolbundledecompiler.py | 36 +++++++++++++------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/obfuscapk/obfuscation.py b/src/obfuscapk/obfuscation.py index ca7ce11b..0d12a17c 100644 --- a/src/obfuscapk/obfuscation.py +++ b/src/obfuscapk/obfuscation.py @@ -47,7 +47,7 @@ def __init__( self.key_password: str = key_password self.ignore_packages_file: str = ignore_packages_file self.use_aapt2 = use_aapt2 - if apk_path.endswith('aab'): + if apk_path.endswith("aab"): self.is_bundle = True else: self.is_bundle = False @@ -119,7 +119,7 @@ def __init__( # If the path of the output obfuscated apk is not specified, save it in the # working directory. if not self.obfuscated_apk_path: - if (self.is_bundle): + if self.is_bundle: self.obfuscated_apk_path = "{0}_obfuscated.aab".format( os.path.join( self.working_dir_path, @@ -352,21 +352,25 @@ def decode_apk(self) -> None: os.path.splitext(os.path.basename(self.apk_path))[0], ) try: - if (self.is_bundle): - bundledecompiler.decode(self.apk_path, self._decoded_apk_path, force=False) + if self.is_bundle: + bundledecompiler.decode( + self.apk_path, self._decoded_apk_path, force=False + ) else: apktool.decode(self.apk_path, self._decoded_apk_path, force=True) - # Path to the decoded manifest file. - if (self.is_bundle): + if self.is_bundle: self._manifest_file = os.path.join( - self._decoded_apk_path, "base", "manifest", "AndroidManifest.xml", + self._decoded_apk_path, + "base", + "manifest", + "AndroidManifest.xml", ) else: self._manifest_file = os.path.join( - self._decoded_apk_path, "AndroidManifest.xml" - ) + self._decoded_apk_path, "AndroidManifest.xml" + ) # A list containing the paths to all the smali files obtained with # apktool or bundledecompiler. @@ -412,9 +416,11 @@ def decode_apk(self) -> None: self._smali_files.sort() # Check if multidex. - if (self.is_bundle): + if self.is_bundle: if os.path.isdir( - os.path.join(self._decoded_apk_path, "base", "dex", "smali_classes2") + os.path.join( + self._decoded_apk_path, "base", "dex", "smali_classes2" + ) ): self._is_multidex = True else: @@ -423,15 +429,19 @@ def decode_apk(self) -> None: ): self._is_multidex = True - if (self._is_multidex): + if self._is_multidex: smali_directories = ["smali"] for i in range(2, 15): smali_directories.append("smali_classes{0}".format(i)) for smali_directory in smali_directories: - if (self.is_bundle): + if self.is_bundle: current_directory = os.path.join( - self._decoded_apk_path, "base", "dex", smali_directory, "" + self._decoded_apk_path, + "base", + "dex", + smali_directory, + "", ) else: current_directory = os.path.join( @@ -539,7 +549,7 @@ def build_obfuscated_apk(self) -> None: bundledecompiler: BundleDecompiler = BundleDecompiler() try: - if (self.is_bundle): + if self.is_bundle: bundledecompiler.build(self._decoded_apk_path, self.obfuscated_apk_path) else: apktool.build(self._decoded_apk_path, self.obfuscated_apk_path) @@ -579,7 +589,7 @@ def sign_obfuscated_apk(self) -> None: ) try: - if (self.is_bundle): + if self.is_bundle: aabsigner.sign( self.obfuscated_apk_path, ) @@ -601,7 +611,7 @@ def align_obfuscated_apk(self) -> None: # The obfuscated apk will be aligned with zipalign. zipalign: Zipalign = Zipalign() - if (self.is_bundle): + if self.is_bundle: return try: @@ -652,7 +662,7 @@ def get_assets_directory(self) -> str: self.decode_apk() # '.join(x, "")' is used to add a trailing slash. - if (self.is_bundle): + if self.is_bundle: return os.path.join(self._decoded_apk_path, "base", "assets", "") else: return os.path.join(self._decoded_apk_path, "assets", "") @@ -663,11 +673,10 @@ def get_resource_directory(self) -> str: self.decode_apk() # '.join(x, "")' is used to add a trailing slash. - if (self.is_bundle): + if self.is_bundle: return os.path.join(self._decoded_apk_path, "base", "res", "") else: return os.path.join(self._decoded_apk_path, "res", "") - def get_ignore_package_names(self) -> List[str]: ignore_package_list = [] diff --git a/src/obfuscapk/toolbundledecompiler.py b/src/obfuscapk/toolbundledecompiler.py index 8fc450ed..73fd23c6 100644 --- a/src/obfuscapk/toolbundledecompiler.py +++ b/src/obfuscapk/toolbundledecompiler.py @@ -15,7 +15,9 @@ def __init__(self): ) if platform.system() == "Windows": - self.logger.warning("BundleDecompiler is not yet available on Windows platform") + self.logger.warning( + "BundleDecompiler is not yet available on Windows platform" + ) return if "BUNDLE_DECOMPILER_PATH" in os.environ: @@ -28,14 +30,18 @@ def __init__(self): # Make sure bundle decompiler is available if not os.path.isfile(full_bundledecompiler_path): raise RuntimeError( - 'Cannot find BundleDecompiler with executable "{0}"'.format(full_bundledecompiler_path) + 'Cannot find BundleDecompiler with executable "{0}"'.format( + full_bundledecompiler_path + ) ) # Make sure to use the full path of the executable (needed for cross-platform # compatibility). if full_bundledecompiler_path is None: raise RuntimeError( - 'Something is wrong with executable "{0}"'.format(self.bundledecompiler_path) + 'Something is wrong with executable "{0}"'.format( + self.bundledecompiler_path + ) ) else: self.bundledecompiler_path = full_bundledecompiler_path @@ -44,7 +50,9 @@ def decode( self, aab_path: str, output_dir_path: str = None, force: bool = False ) -> str: if platform.system() == "Windows": - raise NotImplementedError("BundleDecompiler is not yet available on Windows platform") + raise NotImplementedError( + "BundleDecompiler is not yet available on Windows platform" + ) # Check if the aab file to decode is a valid file. if not os.path.isfile(aab_path): @@ -102,9 +110,7 @@ def decode( ] if force: - self.logger.warning( - 'Bundle Decompiler does not support force' - ) + self.logger.warning("Bundle Decompiler does not support force") try: self.logger.info( @@ -132,7 +138,9 @@ def decode( def build(self, source_dir_path: str, output_aab_path: str = None) -> str: if platform.system() == "Windows": - raise NotImplementedError("BundleDecompiler is not yet available on Windows platform") + raise NotImplementedError( + "BundleDecompiler is not yet available on Windows platform" + ) # Check if the input directory exists. if not os.path.isdir(source_dir_path): @@ -206,7 +214,9 @@ def __init__(self): ) if platform.system() == "Windows": - self.logger.warning("BundleDecompiler is not yet available on Windows platform") + self.logger.warning( + "BundleDecompiler is not yet available on Windows platform" + ) return if "BUNDLE_DECOMPILER_PATH" in os.environ: @@ -230,7 +240,9 @@ def sign( aab_path: str, ) -> str: if platform.system() == "Windows": - raise NotImplementedError("BundleDecompiler is not yet available on Windows platform") + raise NotImplementedError( + "BundleDecompiler is not yet available on Windows platform" + ) # Check if the aab file to sign is a valid file. if not os.path.isfile(aab_path): @@ -243,12 +255,12 @@ def sign( self.aabsigner_path, "sign-bundle", "--in=" + aab_path, - "--out=" + aab_path.replace(".aab","_signed.aab") + "--out=" + aab_path.replace(".aab", "_signed.aab"), ] try: self.logger.info('Running sign command "{0}"'.format(" ".join(sign_cmd))) - output = subprocess.check_output(sign_cmd, stderr=subprocess.STDOUT).strip() + output = subprocess.check_output(sign_cmd, stderr=subprocess.STDOUT).strip() return output.decode(errors="replace") except subprocess.CalledProcessError as e: self.logger.error(