75 size_t fake_len = strlen(fake_text);
80 tmp[
buf->length + fake_len] =
'\0';
108 if (!strncmp(
desc->name, u->
s, u->
len)) {
124 const char *stmts[] = {
171 for (stmt = stmts; *stmt; stmt++) {
172 if (!strncmp(*stmt,
s,
len)) {
183 for (
i = 1;
i <=
bits;
i <<= 1) {
202 rz_list_foreach (asm_plugins, it, plugin) {
203 if (!strncmp(plugin->
name,
s,
len)) {
211 rz_list_foreach (asm_plugins, it, plugin) {
212 if (!strncmp(plugin->
name,
s, delim -
s)) {
230 rz_flag_space_foreach(core->
flags, it, space) {
231 if (!strncmp(space->
name,
s,
len)) {
246 rz_list_foreach (
regs, it, regitem) {
247 if (!strncmp(regitem->
name,
s,
len)) {
263 const char *fmt =
".%s%s";
265 if (strchr(
input,
':')) {
311 const char *
eq = strchr(*
env,
'=');
313 if (!strncmp(envkey,
s,
len)) {
324 char *
p = item->
name;
325 if (!strncmp(
p,
s,
len)) {
335 rz_list_foreach (
list,
iter, item) {
336 char *flag = item->
name;
337 if (!strncmp(flag,
s,
len)) {
366 rz_list_foreach (
list,
iter, item) {
367 if (!strncmp(item,
s,
len)) {
378 rz_list_foreach (
list,
iter, item) {
379 if (!strncmp(item,
s,
len)) {
390 rz_list_foreach (
list,
iter, item) {
391 if (!strncmp(item,
s,
len)) {
402 rz_list_foreach (
list,
iter, item) {
403 if (!strncmp(item,
s,
len)) {
414 rz_list_foreach (
list,
iter, item) {
415 if (!strncmp(item,
s,
len)) {
426 rz_list_foreach (
list,
iter, glob) {
436 bool is_analysis =
cd->name &&
cd->name[0] ==
'a';
459 if (!
reg->name[role]) {
472 rz_list_foreach (
reg->allregs,
iter, ri) {
489 if (!strncmp(*vars,
s,
len)) {
497 return ch ==
'+' || ch ==
'-' || ch ==
'*' || ch ==
'/' || ch ==
'%' ||
498 ch ==
'>' || ch ==
'<';
507 for (
p =
s, plen =
len; *
p && plen > 0;
p++, plen--) {
522 oc =
c =
arg->choices_cb ?
arg->choices_cb(core) : (
char **)
arg->choices;
523 for (
c = oc;
c && *
c;
c++) {
524 if (!strncmp(*
c,
s,
len)) {
528 if (
arg->choices_cb) {
529 for (
c = oc;
c && *
c;
c++) {
571 if (!strncmp(opt,
v,
len)) {
576 if (!strncmp(
"true",
v,
len)) {
579 if (!strncmp(
"false",
v,
len)) {
597 rz_list_foreach (vars,
iter, var) {
606 return !strcmp(
type,
"concatenation") || !strcmp(
type,
"arg") ||
607 !strcmp(
type,
"args") || !strcmp(
type,
"arg_identifier") ||
608 !strcmp(
type,
"double_quoted_arg") || !strcmp(
type,
"single_quoted_arg");
614 char *cmdid =
rz_str_ndup(data + command_start, command_end - command_start);
624 const char *parent_type;
634 if (strcmp(parent_type,
"arged_stmt")) {
640 if (strcmp(node_type,
"cmd_identifier")) {
649 while (strcmp(arg_type,
"arg")) {
785 if (!strcmp(node_type,
"cmd_identifier")) {
817 if (
buf->index > 1 &&
buf->data[
buf->index - 1] ==
'@' &&
buf->data[
buf->index - 2] ==
'@') {
823 if (
buf->index > 2 &&
buf->data[
buf->index - 3] ==
'@') {
832 }
else if (
buf->index > 0 &&
buf->data[
buf->index - 1] ==
'@') {
847 char *start_iter =
buf->data +
buf->index;
848 char *
p = start_iter;
852 char *maximum_search =
buf->index > 4 ? start_iter - 4 : start_iter;
853 while (
p >
buf->data + 2 &&
p > maximum_search && !(*(
p - 1) ==
'@' && *(
p - 2) ==
'@') && *
p !=
' ') {
859 buf->index =
p -
buf->data + 1;
860 char last_char =
buf->data[
buf->index - 1];
861 buf->data[
buf->index - 1] =
'=';
863 buf->data[
buf->index - 1] = last_char;
874 buf->index =
p -
buf->data + 1;
875 char last_char =
buf->data[
buf->index - 1];
876 buf->data[
buf->index - 1] =
'd';
878 buf->data[
buf->index - 1] = last_char;
882 if (!strcmp(node_type,
"iter_dbta_stmt")) {
887 }
else if (
buf->index > 1 &&
buf->data[
buf->index - 2] ==
'@') {
913 if (!strcmp(node_type,
"arg_identifier") && !strcmp(parent_type, tmp_op)) {
972 if (lend >
buf->index) {
978 RZ_LOG_DEBUG(
"lstart = %d, lend = %d, type = %s\n", lstart, lend, root_type);
979 if (!strcmp(root_type,
"cmd_identifier") &&
buf->data[lend - 1] !=
' ') {
983 }
else if (!strcmp(root_type,
"arg_identifier")) {
985 }
else if (!strcmp(root_type,
"double_quoted_arg")) {
990 }
else if (!strcmp(root_type,
"single_quoted_arg")) {
1052 int n = strlen(
buf->data);
1057 size_t len = strlen(
buf->data);
1074 RZ_LOG_DEBUG(
"autocomplete_rzshell root = '%s'\n", root_string);
1075 RZ_LOG_DEBUG(
"autocomplete_rzshell node = '%s'\n", node_string);
const char * ts_node_type(TSNode)
void ts_parser_delete(TSParser *parser)
TSNode ts_node_named_child(TSNode, uint32_t)
uint32_t ts_node_start_byte(TSNode)
char * ts_node_string(TSNode)
uint32_t ts_node_named_child_count(TSNode)
bool ts_node_is_null(TSNode)
TSNode ts_node_prev_sibling(TSNode)
void ts_tree_delete(TSTree *self)
TSNode ts_tree_root_node(const TSTree *self)
bool ts_parser_set_language(TSParser *self, const TSLanguage *language)
bool ts_node_has_error(TSNode)
uint32_t ts_node_end_byte(TSNode)
TSParser * ts_parser_new(void)
TSNode ts_node_parent(TSNode)
TSTree * ts_parser_parse_string(TSParser *self, const TSTree *old_tree, const char *string, uint32_t length)
TSNode ts_node_named_descendant_for_byte_range(TSNode, uint32_t, uint32_t)
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
RZ_API RzList * rz_asm_get_plugins(RzAsm *a)
int bits(struct state *s, int need)
RZ_API char * rz_core_analysis_fcn_name(RzCore *core, RzAnalysisFunction *fcn)
static bool find_autocmplt_type_arg_identifier(struct autocmplt_data_t *ad, RzCore *core, TSNode root, RzLineBuffer *buf, ut32 lstart, ut32 lend)
static void autocmplt_cmd_arg(RzCore *core, RzLineNSCompletionResult *res, const RzCmdDesc *cd, size_t i_arg, const char *s, size_t len)
static bool fill_autocmplt_data(struct autocmplt_data_t *ad, enum autocmplt_type_t type, ut32 start, ut32 end)
static void autocmplt_flag_space(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static RzCmdDesc * get_cd_from_arg(RzCore *core, const char *data, TSNode arg)
static void autocmplt_bits(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
RZ_API RzLineNSCompletionResult * rz_core_autocomplete_rzshell(RzCore *core, RzLineBuffer *buf, RzLinePromptType prompt_type)
static void autocmplt_cmd_arg_eval_key(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_reg(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool find_autocmplt_type_at_stmt_op(struct autocmplt_data_t *ad, RzCore *core, RzLineBuffer *buf, const char *tmp_op, const char *newtext, enum autocmplt_type_t ad_type)
static struct guess_data_t * guess_next_autocmplt_token(RzCore *core, RzLineBuffer *buf, const char *fake_text, size_t offset)
static void autocmplt_cmd_arg_rznum(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_any_type(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
@ AUTOCMPLT_AT_STMT
A temporary modifier operator like @, @a:, @v: or a iter operator like @@., @@, @@i,...
@ AUTOCMPLT_FILE
A file needs to be autocompleted.
@ AUTOCMPLT_RZNUM
A expression that can be parsed by RzNum (e.g. "flag+3")
@ AUTOCMPLT_REG
A cpu register needs to be autocompleted.
@ AUTOCMPLT_BITS
A bits value supported by the currently selected architecture (e asm.bits=?)
@ AUTOCMPLT_FLAG
A flag item needs to be autocompleted.
@ AUTOCMPLT_FLAG_SPACE
A flag space needs to be autocompleted.
@ AUTOCMPLT_CMD_ARG
The argument of an arged_stmt (see grammar.js) needs to be autocompleted.
@ AUTOCMPLT_ARCH
An architecture supported by Rizin (e.g. x86, arm, etc.)
@ AUTOCMPLT_FUNCTION
A function name needs to be autocompleted.
@ AUTOCMPLT_UNKNOWN
Unknown, nothing will be autocompleted.
@ AUTOCMPLT_CMD_ID
A command identifier (aka command name) needs to be autocompleted.
@ AUTOCMPLT_EVAL_FULL
A name=value of a evaluable variable (e.g. e command)
static void autocmplt_cmd_arg_choices(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len, const RzCmdDescArg *arg)
static bool find_autocmplt_type(struct autocmplt_data_t *ad, RzCore *core, TSNode root, RzLineBuffer *buf)
Returns true and a properly filled ad when something to autocomplete was discovered.
static bool fill_autocmplt_data_cmdarg(struct autocmplt_data_t *ad, ut32 start, ut32 end, const char *s, TSNode node, RzCore *core)
static bool find_autocmplt_type_at_stmt(struct autocmplt_data_t *ad, RzCore *core, RzLineBuffer *buf)
static bool is_arg_identifier_in_tmp_stmt(TSNode node)
static void autocmplt_cmd_arg_enum_type(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool fill_autocmplt_data_at_stmt(struct autocmplt_data_t *ad, ut32 start, ut32 end)
static RzCmdDesc * get_cd_from_cmdid(RzCore *core, const char *data, TSNode cmd_id)
static bool fill_autocmplt_data_cmdid(struct autocmplt_data_t *ad, ut32 start, ut32 end)
static void autocmplt_cmd_arg_macro(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool find_autocmplt_type_quoted_arg(struct autocmplt_data_t *ad, RzCore *core, RzLineBuffer *buf, const char *quote, const char *quote_node_type)
static void autocmplt_arch(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool is_op_ch(char ch)
static void autocmplt_at_stmt(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static TSNode get_arg_parent(TSNode node)
static void autocmplt_cmd_arg_help_var(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool is_arg_type(const char *type)
static void autocmplt_cmd_arg_env(RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_reg_type(RzCore *core, const RzCmdDesc *cd, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_fcn(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_fcn_var(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmdidentifier(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_global_var(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static size_t get_arg_number(TSNode arg)
static void autocmplt_cmd_arg_reg_filter(RzCore *core, const RzCmdDesc *cd, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool find_autocmplt_type_newcmd_or_arg(struct autocmplt_data_t *ad, RzCore *core, RzLineBuffer *buf)
static void autocmplt_cmd_arg_union_type(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool offset_prompt_add_flag(RzFlagItem *fi, void *user)
static void autocmplt_bits_plugin(RzAsmPlugin *plugin, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_struct_type(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static bool do_autocmplt_cmdidentifier(RzCmd *cmd, const RzCmdDesc *desc, void *user)
static void guess_data_free(struct guess_data_t *g)
static void autocmplt_cmd_arg_flag(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_alias_type(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_file(RzLineNSCompletionResult *res, const char *s, size_t len)
static void autocmplt_cmd_arg_eval_full(RzCore *core, RzLineNSCompletionResult *res, const char *s, size_t len)
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 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 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.
RZ_API RzCmdDesc * rz_cmd_desc_get_exec(RzCmdDesc *cd)
RZ_API const char ** rz_core_help_vars_get(RzCore *core)
Returns all the $ variable names in a NULL-terminated array.
RZ_API RZ_BORROW RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
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
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
RZ_API RzList * rz_flag_all_list(RzFlag *f, bool by_space)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
RZ_API RzLineNSCompletionResult * rz_line_ns_completion_result_new(size_t start, size_t end, const char *end_string)
RZ_API void rz_line_ns_completion_result_add(RzLineNSCompletionResult *res, const char *option)
RZ_API void rz_line_ns_completion_result_propose(RzLineNSCompletionResult *res, const char *option, const char *cur, size_t cur_len)
Add a new option to the list of possible autocomplete-able value if it matches the given string.
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")
RZ_API const char * rz_reg_get_type(int idx)
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
RZ_API const char * rz_reg_get_role(int role)
#define rz_return_if_fail(expr)
enum rz_cmd_arg_type_t RzCmdArgType
@ 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_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_STRUCT_TYPE
Argument is a C struct type name.
@ RZ_CMD_ARG_TYPE_ENUM_TYPE
Argument is a C enum type name.
@ RZ_CMD_ARG_TYPE_CHOICES
Argument can be one of the provided choices.
@ RZ_CMD_ARG_TYPE_RZNUM
Argument that can be interpreted by RzNum (numbers, flags, operations, etc.)
@ RZ_CMD_ARG_TYPE_REG_TYPE
Argument is a register type/arena like "gpr".
@ RZ_CMD_ARG_TYPE_ANY_TYPE
Argument is the any of the C or C++ type name.
@ RZ_CMD_ARG_TYPE_FLAG
Argument is a rizin flag.
@ 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_REG_FILTER
Argument is a register name, size, type or "all".
@ RZ_CMD_ARG_TYPE_FILE
Argument is a filename.
@ RZ_CMD_ARG_TYPE_GLOBAL_VAR
Argument is a user defined global variable.
@ RZ_CMD_ARG_TYPE_ENV
Argument can be the name of an existing rizin variable.
static bool rz_config_node_is_bool(RzConfigNode *node)
RZ_API const char * rz_file_basename(const char *path)
RZ_API bool rz_file_is_directory(const char *str)
RZ_API bool rz_file_is_abspath(const char *file)
RZ_API char * rz_file_dirname(const char *path)
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
#define RZ_LOG_DEBUG(fmtstr,...)
RZ_API RZ_OWN char * rz_path_home_expand(RZ_NULLABLE const char *path)
Return a new path with the ~ char expanded to the home directory.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
#define RZ_STR_ISEMPTY(x)
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
RZ_API const char * rz_sub_str_rchr(const char *str, int start, int end, char chr)
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 bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
RZ_API RzList * rz_sys_dir(const char *path)
RZ_API char ** rz_sys_get_environ(void)
RzLineNSCompletionResult * res
const RzCmdDesc * cd
Used if type is AUTOCMPLT_CMD_ARG to describe the related command.
size_t i_arg
Used if type is AUTOCMPLT_CMD_ARG to describe the argument that will be autocompleted.
RzLineNSCompletionResult * res
Result returned to RzCons API to provide possible suggestions.
enum autocmplt_type_t type
Type of token that will be autocompleted.
TSNode node
Node identified under the user position cursor when using the modified input.
char * input
Modified input.
TSTree * tree
Pointer to the syntax tree of the modified input.
TSParser * parser
Parser used to parser the modified input.
char * name
name of the variable
size_t start
First byte that was considered for autocompletion. Everything before this will be left intact.
const char * end_string
String to place after the only option available is autocompleted. By default a space is used.
size_t end
Last byte that was considered for autocompletion. Everything after this will be left intact.
RZ_API RZ_OWN RzList * rz_type_db_enum_names(RzTypeDB *typedb)
Returns the list of all enum names.
RZ_API RZ_OWN RzList * rz_type_db_union_names(RzTypeDB *typedb)
Returns the list of all union names.
RZ_API RZ_OWN RzList * rz_type_db_struct_names(RzTypeDB *typedb)
Returns the list of all struct names.
RZ_API RZ_OWN RzList * rz_type_db_all(RzTypeDB *typedb)
Returns the list of all type names.
RZ_API RZ_OWN RzList * rz_type_db_typedef_names(RzTypeDB *typedb)
Returns the list of all typedef (type aliases) names.
RZ_DEPRECATE RZ_API RzList * rz_analysis_var_all_list(RzAnalysis *analysis, RzAnalysisFunction *fcn)
RZ_API RZ_OWN RzList * rz_analysis_var_global_get_all(RzAnalysis *analysis)
Get all of the added global variables.
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)