-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patheeprom2bin.py
32 lines (29 loc) · 1.01 KB
/
eeprom2bin.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
import os, sys
def convert(filename):
print('Processing: ' + filename)
txtFile = open(os.path.splitext(filename)[0] + '.txt', 'r')
Lines = txtFile.readlines()
print('Writing to: ' + os.path.splitext(filename)[0] + '.bin')
binFile = open(os.path.splitext(filename)[0] + '.bin', 'wb')
for line in Lines:
if line.find('0x') > -1:
binFile.write(bytearray.fromhex(line.strip().split('\t')[1].replace(' ','')))
binFile.close()
txtFile.close()
print('Done.');
match len(sys.argv):
case 2:
convert('.\\' + os.path.splitext(sys.argv[1])[0])
case 1:
for root, dirs, files in os.walk("."):
path = root.split(os.sep)
for file in files:
if (root+file).endswith('.txt'):
convert(root+'\\'+file)
case _:
print("Usage: eeprom2bin.py <filename>")
print(" or: eeprom2bin.py")
input("\nPress Enter to exit...")
sys.exit(1)
input("\nPress Enter to exit...")
sys.exit(1)