summaryrefslogtreecommitdiff
path: root/tools/extract_kernel.py
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2019-09-04 12:40:13 -0700
committerYifan Hong <elsk@google.com>2019-09-16 16:30:35 -0700
commit8b727765111bde78d1b1174e0ed54db819605dd8 (patch)
treed18a46179a00d4df3a2e7b77be58fcbcd5af1938 /tools/extract_kernel.py
parent979c9f3117a3ee1d963bba463c772f682e086343 (diff)
extract-kernel: Fix indexing
The original script always tries to extract from index 0 even if header is found in positive indices. Fix that. Also, continue to try other positions if previous run failed. Test: builds Bug: 139348603 Change-Id: Ia54fc709de9ae587fc64b59d94a1fa4ae669c14f
Diffstat (limited to 'tools/extract_kernel.py')
-rwxr-xr-xtools/extract_kernel.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/tools/extract_kernel.py b/tools/extract_kernel.py
index 42561cf0c6..8ca11d1cc6 100755
--- a/tools/extract_kernel.py
+++ b/tools/extract_kernel.py
@@ -100,19 +100,25 @@ def dump_configs(input_bytes):
return o
-def try_decompress(cmd, search_bytes, input_bytes):
- idx = input_bytes.find(search_bytes)
- if idx < 0:
- return None
-
- idx = 0
+def try_decompress_bytes(cmd, input_bytes):
sp = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- o, _ = sp.communicate(input=input_bytes[idx:])
+ o, _ = sp.communicate(input=input_bytes)
# ignore errors
return o
+def try_decompress(cmd, search_bytes, input_bytes):
+ idx = 0
+ while True:
+ idx = input_bytes.find(search_bytes, idx)
+ if idx < 0:
+ raise StopIteration()
+
+ yield try_decompress_bytes(cmd, input_bytes[idx:])
+ idx += 1
+
+
def decompress_dump(func, input_bytes):
"""
Run func(input_bytes) first; and if that fails (returns value evaluates to
@@ -122,15 +128,15 @@ def decompress_dump(func, input_bytes):
if o:
return o
for cmd, search_bytes in COMPRESSION_ALGO:
- decompressed = try_decompress(cmd, search_bytes, input_bytes)
- if decompressed:
- o = func(decompressed)
- if o:
- return o
+ for decompressed in try_decompress(cmd, search_bytes, input_bytes):
+ if decompressed:
+ o = decompress_dump(func, decompressed)
+ if o:
+ return o
# Force decompress the whole file even if header doesn't match
- decompressed = try_decompress(cmd, b"", input_bytes)
+ decompressed = try_decompress_bytes(cmd, input_bytes)
if decompressed:
- o = func(decompressed)
+ o = decompress_dump(func, decompressed)
if o:
return o