12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import sys
- def parse_hex_line( line ):
- if len( current_line ) == 0: return
- bytecount = int( line[0:2], 16 )
- address = int( line[2:6], 16 )
- rec_type = int( line[6:8], 16 )
- rec_output = str(hex(address)) + '\t(' + str(bytecount) + ')\t'
- if rec_type == 0:
- rec_output += '(data)'
- rec_output += '\t\t' + line[8:(8+2*(bytecount))]
- elif rec_type == 1:
- rec_output += '(end of file)'
- elif rec_type == 2:
- rec_output += '(extended segment address)'
- elif rec_type == 3:
- rec_output += '(start segment address)'
- elif rec_type == 4:
- rec_output += '(extended linear address)'
- elif rec_type == 5:
- rec_output += '(start linear address)'
- print (rec_output)
- hex_file_path = sys.argv[1]
- print ("Parsing " + hex_file_path)
- hex_file = open(hex_file_path, "rb")
- current_line = ""
- try:
- byte = "1"
- while byte != "":
- byte = hex_file.read(1)
- if byte == ":":
-
- parse_hex_line( current_line )
-
- current_line = ""
- else:
- current_line += byte
- parse_hex_line( current_line )
- finally:
- hex_file.close()
|