Small script fixes.

Fix a problem with python3 and the zipinfo processing of an apk.

Add sorting of the zipinfo data since it's not guaranteed that
the zip entries will be in sorted order, so sort them.

Bug: https://github.com/android/ndk/issues/1587

Test: Ran a apk stack line through the script.
Test: Ran the stack core unit tests.
Change-Id: Ie5ea67ad54a6b2de077e53740c82265f6bf783c6
This commit is contained in:
Christopher Ferris
2021-10-21 00:20:18 +00:00
parent 4506b51f47
commit 7ea56f02c8

View File

@@ -261,7 +261,8 @@ class TraceConverter:
print("Cannot find apk", apk) print("Cannot find apk", apk)
return None, None return None, None
cmd = subprocess.Popen(["zipinfo", "-v", apk_full_path], stdout=subprocess.PIPE) cmd = subprocess.Popen(["zipinfo", "-v", apk_full_path], stdout=subprocess.PIPE,
encoding='utf8')
# Find the first central info marker. # Find the first central info marker.
for line in cmd.stdout: for line in cmd.stdout:
if self.zipinfo_central_directory_line.search(line): if self.zipinfo_central_directory_line.search(line):
@@ -284,6 +285,10 @@ class TraceConverter:
if not file_name and offset >= start and offset < end: if not file_name and offset >= start and offset < end:
file_name = cur_name file_name = cur_name
# Make sure the offset_list is sorted, the zip file does not guarantee
# that the entries are in order.
offset_list = sorted(offset_list, key=lambda entry: entry[1])
# Save the information from the zip. # Save the information from the zip.
tmp_files = dict() tmp_files = dict()
self.apk_info[apk] = [apk_full_path, offset_list, tmp_files] self.apk_info[apk] = [apk_full_path, offset_list, tmp_files]