-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecodeHexFrame
More file actions
executable file
·46 lines (30 loc) · 918 Bytes
/
decodeHexFrame
File metadata and controls
executable file
·46 lines (30 loc) · 918 Bytes
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
#!/usr/bin/env python3
import sys
def main(argv):
#
dump = []
# try to open file passed by user
try :
with open(argv[0], "r", encoding="utf8") as hexdump:
#assign hexa value table to dump var
dump = hexdump.read().replace("\n", " ").split(" ")
except :
# if no file print err & exit
print("Impossible to open hexa file !")
sys.exit()
dump_length = len(dump)
print(f"Destination:\t{dump[0:6]}")
print(f"Source:\t{dump[6:12]}")
print(f"Type:\t{dump[12:14]}")
print(f"Data:\t{dump[14:dump_length-5]}")
print(f"CRC:\t{dump[dump_length-5:dump_length-1]}\n")
data = []
print(f"Data to text (ASCII)\n")
for c in dump[14:dump_length-5]:
try:
data.append(bytearray.fromhex(c).decode())
except UnicodeDecodeError:
data.append('.')
print(", ".join(data).replace(", ", ""))
if __name__ == "__main__":
main(sys.argv[1:])