Created
February 16, 2018 22:32
-
-
Save kdpatino/c80e6ca353f99572a063faf35bd9fb45 to your computer and use it in GitHub Desktop.
parse hex file
This file contains 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
#include <gflags/gflags.h> | |
#include <cstdint> | |
#include <cstring> | |
#include <iostream> | |
extern "C" { | |
#include "cintelhex.h" | |
} | |
DEFINE_string(hex_file, "", "Hex File"); | |
int main(int argc, char *agrv[]) { | |
google::ParseCommandLineFlags(&argc, &agrv, true); | |
unsigned char sig_id, Signature_ID[5]; | |
unsigned int err, size, offset, n, j, i; | |
uint8_t *buf; | |
ihex_record_t *record; | |
i = 0; | |
ihex_recordset_t *rs; | |
rs = ihex_rs_from_file(FLAGS_hex_file.c_str()); | |
size = ihex_rs_get_size(rs); | |
buf = (uint8_t *)malloc(size); | |
for (n = 0;;) { | |
if ((err = ihex_rs_iterate_data(rs, &i, &record, &offset))) { | |
std::cout << ihex_error() << std::endl; | |
break; | |
} | |
if (!record) break; | |
memcpy(buf + n, record->ihr_data, record->ihr_length); | |
n += record->ihr_length; | |
} | |
ihex_rs_free(rs); | |
std::cout << FLAGS_hex_file << "[" << size << "]={"; | |
for(int k=0;k < size; k++ ){ | |
std::cout << int(buf[k]) << ","; | |
if(k%50==49) | |
std::cout<<std::endl; | |
} | |
std::cout << "}"<<std::endl; | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment