Rizin
unix-like reverse engineering framework and cli tools
cmd_yank.c File Reference
#include <string.h>
#include <rz_core.h>
#include "../core_private.h"

Go to the source code of this file.

Functions

RZ_IPI RzCmdStatus rz_yank_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_yank_editor_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_whole_file_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_print_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_string_print_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_hex_print_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_string_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_to_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_hexpairs_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_yank_paste_handler (RzCore *core, int argc, const char **argv)
 

Function Documentation

◆ rz_yank_editor_handler()

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

Definition at line 22 of file cmd_yank.c.

22  {
23  char *src = rz_core_yank_as_string(core, 0);
24  if (!src) {
25  return RZ_CMD_STATUS_ERROR;
26  }
27  char *new = rz_core_editor(core, NULL, src);
28  if (!new) {
29  free(src);
30  return RZ_CMD_STATUS_ERROR;
31  }
32  if (!rz_core_yank_hexpair(core, src)) {
33  free(src);
34  free(new);
35  return RZ_CMD_STATUS_ERROR;
36  }
37  free(src);
38  free(new);
39  return RZ_CMD_STATUS_OK;
40 }
lzma_index * src
Definition: index.h:567
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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
@ 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 bool rz_core_yank_hexpair(RzCore *core, const char *str)
Definition: yank.c:362
RZ_API RZ_OWN char * rz_core_yank_as_string(RzCore *core, ut64 pos)
Definition: yank.c:203

References free(), NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_editor(), rz_core_yank_as_string(), rz_core_yank_hexpair(), and src.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_file_handler()

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

Definition at line 42 of file cmd_yank.c.

42  {
43  st64 len = rz_num_math(core->num, argv[1]);
44  if (len < 0) {
45  RZ_LOG_ERROR("Yank length cannot be negative");
46  return RZ_CMD_STATUS_ERROR;
47  }
48  return rz_core_yank_file(core, len, core->offset, argv[2]);
49 }
size_t len
Definition: 6502dis.c:15
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#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
#define st64
Definition: rz_types_base.h:10
ut64 offset
Definition: rz_core.h:301
RzNum * num
Definition: rz_core.h:316
RZ_API bool rz_core_yank_file(RzCore *core, ut64 len, ut64 addr, const char *filename)
Definition: yank.c:384

References argv, len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_yank_file(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_handler()

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

Definition at line 8 of file cmd_yank.c.

8  {
9  if (argc > 1) {
10  st64 len = rz_num_math(core->num, argv[1]);
11  if (len < 0) {
12  RZ_LOG_ERROR("Yank length cannot be negative");
13  return RZ_CMD_STATUS_ERROR;
14  }
15  rz_core_yank(core, core->offset, len);
16  } else {
17  rz_core_yank_dump(core, 0, state);
18  }
19  return RZ_CMD_STATUS_OK;
20 }
Definition: dis.h:43
RZ_API bool rz_core_yank(RzCore *core, ut64 addr, ut64 len)
Definition: yank.c:118
RZ_API bool rz_core_yank_dump(RzCore *core, ut64 pos, RzCmdStateOutput *state)
Definition: yank.c:219

References argv, len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_yank(), rz_core_yank_dump(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_hex_print_handler()

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

Definition at line 73 of file cmd_yank.c.

73  {
74  st64 len = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
75  if (len < 0) {
76  RZ_LOG_ERROR("Yank length cannot be negative");
77  return RZ_CMD_STATUS_ERROR;
78  }
80 }
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
RZ_API bool rz_core_yank_print_hexdump(RzCore *core, ut64 pos)
Definition: yank.c:267

References argv, bool2status(), len, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_yank_print_hexdump(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_hexpairs_handler()

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

Definition at line 101 of file cmd_yank.c.

101  {
102  return bool2status(rz_core_yank_hexpair(core, argv[1]));
103 }

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

Referenced by rzshell_cmddescs_init().

◆ rz_yank_paste_handler()

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

Definition at line 105 of file cmd_yank.c.

105  {
106  st64 len = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
107  if (len < 0) {
108  RZ_LOG_ERROR("Yank length cannot be negative");
109  return RZ_CMD_STATUS_ERROR;
110  }
111  return bool2status(rz_core_yank_paste(core, core->offset, len));
112 }
RZ_API bool rz_core_yank_paste(RzCore *core, ut64 addr, ut64 len)
Definition: yank.c:174

References argv, bool2status(), len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_yank_paste(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_print_handler()

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

Definition at line 55 of file cmd_yank.c.

55  {
56  st64 len = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
57  if (len < 0) {
58  RZ_LOG_ERROR("Yank length cannot be negative");
59  return RZ_CMD_STATUS_ERROR;
60  }
61  return bool2status(rz_core_yank_print(core, len));
62 }
RZ_API bool rz_core_yank_print(RzCore *core, ut64 pos)
Definition: yank.c:288

References argv, bool2status(), len, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_yank_print(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_string_handler()

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

Definition at line 82 of file cmd_yank.c.

82  {
83  st64 len = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
84  if (len < 0) {
85  RZ_LOG_ERROR("Yank length cannot be negative");
86  return RZ_CMD_STATUS_ERROR;
87  }
88  return bool2status(rz_core_yank_string(core, core->offset, len));
89 }
RZ_API bool rz_core_yank_string(RzCore *core, ut64 addr, ut64 maxlen)
Definition: yank.c:147

References argv, bool2status(), len, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, rz_core_yank_string(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_string_print_handler()

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

Definition at line 64 of file cmd_yank.c.

64  {
65  st64 len = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
66  if (len < 0) {
67  RZ_LOG_ERROR("Yank length cannot be negative");
68  return RZ_CMD_STATUS_ERROR;
69  }
71 }
RZ_API bool rz_core_yank_print_string(RzCore *core, ut64 pos)
Definition: yank.c:311

References argv, bool2status(), len, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_yank_print_string(), RZ_LOG_ERROR, rz_num_math(), and st64.

Referenced by rzshell_cmddescs_init().

◆ rz_yank_to_handler()

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

Definition at line 91 of file cmd_yank.c.

91  {
92  st64 len = rz_num_math(core->num, argv[1]);
93  if (len < 0) {
94  RZ_LOG_ERROR("Yank length cannot be negative");
95  return RZ_CMD_STATUS_ERROR;
96  }
97  ut64 addr = rz_num_math(core->num, argv[2]);
98  return bool2status(rz_core_yank_to(core, len, addr));
99 }
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
RZ_API bool rz_core_yank_to(RzCore *core, ut64 len, ut64 addr)
Definition: yank.c:193
static int addr
Definition: z80asm.c:58

References addr, argv, bool2status(), len, rz_core_t::num, RZ_CMD_STATUS_ERROR, rz_core_yank_to(), RZ_LOG_ERROR, rz_num_math(), st64, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_yank_whole_file_handler()

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

Definition at line 51 of file cmd_yank.c.

51  {
52  return rz_core_yank_file_all(core, argv[1]);
53 }
RZ_API bool rz_core_yank_file_all(RzCore *core, const char *filename)
Definition: yank.c:398

References argv, and rz_core_yank_file_all().

Referenced by rzshell_cmddescs_init().