-
Notifications
You must be signed in to change notification settings - Fork 82
/
info.py
74 lines (60 loc) · 2.19 KB
/
info.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
"""Extract info from config.bin"""
import argparse
import zcu
def print_payload_info(infile):
"""expects to be at the start of the payload magic"""
# check magic
header = infile.read(4)
if header == b"BAMC":
print(f"ERROR: {infile.name} is base64 encoded, please decode and try again.")
return 1
infile.seek(0)
zcu.zte.read_header(infile)
signature = zcu.zte.read_signature(infile)
payload_header = zcu.zte.read_payload(infile)
assert (
payload_header[0] == zcu.constants.PAYLOAD_MAGIC
), "File does not begin with 0x01020304"
payload_start = infile.tell()
payload_type = payload_header[1]
if payload_type == 0:
payload_type_friendly = "(ZLIB)"
elif payload_type == 1:
payload_type_friendly = "(ZLIB+CRC)"
elif payload_type == 2:
payload_type_friendly = "(ZLIB+AES128ECB)"
elif payload_type == 3:
payload_type_friendly = "(ZLIB+AES256CBCSAMEIV)"
elif payload_type == 4:
payload_type_friendly = "(ZLIB+AES256CBCDIFFIV)"
else:
payload_type_friendly = "(UNKNOWN)"
payload_length = payload_header[2]
penultimate_chunk = payload_header[3]
payload_chunk_size = payload_header[4]
payload_crc = payload_header[5]
payload_header_crc = payload_header[6]
if len(signature) > 0:
print("Signature: ", signature.decode("utf-8"))
print("Payload Type: ", payload_type, payload_type_friendly)
print("Payload Start: ", payload_start)
print("Decompressed size: ", payload_length, "bytes")
print("2nd last chunk: ", penultimate_chunk)
print("Chunk size: ", payload_chunk_size, "bytes")
print("Payload CRC: ", payload_crc)
print("Header CRC: ", payload_header_crc)
def main():
"""the main function"""
parser = argparse.ArgumentParser(
description="Read config.bin for ZTE Routers",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"infile",
type=argparse.FileType("rb"),
help="Raw configuration file (config.xml)",
)
args = parser.parse_args()
print_payload_info(args.infile)
if __name__ == "__main__":
main()