コード例 #1
0
    def insert(self, specific_name, mod_count=1):
        """
        Insert an component based on 'specfic_name' into manifest.xml file
        """
        if not isinstance(specific_name, str) and not os.path.isdir(
                self.disassembly_root):
            raise ValueError("Value error: require str type of variables.")

        manifest_tree = xu.get_xmltree_by_ET(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST))

        info, flag, new_manifest_tree = xu.insert_comp_manifest(
            manifest_tree, self.comp_type, specific_name, mod_count)

        xu.dump_xml(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST),
            new_manifest_tree)

        if self.verbose:
            if flag:
                logger.info(info)
                logger.info(
                    "'{}' insertion: Successfully insert activity '{}' into '{}'/androidmanifest.xml"
                    .format(self.comp_type, specific_name,
                            os.path.basename(self.disassembly_root)))
            else:
                logger.warn(info)
                raise e.ModifyFileException(info)
コード例 #2
0
    def insert(self, specific_name, mod_count=1):
        '''Insert an hardware based on 'specfic_name' into manifest.xml file'''
        if not isinstance(specific_name, str) and not os.path.isdir(
                self.disassembly_root):
            raise TypeError("Type error:")

        if mod_count < 0:
            raise ValueError(
                "The amount of insertion cannot be smaller than 0.")

        manifest_tree = xu.get_xmltree_by_ET(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST))

        info, flag, new_manifest_tree = xu.insert_perm_manifest(
            manifest_tree, self.comp_type, specific_name, mod_count)

        xu.dump_xml(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST),
            new_manifest_tree)

        if self.verbose:
            if flag:
                logger.info(info)
                logger.info(
                    'Hardware insertion: Successfully insert \'{}\' into \'{}/androidmanifest.xml\''
                    .format(specific_name,
                            os.path.basename(self.disassembly_root)))
            else:
                logger.warn(info)
コード例 #3
0
    def remove(self, specific_name, mod_count=-1):
        """
        change the denoted component name to a random string
        mod_count = -1 indicates that all the corresponding elements will be changed
        """

        # step 1: modify the corresponding name in AndroidManifest.xml

        if not isinstance(specific_name, str) and not os.path.exists(
                self.disassembly_root):
            raise ValueError("Value error:")

        # mod_count = -1 change name of all the specified components

        manifest_tree = xu.get_xmltree_by_ET(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST))

        info, flag, new_comp_name, new_manifest_tree = xu.rename_comp_manifest(
            manifest_tree, self.comp_type, specific_name)
        xu.dump_xml(
            os.path.join(self.disassembly_root, droid_modification.MANIFEST),
            new_manifest_tree)

        if self.verbose:
            if flag:
                logger.info(info)
                logger.info(
                    "'{}' name changing: Successfully change name '{}' to '{}' of '{}'/androidmanifest.xml"
                    .format(self.comp_type, specific_name, new_comp_name,
                            os.path.basename(self.disassembly_root)))
            else:
                logger.warn(info + ": {}/androidmanifest.xml".format(
                    os.path.basename(self.disassembly_root)))
                return

        # step 2: modify .smali files accordingly
        package_name = manifest_tree.getroot().get('package')
        smali_paths = du.get_smali_paths(self.disassembly_root)
        related_smali_paths = set(
            du.find_smali_w_name(smali_paths, specific_name))
        du.change_source_name(related_smali_paths, specific_name,
                              new_comp_name)
        changed_class_names = set(
            du.change_class_name(related_smali_paths, specific_name,
                                 new_comp_name, package_name))

        # Change class instantiation
        if len(changed_class_names) > 0:
            du.change_instantition_name(smali_paths, changed_class_names,
                                        specific_name, new_comp_name,
                                        package_name)

        if self.verbose:
            logger.info(
                "'{}' name changing: Successfully change '{}' name in smali files"
                .format(self.comp_type, specific_name))

        # step 3: modify all .xml files accordingly
        if len(changed_class_names) > 0:
            xml_paths = xu.get_xml_paths(self.disassembly_root)
            # todo: change asset xml
            # xu.change_xml(xml_paths, changed_class_names,
            #              specific_name, new_comp_name, package_name)

        if self.verbose:
            logger.info(
                "'{}' name changing: Successfully change '{}' name in xml files"
                .format(self.comp_type, specific_name))

        # step 4: modify folder and file names
        self._rename_files(smali_paths, specific_name, new_comp_name)