-
Notifications
You must be signed in to change notification settings - Fork 82
/
b64_to_bin.py
43 lines (31 loc) · 875 Bytes
/
b64_to_bin.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
import sys
import base64
from pathlib import Path
def main():
if len(sys.argv) < 2:
print(f"Usage: python3 {sys.argv[0]} [infile] <outfile>")
print(f" e.g. python3 {sys.argv[0]} config.bin")
return 1
infile = Path(sys.argv[1])
if len(sys.argv) > 2:
outfile = Path(sys.argv[2])
else:
outfile = infile
if not infile.is_file():
print(f"{infile} not found")
return 1
with infile.open("rb") as f:
data = f.read()
if data[:4] != b"BAMC":
print("This isn't a base64 encoded config.bin")
return 1
try:
decoded = base64.b64decode(data)
except Exception as e:
print(f"Failed to base64 decode {infile}: e")
return
with outfile.open("wb") as f:
f.write(decoded)
print("Success!")
if __name__ == "__main__":
main()