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
def test_init(self): for filename in self.dexes: self.assertTrue(self.dexes[filename] is not None) self.assertTrue(type(self.dexes[filename]) is Dex) # Test the class raise when a non-existing file is given: with self.assertRaises(ParsingError): Dex(join('test', 'data', 'aaa_this_is_a_non_existent_file_xxx'))
def setUpClass(cls): cls.dexes = {} for file in listdir(join('test', 'data')): if file in cls.dex_properties: cls.dexes[file] = Dex(join('test', 'data', file))