Plain C library for manipulating IntelHex files.
- robust intelhex parsing
- binary data segmentation
- dynamic memory allocation
- automatic records aligning
- automatic segments sorting and joining
- data overlapping detection
- CRLF and LF compatible
- small footprint, very fast and resources friendly
- padding byte for unspecified addresses
- trivial api
- unit tests
- error raports
Build and install:
cmake .
make
make check
sudo make installstructihex_object*ihex_new(void);
voidihex_delete(structihex_object*self);
constchar*ihex_get_error_string(structihex_object*self);
intihex_parse_file(structihex_object*self, FILE*fp);
intihex_dump_file(structihex_object*self, FILE*fp);
intihex_set_data(structihex_object*self, uint32_tadr, uint8_t*data, uint32_tsize);
intihex_get_data(structihex_object*self, uint32_tadr, uint8_t*data, uint32_tsize);See ihex.h header file for details.
#include<stdio.h>/* include library header */#include<ihex.h>/* example intelhex data file content */staticcharinput_hex[] =":020000040800F2\n"":0400020001020304F0\n"":00000001FF\n";
intmain(intargc, char**argv)
{
structihex_object*ihex;
FILE*fp;
unsigned chardata[8];
inti;
/* create new intelhex parser instance */ihex=ihex_new();
/* open file with intelhex data */fp=fmemopen(input_hex, sizeof(input_hex), "r");
/* parsing intelhex stream */ihex_parse_file(ihex, fp);
/* close file */fclose(fp);
/* get binary data */ihex_get_data(ihex, 0x08000000, data, sizeof(data));
/* print data output: FF FF 01 02 03 04 FF FF*/for (i=0; i<sizeof(data); i++)
printf("%02X ", data[i]);
/* free resources */ihex_delete(ihex);
return0;
}