Rizin
unix-like reverse engineering framework and cli tools
cmd_write.c File Reference
#include <rz_crypto.h>
#include <rz_config.h>
#include <rz_cons.h>
#include <rz_core.h>
#include <rz_io.h>
#include <rz_socket.h>
#include "../core_private.h"

Go to the source code of this file.

Macros

#define WSEEK(x, y)
 

Functions

static void cmd_write_fail (RzCore *core)
 
static bool encrypt_or_decrypt_block (RzCore *core, const char *algo, const char *key, int direction, const char *iv)
 
static void cmd_write_bits (RzCore *core, int set, ut64 val)
 
static RzCmdStatus common_write_value_handler (RzCore *core, const char *valstr, size_t sz)
 
RZ_IPI RzCmdStatus rz_write_value_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_value1_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_value2_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_value4_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_value8_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_base64_encode_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_base64_decode_handler (RzCore *core, int argc, const char **argv)
 
static bool ioMemcpy (RzCore *core, ut64 dst, ut64 src, int len)
 
RZ_IPI RzCmdStatus rz_write_from_io_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_from_io_xchg_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_from_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_from_socket_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_bits_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_unset_bits_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_zero_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus w_incdec_handler (RzCore *core, int argc, const char **argv, int inc_size)
 
RZ_IPI RzCmdStatus rz_write_1_inc_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_1_dec_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_2_inc_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_2_dec_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_4_inc_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_4_dec_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_8_inc_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_8_dec_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_unified_patch_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_random_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_zero_string_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_wide_string_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_hex_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_hex_from_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_assembly_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_assembly_inside_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_assembly_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_assembly_opcode_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_block_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_mask_set_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_mask_reset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_duplicate_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_length_string_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_cache_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_write_cache_remove_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_cache_remove_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_cache_commit_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_cache_commit_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_pcache_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_write_pcache_commit_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_extend_zero_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_extend_shift_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_extend_hexbytes_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_2byteswap_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_4byteswap_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_8byteswap_handler (RzCore *core, int argc, const char **argv)
 
static RzCmdStatus write_op_val (RzCore *core, int argc, const char **argv, RzCoreWriteOp op)
 
RZ_IPI RzCmdStatus rz_write_op_add_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_sub_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_mul_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_div_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_xor_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_and_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_or_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_shl_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_shr_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_encrypt_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_decrypt_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_op_sequence_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_debruijn_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_write_debruijn_find_handler (RzCore *core, int argc, const char **argv)
 

Macro Definition Documentation

◆ WSEEK

#define WSEEK (   x,
 
)
Value:
if (wseek) \
rz_core_seek_delta(x, y, true)
int x
Definition: mipsasm.c:20

Definition at line 92 of file cmd_write.c.

Function Documentation

◆ cmd_write_bits()

static void cmd_write_bits ( RzCore core,
int  set,
ut64  val 
)
static

Definition at line 78 of file cmd_write.c.

78  {
79  ut64 ret, orig;
80  // used to set/unset bit in current address
81  rz_io_read_at(core->io, core->offset, (ut8 *)&orig, sizeof(orig));
82  if (set) {
83  ret = orig | val;
84  } else {
85  ret = orig & (~(val));
86  }
87  if (!rz_core_write_at(core, core->offset, (const ut8 *)&ret, sizeof(ret))) {
88  cmd_write_fail(core);
89  }
90 }
ut16 val
Definition: armass64_const.h:6
RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size)
Definition: cio.c:145
static void cmd_write_fail(RzCore *core)
Definition: cmd_write.c:12
uint8_t ut8
Definition: lh5801.h:11
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
RzIO * io
Definition: rz_core.h:313
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References cmd_write_fail(), rz_core_t::io, rz_core_t::offset, rz_core_write_at(), rz_io_read_at(), ut64(), and val.

Referenced by rz_write_bits_handler(), and rz_write_unset_bits_handler().

◆ cmd_write_fail()

static void cmd_write_fail ( RzCore core)
static

Definition at line 12 of file cmd_write.c.

12  {
13  eprintf("Failed to write\n");
14  core->num->value = 1;
15 }
#define eprintf(x, y...)
Definition: rlcc.c:7
RzNum * num
Definition: rz_core.h:316
ut64 value
Definition: rz_num.h:63

References eprintf, rz_core_t::num, and rz_num_t::value.

Referenced by cmd_write_bits().

◆ common_write_value_handler()

static RzCmdStatus common_write_value_handler ( RzCore core,
const char *  valstr,
size_t  sz 
)
static

Definition at line 96 of file cmd_write.c.

96  {
97  ut64 value = rz_num_math(core->num, valstr);
98  if (core->num->nc.errors) {
99  RZ_LOG_ERROR("Could not convert argument to number");
100  return RZ_CMD_STATUS_ERROR;
101  }
102 
104 }
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.
Definition: cio.c:506
static int value
Definition: cmd_api.c:93
@ 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
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67

References rz_num_calc_t::errors, rz_num_t::nc, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_value_at(), RZ_LOG_ERROR, rz_num_math(), ut64(), and value.

Referenced by rz_write_value1_handler(), rz_write_value2_handler(), rz_write_value4_handler(), rz_write_value8_handler(), and rz_write_value_handler().

◆ encrypt_or_decrypt_block()

static bool encrypt_or_decrypt_block ( RzCore core,
const char *  algo,
const char *  key,
int  direction,
const char *  iv 
)
static

Definition at line 17 of file cmd_write.c.

17  {
18  // TODO: generalise no_key_mode for all non key encoding/decoding.
19  int keylen = 0;
20  bool no_key_mode = !strcmp("base64", algo) || !strcmp("base91", algo) || !strcmp("punycode", algo);
21  ut8 *binkey = NULL;
22  if (!strncmp(key, "s:", 2)) {
23  binkey = (ut8 *)strdup(key + 2);
24  keylen = strlen(key + 2);
25  } else {
26  binkey = (ut8 *)strdup(key);
27  keylen = rz_hex_str2bin(key, binkey);
28  }
29  if (!no_key_mode && keylen < 1) {
30  eprintf("%s key not defined. Use -S [key]\n", ((!direction) ? "Encryption" : "Decryption"));
31  free(binkey);
32  return false;
33  }
34  RzCrypto *cry = rz_crypto_new();
35  if (rz_crypto_use(cry, algo)) {
36  if (!binkey) {
37  eprintf("Cannot allocate %d byte(s)\n", keylen);
38  rz_crypto_free(cry);
39  return false;
40  }
41  if (rz_crypto_set_key(cry, binkey, keylen, 0, direction)) {
42  if (iv) {
43  ut8 *biniv = malloc(strlen(iv) + 1);
44  int ivlen = rz_hex_str2bin(iv, biniv);
45  if (ivlen < 1) {
46  ivlen = strlen(iv);
47  strcpy((char *)biniv, iv);
48  }
49  if (!rz_crypto_set_iv(cry, biniv, ivlen)) {
50  eprintf("Invalid IV.\n");
51  return 0;
52  }
53  }
54  rz_crypto_update(cry, (const ut8 *)core->block, core->blocksize);
55  rz_crypto_final(cry, NULL, 0);
56 
57  int result_size = 0;
58  const ut8 *result = rz_crypto_get_output(cry, &result_size);
59  if (result) {
60  if (!rz_core_write_at(core, core->offset, result, result_size)) {
61  eprintf("rz_core_write_at failed at 0x%08" PFMT64x "\n", core->offset);
62  }
63  eprintf("Written %d byte(s)\n", result_size);
64  }
65  } else {
66  eprintf("Invalid key\n");
67  }
68  free(binkey);
69  rz_crypto_free(cry);
70  return 0;
71  } else {
72  eprintf("Unknown %s algorithm '%s'\n", ((!direction) ? "encryption" : "decryption"), algo);
73  }
74  rz_crypto_free(cry);
75  return 1;
76 }
#define NULL
Definition: cris-opc.c:27
RZ_API int rz_crypto_update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:166
RZ_API bool rz_crypto_set_iv(RzCrypto *cry, const ut8 *iv, int ivlen)
Definition: crypto.c:161
RZ_API int rz_crypto_final(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:170
RZ_API const ut8 * rz_crypto_get_output(RzCrypto *cry, int *size)
Definition: crypto.c:193
RZ_API bool rz_crypto_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto.c:151
RZ_API void rz_crypto_free(RzCrypto *cry)
Definition: crypto.c:116
RZ_API RzCrypto * rz_crypto_new(void)
Definition: crypto.c:83
RZ_API bool rz_crypto_use(RzCrypto *cry, const char *algo)
Definition: crypto.c:130
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 static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * malloc(size_t size)
Definition: malloc.c:123
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_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
#define PFMT64x
Definition: rz_types.h:393
ut8 * block
Definition: rz_core.h:305
ut32 blocksize
Definition: rz_core.h:303

References rz_core_t::block, rz_core_t::blocksize, eprintf, free(), key, malloc(), NULL, rz_core_t::offset, PFMT64x, rz_core_write_at(), rz_crypto_final(), rz_crypto_free(), rz_crypto_get_output(), rz_crypto_new(), rz_crypto_set_iv(), rz_crypto_set_key(), rz_crypto_update(), rz_crypto_use(), rz_hex_str2bin(), and strdup().

Referenced by rz_write_op_decrypt_handler(), and rz_write_op_encrypt_handler().

◆ ioMemcpy()

static bool ioMemcpy ( RzCore core,
ut64  dst,
ut64  src,
int  len 
)
static

Definition at line 134 of file cmd_write.c.

134  {
135  bool ret = false;
136  if (len > 0) {
137  ut8 *buf = calloc(1, len);
138  if (buf) {
139  if (rz_io_read_at(core->io, src, buf, len)) {
140  if (rz_io_write_at(core->io, dst, buf, len)) {
141  rz_core_block_read(core);
142  ret = true;
143  } else {
144  eprintf("rz_io_write_at failed at 0x%08" PFMT64x "\n", dst);
145  }
146  } else {
147  eprintf("rz_io_read_at failed at 0x%08" PFMT64x "\n", src);
148  }
149  free(buf);
150  }
151  }
152  return ret;
153 }
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
voidpf void * buf
Definition: ioapi.h:138
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
char * dst
Definition: lz4.h:724
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358

References calloc(), dst, eprintf, free(), rz_core_t::io, len, PFMT64x, rz_core_block_read(), rz_io_read_at(), rz_io_write_at(), and src.

Referenced by rz_write_from_io_handler(), and rz_write_from_io_xchg_handler().

◆ rz_write_1_dec_handler()

RZ_IPI RzCmdStatus rz_write_1_dec_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 333 of file cmd_write.c.

333  {
334  return w_incdec_handler(core, argc, argv, 1);
335 }
static RzCmdStatus w_incdec_handler(RzCore *core, int argc, const char **argv, int inc_size)
Definition: cmd_write.c:321
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_1_inc_handler()

RZ_IPI RzCmdStatus rz_write_1_inc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 330 of file cmd_write.c.

330  {
331  return w_incdec_handler(core, argc, argv, 1);
332 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_2_dec_handler()

RZ_IPI RzCmdStatus rz_write_2_dec_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 340 of file cmd_write.c.

340  {
341  return w_incdec_handler(core, argc, argv, 2);
342 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_2_inc_handler()

RZ_IPI RzCmdStatus rz_write_2_inc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 337 of file cmd_write.c.

337  {
338  return w_incdec_handler(core, argc, argv, 2);
339 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_4_dec_handler()

RZ_IPI RzCmdStatus rz_write_4_dec_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 347 of file cmd_write.c.

347  {
348  return w_incdec_handler(core, argc, argv, 4);
349 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_4_inc_handler()

RZ_IPI RzCmdStatus rz_write_4_inc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 344 of file cmd_write.c.

344  {
345  return w_incdec_handler(core, argc, argv, 4);
346 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_8_dec_handler()

RZ_IPI RzCmdStatus rz_write_8_dec_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 354 of file cmd_write.c.

354  {
355  return w_incdec_handler(core, argc, argv, 8);
356 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_8_inc_handler()

RZ_IPI RzCmdStatus rz_write_8_inc_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 351 of file cmd_write.c.

351  {
352  return w_incdec_handler(core, argc, argv, 8);
353 }

References argv, and w_incdec_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_assembly_file_handler()

RZ_IPI RzCmdStatus rz_write_assembly_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 497 of file cmd_write.c.

497  {
498  char *instructions = rz_file_slurp(argv[1], NULL);
499  if (!instructions) {
500  RZ_LOG_ERROR("Cannot read file '%s'\n", argv[1]);
501  return RZ_CMD_STATUS_ERROR;
502  }
503  int res = rz_core_write_assembly(core, core->offset, instructions);
505  return res >= 0 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
506 }
static const AvrInstruction instructions[]
Definition: assembler.c:880
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.
Definition: cio.c:327
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454

References argv, free(), instructions, NULL, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_assembly(), rz_file_slurp(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_write_assembly_handler()

RZ_IPI RzCmdStatus rz_write_assembly_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 477 of file cmd_write.c.

477  {
478  char *instructions = rz_str_array_join(argv + 1, argc - 1, "\n");
479  if (!instructions) {
480  return RZ_CMD_STATUS_ERROR;
481  }
482  int res = rz_core_write_assembly(core, core->offset, instructions);
484  return res >= 0 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
485 }
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861

References argv, free(), instructions, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_assembly(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_write_assembly_inside_handler()

RZ_IPI RzCmdStatus rz_write_assembly_inside_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 487 of file cmd_write.c.

487  {
488  char *instructions = rz_str_array_join(argv + 1, argc - 1, "\n");
489  if (!instructions) {
490  return RZ_CMD_STATUS_ERROR;
491  }
492  int res = rz_core_write_assembly_fill(core, core->offset, instructions);
494  return res >= 0 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
495 }
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.
Definition: cio.c:365

References argv, free(), instructions, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_assembly_fill(), and rz_str_array_join().

Referenced by rzshell_cmddescs_init().

◆ rz_write_assembly_opcode_handler()

RZ_IPI RzCmdStatus rz_write_assembly_opcode_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 508 of file cmd_write.c.

508  {
509  return bool2status(rz_core_hack(core, argv[1]));
510 }
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
RZ_API bool rz_core_hack(RzCore *core, const char *op)
Write/Modify instructions at current offset based on op.
Definition: hack.c:280

References argv, bool2status(), and rz_core_hack().

Referenced by rzshell_cmddescs_init().

◆ rz_write_base64_decode_handler()

RZ_IPI RzCmdStatus rz_write_base64_decode_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 130 of file cmd_write.c.

130  {
132 }
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.
Definition: cio.c:745

References argv, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_write_base64d_at().

Referenced by rzshell_cmddescs_init().

◆ rz_write_base64_encode_handler()

RZ_IPI RzCmdStatus rz_write_base64_encode_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 126 of file cmd_write.c.

126  {
128 }
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.
Definition: cio.c:700

References argv, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_write_base64_at().

Referenced by rzshell_cmddescs_init().

◆ rz_write_bits_handler()

RZ_IPI RzCmdStatus rz_write_bits_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 297 of file cmd_write.c.

297  {
298  cmd_write_bits(core, 1, rz_num_math(core->num, argv[1]));
299  return RZ_CMD_STATUS_OK;
300 }
static void cmd_write_bits(RzCore *core, int set, ut64 val)
Definition: cmd_write.c:78

References argv, cmd_write_bits(), rz_core_t::num, RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_block_handler()

RZ_IPI RzCmdStatus rz_write_block_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 512 of file cmd_write.c.

512  {
513  ut8 *hex = RZ_NEWS0(ut8, (strlen(argv[1]) + 1) / 2);
514  if (!hex) {
515  return RZ_CMD_STATUS_ERROR;
516  }
517 
518  int len = rz_hex_str2bin(argv[1], hex);
519  if (len <= 0) {
520  free(hex);
521  RZ_LOG_ERROR("Cannot convert '%s' to hex data.\n", argv[1]);
522  return RZ_CMD_STATUS_ERROR;
523  }
524 
525  return bool2status(rz_core_write_block(core, core->offset, hex, len));
526 }
RZ_API bool rz_core_write_block(RzCore *core, ut64 addr, ut8 *data, size_t len)
Definition: cio.c:299
static const char hex[16]
Definition: print.c:21
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282

References argv, bool2status(), free(), hex, len, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_write_block(), rz_hex_str2bin(), RZ_LOG_ERROR, and RZ_NEWS0.

Referenced by rzshell_cmddescs_init().

◆ rz_write_cache_commit_all_handler()

RZ_IPI RzCmdStatus rz_write_cache_commit_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 582 of file cmd_write.c.

582  {
583  rz_io_cache_commit(core->io, 0, UT64_MAX);
584  rz_core_block_read(core);
585  return RZ_CMD_STATUS_OK;
586 }
RZ_API void rz_io_cache_commit(RzIO *io, ut64 from, ut64 to)
Definition: io_cache.c:35
#define UT64_MAX
Definition: rz_types_base.h:86

References rz_core_t::io, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_cache_commit(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_write_cache_commit_handler()

RZ_IPI RzCmdStatus rz_write_cache_commit_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 575 of file cmd_write.c.

575  {
576  ut64 from = argc > 1 ? rz_num_math(core->num, argv[1]) : core->offset;
577  ut64 to = argc > 2 ? rz_num_math(core->num, argv[2]) : from + core->blocksize;
578  rz_io_cache_commit(core->io, from, to);
579  return RZ_CMD_STATUS_OK;
580 }
voidpf uLong offset
Definition: ioapi.h:144
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
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
static int blocksize
Definition: visual.c:15

References argv, rz_core_t::blocksize, from, rz_core_t::io, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_io_cache_commit(), rz_num_math(), to, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_cache_list_handler()

RZ_IPI RzCmdStatus rz_write_cache_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 557 of file cmd_write.c.

557  {
558  return rz_core_io_cache_print(core, state);
559 }
RZ_API RzCmdStatus rz_core_io_cache_print(RzCore *core, RzCmdStateOutput *state)
Definition: cio.c:797
Definition: dis.h:43

References rz_core_io_cache_print().

Referenced by rzshell_cmddescs_init().

◆ rz_write_cache_remove_all_handler()

RZ_IPI RzCmdStatus rz_write_cache_remove_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 570 of file cmd_write.c.

570  {
571  rz_io_cache_reset(core->io, core->io->cached);
572  return RZ_CMD_STATUS_OK;
573 }
RZ_API void rz_io_cache_reset(RzIO *io, int set)
Definition: io_cache.c:57
int cached
Definition: rz_io.h:69

References rz_io_t::cached, rz_core_t::io, RZ_CMD_STATUS_OK, and rz_io_cache_reset().

Referenced by rzshell_cmddescs_init().

◆ rz_write_cache_remove_handler()

RZ_IPI RzCmdStatus rz_write_cache_remove_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 561 of file cmd_write.c.

561  {
562  ut64 from = argc > 1 ? rz_num_math(core->num, argv[1]) : core->offset;
563  ut64 to = argc > 2 ? rz_num_math(core->num, argv[2]) : from + core->blocksize;
564  int ninvalid = rz_io_cache_invalidate(core->io, from, to);
565  RZ_LOG_INFO("Invalidated %d cache(s)\n", ninvalid);
566  rz_core_block_read(core);
567  return RZ_CMD_STATUS_OK;
568 }
RZ_API int rz_io_cache_invalidate(RzIO *io, ut64 from, ut64 to)
Definition: io_cache.c:64
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54

References argv, rz_core_t::blocksize, from, rz_core_t::io, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_cache_invalidate(), RZ_LOG_INFO, rz_num_math(), to, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_debruijn_find_handler()

RZ_IPI RzCmdStatus rz_write_debruijn_find_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 785 of file cmd_write.c.

785  {
786  ut64 value = rz_num_math(core->num, argv[1]);
787  int offset = rz_debruijn_offset(0, NULL, value, rz_config_get_b(core->config, "cfg.bigendian"));
788  if (offset < 0) {
789  RZ_LOG_ERROR("Could not find value %" PFMT64x " in Debruijn sequence.\n", value);
790  return RZ_CMD_STATUS_ERROR;
791  }
792  rz_cons_printf("%d\n", offset);
793  return RZ_CMD_STATUS_OK;
794 }
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API int rz_debruijn_offset(int start, const char *charset, ut64 value, bool is_big_endian)
Finds the offset of a given value in a debrujn sequence.
Definition: debruijn.c:112
RzConfig * config
Definition: rz_core.h:300

References argv, rz_core_t::config, NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_cons_printf(), rz_debruijn_offset(), RZ_LOG_ERROR, rz_num_math(), ut64(), and value.

Referenced by rzshell_cmddescs_init().

◆ rz_write_debruijn_handler()

RZ_IPI RzCmdStatus rz_write_debruijn_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 769 of file cmd_write.c.

769  {
770  int len = (int)rz_num_math(core->num, argv[1]);
771  if (len < 0) {
772  RZ_LOG_ERROR("Invalid length: %d\n", len);
773  return RZ_CMD_STATUS_ERROR;
774  }
775  char *p = rz_debruijn_pattern(len, 0, NULL);
776  if (!p) {
777  RZ_LOG_ERROR("Cannot create Debrujn sequence of length %d\n", len);
778  return RZ_CMD_STATUS_ERROR;
779  }
780  bool res = rz_core_write_string_at(core, core->offset, p);
781  free(p);
782  return bool2status(res);
783 }
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.
Definition: cio.c:605
void * p
Definition: libc.cpp:67
RZ_API RZ_OWN char * rz_debruijn_pattern(int size, int start, const char *charset)
Generate a cyclic pattern following the Debruijn pattern.
Definition: debruijn.c:80
static int
Definition: sfsocketcall.h:114

References argv, bool2status(), free(), int, len, NULL, rz_core_t::num, rz_core_t::offset, p, RZ_CMD_STATUS_ERROR, rz_core_write_string_at(), rz_debruijn_pattern(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_duplicate_handler()

RZ_IPI RzCmdStatus rz_write_duplicate_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 543 of file cmd_write.c.

543  {
544  ut64 src = rz_num_math(core->num, argv[1]);
545  int len = (int)rz_num_math(core->num, argv[2]);
546  if (len < 0) {
547  RZ_LOG_ERROR("Negative length is not valid.\n");
548  return RZ_CMD_STATUS_ERROR;
549  }
550  return bool2status(rz_core_write_duplicate_at(core, core->offset, src, len));
551 }
RZ_API bool rz_core_write_duplicate_at(RzCore *core, ut64 addr, ut64 from, int len)
Copy len bytes from from to addr.
Definition: cio.c:1106

References argv, bool2status(), int, len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_write_duplicate_at(), RZ_LOG_ERROR, rz_num_math(), src, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_extend_hexbytes_handler()

RZ_IPI RzCmdStatus rz_write_extend_hexbytes_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 642 of file cmd_write.c.

642  {
643  ut8 *bytes = RZ_NEWS(ut8, (strlen(argv[1]) + 1) / 2);
644  if (!bytes) {
645  return RZ_CMD_STATUS_ERROR;
646  }
647 
648  int len = rz_hex_str2bin(argv[1], bytes);
649  if (len <= 0) {
650  RZ_LOG_ERROR("Cannot convert '%s' to bytes values.\n", argv[1]);
651  free(bytes);
652  return RZ_CMD_STATUS_ERROR;
653  }
654 
655  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : core->offset;
656  bool res = rz_core_extend_at(core, addr, len);
657  if (!res) {
658  RZ_LOG_ERROR("Cannot extend the file.\n");
659  free(bytes);
660  return RZ_CMD_STATUS_ERROR;
661  }
662  bool result = rz_core_write_at(core, addr, bytes, len);
663  free(bytes);
664  return bool2status(result);
665 }
static ut8 bytes[32]
Definition: asm_arc.c:23
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.
Definition: cio.c:172
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
static int addr
Definition: z80asm.c:58

References addr, argv, bool2status(), bytes, free(), len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_extend_at(), rz_core_write_at(), rz_hex_str2bin(), RZ_LOG_ERROR, RZ_NEWS, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_extend_shift_handler()

RZ_IPI RzCmdStatus rz_write_extend_shift_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 632 of file cmd_write.c.

632  {
633  ut64 dist = rz_num_math(core->num, argv[1]);
634  ut64 block_size = argc > 2 ? rz_num_math(core->num, argv[2]) : 0;
635  if (dist == 0) {
636  RZ_LOG_ERROR("Cannot use '%s' as a distance.\n", argv[1]);
637  return RZ_CMD_STATUS_ERROR;
638  }
639  return bool2status(rz_core_shift_block(core, core->offset, block_size, dist));
640 }
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.
Definition: cio.c:197

References argv, bool2status(), rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_shift_block(), RZ_LOG_ERROR, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_extend_zero_handler()

RZ_IPI RzCmdStatus rz_write_extend_zero_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 626 of file cmd_write.c.

626  {
627  ut64 len = rz_num_math(core->num, argv[1]);
628  ut64 addr = argc > 2 ? rz_num_math(core->num, argv[2]) : core->offset;
629  return bool2status(rz_core_extend_at(core, addr, len));
630 }

References addr, argv, bool2status(), len, rz_core_t::num, rz_core_t::offset, rz_core_extend_at(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_from_file_handler()

RZ_IPI RzCmdStatus rz_write_from_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 194 of file cmd_write.c.

194  {
195  int wseek = rz_config_get_i(core->config, "cfg.wseek");
196  ut64 user_size = argc > 2 ? rz_num_math(core->num, argv[2]) : UT64_MAX;
197  ut64 offset = argc > 3 ? rz_num_math(core->num, argv[3]) : 0;
198  const char *filename = argv[1];
199 
201  char *data = NULL;
202  size_t size, w_size;
203  if (!strcmp(filename, "-")) {
204  data = rz_core_editor(core, NULL, NULL);
205  if (!data) {
206  eprintf("No data from editor\n");
207  return RZ_CMD_STATUS_ERROR;
208  }
209  size = strlen(data);
210  } else {
211  data = rz_file_slurp(filename, &size);
212  if (!data) {
213  eprintf("Cannot open file '%s'\n", filename);
214  return RZ_CMD_STATUS_ERROR;
215  }
216  }
217 
218  w_size = RZ_MIN(size, user_size);
219  if (offset > size) {
220  eprintf("Invalid offset provided\n");
221  goto err;
222  }
223  if (UT64_ADD_OVFCHK(offset, w_size) || offset + w_size > size) {
224  eprintf("Invalid offset/size provided\n");
225  goto err;
226  }
227 
228  rz_io_use_fd(core->io, core->file->fd);
229  if (!rz_io_write_at(core->io, core->offset, (ut8 *)data + offset, w_size)) {
230  eprintf("rz_io_write_at failed at 0x%08" PFMT64x "\n", core->offset);
231  goto err;
232  }
233  WSEEK(core, w_size);
234  rz_core_block_read(core);
235  res = RZ_CMD_STATUS_OK;
236 
237 err:
238  free(data);
239  return res;
240 }
static bool err
Definition: armass.c:435
#define WSEEK(x, y)
Definition: cmd_write.c:92
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
voidpf void uLong size
Definition: ioapi.h:138
const char * filename
Definition: ioapi.h:137
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
enum rz_cmd_status_t RzCmdStatus
RZ_API bool rz_io_use_fd(RzIO *io, int fd)
Definition: io_fd.c:118
#define RZ_MIN(x, y)
#define UT64_ADD_OVFCHK(x, y)
RzCoreFile * file
Definition: rz_core.h:314

References argv, rz_core_t::config, eprintf, err, rz_core_file_t::fd, rz_core_t::file, free(), rz_core_t::io, NULL, rz_core_t::num, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_core_block_read(), rz_core_editor(), rz_file_slurp(), rz_io_use_fd(), rz_io_write_at(), RZ_MIN, rz_num_math(), ut64(), UT64_ADD_OVFCHK, UT64_MAX, and WSEEK.

Referenced by rzshell_cmddescs_init().

◆ rz_write_from_io_handler()

RZ_IPI RzCmdStatus rz_write_from_io_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 155 of file cmd_write.c.

155  {
156  ut64 addr = rz_num_math(core->num, argv[1]);
157  ut64 len = rz_num_math(core->num, argv[2]);
158  bool res = ioMemcpy(core, core->offset, addr, len);
159  return res ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
160 }
static bool ioMemcpy(RzCore *core, ut64 dst, ut64 src, int len)
Definition: cmd_write.c:134

References addr, argv, ioMemcpy(), len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_from_io_xchg_handler()

RZ_IPI RzCmdStatus rz_write_from_io_xchg_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 162 of file cmd_write.c.

162  {
163  ut64 dst = core->offset;
164  ut64 src = rz_num_math(core->num, argv[1]);
165  ut64 len = rz_num_math(core->num, argv[2]);
166  if (len < 0) {
167  return RZ_CMD_STATUS_ERROR;
168  }
169 
170  ut8 *buf = RZ_NEWS0(ut8, len);
171  if (!buf) {
172  return RZ_CMD_STATUS_ERROR;
173  }
174 
176  if (!rz_io_read_at(core->io, dst, buf, len)) {
177  eprintf("cmd_wfx: failed to read at 0x%08" PFMT64x "\n", dst);
178  goto err;
179  }
180 
181  ioMemcpy(core, core->offset, src, len);
182  if (!rz_io_write_at(core->io, src, buf, len)) {
183  eprintf("Failed to write at 0x%08" PFMT64x "\n", src);
184  goto err;
185  }
186 
187  rz_core_block_read(core);
188  res = RZ_CMD_STATUS_OK;
189 err:
190  free(buf);
191  return res;
192 }

References argv, dst, eprintf, err, free(), rz_core_t::io, ioMemcpy(), len, rz_core_t::num, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_block_read(), rz_io_read_at(), rz_io_write_at(), RZ_NEWS0, rz_num_math(), src, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_from_socket_handler()

RZ_IPI RzCmdStatus rz_write_from_socket_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 242 of file cmd_write.c.

242  {
244  char *address = strdup(argv[1]);
245  ut64 sz = argc > 2 ? rz_num_math(core->num, argv[2]) : core->blocksize;
246 
247  size_t n_split = rz_str_split(address, ':');
248  if (n_split != 2) {
249  eprintf("Wrong format for <host:port>\n");
250  goto err;
251  }
252  char *host = address;
253  char *port = host + strlen(host) + 1;
254 
255  ut8 *buf = RZ_NEWS0(ut8, sz);
256  if (!buf) {
257  goto err;
258  }
259 
260  RzSocket *s = rz_socket_new(false);
261  if (!rz_socket_listen(s, port, NULL)) {
262  eprintf("Cannot listen on port %s\n", port);
263  goto socket_err;
264  }
265  int done = 0;
267  if (!c) {
268  eprintf("Failing to accept socket\n");
269  goto socket_err;
270  }
271 
272  eprintf("Receiving data from client...\n");
273  while (done < sz) {
274  int rc = rz_socket_read(c, buf + done, sz - done);
275  if (rc < 0) {
276  eprintf("Failing to read data from socket: %d\n", rc);
277  goto socket_err;
278  } else if (rc == 0) {
279  break;
280  }
281  done += rc;
282  }
283  if (!rz_io_write_at(core->io, core->offset, buf, done)) {
284  eprintf("Cannot write\n");
285  goto socket_err;
286  }
287  eprintf("Written %d bytes\n", done);
288  res = RZ_CMD_STATUS_OK;
289 
290 socket_err:
291  rz_socket_free(s);
292 err:
293  free(address);
294  return res;
295 }
struct tab * done
Definition: enough.c:233
static RzSocket * s
Definition: rtr.c:28
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
Definition: socket.c:582
RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile)
Definition: socket.c:474
RZ_API void RZ_API int rz_socket_read(RzSocket *s, ut8 *read, int len)
Definition: socket.c:783
RZ_API RzSocket * rz_socket_new(bool is_ssl)
Definition: socket.c:179
RZ_API int rz_socket_free(RzSocket *s)
Definition: socket.c:453
RZ_API size_t rz_str_split(char *str, char ch)
Split string str in place by using ch as a delimiter.
Definition: str.c:406
#define c(i)
Definition: sha256.c:43

References argv, rz_core_t::blocksize, c, done, eprintf, err, free(), rz_core_t::io, NULL, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_io_write_at(), RZ_NEWS0, rz_num_math(), rz_socket_accept(), rz_socket_free(), rz_socket_listen(), rz_socket_new(), rz_socket_read(), rz_str_split(), s, strdup(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_handler()

RZ_IPI RzCmdStatus rz_write_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 431 of file cmd_write.c.

431  {
432  return bool2status(rz_core_write_string_at(core, core->offset, argv[1]));
433 }

References argv, bool2status(), rz_core_t::offset, and rz_core_write_string_at().

Referenced by rzshell_cmddescs_init().

◆ rz_write_hex_from_file_handler()

RZ_IPI RzCmdStatus rz_write_hex_from_file_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 447 of file cmd_write.c.

447  {
448  char *buf;
449  if (!strcmp(argv[1], "-")) {
450  buf = rz_core_editor(core, NULL, NULL);
451  if (!buf) {
452  RZ_LOG_ERROR("Could not get anything from editor\n");
453  return RZ_CMD_STATUS_ERROR;
454  }
455  } else {
456  if (!rz_file_exists(argv[1])) {
457  RZ_LOG_ERROR("File '%s' does not exist\n", argv[1]);
458  return RZ_CMD_STATUS_ERROR;
459  }
460 
461  buf = rz_file_slurp(argv[1], NULL);
462  if (!buf) {
463  RZ_LOG_ERROR("Cannot open file '%s'\n", argv[1]);
464  return RZ_CMD_STATUS_ERROR;
465  }
466  }
467 
468  int res = rz_core_write_hexpair(core, core->offset, buf);
469  free(buf);
470  if (res < 0) {
471  RZ_LOG_ERROR("Could not write hexpairs to 0x%" PFMT64x "\n", core->offset);
472  return RZ_CMD_STATUS_ERROR;
473  }
474  return RZ_CMD_STATUS_OK;
475 }
RZ_API int rz_core_write_hexpair(RzCore *core, ut64 addr, const char *pairs)
Definition: cio.c:268
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192

References argv, free(), NULL, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_editor(), rz_core_write_hexpair(), rz_file_exists(), rz_file_slurp(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_write_hex_handler()

RZ_IPI RzCmdStatus rz_write_hex_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 443 of file cmd_write.c.

443  {
444  return rz_core_write_hexpair(core, core->offset, argv[1]) > 0 ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
445 }

References argv, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_write_hexpair().

Referenced by rzshell_cmddescs_init().

◆ rz_write_length_string_handler()

RZ_IPI RzCmdStatus rz_write_length_string_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 553 of file cmd_write.c.

553  {
555 }
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.
Definition: cio.c:673

References argv, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and rz_core_write_length_string_at().

Referenced by rzshell_cmddescs_init().

◆ rz_write_mask_reset_handler()

RZ_IPI RzCmdStatus rz_write_mask_reset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 539 of file cmd_write.c.

539  {
540  return bool2status(rz_io_set_write_mask(core->io, NULL, 0));
541 }
RZ_API bool rz_io_set_write_mask(RzIO *io, const ut8 *mask, int len)
Set a mask that is used on all following write operations.
Definition: io.c:517

References bool2status(), rz_core_t::io, NULL, and rz_io_set_write_mask().

Referenced by rzshell_cmddescs_init().

◆ rz_write_mask_set_handler()

RZ_IPI RzCmdStatus rz_write_mask_set_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 528 of file cmd_write.c.

528  {
529  ut8 *buf = RZ_NEWS(ut8, strlen(argv[1]) / 2);
530  if (!buf) {
531  return RZ_CMD_STATUS_ERROR;
532  }
533  int size = rz_hex_str2bin(argv[1], buf);
534  bool result = rz_io_set_write_mask(core->io, buf, size);
535  free(buf);
536  return bool2status(result);
537 }

References argv, bool2status(), free(), rz_core_t::io, RZ_CMD_STATUS_ERROR, rz_hex_str2bin(), rz_io_set_write_mask(), and RZ_NEWS.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_2byteswap_handler()

RZ_IPI RzCmdStatus rz_write_op_2byteswap_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 667 of file cmd_write.c.

667  {
669 }
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.
Definition: cio.c:1038
@ RZ_CORE_WRITE_OP_BYTESWAP2
Swap the endianess of 2-bytes values.
Definition: rz_core.h:106

References bool2status(), NULL, rz_core_t::offset, rz_core_write_block_op_at(), and RZ_CORE_WRITE_OP_BYTESWAP2.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_4byteswap_handler()

RZ_IPI RzCmdStatus rz_write_op_4byteswap_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 671 of file cmd_write.c.

671  {
673 }
@ RZ_CORE_WRITE_OP_BYTESWAP4
Swap the endianess of 4-bytes values.
Definition: rz_core.h:107

References bool2status(), NULL, rz_core_t::offset, rz_core_write_block_op_at(), and RZ_CORE_WRITE_OP_BYTESWAP4.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_8byteswap_handler()

RZ_IPI RzCmdStatus rz_write_op_8byteswap_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 675 of file cmd_write.c.

675  {
677 }
@ RZ_CORE_WRITE_OP_BYTESWAP8
Swap the endianess of 8-bytes values.
Definition: rz_core.h:108

References bool2status(), NULL, rz_core_t::offset, rz_core_write_block_op_at(), and RZ_CORE_WRITE_OP_BYTESWAP8.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_add_handler()

RZ_IPI RzCmdStatus rz_write_op_add_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 693 of file cmd_write.c.

693  {
694  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_ADD);
695 }
static RzCmdStatus write_op_val(RzCore *core, int argc, const char **argv, RzCoreWriteOp op)
Definition: cmd_write.c:679
@ RZ_CORE_WRITE_OP_ADD
Write the addition of existing byte and argument value.
Definition: rz_core.h:109

References argv, RZ_CORE_WRITE_OP_ADD, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_and_handler()

RZ_IPI RzCmdStatus rz_write_op_and_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 713 of file cmd_write.c.

713  {
714  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_AND);
715 }
@ RZ_CORE_WRITE_OP_AND
Write the bitwise-and of existing byte and argument value.
Definition: rz_core.h:113

References argv, RZ_CORE_WRITE_OP_AND, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_decrypt_handler()

RZ_IPI RzCmdStatus rz_write_op_decrypt_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 736 of file cmd_write.c.

736  {
737  const char *algo = argv[1];
738  const char *key = argv[2];
739  const char *iv = argv[3];
740  return bool2status(encrypt_or_decrypt_block(core, algo, key, 1, iv));
741 }
static bool encrypt_or_decrypt_block(RzCore *core, const char *algo, const char *key, int direction, const char *iv)
Definition: cmd_write.c:17

References argv, bool2status(), encrypt_or_decrypt_block(), and key.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_div_handler()

RZ_IPI RzCmdStatus rz_write_op_div_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 705 of file cmd_write.c.

705  {
706  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_DIV);
707 }
@ RZ_CORE_WRITE_OP_DIV
Write the division of existing byte and argument value.
Definition: rz_core.h:111

References argv, RZ_CORE_WRITE_OP_DIV, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_encrypt_handler()

RZ_IPI RzCmdStatus rz_write_op_encrypt_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 729 of file cmd_write.c.

729  {
730  const char *algo = argv[1];
731  const char *key = argv[2];
732  const char *iv = argv[3];
733  return bool2status(encrypt_or_decrypt_block(core, algo, key, 0, iv));
734 }

References argv, bool2status(), encrypt_or_decrypt_block(), and key.

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_mul_handler()

RZ_IPI RzCmdStatus rz_write_op_mul_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 701 of file cmd_write.c.

701  {
702  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_MUL);
703 }
@ RZ_CORE_WRITE_OP_MUL
Write the multiplication of existing byte and argument value.
Definition: rz_core.h:112

References argv, RZ_CORE_WRITE_OP_MUL, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_or_handler()

RZ_IPI RzCmdStatus rz_write_op_or_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 717 of file cmd_write.c.

717  {
718  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_OR);
719 }
@ RZ_CORE_WRITE_OP_OR
Write the bitwise-or of existing byte and argument value.
Definition: rz_core.h:114

References argv, RZ_CORE_WRITE_OP_OR, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_sequence_handler()

RZ_IPI RzCmdStatus rz_write_op_sequence_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 743 of file cmd_write.c.

743  {
744  ut64 from = rz_num_math(NULL, argv[1]);
745  ut64 to = rz_num_math(NULL, argv[2]);
746  ut64 step = rz_num_math(NULL, argv[3]);
747  int value_size = (int)rz_num_math(NULL, argv[4]);
748  if (step < 1) {
749  RZ_LOG_ERROR("Invalid <step> value: %" PFMT64d "\n", step);
750  return RZ_CMD_STATUS_ERROR;
751  }
752  if (value_size != 1 && value_size != 2 && value_size != 4 && value_size != 8) {
753  RZ_LOG_ERROR("Invalid <value_size> value: %d\n", value_size);
754  return RZ_CMD_STATUS_ERROR;
755  }
756  ut64 max_val = (1ULL << (8 * value_size));
757  if (from >= max_val) {
758  RZ_LOG_ERROR("Invalid <from> value: %" PFMT64d "\n", from);
759  return RZ_CMD_STATUS_ERROR;
760  }
761  if (to >= max_val) {
762  RZ_LOG_ERROR("Invalid <to> value: %" PFMT64d "\n", to);
763  return RZ_CMD_STATUS_ERROR;
764  }
765 
766  return bool2status(rz_core_write_seq_at(core, core->offset, from, to, step, value_size));
767 }
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.
Definition: cio.c:1069
static states step(struct re_guts *, sopno, sopno, states, int, states)
Definition: engine.c:888
#define PFMT64d
Definition: rz_types.h:394

References argv, bool2status(), from, int, NULL, rz_core_t::offset, PFMT64d, RZ_CMD_STATUS_ERROR, rz_core_write_seq_at(), RZ_LOG_ERROR, rz_num_math(), step(), to, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_shl_handler()

RZ_IPI RzCmdStatus rz_write_op_shl_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 721 of file cmd_write.c.

721  {
722  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_SHIFT_LEFT);
723 }
@ RZ_CORE_WRITE_OP_SHIFT_LEFT
Write the shift left of existing byte by argument value.
Definition: rz_core.h:116

References argv, RZ_CORE_WRITE_OP_SHIFT_LEFT, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_shr_handler()

RZ_IPI RzCmdStatus rz_write_op_shr_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 725 of file cmd_write.c.

725  {
726  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_SHIFT_RIGHT);
727 }
@ RZ_CORE_WRITE_OP_SHIFT_RIGHT
Write the shift right of existing byte and argument value.
Definition: rz_core.h:117

References argv, RZ_CORE_WRITE_OP_SHIFT_RIGHT, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_sub_handler()

RZ_IPI RzCmdStatus rz_write_op_sub_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 697 of file cmd_write.c.

697  {
698  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_SUB);
699 }
@ RZ_CORE_WRITE_OP_SUB
Write the subtraction of existing byte and argument value.
Definition: rz_core.h:110

References argv, RZ_CORE_WRITE_OP_SUB, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_op_xor_handler()

RZ_IPI RzCmdStatus rz_write_op_xor_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 709 of file cmd_write.c.

709  {
710  return write_op_val(core, argc, argv, RZ_CORE_WRITE_OP_XOR);
711 }
@ RZ_CORE_WRITE_OP_XOR
Write the bitwise-xor of existing byte and argument value.
Definition: rz_core.h:115

References argv, RZ_CORE_WRITE_OP_XOR, and write_op_val().

Referenced by rzshell_cmddescs_init().

◆ rz_write_pcache_commit_handler()

RZ_IPI RzCmdStatus rz_write_pcache_commit_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 607 of file cmd_write.c.

607  {
608  RzIODesc *desc = NULL;
609  if (argc > 1) {
610  int fd = (int)rz_num_math(core->num, argv[1]);
611  if (fd < 0) {
612  RZ_LOG_ERROR("Invalid fd argument %d.\n", fd);
613  return RZ_CMD_STATUS_ERROR;
614  }
615  desc = rz_io_desc_get(core->io, fd);
616  } else {
617  desc = core->io->desc;
618  }
619  if (!desc) {
620  RZ_LOG_ERROR("Cannot retrieve valid file.\n");
621  return RZ_CMD_STATUS_ERROR;
622  }
624 }
const char * desc
Definition: bin_vsf.c:19
RZ_API bool rz_io_desc_cache_commit(RzIODesc *desc)
Definition: p_cache.c:302
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
Definition: io_desc.c:73
struct rz_io_desc_t * desc
Definition: rz_io.h:60
static const z80_opcode fd[]
Definition: z80_tab.h:997

References argv, bool2status(), desc, rz_io_t::desc, fd, int, rz_core_t::io, NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_io_desc_cache_commit(), rz_io_desc_get(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_pcache_list_handler()

RZ_IPI RzCmdStatus rz_write_pcache_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 588 of file cmd_write.c.

588  {
589  RzIODesc *desc = NULL;
590  if (argc > 1) {
591  int fd = (int)rz_num_math(core->num, argv[1]);
592  if (fd < 0) {
593  RZ_LOG_ERROR("Invalid fd argument %d.\n", fd);
594  return RZ_CMD_STATUS_ERROR;
595  }
596  desc = rz_io_desc_get(core->io, fd);
597  } else {
598  desc = core->io->desc;
599  }
600  if (!desc) {
601  RZ_LOG_ERROR("Cannot retrieve valid file.\n");
602  return RZ_CMD_STATUS_ERROR;
603  }
604  return rz_core_io_pcache_print(core, desc, state);
605 }
RZ_API RzCmdStatus rz_core_io_pcache_print(RzCore *core, RzIODesc *desc, RzCmdStateOutput *state)
Definition: cio.c:854

References argv, desc, rz_io_t::desc, fd, int, rz_core_t::io, NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_io_pcache_print(), rz_io_desc_get(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_random_handler()

RZ_IPI RzCmdStatus rz_write_random_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 422 of file cmd_write.c.

422  {
423  if (!rz_num_is_valid_input(core->num, argv[1])) {
424  RZ_LOG_ERROR("Invalid length '%s'\n", argv[1]);
425  return RZ_CMD_STATUS_ERROR;
426  }
427  size_t length = rz_num_math(core->num, argv[1]);
429 }
RZ_API bool rz_core_write_random_at(RzCore *core, ut64 addr, size_t len)
Write len random bytes at address addr.
Definition: cio.c:773
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 static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
RZ_API int rz_num_is_valid_input(RzNum *num, const char *input_value)
Definition: unum.c:676

References argv, length, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_random_at(), RZ_LOG_ERROR, rz_num_is_valid_input(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_unified_patch_handler()

RZ_IPI RzCmdStatus rz_write_unified_patch_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 358 of file cmd_write.c.

358  {
359  // TODO: implement it in an API RzCore.write_unified_hexpatch() is ETOOLONG
360  char *data = rz_file_slurp(argv[1], NULL);
361  if (!data) {
362  RZ_LOG_ERROR("Cannot read data from %s.\n", argv[1]);
363  return RZ_CMD_STATUS_ERROR;
364  }
365  int i;
366  char sign = ' ';
367  int line = 0, offs = 0, hexa = 0;
368  int newline = 1;
369  for (i = 0; data[i]; i++) {
370  switch (data[i]) {
371  case '+':
372  if (newline)
373  sign = 1;
374  break;
375  case '-':
376  if (newline) {
377  sign = 0;
378  offs = i + ((data[i + 1] == ' ') ? 2 : 1);
379  }
380  break;
381  case ' ':
382  data[i] = 0;
383  if (sign) {
384  if (!line)
385  line = i + 1;
386  else if (!hexa)
387  hexa = i + 1;
388  }
389  break;
390  case '\r':
391  break;
392  case '\n':
393  newline = 1;
394  if (sign == ' ') {
395  offs = 0;
396  line = 0;
397  hexa = 0;
398  } else if (sign) {
399  if (offs && hexa) {
400  ut64 dst = rz_num_math(core->num, data + offs);
401  ut8 *buf = RZ_NEWS(ut8, strlen(data + hexa));
402  if (buf) {
403  int len = rz_hex_str2bin(data + hexa, buf);
404  rz_core_write_at(core, dst, buf, len);
405  }
406  } else {
407  eprintf("food\n");
408  }
409  offs = 0;
410  line = 0;
411  } else
412  hexa = 0;
413  sign = -1;
414  continue;
415  }
416  newline = 0;
417  }
418  free(data);
419  return 0;
420 }
lzma_index ** i
Definition: index.h:629
line
Definition: setup.py:34

References argv, dst, eprintf, free(), i, len, setup::line, NULL, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_write_at(), rz_file_slurp(), rz_hex_str2bin(), RZ_LOG_ERROR, RZ_NEWS, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_unset_bits_handler()

RZ_IPI RzCmdStatus rz_write_unset_bits_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 302 of file cmd_write.c.

302  {
303  cmd_write_bits(core, 0, rz_num_math(core->num, argv[1]));
304  return RZ_CMD_STATUS_OK;
305 }

References argv, cmd_write_bits(), rz_core_t::num, RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_write_value1_handler()

RZ_IPI RzCmdStatus rz_write_value1_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 110 of file cmd_write.c.

110  {
111  return common_write_value_handler(core, argv[1], 1);
112 }
static RzCmdStatus common_write_value_handler(RzCore *core, const char *valstr, size_t sz)
Definition: cmd_write.c:96

References argv, and common_write_value_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_value2_handler()

RZ_IPI RzCmdStatus rz_write_value2_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 114 of file cmd_write.c.

114  {
115  return common_write_value_handler(core, argv[1], 2);
116 }

References argv, and common_write_value_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_value4_handler()

RZ_IPI RzCmdStatus rz_write_value4_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 118 of file cmd_write.c.

118  {
119  return common_write_value_handler(core, argv[1], 4);
120 }

References argv, and common_write_value_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_value8_handler()

RZ_IPI RzCmdStatus rz_write_value8_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 122 of file cmd_write.c.

122  {
123  return common_write_value_handler(core, argv[1], 8);
124 }

References argv, and common_write_value_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_value_handler()

RZ_IPI RzCmdStatus rz_write_value_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 106 of file cmd_write.c.

106  {
107  return common_write_value_handler(core, argv[1], 0);
108 }

References argv, and common_write_value_handler().

Referenced by rzshell_cmddescs_init().

◆ rz_write_wide_string_handler()

RZ_IPI RzCmdStatus rz_write_wide_string_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 439 of file cmd_write.c.

439  {
440  return bool2status(rz_core_write_string_wide_at(core, core->offset, argv[1]));
441 }
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.
Definition: cio.c:630

References argv, bool2status(), rz_core_t::offset, and rz_core_write_string_wide_at().

Referenced by rzshell_cmddescs_init().

◆ rz_write_zero_handler()

RZ_IPI RzCmdStatus rz_write_zero_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 307 of file cmd_write.c.

307  {
308  ut64 len = rz_num_math(core->num, argv[1]);
309  ut8 *buf = RZ_NEWS0(ut8, len);
310  if (!buf) {
311  RZ_LOG_ERROR("Cannot allocate %" PFMT64d " bytes", len);
312  return RZ_CMD_STATUS_ERROR;
313  }
314 
315  bool res = rz_core_write_at(core, core->offset, buf, len);
316  free(buf);
317 
318  return res ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
319 }

References argv, free(), len, rz_core_t::num, rz_core_t::offset, PFMT64d, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_at(), RZ_LOG_ERROR, RZ_NEWS0, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_write_zero_string_handler()

RZ_IPI RzCmdStatus rz_write_zero_string_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 435 of file cmd_write.c.

435  {
436  return bool2status(rz_core_write_string_zero_at(core, core->offset, argv[1]));
437 }
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.
Definition: cio.c:905

References argv, bool2status(), rz_core_t::offset, and rz_core_write_string_zero_at().

Referenced by rzshell_cmddescs_init().

◆ w_incdec_handler()

static RzCmdStatus w_incdec_handler ( RzCore core,
int  argc,
const char **  argv,
int  inc_size 
)
static

Definition at line 321 of file cmd_write.c.

321  {
322  st64 num = argc > 1 ? rz_num_math(core->num, argv[1]) : 1;
323  const char *command = argv[0];
324  if (command[strlen(command) - 1] == '-') {
325  num *= -1;
326  }
327  return rz_core_write_value_inc_at(core, core->offset, num, inc_size) ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
328 }
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.
Definition: cio.c:551
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 static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
#define st64
Definition: rz_types_base.h:10
const char * command
Definition: main.c:7

References argv, command, rz_core_t::num, num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_write_value_inc_at(), rz_num_math(), and st64.

Referenced by rz_write_1_dec_handler(), rz_write_1_inc_handler(), rz_write_2_dec_handler(), rz_write_2_inc_handler(), rz_write_4_dec_handler(), rz_write_4_inc_handler(), rz_write_8_dec_handler(), and rz_write_8_inc_handler().

◆ write_op_val()

static RzCmdStatus write_op_val ( RzCore core,
int  argc,
const char **  argv,
RzCoreWriteOp  op 
)
static

Definition at line 679 of file cmd_write.c.

679  {
681 
682  ut8 *hex = RZ_NEWS(ut8, (strlen(argv[1]) + 1) / 2);
683  if (!hex) {
684  return RZ_CMD_STATUS_ERROR;
685  }
686 
687  int hexlen = rz_hex_str2bin(argv[1], hex);
688  RzCmdStatus res = bool2status(rz_core_write_block_op_at(core, core->offset, op, hex, hexlen));
689  free(hex);
690  return res;
691 }
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
Definition: dis.c:32

References argv, bool2status(), free(), hex, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_WRONG_ARGS, rz_core_write_block_op_at(), rz_hex_str2bin(), RZ_NEWS, and rz_return_val_if_fail.

Referenced by rz_write_op_add_handler(), rz_write_op_and_handler(), rz_write_op_div_handler(), rz_write_op_mul_handler(), rz_write_op_or_handler(), rz_write_op_shl_handler(), rz_write_op_shr_handler(), rz_write_op_sub_handler(), and rz_write_op_xor_handler().