Rizin
unix-like reverse engineering framework and cli tools
cio.c File Reference
#include "rz_core.h"
#include "core_private.h"

Go to the source code of this file.

Functions

RZ_API int rz_core_setup_debugger (RzCore *r, const char *debugbackend, bool attach)
 
RZ_API bool rz_core_dump (RzCore *core, const char *file, ut64 addr, ut64 size, int append)
 
RZ_API void rz_core_arch_bits_at (RzCore *core, ut64 addr, RZ_OUT RZ_NULLABLE int *bits, RZ_OUT RZ_BORROW RZ_NULLABLE const char **arch)
 
RZ_API void rz_core_seek_arch_bits (RzCore *core, ut64 addr)
 
RZ_API bool rz_core_write_at (RzCore *core, ut64 addr, const ut8 *buf, int size)
 
RZ_API bool rz_core_extend_at (RzCore *core, ut64 addr, ut64 size)
 Extend the file at current offset by inserting size 0 bytes at addr. More...
 
RZ_API bool rz_core_shift_block (RzCore *core, ut64 addr, ut64 b_size, st64 dist)
 Shift a block of data from addr of size b_size left or right based on dist. More...
 
RZ_API int rz_core_block_read (RzCore *core)
 
RZ_API int rz_core_is_valid_offset (RzCore *core, ut64 offset)
 
RZ_API int rz_core_write_hexpair (RzCore *core, ut64 addr, const char *pairs)
 
RZ_API bool rz_core_write_block (RzCore *core, ut64 addr, ut8 *data, size_t len)
 
RZ_API int rz_core_write_assembly (RzCore *core, ut64 addr, RZ_NONNULL const char *instructions)
 Assembles instructions and writes the resulting data at the given offset. More...
 
RZ_API int rz_core_write_assembly_fill (RzCore *core, ut64 addr, RZ_NONNULL const char *instructions)
 Assemble instructions and write the resulting data inside the current instruction. More...
 
RZ_API RzCmdStatus rz_core_io_plugin_print (RzIOPlugin *plugin, RzCmdStateOutput *state)
 Print an IO plugin according to state. More...
 
RZ_API RzCmdStatus rz_core_io_plugins_print (RzIO *io, RzCmdStateOutput *state)
 Print the registered IO plugins according to state. More...
 
RZ_API bool rz_core_write_value_at (RzCore *core, ut64 addr, ut64 value, int sz)
 Write a given value at the specified address, using sz bytes. More...
 
RZ_API bool rz_core_write_value_inc_at (RzCore *core, ut64 addr, st64 value, int sz)
 Write at addr the current value + value passed as argument. More...
 
RZ_API bool rz_core_write_string_at (RzCore *core, ut64 addr, RZ_NONNULL const char *s)
 Write a given string s at the specified addr. More...
 
RZ_API bool rz_core_write_string_wide_at (RzCore *core, ut64 addr, const char *s)
 Write a given string s as a wide string at the specified addr. More...
 
RZ_API bool rz_core_write_length_string_at (RzCore *core, ut64 addr, const char *s)
 Write at the specified addr the length of the string in one byte, followed by the given string s. More...
 
RZ_API bool rz_core_write_base64_at (RzCore *core, ut64 addr, RZ_NONNULL const char *s)
 Write a given string s at the specified addr encoded as base64. More...
 
RZ_API bool rz_core_write_base64d_at (RzCore *core, ut64 addr, RZ_NONNULL const char *s)
 Write a given base64 string s at the specified addr, decoded. More...
 
RZ_API bool rz_core_write_random_at (RzCore *core, ut64 addr, size_t len)
 Write len random bytes at address addr. More...
 
RZ_API RzCmdStatus rz_core_io_cache_print (RzCore *core, RzCmdStateOutput *state)
 
RZ_API RzCmdStatus rz_core_io_pcache_print (RzCore *core, RzIODesc *desc, RzCmdStateOutput *state)
 
RZ_API bool rz_core_write_string_zero_at (RzCore *core, ut64 addr, const char *s)
 Write a given string s, followed by the zero terminator, at the specified addr. More...
 
RZ_API RZ_OWN ut8rz_core_transform_op (RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen, int *buflen)
 Transform a block of data at addr according to the operation op and the hexvalue hex. More...
 
RZ_API bool rz_core_write_block_op_at (RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen)
 Write a full block of data according to the operation op and the hexvalue hex. More...
 
RZ_API bool rz_core_write_seq_at (RzCore *core, ut64 addr, ut64 from, ut64 to, ut64 step, int value_size)
 Write a full block of data with a sequence. More...
 
RZ_API bool rz_core_write_duplicate_at (RzCore *core, ut64 addr, ut64 from, int len)
 Copy len bytes from from to addr. More...
 

Function Documentation

◆ rz_core_arch_bits_at()

RZ_API void rz_core_arch_bits_at ( RzCore core,
ut64  addr,
RZ_OUT RZ_NULLABLE int bits,
RZ_OUT RZ_BORROW RZ_NULLABLE const char **  arch 
)

Definition at line 97 of file cio.c.

97  {
98  int bitsval = 0;
99  const char *archval = NULL;
100  RzBinObject *o = rz_bin_cur_object(core->bin);
101  RzBinSection *s = o ? rz_bin_get_section_at(o, addr, core->io->va) : NULL;
102  if (s) {
103  if (!core->fixedarch) {
104  archval = s->arch;
105  }
106  if (!core->fixedbits && s->bits) {
107  // only enforce if there's one bits set
108  switch (s->bits) {
109  case RZ_SYS_BITS_16:
110  case RZ_SYS_BITS_32:
111  case RZ_SYS_BITS_64:
112  bitsval = s->bits * 8;
113  break;
114  }
115  }
116  }
117  // if we found bits related with analysis hints pick it up
118  if (bits && !bitsval && !core->fixedbits) {
119  bitsval = rz_analysis_hint_bits_at(core->analysis, addr, NULL);
120  }
121  if (arch && !archval && !core->fixedarch) {
122  archval = rz_analysis_hint_arch_at(core->analysis, addr, NULL);
123  }
124  if (bits && bitsval) {
125  *bits = bitsval;
126  }
127  if (arch && archval) {
128  *arch = archval;
129  }
130 }
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
Definition: bin.c:611
int bits(struct state *s, int need)
Definition: blast.c:72
#define NULL
Definition: cris-opc.c:27
cs_arch arch
Definition: cstool.c:13
RZ_API int rz_analysis_hint_bits_at(RzAnalysis *analysis, ut64 addr, RZ_NULLABLE ut64 *hint_addr)
Definition: hint.c:397
RZ_API RZ_NULLABLE RZ_BORROW const char * rz_analysis_hint_arch_at(RzAnalysis *analysis, ut64 addr, RZ_NULLABLE ut64 *hint_addr)
Definition: hint.c:382
static RzSocket * s
Definition: rtr.c:28
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
@ RZ_SYS_BITS_16
Definition: rz_sys.h:19
RzBin * bin
Definition: rz_core.h:298
RzAnalysis * analysis
Definition: rz_core.h:322
RzIO * io
Definition: rz_core.h:313
bool fixedbits
Definition: rz_core.h:375
bool fixedarch
Definition: rz_core.h:376
int va
Definition: rz_io.h:63
static int addr
Definition: z80asm.c:58

References addr, rz_core_t::analysis, arch, rz_core_t::bin, bits(), rz_core_t::fixedarch, rz_core_t::fixedbits, rz_core_t::io, NULL, rz_analysis_hint_arch_at(), rz_analysis_hint_bits_at(), rz_bin_cur_object(), rz_bin_get_section_at(), RZ_SYS_BITS_16, RZ_SYS_BITS_32, RZ_SYS_BITS_64, s, and rz_io_t::va.

Referenced by bp_bits_at(), and rz_core_seek_arch_bits().

◆ rz_core_block_read()

RZ_API int rz_core_block_read ( RzCore core)

Definition at line 243 of file cio.c.

243  {
244  if (core && core->block) {
245  return rz_io_read_at(core->io, core->offset, core->block, core->blocksize);
246  }
247  return -1;
248 }
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
ut64 offset
Definition: rz_core.h:301
ut8 * block
Definition: rz_core.h:305
ut32 blocksize
Definition: rz_core.h:303

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::io, rz_core_t::offset, and rz_io_read_at().

Referenced by __direction_disassembly_cb(), __print_hexdump_cb(), cb_iova(), cmd_print_bars(), file_resize(), handle_tmp_desc(), ioMemcpy(), open_nobin_file(), perform_mapped_file_yank(), prioritize_file(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_disassembly_n_instrs_as_text_json_handler(), rz_cmd_print(), rz_cmd_sizes_of_n_instructions_handler(), rz_core_bin_raise(), rz_core_binfiles_delete(), rz_core_cmd_subst_i(), rz_core_extend_at(), rz_core_file_open_load(), rz_core_file_reopen(), rz_core_file_reopen_remote_debug(), rz_core_handle_backwards_disasm(), rz_core_io_file_open(), rz_core_seek(), rz_core_serve(), rz_core_visual_cmd(), rz_core_visual_jump(), rz_core_write_at(), rz_main_rizin(), rz_open_binary_reload_handler(), rz_open_exchange_handler(), rz_open_maps_deprioritize_handler(), rz_open_maps_prioritize_handler(), rz_open_use_handler(), rz_write_cache_commit_all_handler(), rz_write_cache_remove_handler(), rz_write_from_file_handler(), and rz_write_from_io_xchg_handler().

◆ rz_core_dump()

RZ_API bool rz_core_dump ( RzCore core,
const char *  file,
ut64  addr,
ut64  size,
int  append 
)

Definition at line 50 of file cio.c.

50  {
51  ut64 i;
52  ut8 *buf;
53  int bs = core->blocksize;
54  FILE *fd;
55  if (append) {
56  fd = rz_sys_fopen(file, "ab");
57  } else {
59  fd = rz_sys_fopen(file, "wb");
60  }
61  if (!fd) {
62  eprintf("Cannot open '%s' for writing\n", file);
63  return false;
64  }
65  /* some io backends seems to be buggy in those cases */
66  if (bs > 4096) {
67  bs = 4096;
68  }
69  buf = malloc(bs);
70  if (!buf) {
71  eprintf("Cannot alloc %d byte(s)\n", bs);
72  fclose(fd);
73  return false;
74  }
76  for (i = 0; i < size; i += bs) {
77  if (rz_cons_is_breaked()) {
78  break;
79  }
80  if ((i + bs) > size) {
81  bs = size - i;
82  }
83  rz_io_read_at(core->io, addr + i, buf, bs);
84  if (fwrite(buf, bs, 1, fd) < 1) {
85  eprintf("write error\n");
86  break;
87  }
88  }
90  fclose(fd);
91  free(buf);
92  return true;
93 }
lzma_index ** i
Definition: index.h:629
#define append(x, y)
Definition: cmd_print.c:1740
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
string FILE
Definition: benchmark.py:21
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_sys_truncate(const char *file, int sz)
Definition: sys.c:1692
RZ_API FILE * rz_sys_fopen(const char *path, const char *mode)
Definition: sys.c:1815
Definition: gzappend.c:170
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997

References addr, append, rz_core_t::blocksize, eprintf, fd, benchmark::FILE, free(), i, rz_core_t::io, malloc(), NULL, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_io_read_at(), rz_sys_fopen(), rz_sys_truncate(), and ut64().

Referenced by rz_cmd_debug_dmi(), and rz_core_visual_cmd().

◆ rz_core_extend_at()

RZ_API bool rz_core_extend_at ( RzCore core,
ut64  addr,
ut64  size 
)

Extend the file at current offset by inserting size 0 bytes at addr.

addr is an physical/virtual address based on the value of eval "io.va". When virtual it is translated to a physical address according to the IO map at the current offset

Parameters
coreReference to RzCore instance
addrAddress where to insert new 0 bytes.
sizeNumber of 0 bytes to insert
Returns
true if extend operation was successful, false otherwise

Definition at line 172 of file cio.c.

172  {
173  rz_return_val_if_fail(core, false);
174 
175  int io_va = rz_config_get_i(core->config, "io.va");
176  if (io_va) {
177  RzIOMap *map = rz_io_map_get(core->io, core->offset);
178  if (map) {
179  addr = addr - map->itv.addr + map->delta;
180  }
181  }
182  bool ret = rz_io_extend_at(core->io, addr, size);
183  rz_core_block_read(core);
184  return ret;
185 }
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
size_t map(int syms, int left, int len)
Definition: enough.c:237
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_io_extend_at(RzIO *io, ut64 addr, ut64 size)
Extend the RzIODesc at addr by inserting size 0 bytes.
Definition: io.c:453
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
RzConfig * config
Definition: rz_core.h:300

References addr, rz_core_t::config, rz_core_t::io, map(), rz_core_t::offset, rz_config_get_i(), rz_core_block_read(), rz_io_extend_at(), rz_io_map_get(), and rz_return_val_if_fail.

Referenced by rz_write_extend_hexbytes_handler(), and rz_write_extend_zero_handler().

◆ rz_core_io_cache_print()

RZ_API RzCmdStatus rz_core_io_cache_print ( RzCore core,
RzCmdStateOutput state 
)

Definition at line 797 of file cio.c.

797  {
799 
800  size_t i, j = 0;
801  void **iter;
802  RzIOCache *c;
803 
804  rz_pvector_foreach (&core->io->cache, iter) {
805  c = *iter;
806  const ut64 dataSize = rz_itv_size(c->itv);
807  switch (state->mode) {
809  rz_cons_printf("idx=%" PFMTSZu " addr=0x%08" PFMT64x " size=%" PFMT64u " ", j, rz_itv_begin(c->itv), dataSize);
810  for (i = 0; i < dataSize; i++) {
811  rz_cons_printf("%02x", c->odata[i]);
812  }
813  rz_cons_printf(" -> ");
814  for (i = 0; i < dataSize; i++) {
815  rz_cons_printf("%02x", c->data[i]);
816  }
817  rz_cons_printf(" %s\n", c->written ? "(written)" : "(not written)");
818  break;
819  case RZ_OUTPUT_MODE_JSON:
820  pj_o(state->d.pj);
821  pj_kn(state->d.pj, "idx", j);
822  pj_kn(state->d.pj, "addr", rz_itv_begin(c->itv));
823  pj_kn(state->d.pj, "size", dataSize);
824  char *hex = rz_hex_bin2strdup(c->odata, dataSize);
825  pj_ks(state->d.pj, "before", hex);
826  free(hex);
827  hex = rz_hex_bin2strdup(c->data, dataSize);
828  pj_ks(state->d.pj, "after", hex);
829  free(hex);
830  pj_kb(state->d.pj, "written", c->written);
831  pj_end(state->d.pj);
832  break;
834  rz_cons_printf("wx ");
835  for (i = 0; i < dataSize; i++) {
836  rz_cons_printf("%02x", (ut8)(c->data[i] & 0xff));
837  }
838  rz_cons_printf(" @ 0x%08" PFMT64x, rz_itv_begin(c->itv));
839  rz_cons_printf(" # replaces: ");
840  for (i = 0; i < dataSize; i++) {
841  rz_cons_printf("%02x", (ut8)(c->odata[i] & 0xff));
842  }
843  rz_cons_printf("\n");
844  break;
845  default:
847  break;
848  }
849  j++;
850  }
851  return RZ_CMD_STATUS_OK;
852 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
static const char hex[16]
Definition: print.c:21
#define rz_warn_if_reached()
Definition: rz_assert.h:29
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RZ_API char * rz_hex_bin2strdup(const ut8 *in, int len)
Definition: hex.c:415
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
#define PFMTSZu
Definition: rz_types.h:399
#define PFMT64u
Definition: rz_types.h:395
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
#define PFMT64x
Definition: rz_types.h:393
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334
#define c(i)
Definition: sha256.c:43
RzPVector cache
Definition: rz_io.h:76
Definition: dis.h:43

References c, rz_io_t::cache, free(), hex, i, rz_core_t::io, PFMT64u, PFMT64x, PFMTSZu, pj_end(), pj_kb(), pj_kn(), pj_ks(), pj_o(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_hex_bin2strdup(), rz_itv_begin(), rz_itv_size(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_pvector_foreach, rz_return_val_if_fail, rz_warn_if_reached, and ut64().

Referenced by rz_write_cache_list_handler().

◆ rz_core_io_pcache_print()

RZ_API RzCmdStatus rz_core_io_pcache_print ( RzCore core,
RzIODesc desc,
RzCmdStateOutput state 
)

Definition at line 854 of file cio.c.

854  {
857 
858  RzList *caches = rz_io_desc_cache_list(desc);
859  RzListIter *iter;
860  RzIOCache *c;
861 
862  if (state->mode == RZ_OUTPUT_MODE_RIZIN) {
863  rz_cons_printf("e io.va = false\n");
864  }
865  rz_list_foreach (caches, iter, c) {
866  const int cacheSize = rz_itv_size(c->itv);
867  int i;
868 
869  switch (state->mode) {
871  rz_cons_printf("0x%08" PFMT64x ": %02x",
872  rz_itv_begin(c->itv), c->odata[0]);
873  for (i = 1; i < cacheSize; i++) {
874  rz_cons_printf("%02x", c->odata[i]);
875  }
876  rz_cons_printf(" -> %02x", c->data[0]);
877  for (i = 1; i < cacheSize; i++) {
878  rz_cons_printf("%02x", c->data[i]);
879  }
880  rz_cons_printf("\n");
881  break;
883  rz_cons_printf("wx %02x", c->data[0]);
884  for (i = 1; i < cacheSize; i++) {
885  rz_cons_printf("%02x", c->data[i]);
886  }
887  rz_cons_printf(" @ 0x%08" PFMT64x " \n", rz_itv_begin(c->itv));
888  break;
889  default:
891  break;
892  }
893  }
894  rz_list_free(caches);
895  return RZ_CMD_STATUS_OK;
896 }
const char * desc
Definition: bin_vsf.c:19
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API RzList * rz_io_desc_cache_list(RzIODesc *desc)
Definition: p_cache.c:249

References c, desc, i, rz_core_t::io, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_io_desc_cache_list(), rz_itv_begin(), rz_itv_size(), rz_list_free(), RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_return_val_if_fail, and rz_warn_if_reached.

Referenced by rz_write_pcache_list_handler().

◆ rz_core_io_plugin_print()

RZ_API RzCmdStatus rz_core_io_plugin_print ( RzIOPlugin plugin,
RzCmdStateOutput state 
)

Print an IO plugin according to state.

Parameters
pluginReference to RzIOPlugin
stateSpecify how the plugin shall be printed

Definition at line 408 of file cio.c.

408  {
409  char str[4];
410  PJ *pj = state->d.pj;
411  str[0] = 'r';
412  str[1] = plugin->write ? 'w' : '_';
413  str[2] = plugin->isdbg ? 'd' : '_';
414  str[3] = 0;
415  switch (state->mode) {
416  case RZ_OUTPUT_MODE_JSON:
417  pj_o(pj);
418  pj_ks(pj, "permissions", str);
419  pj_ks(pj, "name", plugin->name);
420  pj_ks(pj, "description", plugin->desc);
421  pj_ks(pj, "license", plugin->license);
422 
423  if (plugin->uris) {
424  char *uri;
425  char *uris = strdup(plugin->uris);
426  RzList *plist = rz_str_split_list(uris, ",", 0);
427  RzListIter *piter;
428  pj_k(pj, "uris");
429  pj_a(pj);
430  rz_list_foreach (plist, piter, uri) {
431  pj_s(pj, uri);
432  }
433  pj_end(pj);
434  rz_list_free(plist);
435  free(uris);
436  }
437  if (plugin->version) {
438  pj_ks(pj, "version", plugin->version);
439  }
440  if (plugin->author) {
441  pj_ks(pj, "author", plugin->author);
442  }
443  pj_end(pj);
444  break;
446  rz_table_set_columnsf(state->d.t, "sssss", "perm", "license", "name", "uri", "description");
447  rz_table_add_rowf(state->d.t, "sssss", str, plugin->license, plugin->name, plugin->uris, plugin->desc);
448  break;
450  rz_cons_printf("%s\n", plugin->name);
451  break;
453  rz_cons_printf("%s %-8s %s (%s)",
454  str, plugin->name,
455  plugin->desc, plugin->license);
456  if (plugin->uris) {
457  rz_cons_printf(" %s", plugin->uris);
458  }
459  if (plugin->version) {
460  rz_cons_printf(" v%s", plugin->version);
461  }
462  if (plugin->author) {
463  rz_cons_printf(" %s", plugin->author);
464  }
465  rz_cons_printf("\n");
466  break;
467  default: {
470  }
471  }
472  return RZ_CMD_STATUS_OK;
473 }
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
RZ_API RzList * rz_str_split_list(char *str, const char *c, int n)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3429
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
RZ_API void rz_table_set_columnsf(RzTable *t, const char *fmt,...)
Specify the types and names of the referenced table.
Definition: table.c:234
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
Definition: rz_pj.h:12
const char * name
Definition: rz_io.h:115
const char * version
Definition: rz_io.h:117
const char * uris
Definition: rz_io.h:121
int(* write)(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: rz_io.h:131
const char * license
Definition: rz_io.h:119
bool isdbg
Definition: rz_io.h:124
const char * author
Definition: rz_io.h:118
const char * desc
Definition: rz_io.h:116

References rz_io_plugin_t::author, rz_io_plugin_t::desc, free(), rz_io_plugin_t::isdbg, rz_io_plugin_t::license, rz_io_plugin_t::name, pj_a(), pj_end(), pj_k(), pj_ks(), pj_o(), pj_s(), RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_list_free(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_str_split_list(), rz_table_add_rowf(), rz_table_set_columnsf(), rz_warn_if_reached, cmd_descs_generate::str, strdup(), rz_io_plugin_t::uris, rz_io_plugin_t::version, and rz_io_plugin_t::write.

Referenced by rz_core_io_plugins_print().

◆ rz_core_io_plugins_print()

RZ_API RzCmdStatus rz_core_io_plugins_print ( RzIO io,
RzCmdStateOutput state 
)

Print the registered IO plugins according to state.

Parameters
ioReference to RzIO instance
stateSpecify how plugins shall be printed

Definition at line 481 of file cio.c.

481  {
482  RzIOPlugin *plugin;
483  RzListIter *iter;
484  if (!io) {
485  return RZ_CMD_STATUS_ERROR;
486  }
488  rz_cmd_state_output_set_columnsf(state, "sssss", "perm", "license", "name", "uri", "description");
489  rz_list_foreach (io->plugins, iter, plugin) {
491  }
493  return RZ_CMD_STATUS_OK;
494 }
RZ_API RzCmdStatus rz_core_io_plugin_print(RzIOPlugin *plugin, RzCmdStateOutput *state)
Print an IO plugin according to state.
Definition: cio.c:408
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
RzList * plugins
Definition: rz_io.h:80

References rz_io_t::plugins, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_io_plugin_print().

Referenced by rz_main_rizin(), and rz_plugins_io_print_handler().

◆ rz_core_is_valid_offset()

RZ_API int rz_core_is_valid_offset ( RzCore core,
ut64  offset 
)

Definition at line 250 of file cio.c.

250  {
251  if (!core) {
252  eprintf("rz_core_is_valid_offset: core is NULL\n");
254  return -1;
255  }
256  return rz_io_is_valid_offset(core->io, offset, 0);
257 }
voidpf uLong offset
Definition: ioapi.h:144
RZ_API bool rz_io_is_valid_offset(RzIO *io, ut64 offset, int hasperm)
Definition: ioutils.c:20
RZ_API char RZ_API void rz_sys_backtrace(void)
Print the backtrace at the point this function is called from.
Definition: sys.c:265

References eprintf, rz_core_t::io, rz_io_is_valid_offset(), and rz_sys_backtrace().

◆ rz_core_seek_arch_bits()

RZ_API void rz_core_seek_arch_bits ( RzCore core,
ut64  addr 
)

Definition at line 132 of file cio.c.

132  {
133  int bits = 0;
134  const char *arch = NULL;
135  rz_core_arch_bits_at(core, addr, &bits, &arch);
136  if (bits) {
137  rz_config_set_i(core->config, "asm.bits", bits);
138  }
139  if (arch) {
140  rz_config_set(core->config, "asm.arch", arch);
141  }
142 }
RZ_API void rz_core_arch_bits_at(RzCore *core, ut64 addr, RZ_OUT RZ_NULLABLE int *bits, RZ_OUT RZ_BORROW RZ_NULLABLE const char **arch)
Definition: cio.c:97
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419

References addr, arch, bits(), rz_core_t::config, NULL, rz_config_set(), rz_config_set_i(), and rz_core_arch_bits_at().

Referenced by archbits(), rz_core_analysis_esil(), rz_core_analysis_fcn(), rz_core_disasm_pde(), rz_core_print_disasm(), and rz_core_print_disasm_instructions_with_buf().

◆ rz_core_setup_debugger()

RZ_API int rz_core_setup_debugger ( RzCore r,
const char *  debugbackend,
bool  attach 
)

Definition at line 7 of file cio.c.

7  {
8  int pid, *p = NULL;
9  RzIODesc *fd = r->file ? rz_io_desc_get(r->io, r->file->fd) : NULL;
10 
11  p = fd ? fd->data : NULL;
12  rz_config_set_i(r->config, "cfg.debug", 1);
13  if (!p) {
14  eprintf("Invalid debug io\n");
15  return false;
16  }
17 
18  rz_config_set(r->config, "io.ff", "true");
19  rz_config_set(r->config, "dbg.backend", debugbackend);
21  rz_debug_select(r->dbg, pid, r->dbg->tid);
22  r->dbg->main_pid = pid;
23  if (attach) {
25  }
26  // this makes to attach twice showing warnings in the output
27  // we get "resource busy" so it seems isn't an issue
29  /* honor dbg.bep */
30  {
31  const char *bep = rz_config_get(r->config, "dbg.bep");
32  if (bep) {
33  ut64 address = 0;
34  if (!strcmp(bep, "loader")) {
35  /* do nothing here */
36  } else if (!strcmp(bep, "entry")) {
37  address = rz_num_math(r->num, "entry0");
38  rz_core_debug_continue_until(r, address, address);
39  } else {
40  address = rz_num_math(r->num, bep);
41  rz_core_debug_continue_until(r, address, address);
42  }
43  }
44  }
45  rz_core_seek_to_register(r, "PC", false);
46 
47  return true;
48 }
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to)
Definition: cdebug.c:98
RZ_IPI void rz_core_debug_attach(RzCore *core, int pid)
Definition: cdebug.c:284
RZ_IPI bool rz_core_seek_to_register(RzCore *core, const char *regname, bool is_silent)
Definition: cmd_seek.c:22
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
#define r
Definition: crypto_rc6.c:12
void * p
Definition: libc.cpp:67
RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid)
Definition: debug.c:595
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 pid
Definition: sflib.h:64
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
RZ_API int rz_io_desc_get_pid(RzIODesc *desc)
Definition: io_desc.c:310
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456

References eprintf, fd, NULL, p, pid, r, rz_config_get(), rz_config_set(), rz_config_set_i(), rz_core_debug_attach(), rz_core_debug_continue_until(), rz_core_reg_update_flags(), rz_core_seek_to_register(), rz_debug_select(), rz_io_desc_get(), rz_io_desc_get_pid(), rz_num_math(), and ut64().

Referenced by rz_core_file_reopen(), and rz_main_rizin().

◆ rz_core_shift_block()

RZ_API bool rz_core_shift_block ( RzCore core,
ut64  addr,
ut64  b_size,
st64  dist 
)

Shift a block of data from addr of size b_size left or right based on dist.

Parameters
coreReference to RzCore instance
addrAddress of the block of data to move
b_sizeSize of the block of data to move
distWhere to shift the data, whether backward or forward and how distant from the original position
Returns
true if the shift operation was succesful, false otherwise

Definition at line 197 of file cio.c.

197  {
198  // bstart - block start, fstart file start
199  ut64 fend = 0, fstart = 0, bstart = 0, file_sz = 0;
200  ut8 *shift_buf = NULL;
201  int res = false;
202 
203  if (!core->io || !core->file) {
204  return false;
205  }
206 
207  if (b_size == 0 || b_size == (ut64)-1) {
208  rz_io_use_fd(core->io, core->file->fd);
209  file_sz = rz_io_size(core->io);
210  if (file_sz == UT64_MAX) {
211  file_sz = 0;
212  }
213  bstart = 0;
214  fend = file_sz;
215  fstart = file_sz - fend;
216  b_size = fend > bstart ? fend - bstart : 0;
217  }
218 
219  if ((st64)b_size < 1) {
220  return false;
221  }
222  shift_buf = calloc(b_size, 1);
223  if (!shift_buf) {
224  eprintf("Cannot allocated %d byte(s)\n", (int)b_size);
225  return false;
226  }
227 
228  if (addr + dist < fstart) {
229  res = false;
230  } else if ((addr) + dist > fend) {
231  res = false;
232  } else {
233  rz_io_use_fd(core->io, core->file->fd);
234  rz_io_read_at(core->io, addr, shift_buf, b_size);
235  rz_io_write_at(core->io, addr + dist, shift_buf, b_size);
236  res = true;
237  }
238  rz_core_seek(core, addr, true);
239  free(shift_buf);
240  return res;
241 }
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API ut64 rz_io_size(RzIO *io)
Definition: io.c:399
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
RZ_API bool rz_io_use_fd(RzIO *io, int fd)
Definition: io_fd.c:118
#define st64
Definition: rz_types_base.h:10
#define UT64_MAX
Definition: rz_types_base.h:86
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
RzCoreFile * file
Definition: rz_core.h:314

References addr, calloc(), eprintf, rz_core_file_t::fd, rz_core_t::file, free(), rz_core_t::io, NULL, rz_core_seek(), rz_io_read_at(), rz_io_size(), rz_io_use_fd(), rz_io_write_at(), st64, ut64(), and UT64_MAX.

Referenced by rz_write_extend_shift_handler().

◆ rz_core_transform_op()

RZ_API RZ_OWN ut8* rz_core_transform_op ( RzCore core,
ut64  addr,
RzCoreWriteOp  op,
ut8 hex,
int  hexlen,
int buflen 
)

Transform a block of data at addr according to the operation op and the hexvalue hex.

Parameters
coreReference to RzCore instance
addrWhere the block of data to modify starts
opOperation to perform on the block of data
hexOptional hex string that may be required by the specific operation
hexlenOptional length of the hex string. Must be present if hex is specified.
buflenUsed to return the length of the returned buffer
Returns
The transformed buffer

Definition at line 934 of file cio.c.

934  {
936  rz_return_val_if_fail(!hex || hexlen >= 0, NULL);
938 
939  switch (op) {
945  case RZ_CORE_WRITE_OP_OR:
949  rz_return_val_if_fail(hex && hexlen >= 0, NULL);
950  break;
951  default:
952  break;
953  }
954 
955  ut8 *buf = RZ_NEWS(ut8, core->blocksize);
956  if (!buf) {
957  return NULL;
958  }
959 
960  int len = rz_io_nread_at(core->io, addr, buf, core->blocksize);
961  if (len < 0) {
962  free(buf);
963  return NULL;
964  }
965 
966  for (int i = 0, j = 0; i < len; i++, j = (j + 1) % (hexlen ? hexlen : 1)) {
967  ut16 tmp16;
968  ut32 tmp32;
969  ut64 tmp64;
970  switch (op) {
972  if (i + 1 < len) {
973  tmp16 = rz_read_le16(buf + i);
974  rz_write_be16(buf + i, tmp16);
975  i++;
976  }
977  break;
979  if (i + 3 < len) {
980  tmp32 = rz_read_le32(buf + i);
981  rz_write_be32(buf + i, tmp32);
982  i += 3;
983  }
984  break;
986  if (i + 7 < len) {
987  tmp64 = rz_read_le64(buf + i);
988  rz_write_be64(buf + i, tmp64);
989  i += 7;
990  }
991  break;
993  buf[i] += hex[j];
994  break;
996  buf[i] -= hex[j];
997  break;
999  buf[i] = hex[j] ? buf[i] / hex[j] : 0;
1000  break;
1001  case RZ_CORE_WRITE_OP_MUL:
1002  buf[i] *= hex[j];
1003  break;
1004  case RZ_CORE_WRITE_OP_AND:
1005  buf[i] &= hex[j];
1006  break;
1007  case RZ_CORE_WRITE_OP_OR:
1008  buf[i] |= hex[j];
1009  break;
1010  case RZ_CORE_WRITE_OP_XOR:
1011  buf[i] ^= hex[j];
1012  break;
1014  buf[i] <<= hex[j];
1015  break;
1017  buf[i] >>= hex[j];
1018  break;
1019  default:
1021  break;
1022  }
1023  }
1024  *buflen = len;
1025  return buf;
1026 }
size_t len
Definition: 6502dis.c:15
uint16_t ut16
uint32_t ut32
@ RZ_CORE_WRITE_OP_BYTESWAP8
Swap the endianess of 8-bytes values.
Definition: rz_core.h:108
@ RZ_CORE_WRITE_OP_SHIFT_LEFT
Write the shift left of existing byte by argument value.
Definition: rz_core.h:116
@ RZ_CORE_WRITE_OP_AND
Write the bitwise-and of existing byte and argument value.
Definition: rz_core.h:113
@ RZ_CORE_WRITE_OP_SHIFT_RIGHT
Write the shift right of existing byte and argument value.
Definition: rz_core.h:117
@ RZ_CORE_WRITE_OP_BYTESWAP2
Swap the endianess of 2-bytes values.
Definition: rz_core.h:106
@ RZ_CORE_WRITE_OP_OR
Write the bitwise-or of existing byte and argument value.
Definition: rz_core.h:114
@ RZ_CORE_WRITE_OP_ADD
Write the addition of existing byte and argument value.
Definition: rz_core.h:109
@ RZ_CORE_WRITE_OP_MUL
Write the multiplication of existing byte and argument value.
Definition: rz_core.h:112
@ RZ_CORE_WRITE_OP_DIV
Write the division of existing byte and argument value.
Definition: rz_core.h:111
@ RZ_CORE_WRITE_OP_BYTESWAP4
Swap the endianess of 4-bytes values.
Definition: rz_core.h:107
@ RZ_CORE_WRITE_OP_XOR
Write the bitwise-xor of existing byte and argument value.
Definition: rz_core.h:115
@ RZ_CORE_WRITE_OP_SUB
Write the subtraction of existing byte and argument value.
Definition: rz_core.h:110
static void rz_write_be16(void *dest, ut16 val)
Definition: rz_endian.h:60
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
static void rz_write_be64(void *dest, ut64 val)
Definition: rz_endian.h:119
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
static ut64 rz_read_le64(const void *src)
Definition: rz_endian.h:266
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98
RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:338
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
ut64 buflen
Definition: core.c:76
Definition: dis.c:32

References addr, rz_core_t::blocksize, buflen, free(), hex, i, rz_core_t::io, len, NULL, RZ_CORE_WRITE_OP_ADD, RZ_CORE_WRITE_OP_AND, RZ_CORE_WRITE_OP_BYTESWAP2, RZ_CORE_WRITE_OP_BYTESWAP4, RZ_CORE_WRITE_OP_BYTESWAP8, RZ_CORE_WRITE_OP_DIV, RZ_CORE_WRITE_OP_MUL, RZ_CORE_WRITE_OP_OR, RZ_CORE_WRITE_OP_SHIFT_LEFT, RZ_CORE_WRITE_OP_SHIFT_RIGHT, RZ_CORE_WRITE_OP_SUB, RZ_CORE_WRITE_OP_XOR, rz_io_nread_at(), RZ_NEWS, rz_read_le16(), rz_read_le32(), rz_read_le64(), rz_return_val_if_fail, rz_warn_if_reached, rz_write_be16(), rz_write_be32(), rz_write_be64(), and ut64().

Referenced by old_transform_op(), and rz_core_write_block_op_at().

◆ rz_core_write_assembly()

RZ_API int rz_core_write_assembly ( RzCore core,
ut64  addr,
RZ_NONNULL const char *  instructions 
)

Assembles instructions and writes the resulting data at the given offset.

Parameters
coreRzCore reference
addrAddress to where to write
instructionsList of instructions to assemble as a string
Returns
Returns the length of the written data or -1 in case of error

Definition at line 327 of file cio.c.

327  {
328  rz_return_val_if_fail(core && instructions, -1);
329 
330  int ret = -1;
331 
332  rz_asm_set_pc(core->rasm, core->offset);
333  RzAsmCode *acode = rz_asm_massemble(core->rasm, instructions);
334  if (!acode) {
335  return -1;
336  }
337  if (acode->len <= 0) {
338  ret = 0;
339  goto err;
340  }
341 
342  if (!rz_core_write_at(core, core->offset, acode->bytes, acode->len)) {
343  RZ_LOG_ERROR("Cannot write %d bytes at 0x%" PFMT64x "address\n", acode->len, core->offset);
344  core->num->value = 1;
345  goto err;
346  }
347  ret = acode->len;
348 err:
349  rz_asm_code_free(acode);
350  return ret;
351 }
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
static bool err
Definition: armass.c:435
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
static const AvrInstruction instructions[]
Definition: assembler.c:880
RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size)
Definition: cio.c:145
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
ut8 * bytes
Definition: rz_asm.h:80
RzAsm * rasm
Definition: rz_core.h:323
RzNum * num
Definition: rz_core.h:316
ut64 value
Definition: rz_num.h:63

References rz_asm_code_t::bytes, err, instructions, rz_asm_code_t::len, rz_core_t::num, rz_core_t::offset, PFMT64x, rz_core_t::rasm, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_pc(), rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, and rz_num_t::value.

Referenced by rz_core_hack_arm64(), rz_write_assembly_file_handler(), and rz_write_assembly_handler().

◆ rz_core_write_assembly_fill()

RZ_API int rz_core_write_assembly_fill ( RzCore core,
ut64  addr,
RZ_NONNULL const char *  instructions 
)

Assemble instructions and write the resulting data inside the current instruction.

Assemble one or more instructions and write the resulting data inside the current instruction, if the new instructions fit. Fill the rest of the bytes of the old instruction with NOP

Parameters
coreRzCore reference
addrAddress to where to write
instructionsList of instructions to assemble as a string
Returns
Returns the length of the written data or -1 in case of error (e.g. the new instruction does not fit)

Definition at line 365 of file cio.c.

365  {
366  rz_return_val_if_fail(core && instructions, -1);
367 
368  int ret = -1;
369 
370  rz_asm_set_pc(core->rasm, core->offset);
371  RzAsmCode *acode = rz_asm_massemble(core->rasm, instructions);
372  if (!acode) {
373  return -1;
374  }
375  if (acode->len <= 0) {
376  ret = 0;
377  goto err;
378  }
379 
380  RzAnalysisOp op = { 0 };
381  if (rz_analysis_op(core->analysis, &op, core->offset, core->block, core->blocksize, RZ_ANALYSIS_OP_MASK_BASIC) < 1) {
382  RZ_LOG_ERROR("Invalid instruction at %" PFMT64x "\n", core->offset);
383  goto err;
384  }
385  if (op.size < acode->len) {
386  RZ_LOG_ERROR("Instructions do not fit at %" PFMT64x "\n", core->offset);
387  goto err;
388  }
389  rz_core_hack(core, "nop");
390 
391  if (!rz_core_write_at(core, core->offset, acode->bytes, acode->len)) {
392  RZ_LOG_ERROR("Cannot write %d bytes at 0x%" PFMT64x "address\n", acode->len, core->offset);
393  core->num->value = 1;
394  goto err;
395  }
396  ret = acode->len;
397 err:
398  rz_asm_code_free(acode);
399  return ret;
400 }
RZ_API bool rz_core_hack(RzCore *core, const char *op)
Write/Modify instructions at current offset based on op.
Definition: hack.c:280
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440

References rz_core_t::analysis, rz_core_t::block, rz_core_t::blocksize, rz_asm_code_t::bytes, err, instructions, rz_asm_code_t::len, rz_core_t::num, rz_core_t::offset, PFMT64x, rz_core_t::rasm, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_pc(), rz_core_hack(), rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, and rz_num_t::value.

Referenced by rz_write_assembly_inside_handler().

◆ rz_core_write_at()

RZ_API bool rz_core_write_at ( RzCore core,
ut64  addr,
const ut8 buf,
int  size 
)

Definition at line 145 of file cio.c.

145  {
146  rz_return_val_if_fail(core && buf && addr != UT64_MAX, false);
147  if (size < 1) {
148  return false;
149  }
150  bool ret = rz_io_write_at(core->io, addr, buf, size);
151  if (addr >= core->offset && addr <= core->offset + core->blocksize - 1) {
152  rz_core_block_read(core);
153  }
154  if (rz_config_get_i(core->config, "cfg.wseek")) {
155  rz_core_seek_delta(core, size, true);
156  }
157  return ret;
158 }
RZ_API bool rz_core_seek_delta(RzCore *core, st64 delta, bool save)
Seek relative to current offset and optionally save the current offset in seek history.
Definition: seek.c:152

References addr, rz_core_t::blocksize, rz_core_t::config, rz_core_t::io, rz_core_t::offset, rz_config_get_i(), rz_core_block_read(), rz_core_seek_delta(), rz_io_write_at(), rz_return_val_if_fail, and UT64_MAX.

Referenced by cmd_write_bits(), encrypt_or_decrypt_block(), initialize_stack(), insert_mode_enabled(), rz_core_serve(), rz_core_visual_bit_editor(), rz_core_write_assembly(), rz_core_write_assembly_fill(), rz_core_write_base64_at(), rz_core_write_base64d_at(), rz_core_write_block(), rz_core_write_block_op_at(), rz_core_write_duplicate_at(), rz_core_write_hexpair(), rz_core_write_length_string_at(), rz_core_write_random_at(), rz_core_write_seq_at(), rz_core_write_string_at(), rz_core_write_string_wide_at(), rz_core_write_string_zero_at(), rz_core_write_value_at(), rz_core_write_value_inc_at(), rz_core_yank_paste(), rz_write_extend_hexbytes_handler(), rz_write_unified_patch_handler(), and rz_write_zero_handler().

◆ rz_core_write_base64_at()

RZ_API bool rz_core_write_base64_at ( RzCore core,
ut64  addr,
RZ_NONNULL const char *  s 
)

Write a given string s at the specified addr encoded as base64.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to encode as base64 and then written.

Definition at line 700 of file cio.c.

700  {
701  rz_return_val_if_fail(core && s, false);
702 
703  bool res = false;
704  size_t str_len = strlen(s) + 1;
705  ut8 *bin_buf = malloc(str_len);
706  if (!bin_buf) {
707  return false;
708  }
709 
710  const int bin_len = rz_hex_str2bin(s, bin_buf);
711  if (bin_len <= 0) {
712  free(bin_buf);
713  return false;
714  }
715 
716  ut8 *buf = calloc(str_len + 1, 4);
717  if (!buf) {
718  free(bin_buf);
719  return false;
720  }
721 
722  int len = rz_base64_encode((char *)buf, bin_buf, bin_len);
723  free(bin_buf);
724  if (len == 0) {
725  goto err;
726  }
727 
728  if (!rz_core_write_at(core, addr, buf, len)) {
729  RZ_LOG_ERROR("Could not write base64 encoded string '%s' at %" PFMT64x "\n", s, addr);
730  goto err;
731  }
732  res = true;
733 err:
734  free(buf);
735  return res;
736 }
RZ_API size_t rz_base64_encode(char *bout, const ut8 *bin, size_t sz)
Definition: ubase64.c:81
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444

References addr, calloc(), err, free(), len, malloc(), PFMT64x, rz_base64_encode(), rz_core_write_at(), rz_hex_str2bin(), RZ_LOG_ERROR, rz_return_val_if_fail, and s.

Referenced by rz_write_base64_encode_handler().

◆ rz_core_write_base64d_at()

RZ_API bool rz_core_write_base64d_at ( RzCore core,
ut64  addr,
RZ_NONNULL const char *  s 
)

Write a given base64 string s at the specified addr, decoded.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to decode from base64 and then written

Definition at line 745 of file cio.c.

745  {
746  rz_return_val_if_fail(core && s, false);
747 
748  bool res = false;
749  size_t str_len = strlen(s) + 1;
750  ut8 *buf = malloc(str_len);
751  int len = rz_base64_decode(buf, s, -1);
752  if (len < 0) {
753  goto err;
754  }
755 
756  if (!rz_core_write_at(core, addr, buf, len)) {
757  RZ_LOG_ERROR("Could not write base64 decoded string '%s' at %" PFMT64x "\n", s, addr);
758  goto err;
759  }
760  res = true;
761 err:
762  free(buf);
763  return res;
764 }
RZ_API int rz_base64_decode(ut8 *bout, const char *bin, int len)
Definition: ubase64.c:48

References addr, err, free(), len, malloc(), PFMT64x, rz_base64_decode(), rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, and s.

Referenced by rz_write_base64_decode_handler().

◆ rz_core_write_block()

RZ_API bool rz_core_write_block ( RzCore core,
ut64  addr,
ut8 data,
size_t  len 
)

Writes the bytes data at address addr cyclically until it fills the whole block

It repeats the data data with length len until it fills an entire block starting at addr.

Parameters
coreRzCore reference
addrAddress to where to write
dataArray of bytes to cyclically write in the block at addr
lenLength of data

Definition at line 299 of file cio.c.

299  {
300  rz_return_val_if_fail(core && data, 0);
301 
302  ut8 *buf = RZ_NEWS(ut8, core->blocksize);
303  if (!buf) {
304  return false;
305  }
306 
307  bool res = false;
308  rz_mem_copyloop(buf, data, core->blocksize, len);
309  if (!rz_core_write_at(core, addr, buf, core->blocksize)) {
310  RZ_LOG_ERROR("Could not write cyclic data (%d bytes) at %" PFMT64x "\n", core->blocksize, addr);
311  goto err;
312  }
313  res = true;
314 err:
315  free(buf);
316  return res;
317 }
RZ_API void rz_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize)
Definition: mem.c:41

References addr, rz_core_t::blocksize, err, free(), len, PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, rz_mem_copyloop(), RZ_NEWS, and rz_return_val_if_fail.

Referenced by rz_write_block_handler().

◆ rz_core_write_block_op_at()

RZ_API bool rz_core_write_block_op_at ( RzCore core,
ut64  addr,
RzCoreWriteOp  op,
ut8 hex,
int  hexlen 
)

Write a full block of data according to the operation op and the hexvalue hex.

Parameters
coreReference to RzCore instance
addrWhere the block of data to modify starts
opOperation to perform on the block of data
hexOptional hex string that may be required by the specific operation
hexlenOptional length of the hex string. Must be present if hex is specified.
Returns
true if the write operation succeeds, false otherwise

Definition at line 1038 of file cio.c.

1038  {
1039  int buflen;
1040  ut8 *buf = rz_core_transform_op(core, addr, op, hex, hexlen, &buflen);
1041  if (!buf) {
1042  return false;
1043  }
1044 
1045  if (!rz_core_write_at(core, addr, buf, buflen)) {
1046  RZ_LOG_ERROR("Could not write block operation at %" PFMT64x "\n", addr);
1047  free(buf);
1048  return false;
1049  }
1050 
1051  return true;
1052 }
RZ_API RZ_OWN ut8 * rz_core_transform_op(RzCore *core, ut64 addr, RzCoreWriteOp op, ut8 *hex, int hexlen, int *buflen)
Transform a block of data at addr according to the operation op and the hexvalue hex.
Definition: cio.c:934

References addr, buflen, free(), hex, PFMT64x, rz_core_transform_op(), rz_core_write_at(), and RZ_LOG_ERROR.

Referenced by rz_write_op_2byteswap_handler(), rz_write_op_4byteswap_handler(), rz_write_op_8byteswap_handler(), and write_op_val().

◆ rz_core_write_duplicate_at()

RZ_API bool rz_core_write_duplicate_at ( RzCore core,
ut64  addr,
ut64  from,
int  len 
)

Copy len bytes from from to addr.

Parameters
coreReference to RzCore instance
addrWhere the data should be copied to
fromWhere the data should be read from
lenNumber of bytes to copy, expected to not be negative
Returns
true if the write operation succeeds, false otherwise

Definition at line 1106 of file cio.c.

1106  {
1107  rz_return_val_if_fail(core, false);
1108  rz_return_val_if_fail(len >= 0, false);
1109 
1110  bool res = false;
1111  ut8 *data = RZ_NEWS(ut8, len);
1112  if (!data) {
1113  return false;
1114  }
1115 
1116  int n = rz_io_nread_at(core->io, from, data, len);
1117  if (n < 0) {
1118  RZ_LOG_ERROR("Cannot read data from %" PFMT64x ".\n", from);
1119  goto err;
1120  }
1121  if (!rz_core_write_at(core, addr, data, n)) {
1122  RZ_LOG_ERROR("Cannot write %d bytes to %" PFMT64x ".\n", n, addr);
1123  goto err;
1124  }
1125  res = true;
1126 err:
1127  free(data);
1128  return res;
1129 }
int n
Definition: mipsasm.c:19
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123

References addr, err, free(), from, rz_core_t::io, len, n, PFMT64x, rz_core_write_at(), rz_io_nread_at(), RZ_LOG_ERROR, RZ_NEWS, and rz_return_val_if_fail.

Referenced by rz_write_duplicate_handler().

◆ rz_core_write_hexpair()

RZ_API int rz_core_write_hexpair ( RzCore core,
ut64  addr,
const char *  pairs 
)

Writes the hexadecimal string at the given offset

Returns the length of the written data.

Parameters
coreRzCore reference
addrAddress to where to write
pairsData as the hexadecimal string

Definition at line 268 of file cio.c.

268  {
269  rz_return_val_if_fail(core && pairs, 0);
270  ut8 *buf = malloc(strlen(pairs) + 1);
271  if (!buf) {
272  return 0;
273  }
274  int len = rz_hex_str2bin(pairs, buf);
275  if (len < 0) {
276  RZ_LOG_ERROR("Could not convert hexpair '%s' to bin data\n", pairs);
277  goto err;
278  }
279  if (!rz_core_write_at(core, addr, buf, len)) {
280  RZ_LOG_ERROR("Could not write hexpair '%s' at %" PFMT64x "\n", pairs, addr);
281  goto err;
282  }
283 err:
284  free(buf);
285  return len;
286 }

References addr, err, free(), len, malloc(), PFMT64x, rz_core_write_at(), rz_hex_str2bin(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by __insert_value(), insert_mode_enabled(), rz_core_hack_arm(), rz_core_hack_arm64(), rz_core_hack_dalvik(), rz_core_hack_x86(), rz_write_hex_from_file_handler(), and rz_write_hex_handler().

◆ rz_core_write_length_string_at()

RZ_API bool rz_core_write_length_string_at ( RzCore core,
ut64  addr,
const char *  s 
)

Write at the specified addr the length of the string in one byte, followed by the given string s.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to write. The string is unescaped, meaning that if there is \n it becomes 0x0a

Definition at line 673 of file cio.c.

673  {
674  rz_return_val_if_fail(core && s, false);
675 
676  char *str = strdup(s);
677  if (!str) {
678  return false;
679  }
680 
681  int len = rz_str_unescape(str);
682  ut8 ulen = (ut8)len;
683  if (!rz_core_write_at(core, addr, &ulen, sizeof(ulen)) ||
684  !rz_core_write_at(core, addr + 1, (const ut8 *)str, len)) {
685  RZ_LOG_ERROR("Could not write length+'%s' at %" PFMT64x "\n", s, addr);
686  free(str);
687  return false;
688  }
689  free(str);
690  return true;
691 }
#define ut8
Definition: dcpu16.h:8
RZ_API int rz_str_unescape(char *buf)
Definition: str.c:1300

References addr, free(), len, PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_str_unescape(), s, cmd_descs_generate::str, strdup(), and ut8.

Referenced by rz_write_length_string_handler().

◆ rz_core_write_random_at()

RZ_API bool rz_core_write_random_at ( RzCore core,
ut64  addr,
size_t  len 
)

Write len random bytes at address addr.

Parameters
coreRzCore reference
addrAddress where to write the data
lenLength of the random data to write

Definition at line 773 of file cio.c.

773  {
774  rz_return_val_if_fail(core, false);
775 
776  bool res = false;
777  ut8 *buf = malloc(len);
778  if (!buf) {
779  return false;
780  }
781 
782  rz_num_irand();
783  for (int i = 0; i < len; i++) {
784  buf[i] = rz_num_rand(256);
785  }
786 
787  if (!rz_core_write_at(core, addr, buf, len)) {
788  RZ_LOG_ERROR("Could not write random data of length %zd at %" PFMT64x "\n", len, addr);
789  goto err;
790  }
791  res = true;
792 err:
793  free(buf);
794  return res;
795 }
RZ_API int rz_num_rand(int max)
Definition: unum.c:47
RZ_API void rz_num_irand(void)
Definition: unum.c:43

References addr, err, free(), i, len, malloc(), PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, rz_num_irand(), rz_num_rand(), and rz_return_val_if_fail.

Referenced by rz_write_random_handler().

◆ rz_core_write_seq_at()

RZ_API bool rz_core_write_seq_at ( RzCore core,
ut64  addr,
ut64  from,
ut64  to,
ut64  step,
int  value_size 
)

Write a full block of data with a sequence.

Write a full block of data with a sequence of numbers starting from from up to to, with a step of step. The values are written as numbers of value_size bytes.

Parameters
coreReference to RzCore instance
addrWhere the block of data to modify starts
fromFrom where to start the sequence of numbers
toWhere to stop in the sequence
stepDifference between two numbers in the sequence
value_sizeSize of each number of the sequence, in bytes
Returns
true if the write operation succeeds, false otherwise

Definition at line 1069 of file cio.c.

1069  {
1070  rz_return_val_if_fail(core, false);
1071  rz_return_val_if_fail(value_size == 1 || value_size == 2 || value_size == 4 || value_size == 8, false);
1072  ut64 max_val = (1ULL << (8 * value_size));
1073  rz_return_val_if_fail(from < max_val, false);
1074  rz_return_val_if_fail(to < max_val, false);
1075 
1076  ut8 *buf = RZ_NEWS0(ut8, core->blocksize);
1077  if (!buf) {
1078  return false;
1079  }
1080 
1081  ut64 diff = to <= from ? max_val : to - from + 1;
1082  ut64 p = from;
1083  for (size_t i = 0; i < core->blocksize; i += value_size, p = (from + ((p + step - from) % diff)) % max_val) {
1084  rz_write_ble(buf + i, p, rz_config_get_b(core->config, "cfg.bigendian"), value_size * 8);
1085  }
1086 
1087  if (!rz_core_write_at(core, addr, buf, core->blocksize)) {
1088  RZ_LOG_ERROR("Could not write sequence [%" PFMT64d ", %" PFMT64d "] step=%" PFMT64d ",value_size=%d at %" PFMT64x "\n", from, to, step, value_size, addr);
1089  free(buf);
1090  return false;
1091  }
1092 
1093  free(buf);
1094  return true;
1095 }
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
static states step(struct re_guts *, sopno, sopno, states, int, states)
Definition: engine.c:888
static void rz_write_ble(void *dst, ut64 val, bool big_endian, int size)
Definition: rz_endian.h:548
#define PFMT64d
Definition: rz_types.h:394
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125

References addr, rz_core_t::blocksize, rz_core_t::config, free(), from, i, p, PFMT64d, PFMT64x, rz_config_get_b(), rz_core_write_at(), RZ_LOG_ERROR, RZ_NEWS0, rz_return_val_if_fail, rz_write_ble(), step(), to, and ut64().

Referenced by rz_write_op_sequence_handler().

◆ rz_core_write_string_at()

RZ_API bool rz_core_write_string_at ( RzCore core,
ut64  addr,
RZ_NONNULL const char *  s 
)

Write a given string s at the specified addr.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to write. The string is unescaped, meaning that if there is \n it becomes 0x0a

Definition at line 605 of file cio.c.

605  {
606  rz_return_val_if_fail(core && s, false);
607 
608  char *str = strdup(s);
609  if (!str) {
610  return false;
611  }
612 
613  int len = rz_str_unescape(str);
614  if (!rz_core_write_at(core, addr, (const ut8 *)str, len)) {
615  RZ_LOG_ERROR("Could not write '%s' at %" PFMT64x "\n", s, addr);
616  free(str);
617  return false;
618  }
619  free(str);
620  return true;
621 }

References addr, free(), len, PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_str_unescape(), s, cmd_descs_generate::str, and strdup().

Referenced by rz_write_debruijn_handler(), and rz_write_handler().

◆ rz_core_write_string_wide_at()

RZ_API bool rz_core_write_string_wide_at ( RzCore core,
ut64  addr,
const char *  s 
)

Write a given string s as a wide string at the specified addr.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to write. The string is unescaped, meaning that if there is \n it becomes 0x0a

Definition at line 630 of file cio.c.

630  {
631  rz_return_val_if_fail(core && s, false);
632 
633  bool res = false;
634  char *str = strdup(s);
635  if (!str) {
636  return false;
637  }
638 
639  int len = rz_str_unescape(str);
640  if (len < 1) {
641  goto str_err;
642  }
643 
644  len++; // Consider for the terminator char
645  char *tmp = RZ_NEWS(char, len * 2);
646  if (!tmp) {
647  goto str_err;
648  }
649 
650  for (int i = 0; i < len; i++) {
651  tmp[i * 2] = str[i];
652  tmp[i * 2 + 1] = 0;
653  }
654 
655  if (!rz_core_write_at(core, addr, (const ut8 *)tmp, len * 2)) {
656  RZ_LOG_ERROR("Could not write wide string '%s' at %" PFMT64x "\n", s, addr);
657  free(str);
658  return false;
659  }
660  res = true;
661 str_err:
662  free(str);
663  return res;
664 }

References addr, free(), i, len, PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, RZ_NEWS, rz_return_val_if_fail, rz_str_unescape(), s, cmd_descs_generate::str, strdup(), and autogen_x86imm::tmp.

Referenced by rz_write_wide_string_handler().

◆ rz_core_write_string_zero_at()

RZ_API bool rz_core_write_string_zero_at ( RzCore core,
ut64  addr,
const char *  s 
)

Write a given string s, followed by the zero terminator, at the specified addr.

Parameters
coreRzCore reference
addrAddress where to write the string
sString to write. The string is unescaped, meaning that if there is \n it becomes 0x0a

Definition at line 905 of file cio.c.

905  {
906  rz_return_val_if_fail(core && s, false);
907 
908  char *str = strdup(s);
909  if (!str) {
910  return false;
911  }
912 
913  int len = rz_str_unescape(str);
914  if (!rz_core_write_at(core, addr, (const ut8 *)str, len + 1)) {
915  RZ_LOG_ERROR("Could not write '%s' at %" PFMT64x "\n", s, addr);
916  free(str);
917  return false;
918  }
919  free(str);
920  return true;
921 }

References addr, free(), len, PFMT64x, rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_str_unescape(), s, cmd_descs_generate::str, and strdup().

Referenced by rz_write_zero_string_handler().

◆ rz_core_write_value_at()

RZ_API bool rz_core_write_value_at ( RzCore core,
ut64  addr,
ut64  value,
int  sz 
)

Write a given value at the specified address, using sz bytes.

Parameters
coreRzCore reference
addrAddress where to write the value
valueValue to write
szNumber of bytes to write. Can be 1, 2, 4, 8 or the special value 0 if you want the function to choose based on value (4 if value is <4GB, 8 otherwise)

Definition at line 506 of file cio.c.

506  {
507  rz_return_val_if_fail(sz == 0 || sz == 1 || sz == 2 || sz == 4 || sz == 8, false);
508  ut8 buf[sizeof(ut64)];
509  bool be = rz_config_get_i(core->config, "cfg.bigendian");
510 
511  core->num->value = 0;
512  if (sz == 0) {
513  sz = value & UT64_32U ? 8 : 4;
514  }
515 
516  switch (sz) {
517  case 1:
519  break;
520  case 2:
521  rz_write_ble16(buf, (ut16)(value & UT16_MAX), be);
522  break;
523  case 4:
524  rz_write_ble32(buf, (ut32)(value & UT32_MAX), be);
525  break;
526  case 8:
527  rz_write_ble64(buf, value, be);
528  break;
529  default:
530  return false;
531  }
532 
533  if (!rz_core_write_at(core, addr, buf, sz)) {
534  RZ_LOG_ERROR("Could not write %d bytes at %" PFMT64x "\n", sz, addr);
535  core->num->value = 1;
536  return false;
537  }
538  return true;
539 }
static int value
Definition: cmd_api.c:93
static void rz_write_ble8(void *dest, ut8 val)
Definition: rz_endian.h:23
static void rz_write_ble32(void *dest, ut32 val, bool big_endian)
Definition: rz_endian.h:540
static void rz_write_ble64(void *dest, ut64 val, bool big_endian)
Definition: rz_endian.h:544
static void rz_write_ble16(void *dest, ut16 val, bool big_endian)
Definition: rz_endian.h:532
#define UT32_MAX
Definition: rz_types_base.h:99
#define UT64_32U
Definition: rz_types_base.h:90
#define UT8_MAX
#define UT16_MAX

References addr, rz_core_t::config, rz_core_t::num, PFMT64x, rz_config_get_i(), rz_core_write_at(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_write_ble16(), rz_write_ble32(), rz_write_ble64(), rz_write_ble8(), UT16_MAX, UT32_MAX, ut64(), UT64_32U, UT8_MAX, value, and rz_num_t::value.

Referenced by common_write_value_handler().

◆ rz_core_write_value_inc_at()

RZ_API bool rz_core_write_value_inc_at ( RzCore core,
ut64  addr,
st64  value,
int  sz 
)

Write at addr the current value + value passed as argument.

The values read/written are considered as integers of sz bytes.

Parameters
coreRzCore reference
addrAddress where to overwrite the value
valueValue to sum to the existing value in addr
szSize of the values, in bytes, to consider. Can be 1, 2, 4, 8.

Definition at line 551 of file cio.c.

551  {
552  rz_return_val_if_fail(sz == 1 || sz == 2 || sz == 4 || sz == 8, false);
553 
554  ut8 buf[sizeof(ut64)];
555  bool be = rz_config_get_i(core->config, "cfg.bigendian");
556 
557  if (!rz_io_read_at_mapped(core->io, addr, buf, sz)) {
558  return false;
559  }
560 
561  switch (sz) {
562  case 1: {
563  ut8 cur = rz_read_ble8(buf);
564  cur += value;
565  rz_write_ble8(buf, cur);
566  break;
567  }
568  case 2: {
569  ut16 cur = rz_read_ble16(buf, be);
570  cur += value;
571  rz_write_ble16(buf, cur, be);
572  break;
573  }
574  case 4: {
575  ut32 cur = rz_read_ble32(buf, be);
576  cur += value;
577  rz_write_ble32(buf, cur, be);
578  break;
579  }
580  case 8: {
581  ut64 cur = rz_read_ble64(buf, be);
582  cur += value;
583  rz_write_ble64(buf, cur, be);
584  break;
585  }
586  default:
588  break;
589  }
590 
591  if (!rz_core_write_at(core, addr, buf, sz)) {
592  RZ_LOG_ERROR("Could not write %d bytes at %" PFMT64x "\n", sz, addr);
593  return false;
594  }
595  return true;
596 }
static ut64 rz_read_ble64(const void *src, bool big_endian)
Definition: rz_endian.h:501
static ut8 rz_read_ble8(const void *src)
Definition: rz_endian.h:12
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
RZ_API bool rz_io_read_at_mapped(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:318

References addr, rz_core_t::config, rz_core_t::io, PFMT64x, rz_config_get_i(), rz_core_write_at(), rz_io_read_at_mapped(), RZ_LOG_ERROR, rz_read_ble16(), rz_read_ble32(), rz_read_ble64(), rz_read_ble8(), rz_return_val_if_fail, rz_warn_if_reached, rz_write_ble16(), rz_write_ble32(), rz_write_ble64(), rz_write_ble8(), ut64(), and value.

Referenced by w_incdec_handler().