30 #define MAX_CHILDREN_SHOW 7
32 #define MIN_SUMMARY_WIDTH 6
33 #define MAX_RIGHT_ALIGHNMENT 20
46 .
usage =
"Usage not defined",
47 .summary =
"Help summary not defined",
48 .description =
"Help description not defined.",
52 .
usage =
"[.][times][cmd][~grep][@[@iter]addr][|>pipe] ; ...",
54 .sort_subcommands =
true,
95 #define NCMDS (sizeof(cmd->cmds) / sizeof(*cmd->cmds))
109 switch (parent->
type) {
143 bool res = ht_pp_delete(
cmd->ht_cmds,
cd->name);
145 rz_cmd_desc_children_foreach(
cd, it_cd) {
174 if (ht_insert && !ht_pp_insert(
cmd->ht_cmds,
name, res)) {
185 cmd->aliases.count = 0;
196 cmd->has_cons = has_cons;
201 cmd->ht_cmds = ht_pp_new0();
213 ht_up_free(
cmd->ts_symbols_ht);
216 ht_pp_free(
cmd->ht_cmds);
231 return cmd->root_cmd_desc;
250 rz_cmd_desc_children_foreach(group, it_cd) {
252 if (
cd->n_children) {
287 char suffix[] = { last_letter,
'\0' };
297 return cd->d.group_data.exec_cd;
305 char *cmdid =
strdup(cmd_identifier);
306 char *end_cmdid = cmdid + strlen(cmdid);
308 bool is_exact_match =
true;
309 char last_letter =
'\0', o_last_letter = end_cmdid > cmdid ? *(end_cmdid - 1) :
'\0';
333 last_letter = o_last_letter;
334 o_last_letter =
'\0';
336 is_exact_match =
false;
337 *(--end_cmdid) =
'\0';
392 cd->d.argv_modes_data.default_mode =
mode;
398 cd->d.argv_state_data.default_mode =
mode;
414 *sz =
cmd->aliases.count;
416 return cmd->aliases.keys;
421 for (
i = 0;
i <
cmd->aliases.count;
i++) {
425 cmd->aliases.count = 0;
433 for (
i = 0;
i <
cmd->aliases.count;
i++) {
434 if (!
k || !strcmp(
k,
cmd->aliases.keys[
i])) {
436 cmd->aliases.count--;
437 if (
cmd->aliases.count > 0) {
440 cmd->aliases.keys[
i] =
cmd->aliases.keys[0];
442 cmd->aliases.values[
i] =
cmd->aliases.values[0];
444 memmove(
cmd->aliases.values,
445 cmd->aliases.values + 1,
446 cmd->aliases.count *
sizeof(
void *));
447 memmove(
cmd->aliases.keys,
448 cmd->aliases.keys + 1,
449 cmd->aliases.count *
sizeof(
void *));
460 if (!strncmp(
v,
"base64:", 7)) {
468 for (
i = 0;
i <
cmd->aliases.count;
i++) {
469 int matches = !strcmp(
k,
cmd->aliases.keys[
i]);
478 i =
cmd->aliases.count++;
479 char **K = (
char **)
realloc(
cmd->aliases.keys,
480 sizeof(
char *) *
cmd->aliases.count);
482 cmd->aliases.keys = K;
484 sizeof(
int) *
cmd->aliases.count);
486 cmd->aliases.remote =
R;
488 sizeof(
char *) *
cmd->aliases.count);
490 cmd->aliases.values =
V;
493 cmd->aliases.remote[
i] = remote;
506 for (
i = 0;
i <
cmd->aliases.count;
i++) {
509 if (
cmd->aliases.remote[
i]) {
510 matches = !strncmp(
k,
cmd->aliases.keys[
i],
511 strlen(
cmd->aliases.keys[
i]));
514 matches = !strcmp(
k,
cmd->aliases.keys[
i]);
517 return cmd->aliases.values[
i];
535 strncpy(item->
cmd,
cmd,
sizeof(item->
cmd) - 1);
551 if (
cmd->nullcallback) {
552 ret =
cmd->nullcallback(
cmd->data);
571 if (
c &&
c->callback) {
572 const char *inp = (*input) ?
input + 1 :
"";
573 ret =
c->callback(
cmd->data, inp);
628 return cd->d.argv_modes_data.default_mode;
630 return cd->d.argv_state_data.default_mode;
674 for (j =
i; j <
args->argc; j++) {
676 if (strcmp(
s,
args->argv[j])) {
689 for (j =
i; j <
args->argc; j++) {
698 if (
arg->default_value &&
i >=
args->argc) {
713 rz_cmd_parsed_args_foreach_arg(
args,
i,
s) {
720 if (
args->argc <
cd->d.argv_data.min_argc ||
args->argc >
cd->d.argv_data.max_argc) {
723 return cd->d.argv_data.cb(
cmd->data,
args->argc, (
const char **)
args->argv);
729 if (
args->argc <
cd->d.argv_modes_data.min_argc ||
args->argc >
cd->d.argv_modes_data.max_argc) {
732 return cd->d.argv_modes_data.cb(
cmd->data,
args->argc, (
const char **)
args->argv,
mode);
738 if (
args->argc <
cd->d.argv_state_data.min_argc ||
args->argc >
cd->d.argv_state_data.max_argc) {
769 rz_cmd_parsed_args_foreach_arg(
args,
i,
s) {
775 if (!
cd->d.group_data.exec_cd) {
804 return s ? strlen(
s) : 0;
824 if (
cd->help->options) {
832 bool has_other_commands =
false;
835 switch (exec_cd->
type) {
844 rz_cmd_desc_children_foreach(
cd, it) {
848 }
else if (strcmp(child->
name,
cd->name)) {
849 has_other_commands =
true;
856 has_other_commands =
false;
859 if (has_other_commands) {
883 const char *pal_args_color =
"";
884 if (
cmd->has_cons && use_color) {
890 const char *close_arg =
NULL;
891 const char *open_arg = strchr(
line,
'<');
895 close_arg = strchr(open_arg,
'>');
901 line = close_arg + 1;
908 bool is_interactive =
false;
909 const char *help_color =
"";
922 rz_list_foreach (wrapped_text, it,
line) {
940 for (; *n_optionals > 0; (*n_optionals)--) {
948 size_t n_optionals = 0;
950 bool has_array =
false;
953 if (!
arg->optional) {
966 if (!
arg->no_space) {
987 if (
arg->default_value) {
989 len += strlen(
arg->default_value) + 1;
998 const char *pal_label_color =
"",
999 *pal_args_color =
"",
1000 *pal_input_color =
"",
1001 *pal_help_color =
"",
1004 if (
cmd->has_cons && use_color) {
1017 if (
cd->help->usage) {
1028 if (
cd->help->args_str) {
1035 if (
cd->help->summary) {
1052 size_t name_len = strlen(
name);
1053 size_t args_len = 0;
1054 size_t children_length = 0;
1062 if (
cd->help->args_str) {
1071 return name_len + args_len + children_length;
1076 *max_len =
val > *max_len ?
val : *max_len;
1077 *min_len =
val < *min_len ?
val : *min_len;
1082 int padding = str_len < max_len ? max_len - str_len : 0;
1083 const char *pal_args_color =
"",
1084 *pal_opt_color =
"",
1085 *pal_help_color =
"",
1086 *pal_input_color =
"",
1089 if (
cmd->has_cons && use_color) {
1107 if (
cd->help->args_str) {
1113 columns += padding + 1;
1129 size_t max_len = 0, min_len =
SIZE_MAX;
1131 rz_cmd_desc_children_foreach(
cd, it_cd) {
1139 rz_cmd_desc_children_foreach(
cd, it_cd) {
1149 size_t max_len = 0, min_len =
SIZE_MAX;
1170 if (
cd->help->details) {
1171 return cd->help->details;
1180 if (
cd->help->details ||
cd->help->details_cb) {
1182 return cd->help->details_cb ?
cd->help->details_cb(
cmd->data, 1,
argv) :
NULL;
1190 const char *pal_help_color =
"",
1191 *pal_input_color =
"",
1192 *pal_label_color =
"",
1193 *pal_args_color =
"",
1195 if (
cmd->has_cons && use_color) {
1204 while (detail_it->
name) {
1209 size_t max_len = 0, min_len =
SIZE_MAX;
1210 while (entry_it && entry_it->
text) {
1212 if (max_len <
len) {
1215 if (min_len >
len) {
1224 entry_it = detail_it->
entries;
1225 while (entry_it && entry_it->
text) {
1227 int padding =
len < max_len ? max_len -
len : 0;
1228 const char *arg_str = entry_it->
arg_str ? entry_it->
arg_str :
"";
1230 pal_input_color, entry_it->
text,
1231 pal_args_color, arg_str,
1234 size_t columns = strlen(
"| ") + strlen(entry_it->
text) +
1235 strlen(
" ") + strlen(arg_str) + padding;
1268 const char *pal_reset =
"";
1269 if (
cmd->has_cons && use_color) {
1283 if (
cd->help->description) {
1303 if (!
cmd->has_cons) {
1327 if (
cd->d.group_data.exec_cd && (
detail > 1 || (
detail == 1 && strcmp(cmdid,
cd->name)))) {
1355 bool has_array =
false;
1357 const char *argtype =
NULL;
1364 #define CASE_TYPE(x, y) \
1368 switch (
arg->type) {
1384 argtype =
"unknown";
1387 pj_ks(j,
"type", argtype);
1393 if (
arg->no_space) {
1394 pj_kb(j,
"nospace",
true);
1396 if (!
arg->optional) {
1397 pj_kb(j,
"required",
true);
1400 pj_kb(j,
"is_last",
true);
1403 pj_kb(j,
"is_array",
true);
1406 pj_kb(j,
"is_option",
true);
1408 if (
arg->default_value) {
1409 pj_ks(j,
"default",
arg->default_value);
1412 pj_ka(j,
"choices");
1413 char **ochoice =
arg->choices_cb ?
arg->choices_cb(
cmd->data) : (
char **)
arg->choices;
1414 for (
char **choice = ochoice; *choice; choice++) {
1418 if (
arg->choices_cb) {
1419 for (
char **choice = ochoice; *choice; choice++) {
1445 #define CASE_CDTYPE(x, y) \
1462 if (
cd->help->args_str) {
1463 pj_ks(j,
"args_str",
cd->help->args_str);
1472 pj_ks(j,
"description",
cd->help->description ?
cd->help->description :
"");
1473 pj_ks(j,
"summary",
cd->help->summary ?
cd->help->summary :
"");
1499 char *cmdid_p = cmdid + strlen(cmdid) - 1;
1501 while (cmdid_p >= cmdid && *cmdid_p ==
'?' &&
detail < 2) {
1514 if (!
cd || !
cd->help) {
1581 pbody = strchr(
name,
';');
1583 eprintf(
"Invalid macro body\n");
1591 eprintf(
"rz_cmd_macro_add: missing macro body?\n");
1597 ptr = strchr(
name,
' ');
1604 if (!strcmp(
name,
m->name)) {
1625 macro->codelen = (pbody[0]) ? strlen(pbody) + 2 : 4096;
1627 *
macro->code =
'\0';
1639 for (lidx = 0; pbody[lidx]; lidx++) {
1640 if (pbody[lidx] ==
';') {
1642 }
else if (pbody[lidx] ==
')' && pbody[lidx - 1] ==
'\n') {
1648 if (macro_update == 0) {
1662 char *ptr = strchr(
name,
')');
1668 if (!strcmp(
m->name,
name)) {
1686 for (j = 0;
m->code[j]; j++) {
1687 if (
m->code[j] ==
'\n') {
1705 for (j = 0;
m->code[j]; j++) {
1706 if (
m->code[j] ==
'\n') {
1735 if (ptr[j] ==
'$') {
1736 if (ptr[j + 1] >=
'0' && ptr[j + 1] <=
'9') {
1738 int w = ptr[j + 1] -
'0';
1740 if (word && *word) {
1741 wordlen = strlen(word);
1742 if ((
i + wordlen + 1) >=
sizeof(
cmd)) {
1749 eprintf(
"Undefined argument %d\n",
w);
1751 }
else if (ptr[j + 1] ==
'@') {
1756 if ((
i + offlen + 1) >=
sizeof(
cmd)) {
1771 for (pcmd =
cmd; *pcmd && (*pcmd ==
' ' || *pcmd ==
'\t'); pcmd++) {
1775 int xx = (*pcmd ==
')') ? 0 : mac->
cmd(mac->
user, pcmd);
1782 for (; *ptr ==
' '; ptr++) {
1785 if (ptr[strlen(ptr) - 1] ==
':' && !strchr(ptr,
' ')) {
1787 if (ptr[0] ==
'.') {
1790 for (
i = 0;
i < *labels_n;
i++) {
1792 if (!strcmp(ptr + 1, labels[
i].
name)) {
1793 return labels[
i].
ptr;
1799 if (ptr[0] ==
'?' && ptr[1] ==
'!' && ptr[2] !=
'?') {
1801 char *
label = ptr + 3;
1807 for (
i = 0;
i < *labels_n;
i++) {
1809 return labels[
i].
ptr;
1816 if (ptr[0] ==
'?' && ptr[1] ==
'?' && ptr[2] !=
'?') {
1818 char *
label = ptr + 3;
1824 for (
i = 0;
i < *labels_n;
i++) {
1826 return labels[
i].
ptr;
1832 for (
i = 0;
i < *labels_n;
i++) {
1834 if (!strcmp(ptr + 1, labels[
i].
name)) {
1842 strncpy(labels[*labels_n].
name, ptr, 64);
1843 labels[*labels_n].
ptr = ptr + strlen(ptr) + 1;
1844 *labels_n = *labels_n + 1;
1847 return ptr + strlen(ptr) + 1;
1856 char *
str, *ptr, *ptr2;
1858 static int macro_level = 0;
1899 if (!strcmp(
str,
m->name)) {
1900 char *
ptr =
m->code;
1901 char *
end = strchr(
ptr,
'\n');
1902 char *init_ptr =
ptr;
1903 char *init_end =
end;
1904 if ((
m->nargs == 0 &&
nargs !=
m->nargs) ||
1906 ((multiple && (
nargs %
m->nargs != 0 ||
nargs == 0)) ||
1907 (!multiple &&
nargs !=
m->nargs)))) {
1908 if (!multiple ||
m->nargs == 0 ||
nargs == 0) {
1911 RZ_LOG_ERROR(
"Macro '%s' expects %d args and %d is not a multiple of %d\n",
1912 m->name,
m->nargs,
nargs,
m->nargs);
1920 int args_processed = 0;
1940 }
else if (
ptr != ptr2) {
1967 args_processed +=
m->nargs;
1968 if (!multiple || args_processed >=
nargs) {
1977 }
while (!mac->
brk);
2017 res->
argc = n_args + 1;
2021 for (
i = 1;
i < res->
argc;
i++) {
2042 for (
i = 0;
i <
a->argc;
i++) {
2051 for (
i = 0;
i <
n;
i++) {
2065 for (
i = 1;
i < n_args + 1;
i++) {
2074 a->argc = n_args + 1;
2082 char **
tmp =
realloc(
a->argv,
sizeof(
a->argv[0]) * (
a->argc + 2));
2089 a->argv[
a->argc + 1] =
NULL;
2107 for (
i = 1;
i <
a->argc;
i++) {
2125 if (
a->argc > 1 &&
a->has_space_after_cmd) {
2340 return cd->d.argv_data.cb;
2342 return cd->d.argv_modes_data.cb;
2344 return cd->d.argv_state_data.cb;
2346 return cd->d.oldinput_data.cb;
2397 dst->description =
src->description;
2398 dst->args_str =
src->args_str;
2400 dst->options =
src->options;
2401 dst->details =
src->details;
2455 rz_cmd_desc_children_foreach(
cd, it_cd) {
2480 size_t s_len = strlen(
s);
2481 char *
d =
RZ_NEWS(
char, s_len * 2 + 1);
2483 for (
i = 0;
i < s_len;
i++) {
2484 if (strchr(special_chars,
s[
i])) {
2497 for (
i = 0;
s[
i];
i++) {
2498 if (
s[
i] !=
'\\' || !strchr(special_chars,
s[
i + 1])) {
2606 switch (
state->mode) {
2638 switch (
state->mode) {
2672 switch (
state->mode) {
2700 while (detail_it->
name) {
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
static void rz_cmd(int in, int out, const char *cmd)
const lzma_allocator const uint8_t size_t uint8_t * out
static void print_child_help(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, size_t max_len, bool use_color)
RZ_IPI int rz_output_mode_to_char(RzOutputMode mode)
static void fill_args_json(const RzCmd *cmd, const RzCmdDesc *cd, PJ *j)
static void cmd_desc_remove_from_ht_cmds(RzCmd *cmd, RzCmdDesc *cd)
static const RzCmdDescDetail * get_cd_details(RzCmdDesc *cd)
static const RzCmdDescHelp root_help
static const char * SPECIAL_CHARS_SINGLE_QUOTED
RZ_API void rz_cmd_macro_item_free(RzCmdMacroItem *item)
RZ_API RzCmdParsedArgs * rz_cmd_parsed_args_newargs(int n_args, char **args)
RZ_API void rz_cmd_desc_details_free(RzCmdDescDetail *details)
Free an array of RzCmdDescDetail sections.
RZ_API bool rz_cmd_get_help_json(RzCmd *cmd, const RzCmdDesc *cd, PJ *j)
Generates a JSON output of the given help message description.
RZ_API void rz_cmd_state_output_free(RZ_NONNULL RzCmdStateOutput *state)
Free the RzCmdStateOutput structure and its inner fields appropriately.
static RzCmdDesc * cmd_get_desc_best(RzCmd *cmd, const char *cmd_identifier, bool best_match)
static void cmd_foreach_cmdname(RzCmd *cmd, RzCmdDesc *cd, RzCmdForeachNameCb cb, void *user)
RZ_API RzCmdDesc * rz_cmd_get_desc(RzCmd *cmd, const char *cmd_identifier)
Retrieve the command descriptor for the command named cmd_identifier.
RZ_API char * rz_cmd_parsed_args_argstr(RzCmdParsedArgs *a)
RZ_API void rz_cmd_batch_end(RzCmd *cmd)
Mark the end of the batched changes to RzCmd.
static char * escape_special_chars(const char *s, const char *special_chars)
RZ_API int rz_cmd_macro_call_multiple(RzCmdMacro *mac, const char *name)
RZ_API char * rz_cmd_parsed_args_execstr(RzCmdParsedArgs *a)
RZ_API bool rz_cmd_desc_set_default_mode(RzCmdDesc *cd, RzOutputMode mode)
Set the default mode of the command descriptor, if the type allows it.
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
RZ_API RzCmdDesc * rz_cmd_desc_fake_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help)
RZ_API RzCmdDesc * rz_cmd_desc_argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help)
RZ_API const char * rz_cmd_parsed_args_cmd(RzCmdParsedArgs *a)
RZ_API void rz_cmd_foreach_cmdname(RzCmd *cmd, RzCmdDesc *begin, RzCmdForeachNameCb cb, void *user)
Execute a callback function on each possible command the user can execute.
RZ_API void rz_cmd_alias_free(RzCmd *cmd)
RZ_API RzCmdDesc * rz_cmd_desc_oldinput_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdCb cb, const RzCmdDescHelp *help)
#define MIN_SUMMARY_WIDTH
static RzCmdDesc * argv_modes_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help, bool ht_insert)
static bool show_children_shortcut(const RzCmdDesc *cd)
static const char * SPECIAL_CHARS_DOUBLE_QUOTED
#define MAX_CHILDREN_SHOW
static size_t strlen0(const char *s)
static void cmd_desc_free(RzCmdDesc *cd)
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
RZ_API bool rz_cmd_alias_del(RzCmd *cmd, const char *k)
RZ_API bool rz_cmd_parsed_args_setcmd(RzCmdParsedArgs *a, const char *cmd)
RZ_API int rz_cmd_add(RzCmd *c, const char *cmd, RzCmdCb cb)
static RzCmdDescHelp * mode_cmd_desc_help(RzCmdDescHelp *dst, const RzCmdDescHelp *src, const char *suffix)
RZ_API char * rz_cmd_unescape_arg(const char *arg, RzCmdEscape esc)
static RzCmdDesc * argv_state_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help, bool ht_insert)
static char * argv_get_help(RzCmd *cmd, RzCmdDesc *cd, size_t detail, bool use_color)
RZ_API int rz_cmd_macro_add(RzCmdMacro *mac, const char *oname)
static const char * SPECIAL_CHARS_REGULAR_SINGLE
static void fill_details_do(RzCmd *cmd, const RzCmdDescDetail *detail_it, RzStrBuf *sb, bool use_color)
static bool is_valid_argv_modes(RzCmdDesc *cd, char last_letter)
RZ_API void rz_cmd_macro_init(RzCmdMacro *mac)
static char * fake_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color)
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
RZ_API int rz_cmd_call(RzCmd *cmd, const char *input)
static void fill_argv_modes_help_strbuf(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
static int cd_sort(const void *a, const void *b)
static char * group_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color)
static const RzCmdDescHelp not_defined_help
static void fill_modes_children_chars(RzStrBuf *sb, const RzCmdDesc *cd)
RZ_IPI const char * rz_output_mode_to_summary(RzOutputMode mode)
static char * unescape_special_chars(const char *s, const char *special_chars)
RZ_API bool rz_cmd_desc_has_handler(const RzCmdDesc *cd)
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
static void update_minmax_len(RzCmdDesc *cd, size_t *max_len, size_t *min_len, bool show_children)
static bool has_cd_submodes(const RzCmdDesc *cd)
static char * get_help(RzCmd *cmd, RzCmdDesc *cd, const char *cmdid, RzCmdParsedArgs *args, bool use_color, size_t detail)
RZ_API bool rz_cmd_get_help_strbuf(RzCmd *cmd, const RzCmdDesc *cd, bool use_color, RzStrBuf *sb)
Generates a text output of the given help message description (summary format)
#define CASE_CDTYPE(x, y)
RZ_API RzCmdParsedArgs * rz_cmd_parsed_args_newcmd(const char *cmd)
static RzCmdDesc * create_cmd_desc(RzCmd *cmd, RzCmdDesc *parent, RzCmdDescType type, const char *name, const RzCmdDescHelp *help, bool ht_insert)
RZ_API bool rz_cmd_parsed_args_setargs(RzCmdParsedArgs *a, int n_args, char **args)
static void fill_details(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
RZ_API int rz_cmd_alias_set(RzCmd *cmd, const char *k, const char *v, int remote)
static void sort_groups(RzCmdDesc *group)
static void args_preprocessing(RzCmdDesc *cd, RzCmdParsedArgs *args)
static void cmd_foreach_cmdname_modes(RzCmd *cmd, RzCmdDesc *cd, int modes, RzCmdForeachNameCb cb, void *user)
RZ_API int rz_cmd_del(RzCmd *cmd, const char *command)
static RzCmdStatus call_cd(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
RZ_API char * rz_cmd_alias_get(RzCmd *cmd, const char *k, int remote)
RZ_API void rz_cmd_macro_fini(RzCmdMacro *mac)
RZ_API bool rz_cmd_desc_remove(RzCmd *cmd, RzCmdDesc *cd)
static size_t strbuf_append_calc(RzStrBuf *sb, const char *s)
RZ_API int rz_cmd_macro_cmd_args(RzCmdMacro *mac, const char *ptr, const char *args, int nargs)
RZ_API RzCmdDesc * rz_cmd_get_root(RzCmd *cmd)
Get the root command descriptor.
static void do_print_child_help(RzCmd *cmd, RzStrBuf *sb, const RzCmdDesc *cd, const char *name, const char *summary, bool show_children, size_t max_len, bool use_color)
RZ_API int rz_cmd_macro_call(RzCmdMacro *mac, const char *name)
RZ_API RzCmd * rz_cmd_free(RzCmd *cmd)
RZ_API RzCmdDesc * rz_cmd_desc_inner_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help)
RZ_API void rz_cmd_batch_start(RzCmd *cmd)
Mark the start of the batched changes to RzCmd.
RZ_API char * rz_cmd_macro_label_process(RzCmdMacro *mac, RzCmdMacroLabel *labels, int *labels_n, char *ptr)
static RzOutputMode cd_suffix2mode(RzCmdDesc *cd, const char *cmdid)
RZ_API RzCmdStatus rz_cmd_call_parsed_args(RzCmd *cmd, RzCmdParsedArgs *args)
RZ_API RzCmdDesc * rz_cmd_desc_group_modes_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
Create a new command descriptor for a name that is used both as a group but that has a sub-command wi...
RZ_API int rz_cmd_set_data(RzCmd *cmd, void *data)
static int macro_call(RzCmdMacro *mac, const char *name, bool multiple)
RZ_API char * rz_cmd_get_help(RzCmd *cmd, RzCmdParsedArgs *args, bool use_color)
RZ_API RzCmdDesc * rz_cmd_desc_argv_modes_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvModesCb cb, const RzCmdDescHelp *help)
Create a new command descriptor for a command that supports multiple output modes (e....
RZ_API void rz_cmd_macro_meta(RzCmdMacro *mac)
RZ_API RzCmd * rz_cmd_new(bool has_cons)
RZ_API int rz_cmd_macro_break(RzCmdMacro *mac, const char *value)
RZ_API int rz_cmd_macro_rm(RzCmdMacro *mac, const char *_name)
RZ_API RzCmdDesc * rz_cmd_desc_group_state_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
Create a new command descriptor for a name that is used both as a group but that has a sub-command wi...
static void get_minmax_argc(RzCmdDesc *cd, int *min_argc, int *max_argc)
static RzCmdStatus int2cmdstatus(int v)
RZ_API const RzCmdDescArg * rz_cmd_desc_get_arg(RzCmd *cmd, const RzCmdDesc *cd, size_t i)
Get a reference to the i-th argument of a command descriptor.
static bool cmd_desc_set_parent(RzCmd *cmd, RzCmdDesc *cd, RzCmdDesc *parent)
RZ_API RzCmdMacroItem * rz_cmd_macro_item_new(void)
#define MAX_RIGHT_ALIGHNMENT
static bool has_cd_default_mode(RzCmdDesc *cd)
static size_t fill_children_chars(RzStrBuf *sb, const RzCmdDesc *cd)
static RzOutputMode get_cd_default_mode(RzCmdDesc *cd)
static const char * SPECIAL_CHARS_REGULAR
RZ_API RzCmdDesc * rz_cmd_desc_parent(RzCmdDesc *cd)
RZ_API RzCmdDesc * rz_cmd_get_desc_best(RzCmd *cmd, const char *cmd_identifier)
Retrieve the command descriptor that best matches the name cmd_identifier.
RZ_API void rz_cmd_parsed_args_free(RzCmdParsedArgs *a)
static void fill_wrapped_comment(RzCmd *cmd, RzStrBuf *sb, const char *comment, size_t columns, bool use_color)
static const char * SPECIAL_CHARS_PF
RZ_API RzCmdDesc * rz_cmd_desc_get_exec(RzCmdDesc *cd)
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
static void free_array(char **arr, int n)
static RzCmdStatus argv_call_cb(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *args)
static size_t calc_padding_len(const RzCmdDesc *cd, const char *name, bool show_children)
RZ_API char * rz_cmd_escape_arg(const char *arg, RzCmdEscape esc)
RZ_API bool rz_cmd_parsed_args_addarg(RzCmdParsedArgs *a, const char *arg)
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
static RzCmdDesc * argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, bool ht_insert)
static void parsed_args_iterateargs(RzCmdParsedArgs *a, RzStrBuf *sb)
static void fill_details_cb(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
static size_t fill_args(RzStrBuf *sb, const RzCmdDesc *cd)
static void fill_details_static(RzCmd *cmd, RzCmdDesc *cd, RzStrBuf *sb, bool use_color)
static void close_optionals(size_t *n_optionals, RzStrBuf *sb, size_t *len)
static void fill_usage_strbuf(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, bool use_color)
static void fill_colored_args(RzCmd *cmd, RzStrBuf *sb, const char *line, bool use_color, const char *reset_color)
static RzCmdDescDetail * get_cd_details_cb(RzCmd *cmd, RzCmdDesc *cd)
RZ_API void rz_cmd_alias_init(RzCmd *cmd)
static char * oldinput_get_help(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *a)
RZ_API RzCmdDesc * rz_cmd_desc_argv_state_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, int modes, RzCmdArgvStateCb cb, const RzCmdDescHelp *help)
Create a new command descriptor for a command that supports multiple output modes (e....
static RzOutputMode suffix2mode(const char *suffix)
RZ_API RzCmdParsedArgs * rz_cmd_parsed_args_new(const char *cmd, int n_args, char **args)
static void cmd_desc_unset_parent(RzCmdDesc *cd)
RZ_API void rz_cmd_macro_list(RzCmdMacro *mac)
RZ_API char ** rz_cmd_alias_keys(RzCmd *cmd, int *sz)
RZ_API RzCmdDesc * rz_cmd_desc_group_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help)
Create a new command descriptor for a name that is used both as a group but that has a sub-command wi...
static const struct argv_modes_t argv_modes[]
RZ_API void rz_cons_filter(void)
RZ_API int rz_cons_get_size(int *rows)
RZ_API RZ_OWN char * rz_cons_get_buffer_dup(void)
Return a newly allocated buffer containing what's currently in RzCons buffer.
RZ_API RzCons * rz_cons_singleton(void)
RZ_API void rz_cons_strcat(const char *str)
RZ_API void rz_cons_break_pop(void)
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
RZ_API int rz_cons_printf(const char *format,...)
RZ_API bool rz_cons_is_interactive(void)
RZ_API void rz_cons_flush(void)
RZ_API bool rz_cons_is_breaked(void)
RZ_API void rz_cons_println(const char *str)
RZ_API void rz_cons_set_flush(bool flush)
Set whether RzCons should flush content to screen or not.
RZ_API void rz_cons_pop(void)
RZ_API void rz_cons_push(void)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
unsigned char suffix[65536]
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static const char struct stat static buf struct stat static buf static vhangup int status
while(len< limit &&buf1[len]==buf2[len])++len
#define rz_warn_if_reached()
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
#define rz_return_val_if_reached(val)
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
bool(* RzCmdForeachNameCb)(RzCmd *cmd, const RzCmdDesc *desc, void *user)
RzCmdStatus(* RzCmdArgvModesCb)(RzCore *core, int argc, const char **argv, RzOutputMode mode)
@ RZ_CMD_ESCAPE_MULTI_ARG
The string should be escaped so that it appears as one or multiple arguments.
@ RZ_CMD_ESCAPE_SINGLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in '....'.
@ RZ_CMD_ESCAPE_PF_ARG
The string should be escaped so that it appears as one or multiple pf arguments.
@ RZ_CMD_ESCAPE_ONE_ARG
The string should be escaped so that it appears as one single argument.
@ RZ_CMD_ESCAPE_DOUBLE_QUOTED_ARG
The string should be escaped so that it can be wrapped in "....".
#define RZ_CMD_ARG_FLAG_ARRAY
int(* RzCmdCb)(void *user, const char *input)
enum rz_cmd_desc_type_t RzCmdDescType
@ RZ_CMD_DESC_TYPE_ARGV_STATE
@ RZ_CMD_DESC_TYPE_ARGV_MODES
@ RZ_CMD_DESC_TYPE_OLDINPUT
enum rz_cmd_status_t RzCmdStatus
enum rz_cmd_escape_t RzCmdEscape
#define RZ_CMD_ARG_FLAG_LAST
@ RZ_CMD_ARG_TYPE_FCN
Argument can be the name of an existing function.
@ RZ_CMD_ARG_TYPE_MACRO
Argument is the name of a pre-defined macro.
@ RZ_CMD_ARG_TYPE_CMD
Argument is an rizin command.
@ RZ_CMD_ARG_TYPE_STRING
Argument that can be an arbitrary string.
@ 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_OPTION
Argument is an option, prefixed with -. It is present or not. No argument.
@ RZ_CMD_ARG_TYPE_CHOICES
Argument can be one of the provided choices.
@ 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_FILE
Argument is a filename.
@ RZ_CMD_ARG_TYPE_ENV
Argument can be the name of an existing rizin variable.
@ 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...
RzCmdStatus(* RzCmdArgvCb)(RzCore *core, int argc, const char **argv)
@ 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_NONEXISTINGCMD
command does not exist
@ RZ_CMD_STATUS_INVALID
command could not be executed (e.g. shell level error, bad expression, etc.)
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
@ RZ_CMD_STATUS_EXIT
command handler asks to exit the prompt loop
#define RZ_CMD_ARG_FLAG_OPTION
RzCmdStatus(* RzCmdArgvStateCb)(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
void(* RzListFree)(void *ptr)
#define RZ_LOG_DEBUG(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API PJ * pj_ko(PJ *j, const char *k)
RZ_API PJ * pj_ka(PJ *j, const char *k)
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
RZ_API PJ * pj_end(PJ *j)
RZ_API const char * pj_string(PJ *pj)
RZ_API void pj_free(PJ *j)
RZ_API PJ * pj_s(PJ *j, const char *k)
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
#define RZ_STR_ISEMPTY(x)
RZ_API RzList * rz_str_wrap(char *str, size_t width)
RZ_API int rz_str_word_set0(char *str)
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
RZ_API const char * rz_str_word_get0(const char *str, int idx)
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API bool rz_strbuf_prepend(RzStrBuf *sb, const char *s)
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
RZ_API void rz_strbuf_free(RzStrBuf *sb)
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
RZ_API bool rz_strbuf_is_empty(RzStrBuf *sb)
RZ_API int rz_strbuf_length(RzStrBuf *sb)
RZ_API void rz_table_free(RzTable *t)
RZ_API bool rz_table_query(RzTable *t, const char *q)
RZ_API void rz_table_set_vcolumnsf(RzTable *t, const char *fmt, va_list ap)
Specify the types and names of the referenced table.
RZ_API char * rz_table_tostring(RzTable *t)
RZ_API RzTable * rz_table_new(void)
RzOutputMode
Enum to describe the way data are printed.
@ RZ_OUTPUT_MODE_LONG_JSON
@ RZ_OUTPUT_MODE_QUIETEST
@ RZ_OUTPUT_MODE_STANDARD
RZ_API void rz_pvector_sort(RzPVector *vec, RzPVectorComparator cmp)
RZ_API void rz_pvector_remove_data(RzPVector *vec, void *x)
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
void(* RzPVectorFree)(void *e)
static void ** rz_pvector_push(RzPVector *vec, void *x)
RZ_API void rz_pvector_clear(RzPVector *vec)
const char * summary_suffix
A detailed entry that can be used to show additional info about a command entry.
const RzCmdDescDetailEntry * entries
const RzCmdDescHelp * help
struct rz_cmd_desc_t::@262::@267 argv_state_data
union rz_cmd_desc_t::@262 d
struct rz_cmd_desc_t::@262::@264 argv_data
struct rz_cmd_desc_t::@262::@265 group_data
struct rz_cmd_desc_t::@262::@263 oldinput_data
struct rz_cmd_desc_t::@262::@266 argv_modes_data
Represent the output state of a command handler.
RzConsPrintablePalette pal
#define V(handle, symbol)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)