-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinToArrayC.py
More file actions
51 lines (38 loc) · 1.07 KB
/
BinToArrayC.py
File metadata and controls
51 lines (38 loc) · 1.07 KB
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
'''
Created on 30.01.2017
@author: Haz
'''
import os
import sys
if len(sys.argv) > 1:
input_file_name = sys.argv[1]
else:
input_file_name = "FSB_TouchReaderManager.bin"
scritDirectory = os.path.dirname(sys.argv[0])
output_file_name = "BinArray.c"
bin_list = []
with open(input_file_name, 'rb') as f:
while True:
b = f.read(1)
if not b:
# eof
break
bin_list.append(b)
output_content = ""
output_content += "#include \"stdint.h\"\n\n"
output_content += "static uint32_t BinArraySize = " + str(len(bin_list)) + ";\n"
output_content += "static uint8_t BinArray[] =\n{ \n"
output_content += " "
item_iterator = 0
for item in bin_list:
byte_string = '0x' + hex(ord(item))[2:].zfill(2)
output_content += byte_string + ", "
item_iterator += 1
if item_iterator == 20:
output_content += "\n "
item_iterator = 0
output_content = output_content[:-2]
output_content += "\n"
output_content += "};"
print output_content
open(scritDirectory + '\\' + output_file_name, 'wb').write(output_content)