Example #1
0
    def _extract_and_set_entries(self, string_processing):
        exists_invalid_entry = False

        apk_filepath = self.get_file_path()
        with ZipFile(apk_filepath) as apk:
            tmpdir = tempfile.mkdtemp(APK._TEMPORARY_DIR)

            for filename in apk.namelist():
                entry_filepath = apk.extract(filename, tmpdir)

                try:
                    if AndroidManifest.looks_like_a_manifest(filename):
                        self._manifest = AndroidManifest(entry_filepath, True, apk_filepath)
                    elif CERT.looks_like_a_cert(filename):
                        self._cert = CERT(entry_filepath, filename)
                    elif Dex.looks_like_a_dex(filename):
                        self._dex = Dex(entry_filepath, string_processing)
                    else:
                        if not os.path.isdir(entry_filepath):
                            self._files.append(File(entry_filepath, filename))
                except (ParsingError, AndroidManifestParsingError, CERTParsingError):
                    exists_invalid_entry = True

            try:
                shutil.rmtree(tmpdir)
            except OSError:
                pass

            if exists_invalid_entry:
                raise APKParsingError