Rizin
unix-like reverse engineering framework and cli tools
cmd_block.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 <rz_core.h>
5 
7  if (argc > 1) {
8  ut64 newsize = rz_num_math(core->num, argv[1]);
9  rz_core_block_size(core, newsize);
10  } else {
11  switch (state->mode) {
12  case RZ_OUTPUT_MODE_JSON: {
13  PJ *pj = state->d.pj;
14  pj_o(pj);
15  pj_ki(pj, "blocksize", core->blocksize);
16  pj_ki(pj, "blocksize_limit", core->blocksize_max);
17  pj_end(pj);
18  break;
19  }
21  rz_cons_printf("b 0x%x\n", core->blocksize);
22  break;
24  rz_cons_printf("0x%x\n", core->blocksize);
25  break;
26  default:
28  break;
29  }
30  }
31  return RZ_CMD_STATUS_OK;
32 }
33 
34 RZ_IPI RzCmdStatus rz_block_decrease_handler(RzCore *core, int argc, const char **argv) {
35  ut64 n = rz_num_math(core->num, argv[1]);
36  rz_core_block_size(core, core->blocksize - n);
37  return RZ_CMD_STATUS_OK;
38 }
39 
40 RZ_IPI RzCmdStatus rz_block_increase_handler(RzCore *core, int argc, const char **argv) {
41  ut64 n = rz_num_math(core->num, argv[1]);
42  rz_core_block_size(core, core->blocksize + n);
43  return RZ_CMD_STATUS_OK;
44 }
45 
46 RZ_IPI RzCmdStatus rz_block_flag_handler(RzCore *core, int argc, const char **argv) {
47  RzFlagItem *flag = rz_flag_get(core->flags, argv[1]);
48  if (!flag) {
49  RZ_LOG_ERROR("Cannot find flag named \"%s\"", argv[1]);
50  return RZ_CMD_STATUS_ERROR;
51  }
52  rz_core_block_size(core, flag->size);
53  return RZ_CMD_STATUS_OK;
54 }
55 
56 RZ_IPI RzCmdStatus rz_block_max_handler(RzCore *core, int argc, const char **argv) {
57  if (argc > 1) {
58  ut64 n = rz_num_math(core->num, argv[1]);
59  core->blocksize_max = n;
60  } else {
61  rz_cons_printf("0x%x\n", core->blocksize_max);
62  }
63  return RZ_CMD_STATUS_OK;
64 }
#define RZ_IPI
Definition: analysis_wasm.c:11
RZ_IPI RzCmdStatus rz_block_max_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_block.c:56
RZ_IPI RzCmdStatus rz_block_increase_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_block.c:40
RZ_IPI RzCmdStatus rz_block_flag_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_block.c:46
RZ_IPI RzCmdStatus rz_block_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
Definition: cmd_block.c:6
RZ_IPI RzCmdStatus rz_block_decrease_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_block.c:34
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int n
Definition: mipsasm.c:19
#define rz_warn_if_reached()
Definition: rz_assert.h:29
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
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
@ 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
Definition: rz_pj.h:12
Represent the output state of a command handler.
Definition: rz_cmd.h:91
ut32 blocksize_max
Definition: rz_core.h:304
RzNum * num
Definition: rz_core.h:316
RzFlag * flags
Definition: rz_core.h:330
ut32 blocksize
Definition: rz_core.h:303
Definition: dis.h:43
ut64(WINAPI *w32_GetEnabledXStateFeatures)()