Exemplo n.º 1
0
    def __init__(self, filepath, binary=False, apk_path=""):
        super(AndroidManifest, self).__init__(filepath, "AndroidManifest.xml")

        # Load the AndroidManifest.xml structure:
        with open(AndroidManifest.__MANIFEST_CONFIG_FILE, 'r') as config:
            cfg = json.load(config)

        with open(filepath, 'rb') as fp:
            try:
                if binary:
                    self._raw = AXMLPrinter(fp.read()).getBuff()
                    xml = minidom.parseString(self._raw)
                else:
                    xml = minidom.parse(filepath)
            except ExpatError:
                if apk_path != "":
                    apk = Aapt.get_apk_info(apk_path)
                    self._package_name = apk["package_name"]
                    self._version = apk["version"]
                    self._sdk = apk["sdk"]
                    self._permissions = Aapt.get_app_permissions(apk_path)
                    man = Aapt.get_manifest_info(apk_path)
                    self._activities = man["activities"]
                    self._services = man["services"]
                    self._receivers = man["receivers"]
                else:
                    raise AndroidManifestParsingError
            except IOError:
                raise AndroidManifestParsingError
            else:
                manifest = xml.documentElement

                # Extract the package info:
                self._package_name = manifest.getAttribute(
                    cfg['package']['name'])
                self._version = {"code": "", "name": ""}
                try:
                    self._version['code'] = int(
                        manifest.getAttribute(
                            cfg['package']['version']['code']))
                except ValueError:
                    pass
                self._version['name'] = manifest.getAttribute(
                    cfg['package']['version']['name'])

                # Extract the SDK info:
                sdk = self._parse_element_to_list_of_dict(
                    manifest, cfg['uses-sdk'], "uses-sdk")
                if len(sdk) > 0:
                    self._sdk = sdk[0]
                else:
                    self._sdk = {}

                # Extract the permissions info:
                self._permissions = AndroidManifest._parse_element_to_simple_list(
                    manifest, "uses-permission", cfg['uses-permission'][0])

                # Extract the application info:
                application = manifest.getElementsByTagName(
                    cfg['application']['tag'])
                application = application[0]
                self._activities = AndroidManifest._parse_element_to_list_of_dict(
                    application, cfg['application']['activity'], "activity")
                self._services = AndroidManifest._parse_element_to_list_of_dict(
                    application, cfg['application']['service'], "service")
                self._receivers = AndroidManifest._parse_element_to_list_of_dict(
                    application, cfg['application']['receiver'], "receiver")
Exemplo n.º 2
0
 def test_get_manifest_info(self):
     for filename in self.files:
         man = Aapt.get_manifest_info(self.files[filename])
         self.assertTrue(man['activities'] == self.files_properties[filename]['activities'])
         self.assertTrue(man['services'] == self.files_properties[filename]['services'])
         self.assertTrue(man['receivers'] == self.files_properties[filename]['receivers'])
Exemplo n.º 3
0
 def test_get_manifest_info(self):
     for filename in self.files:
         man = Aapt.get_manifest_info(self.files[filename])
         self.assertTrue(man['activities'] == self.files_properties[filename]['activities'])
         self.assertTrue(man['services'] == self.files_properties[filename]['services'])
         self.assertTrue(man['receivers'] == self.files_properties[filename]['receivers'])