tree-sitter: support iter commands (#16111) ##core

* radare2-shell-parser: shrink to single-command output when substituing

Before this patch, when substituing arguments the entire input string
was considered, making the process potentially slow if the input was
long. With this patch, substitute_args and parse_args work on a shrinked
version of the input, which includes only the current command.

Not only it improves performance, but it also prevents issues where
other non-related parts of the input string could be replaced during
apply_edits.

* radare2-shell-parser: implement some iter commands
* Add support for number_command and recursive help
* cmd_ignbithints should be set everywhere for consistency
* Save rnum->value before doing a cmd substitution
* Update radare2-shell-parser to fix null deref in html_disable_command
This commit is contained in:
Riccardo Schirone 2020-03-03 12:42:38 +01:00 committed by GitHub
parent b82b24c135
commit d88a76d2df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 655 additions and 154 deletions

View File

@ -120,6 +120,16 @@ R_API bool r_anal_bb_op_starts_at(RAnalBlock *bb, ut64 addr) {
return false;
}
// returns the size of the i-th instruction in a basic block
R_API ut64 r_anal_bb_size_i(RAnalBlock *bb, int i) {
if (i < 0 || i >= bb->ninstr) {
return UT64_MAX;
}
ut16 idx_cur = r_anal_bb_offset_inst (bb, i);
ut16 idx_next = r_anal_bb_offset_inst (bb, i + 1);
return idx_next != UT16_MAX? idx_next - idx_cur: bb->size - idx_cur;
}
/* returns the address of the basic block that contains addr or UT64_MAX if
* there is no such basic block */
R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr) {

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
// mark with HANDLER_RULE_OP every rule that is a _command
// mark with RULE_OP every rule that you use with DEFINE_IS_TS_FCN or with its TSSymbol (e.g. ts_##name##_symbol)
HANDLER_RULE_OP (number_command)
HANDLER_RULE_OP (commands)
HANDLER_RULE_OP (arged_command)
HANDLER_RULE_OP (legacy_quoted_command)
@ -23,6 +24,19 @@ HANDLER_RULE_OP (tmp_string_command)
HANDLER_RULE_OP (tmp_hex_command)
HANDLER_RULE_OP (last_command)
HANDLER_RULE_OP (grep_command)
HANDLER_RULE_OP (iter_flags_command)
HANDLER_RULE_OP (iter_dbta_command)
HANDLER_RULE_OP (iter_dbtb_command)
HANDLER_RULE_OP (iter_dbts_command)
HANDLER_RULE_OP (iter_file_lines_command)
HANDLER_RULE_OP (iter_offsets_command)
HANDLER_RULE_OP (iter_sdbquery_command)
HANDLER_RULE_OP (iter_threads_command)
HANDLER_RULE_OP (iter_bbs_command)
HANDLER_RULE_OP (iter_instrs_command)
HANDLER_RULE_OP (iter_functions_command)
HANDLER_RULE_OP (iter_step_command)
HANDLER_RULE_OP (iter_interpret_command)
HANDLER_RULE_OP (html_disable_command)
HANDLER_RULE_OP (html_enable_command)
HANDLER_RULE_OP (pipe_command)

View File

@ -1468,6 +1468,7 @@ R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i);
R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i);
R_API ut64 r_anal_bb_opaddr_at(RAnalBlock *bb, ut64 addr);
R_API bool r_anal_bb_op_starts_at(RAnalBlock *bb, ut64 addr);
R_API ut64 r_anal_bb_size_i(RAnalBlock *bb, int i);
/* op.c */
R_API const char *r_anal_stackop_tostring(int s);

View File

@ -34,7 +34,7 @@ TS_TIP=f049ba350f3f6019ce9a1cbb0975ebd154ef7ad3
# NOTE: when you update SHELLPARSER_TIP or SHELLPARSER_BRA, also update them in shlr/meson.build
SHELLPARSER_URL=https://github.com/ret2libc/radare2-shell-parser.git
SHELLPARSER_BRA=master
SHELLPARSER_TIP=34034bdc8ee34592c507ea6943c66234e48762de
SHELLPARSER_TIP=d83db3c86214f6c3d3187dddb990e0b847888c9b
ifeq ($(CS_RELEASE),1)
CS_VER=4.0.1

View File

@ -295,7 +295,7 @@ if get_option('use_treesitter')
endif
# NOTE: when you update SHELLPARSER_TIP or SHELLPARSER_BRA, also update them in shlr/Makefile
SHELLPARSER_TIP = '34034bdc8ee34592c507ea6943c66234e48762de'
SHELLPARSER_TIP = 'd83db3c86214f6c3d3187dddb990e0b847888c9b'
SHELLPARSER_BRA = 'master'
shell_parser_user = 'ret2libc'

View File

@ -1,7 +1,7 @@
NAME=t/bug_backtick
FILE=-
BROKEN=1
EXPECT=<<EOF
000000
EOF
CMDS=<<EOF
p8 3`~`

View File

@ -1654,7 +1654,7 @@ ahb 16 @ 0x5c20
0000:5c20 31ed xor bp, bp
aha arm @ 0x5c20
ahb 16 @ 0x5c20
0x00005c20 31ed xor bp, bp
0x00005c20 31ed xor ebp, ebp
aha arm @ 0x5c20
ahb 16 @ 0x5c20
EOF

View File

@ -1216,7 +1216,7 @@ aeip
13aes
*ebp+0x8 = 0x09
aesu 0x460
ps @ ebp - 0x24
ps @ ebp-0x24
EOF
RUN

View File

@ -31,7 +31,7 @@ RUN
NAME=ELF: .plt/.plt.sec sections
FILE=../bins/elf/ls-cet
CMDS=<<EOF
pdi 10 @ main + 0x28
pdi 10 @ main+0x28
EOF
EXPECT=<<EOF
0x00004e98 31c0 xor eax, eax

View File

@ -34,7 +34,7 @@ EXPECT=<<EOF
<Test + 'static as foo::Bar<Test>>::bar
EOF
CMDS=<<EOF
!rabin2 -D rust _ZN71_\$LT\$Test\$u20\$\$u2b\$\$u20\$\$u27\$static\$u20\$as\$u20\$foo..Bar\$LT\$Test\$GT\$\$GT\$3barE
!rabin2 -D rust "_ZN71_\$LT\$Test\$u20\$\$u2b\$\$u20\$\$u27\$static\$u20\$as\$u20\$foo..Bar\$LT\$Test\$GT\$\$GT\$3barE"
EOF
RUN

View File

@ -292,7 +292,7 @@ RUN
NAME=C string "\x33\x44\x88"
FILE=-
CMDS=echo "main(){const char *foo = "\x33\x44\x88"; }" | rax2 -F
CMDS=echo 'main(){const char *foo = "\x33\x44\x88"; }' | rax2 -F
EXPECT=<<EOF
334488
EOF