#include "rz_io.h"
#include "rz_lib.h"
#include "rz_util.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
Go to the source code of this file.
|
static bool | ihex_write (RzIODesc *desc, Rihex *rih) |
|
static int | __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count) |
|
static int | fw04b (FILE *fd, ut16 eaddr) |
|
static int | fwblock (FILE *fd, ut8 *b, ut32 start_addr, ut32 size) |
|
static int | __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count) |
|
static int | __close (RzIODesc *fd) |
|
static ut64 | __lseek (struct rz_io_t *io, RzIODesc *fd, ut64 offset, int whence) |
|
static bool | __plugin_open (RzIO *io, const char *pathname, bool many) |
|
static bool | ihex_parse (RzBuffer *rbuf, char *str) |
|
static RzIODesc * | __open (RzIO *io, const char *pathname, int rw, int mode) |
|
static bool | __resize (RzIO *io, RzIODesc *fd, ut64 size) |
|
◆ SEC_MAX
◆ __close()
Definition at line 139 of file io_ihex.c.
140 if (!
fd || !
fd->data) {
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
static const z80_opcode fd[]
References fd, free(), NULL, Rihex::rbuf, and rz_buf_free().
◆ __lseek()
◆ __open()
Definition at line 389 of file io_ihex.c.
409 eprintf(
"ihex: failed to parse file\n");
RzIOPlugin rz_io_plugin_ihex
static bool __plugin_open(RzIO *io, const char *pathname, bool many)
static bool ihex_parse(RzBuffer *rbuf, char *str)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
RZ_API RZ_OWN RzBuffer * rz_buf_new_sparse(ut8 Oxff)
Creates a sparse buffer.
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
References __plugin_open(), eprintf, free(), ihex_parse(), mal, NULL, rz_io_t::Oxff, pathname, rz_buf_free(), rz_buf_new_sparse(), rz_file_slurp(), rz_io_desc_new(), rz_io_plugin_ihex, RZ_NEW0, and cmd_descs_generate::str.
◆ __plugin_open()
◆ __read()
Definition at line 124 of file io_ihex.c.
136 return r < 0 ? -1 :
count;
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
return memset(p, 0, total)
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
References count, fd, memset(), rz_io_t::off, rz_io_t::Oxff, r, Rihex::rbuf, RZ_BUF_CUR, rz_buf_read_at(), and rz_buf_seek().
◆ __resize()
◆ __write()
Definition at line 46 of file io_ihex.c.
53 eprintf(
"ihex:write(): sparse write failed\n");
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
References count, eprintf, fd, ihex_write(), rz_io_t::off, Rihex::rbuf, RZ_BUF_CUR, rz_buf_seek(), rz_buf_write_at(), and RZ_PERM_W.
◆ fw04b()
static int fw04b |
( |
FILE * |
fd, |
|
|
ut16 |
eaddr |
|
) |
| |
|
static |
Definition at line 64 of file io_ihex.c.
65 ut8 cks = 0 - (6 + (eaddr >> 8) + (eaddr & 0xff));
66 return fprintf(
fd,
":02000004%04X%02X\n", eaddr, cks);
References fd.
Referenced by fwblock(), and ihex_write().
◆ fwblock()
Definition at line 71 of file io_ihex.c.
82 for (
i = 0; (
i + 0x10) <
size;
i += 0x10) {
84 cks += (
i + start_addr) >> 8;
85 cks += (
i + start_addr);
86 for (j = 0; j < 0x10; j++) {
90 if (fprintf(
fd,
":10%04x00%02x%02x%02x%02x%02x%02x%02x"
91 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
92 (
i + start_addr) & 0xffff,
b[0],
b[1],
b[2],
b[3],
b[4],
b[5],
b[6],
93 b[7],
b[8],
b[9],
b[10],
b[11],
b[12],
b[13],
94 b[14],
b[15], cks) < 0) {
98 if (((
i + start_addr) & 0xffff) < 0x10) {
100 if (
fw04b(
fd, (
i + start_addr) >> 16) < 0) {
109 last_addr =
i + start_addr;
111 cks -= last_addr >> 8;
112 for (j = 0;
i <
size;
i++, j++) {
114 sprintf(linebuf + (2 * j),
"%02X",
b[j]);
118 if (fprintf(
fd,
":%02X%04X00%.*s%02X\n", j, last_addr, 2 * j, linebuf, cks) < 0) {
static int fw04b(FILE *fd, ut16 eaddr)
References b, fd, fw04b(), i, and sprintf.
Referenced by ihex_write().
◆ ihex_parse()
Definition at line 167 of file io_ihex.c.
176 int bc = 0,
type, byte,
i, l;
178 #define SEC_MAX (sec_size < INT_MAX) ? sec_size : INT_MAX
181 sec_tmp =
calloc(1, sec_count);
186 l = sscanf(
str,
":%02x%04x%02x", &bc, &addr_tmp, &
type);
188 eprintf(
"Invalid data in ihex file (%.*s)\n", 80,
str);
197 eol = strchr(
str + 1,
':');
202 cksum += addr_tmp >> 8;
206 if ((next_addr != addr_tmp) || ((sec_size + bc) >
SEC_MAX)) {
209 if (sec_size && sec_size <
UT16_MAX) {
210 if (
rz_buf_write_at(rbuf, sec_start, sec_tmp, (
int)sec_size) != sec_size) {
211 eprintf(
"sparse buffer problem, giving up\n");
216 sec_start = segreg + addr_tmp;
217 next_addr = addr_tmp;
221 for (
i = 0;
i < bc;
i++) {
222 if (sscanf(
str + 9 + (
i * 2),
"%02x", &
byte) != 1) {
223 eprintf(
"unparsable data !\n");
226 if (sec_size +
i < sec_count) {
227 sec_tmp[sec_size +
i] = (
ut8)
byte & 0xff;
235 if (sscanf(
str + 9 + (
i * 2),
"%02x", &
byte) != 1) {
236 eprintf(
"unparsable data !\n");
241 ut8 fixedcksum = 0 - (cksum - byte);
242 eprintf(
"Checksum failed %02x (got %02x expected %02x)\n",
243 cksum,
byte, fixedcksum);
253 eprintf(
"sparse buffer problem, giving up. ssiz=%X, sstart=%X\n", sec_size, sec_start);
266 eprintf(
"sparse buffer problem, giving up\n");
272 eol = strchr(
str + 1,
':');
277 cksum += addr_tmp >> 8;
280 if ((bc != 2) || (addr_tmp != 0)) {
281 eprintf(
"invalid type 02/04 record!\n");
284 if ((sscanf(
str + 9 + 0,
"%02x", &extH) != 1) ||
285 (sscanf(
str + 9 + 2,
"%02x", &extL) != 1)) {
286 eprintf(
"unparsable data !\n");
291 cksum += extH + extL;
293 segreg = extH << 8 | extL;
296 segreg = segreg << ((
type == 2) ? 4 : 16);
303 if (sscanf(
str + 9 + 4,
"%02x", &
byte) != 1) {
308 ut8 fixedcksum = 0 - (cksum - byte);
309 eprintf(
"Checksum failed %02x (got %02x expected %02x)\n",
310 cksum,
byte, fixedcksum);
319 str = strchr(
str + 1,
':');
void * calloc(size_t number, size_t size)
References calloc(), eprintf, fail, free(), i, NULL, rz_buf_write_at(), SEC_MAX, cmd_descs_generate::str, type, UT16_MAX, and ut8.
Referenced by __open().
◆ ihex_write()
Definition at line 330 of file io_ihex.c.
341 for (
size_t i = 0;
i < chunks_count;
i++) {
344 while (
from >> 16 != rbs->
to >> 16) {
348 if (addh != addh_cur) {
352 eprintf(
"ihex:write: file error\n");
360 eprintf(
"ihex:fwblock error\n");
367 if (addh != addh_cur) {
371 eprintf(
"ihex:write: file error\n");
378 eprintf(
"ihex:fwblock error 2\n");
384 fprintf(
out,
":00000001FF\n");
const lzma_allocator const uint8_t size_t uint8_t * out
static int fwblock(FILE *fd, ut8 *b, ut32 start_addr, ut32 size)
RZ_API const RzBufferSparseChunk * rz_buf_sparse_get_chunks(RzBuffer *b, RZ_NONNULL size_t *count)
Only for sparse RzBuffers, get all sparse data chunks currently populated.
RZ_API FILE * rz_sys_fopen(const char *path, const char *mode)
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
ut8 * data
size == to - from + 1
ut64 to
inclusive, there can't be chunks with size == 0
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
References rz_buf_sparse_chunk_t::data, desc, eprintf, benchmark::FILE, rz_buf_sparse_chunk_t::from, from, fw04b(), fwblock(), i, out, pathname, Rihex::rbuf, rz_buf_sparse_get_chunks(), rz_sys_fopen(), rz_buf_sparse_chunk_t::to, and ut64().
Referenced by __resize(), and __write().
◆ rizin_plugin
◆ rz_io_plugin_ihex
Initial value:= {
.name = "ihex",
.desc = "Open intel HEX file",
.uris = "ihex://",
.license = "LGPL",
}
static ut64 __lseek(struct rz_io_t *io, RzIODesc *fd, ut64 offset, int whence)
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
static bool __resize(RzIO *io, RzIODesc *fd, ut64 size)
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
static int __close(RzIODesc *fd)
Definition at line 436 of file io_ihex.c.
Referenced by __open().