Created
May 2, 2019 22:42
-
-
Save i5ar/2f422afc514ef07cc81aec0b88b5eade to your computer and use it in GitHub Desktop.
Edit Intel HEX file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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