def obfuscate(self, obfuscation_info: Obfuscation): self.logger.info('Running "{0}" obfuscator'.format( self.__class__.__name__)) # Get user defined ignore package list. self.ignore_package_names = obfuscation_info.get_ignore_package_names() try: sdk_class_declarations = self.get_sdk_class_names( obfuscation_info.get_smali_files()) renamed_field_declarations: Set[str] = set() # There is a field limit for dex files. self.max_fields_to_add = ( obfuscation_info.get_remaining_fields_per_obfuscator()) self.added_fields = 0 if obfuscation_info.is_multidex(): for index, dex_smali_files in enumerate( util.show_list_progress( obfuscation_info.get_multidex_smali_files(), interactive=obfuscation_info.interactive, unit="dex", description="Processing multidex", )): self.max_fields_to_add = ( obfuscation_info.get_remaining_fields_per_obfuscator() [index]) self.added_fields = 0 renamed_field_declarations.update( self.rename_field_declarations( dex_smali_files, obfuscation_info.interactive)) else: renamed_field_declarations = self.rename_field_declarations( obfuscation_info.get_smali_files(), obfuscation_info.interactive) # When renaming field references it makes no difference if this is a # multidex application, since at this point we are not introducing any new # field. self.rename_field_references( renamed_field_declarations, obfuscation_info.get_smali_files(), sdk_class_declarations, obfuscation_info.interactive, ) except Exception as e: self.logger.error( 'Error during execution of "{0}" obfuscator: {1}'.format( self.__class__.__name__, e)) raise finally: obfuscation_info.used_obfuscators.append(self.__class__.__name__)
def test_obfuscation_remaining_fields_per_obfuscator( self, tmp_demo_apk_v10_original_path: str): obfuscation = Obfuscation(tmp_demo_apk_v10_original_path) obfuscators_adding_fields = 3 obfuscation.obfuscators_adding_fields = obfuscators_adding_fields result = obfuscation.get_remaining_fields_per_obfuscator() assert isinstance(result, int) assert (result == obfuscation._get_remaining_fields() // obfuscators_adding_fields)