forked from LineageOS/android_tools_extract-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.py
executable file
·127 lines (110 loc) · 3.06 KB
/
extract.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: 2024 The LineageOS Project
# SPDX-License-Identifier: Apache-2.0
#
import argparse
from extract_utils.extract import (
ExtractCtx,
extract_fns_type,
extract_image,
filter_already_extracted_partitions,
get_dump_dir,
)
from extract_utils.extract_pixel import (
extract_pixel_factory_image,
extract_pixel_firmware,
pixel_factory_image_regex,
pixel_firmware_regex,
)
from extract_utils.extract_star import (
extract_star_firmware,
star_firmware_regex,
)
DEFAULT_EXTRACTED_PARTITIONS = [
'odm',
'product',
'system',
'system_ext',
'vendor',
]
parser = argparse.ArgumentParser(description='Extract')
parser.add_argument(
'--partitions',
nargs='+',
type=str,
help='Partitions to extract',
default=DEFAULT_EXTRACTED_PARTITIONS,
)
parser.add_argument(
'--extra-partitions',
nargs='+',
type=str,
help='Extra partitions to extract',
)
parser.add_argument(
'--all',
action='store_true',
help='Extract all files from archive',
)
parser.add_argument(
'--pixel-factory',
nargs='*',
type=str,
help='Files to extract as pixel factory image',
)
parser.add_argument(
'--pixel-firmware',
nargs='*',
type=str,
help='Files to extract as pixel firmware',
)
parser.add_argument(
'--star-firmware',
nargs='*',
type=str,
help='Files to extract as star firmware',
)
parser.add_argument(
'source',
default='adb',
help='sources from which to extract',
nargs='?',
)
if __name__ == '__main__':
args = parser.parse_args()
if args.pixel_factory is not None and not args.pixel_factory:
args.pixel_factory = [pixel_factory_image_regex]
if args.pixel_firmware is not None and not args.pixel_firmware:
args.pixel_firmware = [pixel_firmware_regex]
if args.star_firmware is not None and not args.star_firmware:
args.star_firmware = [star_firmware_regex]
extract_fns: extract_fns_type = {}
if args.pixel_factory:
for extract_pattern in args.pixel_factory:
extract_fns.setdefault(extract_pattern, []).append(
extract_pixel_factory_image,
)
if args.pixel_firmware:
for extract_pattern in args.pixel_firmware:
extract_fns.setdefault(extract_pattern, []).append(
extract_pixel_firmware,
)
if args.star_firmware:
for extract_pattern in args.star_firmware:
extract_fns.setdefault(extract_pattern, []).append(
extract_star_firmware,
)
extract_partitions = args.partitions
if args.extra_partitions is not None:
extract_partitions += args.extra_partitions
ctx = ExtractCtx(
keep_dump=True,
extract_partitions=extract_partitions,
extract_fns=extract_fns,
extract_all=args.all,
)
with get_dump_dir(args.source, ctx) as dump_dir:
filter_already_extracted_partitions(dump_dir, ctx)
if ctx.extract_partitions:
extract_image(args.source, ctx, dump_dir)