From 2129d854222a932264907c9af98626750408af31 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Thu, 9 Jul 2020 15:26:40 +0100 Subject: [PATCH] utils/android: Use separate tmp dirs when extracting apk methods Create a new temporary directory to use when extracting apk methods, as when running multiple processes in parallel the extracted files could be overwritten by each other. --- devlib/utils/android.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index a5540ec..df96be5 100755 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -214,12 +214,13 @@ class ApkInfo(object): @property def methods(self): if self._methods is None: - with zipfile.ZipFile(self._apk_path, 'r') as z: - extracted = z.extract('classes.dex', tempfile.gettempdir()) + with tempfile.TemporaryDirectory() as tmp_dir: + with zipfile.ZipFile(self._apk_path, 'r') as z: + extracted = z.extract('classes.dex', tmp_dir) - dexdump = os.path.join(os.path.dirname(aapt), 'dexdump') - command = [dexdump, '-l', 'xml', extracted] - dump = self._run(command) + dexdump = os.path.join(os.path.dirname(aapt), 'dexdump') + command = [dexdump, '-l', 'xml', extracted] + dump = self._run(command) xml_tree = xml.etree.ElementTree.fromstring(dump)