Skip to content

Instantly share code, notes, and snippets.

@i5ar
Created May 2, 2019 22:42
Show Gist options
  • Save i5ar/2f422afc514ef07cc81aec0b88b5eade to your computer and use it in GitHub Desktop.
Save i5ar/2f422afc514ef07cc81aec0b88b5eade to your computer and use it in GitHub Desktop.
Edit Intel HEX file
from intelhex import IntelHex
from pathlib import Path
FILE_IN = Path('./in.hex')
FILE_OUT = Path('./out.hex')
# Open HEX file, replace a byte and save in a new HEX file.
# https://python-intelhex.readthedocs.io/en/latest/part2-2.html
ih = IntelHex()
with open(FILE_IN) as in_, open(FILE_OUT, 'w') as out:
ih.fromfile(in_, format='hex') # read
# NOTE: Replace first byte.
ih[0] = 0x55
ih.tofile(out, format='hex') # or `ih.write_hex_file(out)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment