Rizin
unix-like reverse engineering framework and cli tools
rz_cmd.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_bind.h>

Go to the source code of this file.

Classes

struct  rz_cmd_state_output_t
 Represent the output state of a command handler. More...
 
struct  rz_cmd_parsed_args_t
 
struct  rz_cmd_macro_label_t
 
struct  rz_cmd_macro_item_t
 
struct  rz_cmd_macro_t
 
struct  rz_cmd_item_t
 
struct  rz_cmd_alias_t
 
struct  rz_cmd_desc_detail_entry_t
 A detailed entry that can be used to show additional info about a command entry. More...
 
struct  rz_cmd_desc_detail_t
 
struct  rz_cmd_desc_arg_t
 
struct  rz_cmd_desc_help_t
 
struct  rz_cmd_desc_t
 
struct  rz_cmd_t
 
struct  rz_cmd_descriptor_t
 

Macros

#define MACRO_LIMIT   1024
 
#define MACRO_LABELS   20
 
#define RZ_CMD_MAXLEN   4096
 
#define RZ_CMD_ARG_FLAG_LAST   (1 << 0)
 
#define RZ_CMD_ARG_FLAG_ARRAY   (1 << 1)
 
#define RZ_CMD_ARG_FLAG_OPTION   (1 << 2)
 

Typedefs

typedef struct rz_core_t RzCore
 
typedef enum rz_cmd_status_t RzCmdStatus
 
typedef enum rz_cmd_arg_type_t RzCmdArgType
 
typedef enum rz_cmd_escape_t RzCmdEscape
 
typedef struct rz_cmd_state_output_t RzCmdStateOutput
 Represent the output state of a command handler. More...
 
typedef int(* RzCmdCb) (void *user, const char *input)
 
typedef RzCmdStatus(* RzCmdArgvCb) (RzCore *core, int argc, const char **argv)
 
typedef RzCmdStatus(* RzCmdArgvModesCb) (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
typedef RzCmdStatus(* RzCmdArgvStateCb) (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
typedef int(* RzCmdNullCb) (void *user)
 
typedef struct rz_cmd_parsed_args_t RzCmdParsedArgs
 
typedef struct rz_cmd_macro_label_t RzCmdMacroLabel
 
typedef struct rz_cmd_macro_item_t RzCmdMacroItem
 
typedef struct rz_cmd_macro_t RzCmdMacro
 
typedef struct rz_cmd_item_t RzCmdItem
 
typedef struct rz_cmd_alias_t RzCmdAlias
 
typedef struct rz_cmd_desc_detail_entry_t RzCmdDescDetailEntry
 A detailed entry that can be used to show additional info about a command entry. More...
 
typedef struct rz_cmd_desc_detail_t RzCmdDescDetail
 
typedef RZ_OWN RzCmdDescDetail *(* RzCmdDescDetailCb) (RzCore *core, int argc, const char **argv)
 
typedef RZ_OWN char **(* RzCmdArgChoiceCb) (RzCore *core)
 
typedef struct rz_cmd_desc_arg_t RzCmdDescArg
 
typedef struct rz_cmd_desc_help_t RzCmdDescHelp
 
typedef enum rz_cmd_desc_type_t RzCmdDescType
 
typedef struct rz_cmd_desc_t RzCmdDesc
 
typedef struct rz_cmd_t RzCmd
 
typedef struct rz_cmd_descriptor_t RzCmdDescriptor
 
typedef bool(* RzCmdForeachNameCb) (RzCmd *cmd, const RzCmdDesc *desc, void *user)
 

Enumerations

enum  rz_cmd_status_t {
  RZ_CMD_STATUS_OK = 0 , RZ_CMD_STATUS_WRONG_ARGS , RZ_CMD_STATUS_ERROR , RZ_CMD_STATUS_INVALID ,
  RZ_CMD_STATUS_NONEXISTINGCMD , RZ_CMD_STATUS_EXIT
}
 
enum  rz_cmd_arg_type_t {
  RZ_CMD_ARG_TYPE_FAKE , RZ_CMD_ARG_TYPE_NUM , RZ_CMD_ARG_TYPE_RZNUM , RZ_CMD_ARG_TYPE_STRING ,
  RZ_CMD_ARG_TYPE_ENV , RZ_CMD_ARG_TYPE_CHOICES , RZ_CMD_ARG_TYPE_FCN , RZ_CMD_ARG_TYPE_FILE ,
  RZ_CMD_ARG_TYPE_OPTION , RZ_CMD_ARG_TYPE_CMD , RZ_CMD_ARG_TYPE_MACRO , RZ_CMD_ARG_TYPE_EVAL_KEY ,
  RZ_CMD_ARG_TYPE_EVAL_FULL , RZ_CMD_ARG_TYPE_FCN_VAR , RZ_CMD_ARG_TYPE_FLAG , RZ_CMD_ARG_TYPE_ENUM_TYPE ,
  RZ_CMD_ARG_TYPE_STRUCT_TYPE , RZ_CMD_ARG_TYPE_UNION_TYPE , RZ_CMD_ARG_TYPE_ALIAS_TYPE , RZ_CMD_ARG_TYPE_CLASS_TYPE ,
  RZ_CMD_ARG_TYPE_ANY_TYPE , RZ_CMD_ARG_TYPE_GLOBAL_VAR , RZ_CMD_ARG_TYPE_REG_FILTER , RZ_CMD_ARG_TYPE_REG_TYPE
}
 
enum  rz_cmd_escape_t {
  RZ_CMD_ESCAPE_ONE_ARG , RZ_CMD_ESCAPE_MULTI_ARG , RZ_CMD_ESCAPE_PF_ARG , RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG ,
  RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG
}
 
enum  rz_cmd_desc_type_t {
  RZ_CMD_DESC_TYPE_OLDINPUT = 0 , RZ_CMD_DESC_TYPE_ARGV , RZ_CMD_DESC_TYPE_GROUP , RZ_CMD_DESC_TYPE_INNER ,
  RZ_CMD_DESC_TYPE_FAKE , RZ_CMD_DESC_TYPE_ARGV_MODES , RZ_CMD_DESC_TYPE_ARGV_STATE
}
 

Macro Definition Documentation

◆ MACRO_LABELS

#define MACRO_LABELS   20

Definition at line 17 of file rz_cmd.h.

◆ MACRO_LIMIT

#define MACRO_LIMIT   1024

Definition at line 16 of file rz_cmd.h.

◆ RZ_CMD_ARG_FLAG_ARRAY

#define RZ_CMD_ARG_FLAG_ARRAY   (1 << 1)

Argument is an array of elements. It must be the last in the list of arguments of a command.

Definition at line 72 of file rz_cmd.h.

◆ RZ_CMD_ARG_FLAG_LAST

#define RZ_CMD_ARG_FLAG_LAST   (1 << 0)

Argument can contain spaces when it is the last of a command and it would be considered as a single argument by the command handler.

Definition at line 67 of file rz_cmd.h.

◆ RZ_CMD_ARG_FLAG_OPTION

#define RZ_CMD_ARG_FLAG_OPTION   (1 << 2)

Argument is an option, prefixed with -. It is present or not.

Definition at line 76 of file rz_cmd.h.

◆ RZ_CMD_MAXLEN

#define RZ_CMD_MAXLEN   4096

Definition at line 18 of file rz_cmd.h.

Typedef Documentation

◆ RzCmd

typedef struct rz_cmd_t RzCmd

◆ RzCmdAlias

typedef struct rz_cmd_alias_t RzCmdAlias

◆ RzCmdArgChoiceCb

typedef RZ_OWN char**(* RzCmdArgChoiceCb) (RzCore *core)

Callback used to dynamically generate the choices of an argument with type RZ_CMD_ARG_TYPE_CHOICES

Definition at line 214 of file rz_cmd.h.

◆ RzCmdArgType

Type of argument a command handler can have. This is used for visualization in help messages and for autocompletion as well.

◆ RzCmdArgvCb

typedef RzCmdStatus(* RzCmdArgvCb) (RzCore *core, int argc, const char **argv)

Definition at line 108 of file rz_cmd.h.

◆ RzCmdArgvModesCb

typedef RzCmdStatus(* RzCmdArgvModesCb) (RzCore *core, int argc, const char **argv, RzOutputMode mode)

Definition at line 109 of file rz_cmd.h.

◆ RzCmdArgvStateCb

typedef RzCmdStatus(* RzCmdArgvStateCb) (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)

Definition at line 110 of file rz_cmd.h.

◆ RzCmdCb

typedef int(* RzCmdCb) (void *user, const char *input)

Definition at line 107 of file rz_cmd.h.

◆ RzCmdDesc

typedef struct rz_cmd_desc_t RzCmdDesc

Command Descriptor structure. It represents a command that can be executed by the user on the shell or a part of the command help (e.g. groups of commands). Anything that appears under ? has an associated command descriptor.

◆ RzCmdDescArg

A description of an argument of a RzCmdDesc.

◆ RzCmdDescDetail

A detail section used to better describe a command.

◆ RzCmdDescDetailCb

typedef RZ_OWN RzCmdDescDetail*(* RzCmdDescDetailCb) (RzCore *core, int argc, const char **argv)

Callback used to dynamically generate the details sections in the help of a command. NOTE: The array of RzCmdDescDetail returned will be freed, so all fields within need to be dynamically allocated even if they are marked as const.

Definition at line 209 of file rz_cmd.h.

◆ RzCmdDescDetailEntry

A detailed entry that can be used to show additional info about a command entry.

It can contain whatever relevant information (e.g. examples, specific uses of a command, variables, etc.).

Displayed as: | <text><arg_str> # <comment>

◆ RzCmdDescHelp

Define how the command looks like in the help.

◆ RzCmdDescriptor

◆ RzCmdDescType

◆ RzCmdEscape

◆ RzCmdForeachNameCb

typedef bool(* RzCmdForeachNameCb) (RzCmd *cmd, const RzCmdDesc *desc, void *user)

Definition at line 512 of file rz_cmd.h.

◆ RzCmdItem

typedef struct rz_cmd_item_t RzCmdItem

◆ RzCmdMacro

typedef struct rz_cmd_macro_t RzCmdMacro

◆ RzCmdMacroItem

◆ RzCmdMacroLabel

◆ RzCmdNullCb

typedef int(* RzCmdNullCb) (void *user)

Definition at line 111 of file rz_cmd.h.

◆ RzCmdParsedArgs

argc/argv data created from parsing the input command string.

◆ RzCmdStateOutput

Represent the output state of a command handler.

This structure is passed to commands of type RZ_CMD_DESC_TYPE_ARGV_STATE .

◆ RzCmdStatus

Value returned by a command handler.

◆ RzCore

typedef struct rz_core_t RzCore

Definition at line 1 of file rz_cmd.h.

Enumeration Type Documentation

◆ rz_cmd_arg_type_t

Type of argument a command handler can have. This is used for visualization in help messages and for autocompletion as well.

Enumerator
RZ_CMD_ARG_TYPE_FAKE 

This is not considered a real argument, just used to show something in the help. Name of arg is shown as-is and it is not counted.

RZ_CMD_ARG_TYPE_NUM 

Argument is a number.

RZ_CMD_ARG_TYPE_RZNUM 

Argument that can be interpreted by RzNum (numbers, flags, operations, etc.)

RZ_CMD_ARG_TYPE_STRING 

Argument that can be an arbitrary string.

RZ_CMD_ARG_TYPE_ENV 

Argument can be the name of an existing rizin variable.

RZ_CMD_ARG_TYPE_CHOICES 

Argument can be one of the provided choices.

RZ_CMD_ARG_TYPE_FCN 

Argument can be the name of an existing function.

RZ_CMD_ARG_TYPE_FILE 

Argument is a filename.

RZ_CMD_ARG_TYPE_OPTION 

Argument is an option, prefixed with -. It is present or not. No argument.

RZ_CMD_ARG_TYPE_CMD 

Argument is an rizin command.

RZ_CMD_ARG_TYPE_MACRO 

Argument is the name of a pre-defined macro.

RZ_CMD_ARG_TYPE_EVAL_KEY 

Argument is the name of a evaluable variable (e.g. et command)

RZ_CMD_ARG_TYPE_EVAL_FULL 

Argument is the name+(optional)value of a evaluable variable (e.g. e command)

RZ_CMD_ARG_TYPE_FCN_VAR 

Argument is the name of a function variable/argument.

RZ_CMD_ARG_TYPE_FLAG 

Argument is a rizin flag.

RZ_CMD_ARG_TYPE_ENUM_TYPE 

Argument is a C enum type name.

RZ_CMD_ARG_TYPE_STRUCT_TYPE 

Argument is a C struct type name.

RZ_CMD_ARG_TYPE_UNION_TYPE 

Argument is a C union type name.

RZ_CMD_ARG_TYPE_ALIAS_TYPE 

Argument is a C typedef (alias) name.

RZ_CMD_ARG_TYPE_CLASS_TYPE 

Argument is a C++/etc class name.

RZ_CMD_ARG_TYPE_ANY_TYPE 

Argument is the any of the C or C++ type name.

RZ_CMD_ARG_TYPE_GLOBAL_VAR 

Argument is a user defined global variable.

RZ_CMD_ARG_TYPE_REG_FILTER 

Argument is a register name, size, type or "all".

RZ_CMD_ARG_TYPE_REG_TYPE 

Argument is a register type/arena like "gpr".

Definition at line 36 of file rz_cmd.h.

36  {
61 } RzCmdArgType;
enum rz_cmd_arg_type_t RzCmdArgType
@ RZ_CMD_ARG_TYPE_FCN
Argument can be the name of an existing function.
Definition: rz_cmd.h:43
@ RZ_CMD_ARG_TYPE_CLASS_TYPE
Argument is a C++/etc class name.
Definition: rz_cmd.h:56
@ RZ_CMD_ARG_TYPE_MACRO
Argument is the name of a pre-defined macro.
Definition: rz_cmd.h:47
@ RZ_CMD_ARG_TYPE_CMD
Argument is an rizin command.
Definition: rz_cmd.h:46
@ RZ_CMD_ARG_TYPE_STRING
Argument that can be an arbitrary string.
Definition: rz_cmd.h:40
@ RZ_CMD_ARG_TYPE_EVAL_KEY
Argument is the name of a evaluable variable (e.g. et command)
Definition: rz_cmd.h:48
@ RZ_CMD_ARG_TYPE_EVAL_FULL
Argument is the name+(optional)value of a evaluable variable (e.g. e command)
Definition: rz_cmd.h:49
@ RZ_CMD_ARG_TYPE_FCN_VAR
Argument is the name of a function variable/argument.
Definition: rz_cmd.h:50
@ RZ_CMD_ARG_TYPE_STRUCT_TYPE
Argument is a C struct type name.
Definition: rz_cmd.h:53
@ RZ_CMD_ARG_TYPE_ENUM_TYPE
Argument is a C enum type name.
Definition: rz_cmd.h:52
@ RZ_CMD_ARG_TYPE_OPTION
Argument is an option, prefixed with -. It is present or not. No argument.
Definition: rz_cmd.h:45
@ RZ_CMD_ARG_TYPE_CHOICES
Argument can be one of the provided choices.
Definition: rz_cmd.h:42
@ RZ_CMD_ARG_TYPE_NUM
Argument is a number.
Definition: rz_cmd.h:38
@ RZ_CMD_ARG_TYPE_RZNUM
Argument that can be interpreted by RzNum (numbers, flags, operations, etc.)
Definition: rz_cmd.h:39
@ RZ_CMD_ARG_TYPE_REG_TYPE
Argument is a register type/arena like "gpr".
Definition: rz_cmd.h:60
@ RZ_CMD_ARG_TYPE_ANY_TYPE
Argument is the any of the C or C++ type name.
Definition: rz_cmd.h:57
@ RZ_CMD_ARG_TYPE_FLAG
Argument is a rizin flag.
Definition: rz_cmd.h:51
@ RZ_CMD_ARG_TYPE_UNION_TYPE
Argument is a C union type name.
Definition: rz_cmd.h:54
@ RZ_CMD_ARG_TYPE_ALIAS_TYPE
Argument is a C typedef (alias) name.
Definition: rz_cmd.h:55
@ RZ_CMD_ARG_TYPE_REG_FILTER
Argument is a register name, size, type or "all".
Definition: rz_cmd.h:59
@ RZ_CMD_ARG_TYPE_FILE
Argument is a filename.
Definition: rz_cmd.h:44
@ RZ_CMD_ARG_TYPE_GLOBAL_VAR
Argument is a user defined global variable.
Definition: rz_cmd.h:58
@ RZ_CMD_ARG_TYPE_ENV
Argument can be the name of an existing rizin variable.
Definition: rz_cmd.h:41
@ RZ_CMD_ARG_TYPE_FAKE
This is not considered a real argument, just used to show something in the help. Name of arg is shown...
Definition: rz_cmd.h:37

◆ rz_cmd_desc_type_t

Enumerator
RZ_CMD_DESC_TYPE_OLDINPUT 

For old handlers that parse their own input and accept a single string. Mainly used for legacy reasons with old command handlers.

RZ_CMD_DESC_TYPE_ARGV 

For handlers that accept argc/argv. It cannot have children. Use RZ_CMD_DESC_TYPE_GROUP if you need a command that can be both executed and has sub-commands.

RZ_CMD_DESC_TYPE_GROUP 

For cmd descriptors that are parent of other sub-commands, even if they may also have a sub-command with the same name. For example, wc is both the parent of wci, wc*, etc. but there is also wc as a sub-command.

RZ_CMD_DESC_TYPE_INNER 

For cmd descriptors that are just used to group together related sub-commands. Do not use this if the command can be used by itself or if it's necessary to show its help, because this descriptor is not stored in the hashtable and cannot be retrieved except by listing the children of its parent. Most of the time you want RZ_CMD_DESC_TYPE_GROUP.

RZ_CMD_DESC_TYPE_FAKE 

For entries that shall be shown in the help tree but that are not commands on their own. |?, @?, >? are example of this. It is useful to provide help entries for them in the tree, but there are no command handlers for these. The RzCmdDescDetail in the help can be used to show fake children of this descriptor.

RZ_CMD_DESC_TYPE_ARGV_MODES 

For handlers that accept argc/argv and that provides multiple output modes (e.g. rizin commands, quiet output, json, long). It cannot have children. Use RZ_CMD_DESC_TYPE_GROUP if you need a command that can be both executed and has sub-commands.

RZ_CMD_DESC_TYPE_ARGV_STATE 

For handlers that accept argc/argv and that provides multiple output modes (e.g. rizin commands, quiet output, json, long). It cannot have children. Use RZ_CMD_DESC_TYPE_GROUP if you need a command that can be both executed and has sub-commands.

Differently from RZ_CMD_DESC_TYPE_ARGV_MODES, these handlers receive an output structure with the mode and data already initialized (e.g. PJ, RzTable, etc.) and the handler just has to fill the data in those structure, while RzCmd will allocate, free and print the data within.

Definition at line 350 of file rz_cmd.h.

350  {
404 } RzCmdDescType;
enum rz_cmd_desc_type_t RzCmdDescType
@ RZ_CMD_DESC_TYPE_ARGV_STATE
Definition: rz_cmd.h:403
@ RZ_CMD_DESC_TYPE_GROUP
Definition: rz_cmd.h:368
@ RZ_CMD_DESC_TYPE_ARGV
Definition: rz_cmd.h:361
@ RZ_CMD_DESC_TYPE_FAKE
Definition: rz_cmd.h:384
@ RZ_CMD_DESC_TYPE_ARGV_MODES
Definition: rz_cmd.h:391
@ RZ_CMD_DESC_TYPE_OLDINPUT
Definition: rz_cmd.h:355
@ RZ_CMD_DESC_TYPE_INNER
Definition: rz_cmd.h:376

◆ rz_cmd_escape_t

Enumerator
RZ_CMD_ESCAPE_ONE_ARG 

The string should be escaped so that it appears as one single argument.

RZ_CMD_ESCAPE_MULTI_ARG 

The string should be escaped so that it appears as one or multiple arguments.

RZ_CMD_ESCAPE_PF_ARG 

The string should be escaped so that it appears as one or multiple pf arguments.

RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG 

The string should be escaped so that it can be wrapped in "....".

RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG 

The string should be escaped so that it can be wrapped in '....'.

Definition at line 78 of file rz_cmd.h.

78  {
84 } RzCmdEscape;
@ RZ_CMD_ESCAPE_MULTI_ARG
The string should be escaped so that it appears as one or multiple arguments.
Definition: rz_cmd.h:80
@ RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in '....'.
Definition: rz_cmd.h:83
@ RZ_CMD_ESCAPE_PF_ARG
The string should be escaped so that it appears as one or multiple pf arguments.
Definition: rz_cmd.h:81
@ RZ_CMD_ESCAPE_ONE_ARG
The string should be escaped so that it appears as one single argument.
Definition: rz_cmd.h:79
@ RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in "....".
Definition: rz_cmd.h:82
enum rz_cmd_escape_t RzCmdEscape

◆ rz_cmd_status_t

Value returned by a command handler.

Enumerator
RZ_CMD_STATUS_OK 

command handler exited in the right way

RZ_CMD_STATUS_WRONG_ARGS 

command handler could not handle the arguments passed to it

RZ_CMD_STATUS_ERROR 

command handler had issues while running (e.g. allocation error, etc.)

RZ_CMD_STATUS_INVALID 

command could not be executed (e.g. shell level error, bad expression, etc.)

RZ_CMD_STATUS_NONEXISTINGCMD 

command does not exist

RZ_CMD_STATUS_EXIT 

command handler asks to exit the prompt loop

Definition at line 23 of file rz_cmd.h.

23  {
24  RZ_CMD_STATUS_OK = 0,
30 } RzCmdStatus;
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_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
@ RZ_CMD_STATUS_INVALID
command could not be executed (e.g. shell level error, bad expression, etc.)
Definition: rz_cmd.h:27
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
@ RZ_CMD_STATUS_EXIT
command handler asks to exit the prompt loop
Definition: rz_cmd.h:29