Rizin
unix-like reverse engineering framework and cli tools
core_plugin_example.c File Reference
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_cmd.h>
#include <rz_core.h>

Go to the source code of this file.

Macros

#define RZ_API   static
 
#define RZ_IPI   static
 
#define _RZ_API
 

Functions

RZ_IPI RzCmdStatus rz_cmd_example_handler (RzCore *core, int argc, const char **argv)
 
static bool rz_cmd_example_init (RzCore *core)
 
static bool rz_cmd_example_fini (RzCore *core)
 

Variables

static const RzCmdDescArg cmd_example_args []
 
static const RzCmdDescHelp cmd_example_help
 
RzCorePlugin rz_core_plugin_example
 
_RZ_API RzLibStruct rizin_plugin
 

Detailed Description

This file is an example on how to write core plugins for rizin.

Compilation:

  • gcc -o core_plugin_example.so -O3 -std=c99 -Wall -fPIC pkg-config --cflags --libs rz_core core_plugin_example.c -shared

Installation via the RZ_USER_PLUGINS folder:

  • mkdir -p ~/.local/share/rizin/plugins/
  • rizin -H | grep RZ_USER_PLUGINS
  • RZ_USER_PLUGINS=/home/username/.local/share/rizin/plugins
  • mv core_plugin_example.so ~/.local/share/rizin/plugins/

Example of usage

  • rizin = This init was called!
  • [0x00000000]> example? Usage: example <number> # example summary that contains some description
  • [0x00000000]> example 1777 WARNING: the parsed number is 1777
  • [0x00000000]> example -777 ERROR: only positive numbers are accepted -777 Error while executing command: example -777
  • [0x00000000]> q This fini was called!

Definition in file core_plugin_example.c.

Macro Definition Documentation

◆ _RZ_API

#define _RZ_API

Definition at line 111 of file core_plugin_example.c.

◆ RZ_API

#define RZ_API   static

Definition at line 36 of file core_plugin_example.c.

◆ RZ_IPI

#define RZ_IPI   static

Definition at line 38 of file core_plugin_example.c.

Function Documentation

◆ rz_cmd_example_fini()

static bool rz_cmd_example_fini ( RzCore core)
static

Definition at line 90 of file core_plugin_example.c.

90  {
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 }
#define eprintf(x, y...)
Definition: rlcc.c:7

References eprintf.

◆ rz_cmd_example_handler()

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

Definition at line 53 of file core_plugin_example.c.

53  {
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 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
@ 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
#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
RzNum * num
Definition: rz_core.h:316

References argv, rz_core_t::num, RZ_CMD_STATUS_INVALID, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, RZ_LOG_ERROR, RZ_LOG_WARN, rz_num_math(), and st32.

Referenced by rz_cmd_example_init().

◆ rz_cmd_example_init()

static bool rz_cmd_example_init ( RzCore core)
static

Definition at line 69 of file core_plugin_example.c.

69  {
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 }
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
static const RzCmdDescHelp cmd_example_help
RZ_IPI RzCmdStatus rz_cmd_example_handler(RzCore *core, int argc, const char **argv)
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RzCmd * rcmd
Definition: rz_core.h:319

References cd, cmd_example_help, eprintf, rz_core_t::rcmd, cmd_descs_generate::root_cd, rz_cmd_desc_argv_new(), rz_cmd_example_handler(), rz_cmd_get_root(), and rz_warn_if_reached.

Variable Documentation

◆ cmd_example_args

const RzCmdDescArg cmd_example_args[]
static
Initial value:
= {
{
.name = "number",
},
{ 0 },
}
@ RZ_CMD_ARG_TYPE_NUM
Argument is a number.
Definition: rz_cmd.h:38

Definition at line 40 of file core_plugin_example.c.

◆ cmd_example_help

const RzCmdDescHelp cmd_example_help
static
Initial value:
= {
.summary = "example summary that contains some description",
}
static const RzCmdDescArg cmd_example_args[]

Definition at line 48 of file core_plugin_example.c.

Referenced by rz_cmd_example_init().

◆ rizin_plugin

_RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.pkgname = "example_package"
}
RzCorePlugin rz_core_plugin_example
@ RZ_LIB_TYPE_CORE
Definition: rz_lib.h:83
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_core.h:128

Definition at line 115 of file core_plugin_example.c.

◆ rz_core_plugin_example

RzCorePlugin rz_core_plugin_example
Initial value:
= {
.name = "test",
.desc = "description of the example core plugin",
.license = "LGPL",
.author = "somebody",
.version = "1.0",
}
static bool rz_cmd_example_fini(RzCore *core)
static bool rz_cmd_example_init(RzCore *core)

Definition at line 98 of file core_plugin_example.c.