File: hex2rapatch.py

package info (click to toggle)
radare2 6.0.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,360 kB
  • sloc: ansic: 903,263; sh: 8,137; javascript: 7,911; makefile: 5,503; python: 2,730; cpp: 789; perl: 404; lisp: 122; sed: 85; asm: 57; cs: 37; xml: 32; ruby: 29; java: 21
file content (26 lines) | stat: -rwxr-xr-x 641 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

""" Portable python script to convert Intel hex file to rapatch """

from intelhex import IntelHex
import argparse

parser = argparse.ArgumentParser(
    prog='ihex2rapatch',
    description='Convert Intel hex file to radare2 patch file')

parser.add_argument('source', help='Intel Hex source file')
parser.add_argument('target', help='radare2 patch target file')

args = parser.parse_args()

f = open(args.target, 'w')

ih = IntelHex(args.source)
for segment in ih.segments():
    f.write(hex(segment[0]) + ': ')
    for x in range(segment[0],segment[1]):
        f.write(f'{ih[x]:02x}')
    f.write('\n')

f.close()