Skip to content

Commit fb9796e

Browse files
authored
Remove the deprecated double-quote raw call ##shell
1 parent 2862fd5 commit fb9796e

4 files changed

Lines changed: 68 additions & 86 deletions

File tree

libr/core/cmd.c

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,9 @@ static RCoreHelpMessage help_msg_l = {
155155

156156
static RCoreHelpMessage help_msg_quote = {
157157
"Usage:", "\"[\"..|..\"]", "quote the command to avoid evaluating special characters",
158-
"\"?", "", "show this help, NOTE that a single quote is simpler and works the same",
158+
"\"?", "", "show this help",
159159
"\"", "?e hello \\\"world\\\"\"", "print (hello \"world\")",
160160
"\"", "?e x;y\";\"?e y;x\"", "run two commands (prints x;y\ny;x)",
161-
"\"\"", "[cmd]", "directly call a command ignoring all special chars (fast)",
162-
"\"\"@addr\"\"", "[cmd]", "call a command with a temporal seek (EXPERIMENTAL)",
163-
"\"\"?e x;y\";\"?e y;x", "", "run two commands ignoring special chars (prints x;y\";\"?e y;x) ",
164161
NULL
165162
};
166163

@@ -3933,67 +3930,45 @@ static char *find_ch_after_macro(char *ptr, char ch) {
39333930
}
39343931

39353932
static int handle_command_call(RCore *core, const char *cmd) {
3936-
const char cmd0 = *cmd;
3937-
if (cmd0 != '\'' && cmd0 != '"') {
3933+
if (*cmd != '\'') {
39383934
return -1;
39393935
}
3940-
if (R_UNLIKELY (*cmd == '\'')) {
3941-
bool isaddr = cmd[1] == '@';
3942-
if (!strcmp (cmd, "'?")) {
3943-
r_core_cmd_help (core, help_msg_single_quote);
3944-
return true;
3945-
}
3946-
if (isaddr) {
3947-
cmd += 2;
3936+
bool isaddr = cmd[1] == '@';
3937+
if (!strcmp (cmd, "'?")) {
3938+
r_core_cmd_help (core, help_msg_single_quote);
3939+
return true;
3940+
}
3941+
if (isaddr) {
3942+
cmd += 2;
3943+
} else {
3944+
cmd++;
3945+
}
3946+
if (isaddr || r_str_startswith (cmd, "0x")) {
3947+
int res = 1;
3948+
char *arg = strdup (cmd);
3949+
char *end = strstr (arg, "'");
3950+
if (end) {
3951+
*end = 0;
3952+
cmd = end + 1;
3953+
ut64 addr = core->addr;
3954+
ut64 at = r_num_math (core->num, arg);
3955+
r_core_seek (core, at, true);
3956+
res = r_core_call (core, cmd);
3957+
r_core_seek (core, addr, true);
3958+
free (arg);
39483959
} else {
3949-
cmd++;
3950-
}
3951-
if (isaddr || r_str_startswith (cmd, "0x")) {
3952-
int res = 1;
3953-
char *arg = strdup (cmd);
3954-
char *end = strstr (arg, "'");
3955-
if (end) {
3956-
*end = 0;
3957-
cmd = end + 1;
3958-
ut64 addr = core->addr;
3959-
ut64 at = r_num_math (core->num, arg);
3960-
r_core_seek (core, at, true);
3961-
res = r_core_call (core, cmd);
3962-
r_core_seek (core, addr, true);
3963-
free (arg);
3964-
} else {
3965-
R_LOG_ERROR ("Invalid syntax, expected \"'@addr'command\"");
3966-
free (arg);
3967-
}
3968-
return res;
3960+
R_LOG_ERROR ("Invalid syntax, expected \"'@addr'command\"");
3961+
free (arg);
39693962
}
3970-
return r_core_call (core, cmd);
3963+
return res;
39713964
}
3972-
if (R_UNLIKELY (r_str_startswith (cmd, "\"\""))) {
3973-
R_LOG_DEBUG ("The double quote syntax is now deprecated, use the single quote instead");
3974-
// R2_600 - deprecate "" -> use ' <---------- discuss!
3975-
if (cmd[2] == '@') {
3976-
int res = 1;
3977-
char *arg = strdup (cmd + 2);
3978-
char *end = strstr (arg, "\"\"");
3979-
if (!end) {
3980-
R_LOG_ERROR ("Invalid syntax, expected \"\"@addr\"\"command");
3981-
free (arg);
3982-
} else {
3983-
*end = 0;
3984-
cmd = end + 2;
3985-
ut64 addr = core->addr;
3986-
ut64 at = r_num_math (core->num, arg + 1);
3987-
r_core_seek (core, at, true);
3988-
res = r_core_call (core, cmd);
3989-
r_core_seek (core, addr, true);
3990-
free (arg);
3991-
}
3992-
return res;
3993-
}
3994-
return r_core_call (core, cmd + 2);
3965+
return r_core_call (core, cmd);
3966+
}
3967+
3968+
static void remove_leading_empty_quotes(char *cmd) {
3969+
while (r_str_startswith (cmd, "\"\"")) {
3970+
memmove (cmd, cmd + 2, strlen (cmd + 2) + 1);
39953971
}
3996-
return -1;
39973972
}
39983973

39993974
static int r_core_cmd_subst(RCore *core, char *cmd) {
@@ -4009,9 +3984,6 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
40093984
return res;
40103985
}
40113986
if (R_UNLIKELY (r_str_startswith (cmd, "?t"))) {
4012-
if (r_str_startswith (cmd + 2, "\"\"")) {
4013-
return r_core_callf (core, "?t'%s", cmd + 4);
4014-
}
40153987
if (r_str_startswith (cmd + 2, "'")) {
40163988
return r_core_callf (core, "?t'%s", cmd + 3);
40173989
}
@@ -4047,6 +4019,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
40474019
}
40484020
cmd = (char *)r_str_trim_head_ro (icmd);
40494021
r_str_trim_tail (cmd);
4022+
remove_leading_empty_quotes (cmd);
40504023
rep = isdigit ((ut8)*cmd)? strtoull (cmd, NULL, 10): 0;
40514024
R_CRITICAL_LEAVE (core);
40524025
// lines starting with # are ignored (never reach cmd_hash()), except #! and #?
@@ -4571,6 +4544,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
45714544
return 0;
45724545
}
45734546
r_str_trim (cmd);
4547+
remove_leading_empty_quotes (cmd);
45744548

45754549
R_CRITICAL_LEAVE (core);
45764550
/* quoted / raw command */

test/db/cmd/cmd_fnj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fj~{} > $fj
77
$fj~__throw_length_error_char_const_
88
fnj~{} > $fnj
99
$fnj~__throw_length_error_char_const_
10-
""js a=r2.cmdj("fj").filter((x)=>x.name.indexOf("throw") !== -1);console.log(JSON.stringify(a,null, 2))
10+
'js a=r2.cmdj("fj").filter((x)=>x.name.indexOf("throw") !== -1);console.log(JSON.stringify(a,null, 2))
1111
EOF
1212
EXPECT=<<EOF
1313
"name": "sym.imp.std::__throw_length_error_char_const_",

test/db/cmd/cmd_js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NAME=qjs async test
2121
BROKEN=1
2222
FILE=-
2323
CMDS=<<EOF
24-
""js import("r2pipe").then((r2pipe)=> {console.log(r2pipe.open());}).catch(console.error);
24+
'js import("r2pipe").then((r2pipe)=> {console.log(r2pipe.open());}).catch(console.error);
2525
EOF
2626
EXPECT=<<EOF
2727
[object Object]
@@ -34,26 +34,26 @@ FILE=-
3434
CMDS=<<EOF
3535
Lc~qjs?
3636
?e
37-
""js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
37+
'js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
3838
Lc~qjs
3939
?e
40-
""js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
40+
'js (function() { function examplePlugin() { function coreCall(input) { if (input.startsWith("t1")) { console.log("This is a QJS test"); return true; } return false; } return { name: "qjs-example", desc: "Example QJS plugin (type 't1') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example", r2.plugin("core", examplePlugin)); })();
4141
Lc~qjs
4242
?e
43-
""js (function() { function examplePlugin2() { function coreCall(input) { if (input.startsWith("t2")) { console.log("This is another QJS test"); return true; } return false; } return { name: "qjs-example2", desc: "Example QJS plugin (type 't2') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example2", r2.plugin("core", examplePlugin2)); })();
43+
'js (function() { function examplePlugin2() { function coreCall(input) { if (input.startsWith("t2")) { console.log("This is another QJS test"); return true; } return false; } return { name: "qjs-example2", desc: "Example QJS plugin (type 't2') in the r2 shell", call: coreCall, }; }; console.log("load qjs-example2", r2.plugin("core", examplePlugin2)); })();
4444
Lc~qjs
4545
t1
4646
t2
47-
""js console.log("unload unknown", r2.unload("core", "unknownPlugin"))
47+
'js console.log("unload unknown", r2.unload("core", "unknownPlugin"))
4848
Lc~qjs
4949
?e
50-
""js console.log("unload qjs-example", r2.unload("core", "qjs-example"))
50+
'js console.log("unload qjs-example", r2.unload("core", "qjs-example"))
5151
Lc~qjs
5252
?e
53-
""js console.log("unload qjs-example again", r2.unload("core", "qjs-example"))
53+
'js console.log("unload qjs-example again", r2.unload("core", "qjs-example"))
5454
Lc~qjs
5555
?e
56-
""js console.log("unload qjs-example2", r2.unload("core", "qjs-example2"))
56+
'js console.log("unload qjs-example2", r2.unload("core", "qjs-example2"))
5757
?e
5858
Lc~qjs?
5959
EOF
@@ -96,25 +96,25 @@ FILE=-
9696
CMDS=<<EOF
9797
LA~qjs?
9898
?e
99-
""js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1', r2.plugin("arch", archPlugin)); })()
99+
'js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1', r2.plugin("arch", archPlugin)); })()
100100
LA~qjs
101101
?e
102-
""js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1 again', r2.plugin("arch", archPlugin)); })()
102+
'js (function() { function archPlugin() { return { name: "myarch qjs plugin", arch: "myarch_qjs", desc: "this is a test arch", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin1 again', r2.plugin("arch", archPlugin)); })()
103103
LA~qjs
104104
?e
105-
""js (function() { function archPlugin2() { return { name: "myarch qjs plugin2", arch: "myarch_qjs2", desc: "this is a test arch2", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin2', r2.plugin("arch", archPlugin2)); })()
105+
'js (function() { function archPlugin2() { return { name: "myarch qjs plugin2", arch: "myarch_qjs2", desc: "this is a test arch2", license: "LGPL3", decode: function(op) { op.mnemonic = "nop"; return true; } } }; console.log('load plugin2', r2.plugin("arch", archPlugin2)); })()
106106
LA~qjs
107107
?e
108-
""js console.log("unload unknown", r2.unload("arch", "unknownPlugin"))
108+
'js console.log("unload unknown", r2.unload("arch", "unknownPlugin"))
109109
LA~qjs
110110
?e
111-
""js console.log("unload qjs-example", r2.unload("arch", "myarch_qjs"))
111+
'js console.log("unload qjs-example", r2.unload("arch", "myarch_qjs"))
112112
LA~qjs
113113
?e
114-
""js console.log("unload qjs-example again", r2.unload("arch", "myarch_qjs"))
114+
'js console.log("unload qjs-example again", r2.unload("arch", "myarch_qjs"))
115115
LA~qjs
116116
?e
117-
""js console.log("unload qjs-example2", r2.unload("arch", "myarch_qjs2"))
117+
'js console.log("unload qjs-example2", r2.unload("arch", "myarch_qjs2"))
118118
?e
119119
LA~qjs?
120120
EOF

test/db/cmd/shell

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,24 @@ EXPECT=<<EOF
136136
EOF
137137
RUN
138138

139-
NAME=quote + quoteseek
139+
NAME=empty leading double quotes use normal parser
140140
FILE=malloc://32
141141
CMDS=<<EOF
142-
woe 1
143-
""p8 8
144-
""@16""p8 8
142+
""?e ONE;?e TWO
143+
""?e $(?e THREE)
144+
""""?e FOUR
145+
3""?e REPEAT
146+
""?e "FIVE;SIX"
145147
EOF
146148
EXPECT=<<EOF
147-
0001020304050607
148-
1011121314151617
149+
ONE
150+
TWO
151+
THREE
152+
FOUR
153+
REPEAT
154+
REPEAT
155+
REPEAT
156+
FIVE;SIX
149157
EOF
150158
RUN
151159

@@ -192,10 +200,10 @@ EXPECT=<<EOF
192200
EOF
193201
RUN
194202

195-
NAME=nested escaped or with double quote
203+
NAME=nested escaped or after empty double quotes
196204
FILE=malloc://32
197205
CMDS=<<EOF
198-
?v 4 \| `""?v 1 | 2`
206+
?v 4 \| `""?v 1 \| 2`
199207
EOF
200208
EXPECT=<<EOF
201209
0x7

0 commit comments

Comments
 (0)