def main(): """ A full command to obfuscate an application: python3 -m obfuscapk.cli -p -i -w /working/dir/path -d /path/to/obfuscated.apk \ -o DebugRemoval -o LibEncryption -o CallIndirection -o MethodRename \ -o AssetEncryption -o MethodOverload -o ConstStringEncryption \ -o ResStringEncryption -o ArithmeticBranch -o FieldRename -o Nop -o Goto \ -o ClassRename -o Reflection -o AdvancedReflection -o Reorder -o RandomManifest \ -o Rebuild -o NewSignature -o NewAlignment \ -o VirusTotal -k virus_total_key_1 -k virus_total_key_2 \ /path/to/original.apk """ # Verify that the external dependencies are available even before showing the help # message: this way, if the help message is displayed correctly it means that all # the needed external tools are available and ready to be used. check_external_tool_dependencies() arguments = get_cmd_args() if arguments.apk_file: arguments.apk_file = arguments.apk_file.strip(" '\"") if arguments.working_dir: arguments.working_dir = arguments.working_dir.strip(" '\"") if arguments.destination: arguments.destination = arguments.destination.strip(" '\"") if arguments.virus_total_key: arguments.virus_total_key = [ key.strip(" '\"") for key in arguments.virus_total_key ] if arguments.keystore_file: arguments.keystore_file = arguments.keystore_file.strip(" '\"") if arguments.keystore_password: arguments.keystore_password = arguments.keystore_password.strip(" '\"") if arguments.key_alias: arguments.key_alias = arguments.key_alias.strip(" '\"") if arguments.key_password: arguments.key_password = arguments.key_password.strip(" '\"") perform_obfuscation( arguments.apk_file, arguments.obfuscator, arguments.working_dir, arguments.destination, arguments.interactive, arguments.ignore_libs, arguments.virus_total_key, arguments.keystore_file, arguments.keystore_password, arguments.key_alias, arguments.key_password, )
def test_perform_obfuscation_error_invalid_obfuscator_name( self, tmp_demo_apk_v10_original_path: str, ): with pytest.raises(ValueError): perform_obfuscation( tmp_demo_apk_v10_original_path, ["invalid.obfuscator.name"], )
def test_perform_obfuscation_error_generic_obfuscator_error( self, tmp_working_directory_path: str): # The Rebuild obfuscator will fail with an invalid input file. invalid_file_path = os.path.join(tmp_working_directory_path, "invalid.apk") with open(invalid_file_path, "w") as invalid_file: invalid_file.write("This is not an apk file\n") with pytest.raises(Exception): perform_obfuscation(invalid_file_path, ["Rebuild"])
def home(request): if request.method == "POST": name = request.FILES['lib'] contac = Apps(app=name) if name.name[:-5:-1] != "kpa.": print("wrong file") delete() else: contac.save() main.perform_obfuscation(f"Apps/AppTools/{name.name}",["Nop","Rebuild"],interactive=True) try: app = os.path.splitext(f"Apps/AppTools/obfuscation_working_dir/{name.name}")[0]+"_obfuscated.apk" with open(app,"rb") as f: response=HttpResponse(f.read(),content_type="application/adminupload") response['Content-Disposition']='inline;filename='+os.path.basename(app) os.remove(f"Apps/AppTools/{name.name}") return response except Exception as e: print("serger f****d",e) return render(request,"list.html")
def test_perform_full_obfuscation_valid_apk( self, tmp_working_directory_path: str, tmp_demo_apk_v10_original_path: str, ): obfuscated_apk_path = os.path.join(tmp_working_directory_path, "obfuscated.apk") perform_obfuscation( tmp_demo_apk_v10_original_path, [ "DebugRemoval", "LibEncryption", "CallIndirection", "MethodRename", "AssetEncryption", "MethodOverload", "ConstStringEncryption", "ResStringEncryption", "ArithmeticBranch", "FieldRename", "Nop", "Goto", "ClassRename", "Reflection", "AdvancedReflection", "Reorder", "RandomManifest", "Rebuild", "NewSignature", "NewAlignment", ], tmp_working_directory_path, obfuscated_apk_path, interactive=True, ignore_libs=True, ) assert os.path.isfile(obfuscated_apk_path)
def test_perform_obfuscation_error_invalid_apk_path(self): with pytest.raises(FileNotFoundError): perform_obfuscation("invalid.apk.path", [])
def test_perform_obfuscation_error_missing_external_tool( self, monkeypatch): monkeypatch.setenv("APKTOOL_PATH", "invalid.apktool.path") with pytest.raises(RuntimeError) as e: perform_obfuscation("ignore.apk", []) assert "Something is wrong with executable" in str(e.value)