Rizin
unix-like reverse engineering framework and cli tools
core_plugin_example.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 RizinOrg <info@rizin.re>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
30 #include <rz_types.h>
31 #include <rz_lib.h>
32 #include <rz_cmd.h>
33 #include <rz_core.h>
34 
35 #undef RZ_API
36 #define RZ_API static
37 #undef RZ_IPI
38 #define RZ_IPI static
39 
40 static const RzCmdDescArg cmd_example_args[] = {
41  {
42  .name = "number",
43  .type = RZ_CMD_ARG_TYPE_NUM,
44  },
45  { 0 },
46 };
47 
49  .summary = "example summary that contains some description",
50  .args = cmd_example_args,
51 };
52 
53 RZ_IPI RzCmdStatus rz_cmd_example_handler(RzCore *core, int argc, const char **argv) {
54  /* This is the handler on when `example [args]` is called. */
55  if (argc != 2) {
57  }
58 
59  st32 index = rz_num_math(core->num, argv[1]);
60  if (index < 1) {
61  RZ_LOG_ERROR("only positive numbers are accepted %d\n", index);
62  return RZ_CMD_STATUS_INVALID;
63  }
64 
65  RZ_LOG_WARN("the parsed number is %d\n", index);
66  return RZ_CMD_STATUS_OK;
67 }
68 
69 static bool rz_cmd_example_init(RzCore *core) {
70  /* Here you can initialize any aspect of the
71  * core plugin (like allocate memory or register
72  * the core plugin on the shell or create a socket) */
73  eprintf("This init was called!\n");
74  RzCmd *rcmd = core->rcmd;
76  if (!root_cd) {
77  return false;
78  }
79 
80  /* Here you will add your custom command and add it into the root tree. */
82  if (!cd) {
84  return false;
85  }
86 
87  return true;
88 }
89 
90 static bool rz_cmd_example_fini(RzCore *core) {
91  /* Here you can end any aspect of the core
92  * plugin (like free allocated memory, or
93  * end sockets, etc..) */
94  eprintf("This fini was called!\n");
95  return true;
96 }
97 
99  .name = "test",
100  .desc = "description of the example core plugin",
101  .license = "LGPL",
102  .author = "somebody",
103  .version = "1.0",
104  .init = rz_cmd_example_init,
105  .fini = rz_cmd_example_fini,
106 };
107 
108 #ifdef _MSC_VER
109 #define _RZ_API __declspec(dllexport)
110 #else
111 #define _RZ_API
112 #endif
113 
114 #ifndef RZ_PLUGIN_INCORE
117  .data = &rz_core_plugin_example,
118  .version = RZ_VERSION,
119  .pkgname = "example_package"
120 };
121 #endif
static csh cd
Definition: asm_mips_cs.c:10
RZ_API RzCmdDesc * rz_cmd_desc_argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help)
Definition: cmd_api.c:2153
RZ_API RzCmdDesc * rz_cmd_get_root(RzCmd *cmd)
Get the root command descriptor.
Definition: cmd_api.c:230
#define RZ_IPI
RzCorePlugin rz_core_plugin_example
_RZ_API RzLibStruct rizin_plugin
static bool rz_cmd_example_fini(RzCore *core)
static const RzCmdDescHelp cmd_example_help
static const RzCmdDescArg cmd_example_args[]
static bool rz_cmd_example_init(RzCore *core)
RZ_IPI RzCmdStatus rz_cmd_example_handler(RzCore *core, int argc, const char **argv)
#define _RZ_API
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define eprintf(x, y...)
Definition: rlcc.c:7
#define rz_warn_if_reached()
Definition: rz_assert.h:29
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_ARG_TYPE_NUM
Argument is a number.
Definition: rz_cmd.h:38
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
@ RZ_CMD_STATUS_INVALID
command could not be executed (e.g. shell level error, bad expression, etc.)
Definition: rz_cmd.h:27
@ RZ_LIB_TYPE_CORE
Definition: rz_lib.h:83
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#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 st32
Definition: rz_types_base.h:12
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_cmd.h:223
const char * summary
Definition: rz_cmd.h:289
const char * version
Definition: rz_core.h:128
const char * name
Definition: rz_core.h:124
RzCmd * rcmd
Definition: rz_core.h:319
RzNum * num
Definition: rz_core.h:316