Rizin
unix-like reverse engineering framework and cli tools
cmd_yank.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Anton Kochkov <anton.kochkov@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <string.h>
5 #include <rz_core.h>
6 #include "../core_private.h"
7 
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 }
21 
22 RZ_IPI RzCmdStatus rz_yank_editor_handler(RzCore *core, int argc, const char **argv) {
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 }
41 
42 RZ_IPI RzCmdStatus rz_yank_file_handler(RzCore *core, int argc, const char **argv) {
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 }
50 
51 RZ_IPI RzCmdStatus rz_yank_whole_file_handler(RzCore *core, int argc, const char **argv) {
52  return rz_core_yank_file_all(core, argv[1]);
53 }
54 
55 RZ_IPI RzCmdStatus rz_yank_print_handler(RzCore *core, int argc, const char **argv) {
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 }
63 
64 RZ_IPI RzCmdStatus rz_yank_string_print_handler(RzCore *core, int argc, const char **argv) {
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 }
72 
73 RZ_IPI RzCmdStatus rz_yank_hex_print_handler(RzCore *core, int argc, const char **argv) {
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 }
81 
82 RZ_IPI RzCmdStatus rz_yank_string_handler(RzCore *core, int argc, const char **argv) {
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 }
90 
91 RZ_IPI RzCmdStatus rz_yank_to_handler(RzCore *core, int argc, const char **argv) {
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 }
100 
101 RZ_IPI RzCmdStatus rz_yank_hexpairs_handler(RzCore *core, int argc, const char **argv) {
102  return bool2status(rz_core_yank_hexpair(core, argv[1]));
103 }
104 
105 RZ_IPI RzCmdStatus rz_yank_paste_handler(RzCore *core, int argc, const char **argv) {
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 }
size_t len
Definition: 6502dis.c:15
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index * src
Definition: index.h:567
RZ_IPI RzCmdStatus rz_yank_whole_file_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:51
RZ_IPI RzCmdStatus rz_yank_editor_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:22
RZ_IPI RzCmdStatus rz_yank_to_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:91
RZ_IPI RzCmdStatus rz_yank_print_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:55
RZ_IPI RzCmdStatus rz_yank_hexpairs_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:101
RZ_IPI RzCmdStatus rz_yank_file_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:42
RZ_IPI RzCmdStatus rz_yank_paste_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:105
RZ_IPI RzCmdStatus rz_yank_hex_print_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:73
RZ_IPI RzCmdStatus rz_yank_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_yank.c:8
RZ_IPI RzCmdStatus rz_yank_string_print_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:64
RZ_IPI RzCmdStatus rz_yank_string_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_yank.c:82
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208
#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
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
enum rz_cmd_status_t RzCmdStatus
@ 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
#define st64
Definition: rz_types_base.h:10
Represent the output state of a command handler.
Definition: rz_cmd.h:91
ut64 offset
Definition: rz_core.h:301
RzNum * num
Definition: rz_core.h:316
Definition: dis.h:43
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
RZ_API bool rz_core_yank_to(RzCore *core, ut64 len, ut64 addr)
Definition: yank.c:193
RZ_API bool rz_core_yank(RzCore *core, ut64 addr, ut64 len)
Definition: yank.c:118
RZ_API bool rz_core_yank_hexpair(RzCore *core, const char *str)
Definition: yank.c:362
RZ_API bool rz_core_yank_file_all(RzCore *core, const char *filename)
Definition: yank.c:398
RZ_API bool rz_core_yank_file(RzCore *core, ut64 len, ut64 addr, const char *filename)
Definition: yank.c:384
RZ_API bool rz_core_yank_string(RzCore *core, ut64 addr, ut64 maxlen)
Definition: yank.c:147
RZ_API bool rz_core_yank_print_string(RzCore *core, ut64 pos)
Definition: yank.c:311
RZ_API bool rz_core_yank_dump(RzCore *core, ut64 pos, RzCmdStateOutput *state)
Definition: yank.c:219
RZ_API bool rz_core_yank_paste(RzCore *core, ut64 addr, ut64 len)
Definition: yank.c:174
RZ_API bool rz_core_yank_print(RzCore *core, ut64 pos)
Definition: yank.c:288
RZ_API RZ_OWN char * rz_core_yank_as_string(RzCore *core, ut64 pos)
Definition: yank.c:203
RZ_API bool rz_core_yank_print_hexdump(RzCore *core, ut64 pos)
Definition: yank.c:267
static int addr
Definition: z80asm.c:58