forked from alephsecurity/abootool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abootool.py
executable file
·96 lines (71 loc) · 3.48 KB
/
abootool.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
#!/usr/bin/python
"""
Author: Roee Hay / Aleph Research / HCL Technologies
"""
import device
from oemtester import OEMTester
import argparse
from config import Config
import log
from log import *
import aboot
import image
def main():
adjustLevels()
parser = argparse.ArgumentParser("ABOOTOOL")
parser.add_argument('-e','--oem', dest='oem', help='Specify OEM to load ABOOT strings of, otherwise try to autodetect')
parser.add_argument('-d','--device', dest='device', help='Specify device to load ABOOT strings of, otherwise try to autodetect')
parser.add_argument('-b','--build', dest='build', help='Specify build to load ABOOT strings of, otherwise try to autodetect')
parser.add_argument('-r', '--resume', type=int, default=0, dest='index', help='Resume from specified string index')
parser.add_argument('-i', '--ignore', dest='ignore_re', help='Ignore pattern (regexp)')
parser.add_argument('-g', '--use-strings-generator', action='store_true', default=False, dest='use_strings_generator', help='Use strings generator instead of loading everything a priori (fast but degrades progress)')
parser.add_argument('-o', '--output', action='store_true', dest='show_output', help="Show output of succeeded fastboot commands. Verbose logging overrides this")
parser.add_argument('-l','--aboots-list', action='store_true', dest='aboots', help="List available ABOOTs")
parser.add_argument('-a','--images-add', dest='images_path', help="Add ABOOT strings from OTA/Factory images. Either a file or a directory.")
parser.add_argument('-B','--blob', action='store_true', default=False, dest='treat_as_blob', help="Treat specified path as ABOOT blob")
parser.add_argument('-S','--string-prefix', default="", dest='string_prefix', help="When inserting new images, only treat strings with specified prefix")
parser.add_argument('-s','--device-serial', dest='serial', help="Specify device fastboot SN")
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', help='Enable verbose logging')
parser.add_argument('-vv', '--moreverbose', action='store_true', dest='moreverbose', help='Even more logging')
parser.add_argument('-t', '--timeout', type=int, default=5000, dest='timeout', help='USB I/O timeout (ms)')
args = parser.parse_args()
if args.verbose:
log.setVerbose()
if args.moreverbose:
log.setVerbose(True)
I("Welcome to abootool by Aleph Research, HCL technologies")
Config.overlay(args.__dict__)
T("Config = %s", Config)
if args.treat_as_blob:
if not args.oem or not args.device or not args.build:
E("Missing OEM/Device/Build specifiers")
return 1
if args.aboots:
I("BY OEM:")
I("-------")
dump_data(aboot.by_oem())
I("")
I("BY DEVICE:")
I("----------")
dump_data(aboot.by_device())
return 0
if args.images_path:
image.add(args.images_path)
return 0
dev = device.Device(args.serial)
name = dev.device()
adjustLevels()
if name:
I("Device reported name = %s", name)
OEMTester(dev).test(args.index)
return 0
def dump_data(data):
keys = data.keys()
keys.sort()
nkeys = len(keys)
for i in xrange(0, nkeys - 1, 2):
I("%17s: %3d %17s: %3d", keys[i], len(data[keys[i]]), keys[i + 1], len(data[keys[i + 1]]))
if 1 == nkeys % 2:
I("%17s: %3d", keys[nkeys - 1], len(data[keys[nkeys - 1]]))
if __name__ == "__main__":
sys.exit(main())