-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_partition.py
executable file
·61 lines (53 loc) · 1.77 KB
/
extract_partition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Extracts an LLD partition from an ELF file."""
import argparse
import subprocess
import sys
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--partition',
help='Name of partition if not the main partition',
metavar='PART')
parser.add_argument(
'--objcopy',
required=True,
help='Path to llvm-objcopy binary',
metavar='FILE')
parser.add_argument(
'--unstripped-output',
required=True,
help='Unstripped output file',
metavar='FILE')
parser.add_argument(
'--stripped-output',
required=True,
help='Stripped output file',
metavar='FILE')
parser.add_argument('--dwp', help='Path to dwp binary', metavar='FILE')
parser.add_argument('input', help='Input file')
args = parser.parse_args()
objcopy_args = [args.objcopy]
if args.partition:
objcopy_args += ['--extract-partition', args.partition]
else:
objcopy_args += ['--extract-main-partition']
objcopy_args += [args.input, args.unstripped_output]
subprocess.check_call(objcopy_args)
objcopy_args = [
args.objcopy, '--strip-all', args.unstripped_output, args.stripped_output
]
subprocess.check_call(objcopy_args)
if args.dwp:
dwp_args = [
args.dwp, '-e', args.unstripped_output, '-o',
args.unstripped_output + '.dwp'
]
# Suppress output here because it doesn't seem to be useful. The most
# common error is a segfault, which will happen if files are missing.
subprocess.check_output(dwp_args, stderr=subprocess.STDOUT)
if __name__ == '__main__':
sys.exit(main())