Add test for 'q' return code bug and minor cleanup r2r ##tests

This commit is contained in:
pancake 2022-05-26 12:41:49 +02:00 committed by GitHub
parent 597496e17a
commit 93d9860f41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 139 additions and 132 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2021 - pancake */
/* radare - LGPL - Copyright 2009-2022 - pancake */
#include <r_main.h>
#include <r_util.h>

View File

@ -1041,7 +1041,7 @@ static int cmd_rap_run(void *data, const char *input) {
if (res) {
int ret = atoi (res);
free (res);
r_core_return_code (core, ret);
r_core_return_value (core, ret);
return ret;
}
return false;
@ -1055,7 +1055,7 @@ static int cmd_yank(void *data, const char *input) {
r_core_yank (core, core->offset, r_num_math (core->num, input + 1));
break;
case 'l': // "yl"
r_core_return_code (core, r_buf_size (core->yank_buf));
r_core_return_value (core, r_buf_size (core->yank_buf));
break;
case 'y': // "yy"
while (input[1] == ' ') {
@ -1961,9 +1961,9 @@ static int cmd_interpret(void *data, const char *input) {
} else {
if (!r_core_run_script (core, script_file)) {
eprintf ("Cannot find script '%s'\n", script_file);
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
} else {
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
}
}
}
@ -2382,7 +2382,8 @@ static bool cmd_r2cmd(RCore *core, const char *_input) {
return false;
}
free (input);
r_core_return_code (core, rc);
r_core_return_value (core, rc);
// r_core_return_code (core, rc);
return true;
}
@ -3749,7 +3750,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
free (res);
}
}
r_core_return_code (core, value);
r_core_return_value (core, value);
r_list_free (tmpenvs);
return 0;
} else { // "|"
@ -3985,7 +3986,7 @@ next2:
}
str = r_str_append (str, ptr2 + 1);
cmd = r_str_append (strdup (cmd), str);
r_core_return_code (core, value);
r_core_return_value (core, value);
ret = r_core_cmd_subst (core, cmd);
free (cmd);
if (scr_html != -1) {
@ -4530,7 +4531,7 @@ fuji:
rc = 0;
}
if (rc == 1) {
r_core_return_code (core, rc);
r_core_return_value (core, rc);
}
beach:
if (grep) {

View File

@ -5322,7 +5322,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL);
if (rf) {
int o = r_reg_cond_bits (core->dbg->reg, id, rf);
r_core_return_code (core, o);
r_core_return_value (core, o);
// ORLY?
r_cons_printf ("%d\n", o);
free (rf);
@ -7685,10 +7685,10 @@ static void cmd_anal_esil(RCore *core, const char *input, bool verbose) {
char *str2 = r_str_newf (" %s", str);
cmd_anal_esil (core, str2, false);
free (str2);
r_core_return_code (core, 1);
r_core_return_value (core, 1);
} else {
// fail to exevute, update code
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
r_anal_op_fini (&aop);
} else if (input[1] == 'a') { // "aexa"

View File

@ -1434,9 +1434,9 @@ static int cmd_cmp(void *data, const char *input) {
ut8 n = (ut8) r_num_math (core->num, input + 2);
if (block[0] == n) {
r_cons_printf ("0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
break;
}
@ -1444,9 +1444,9 @@ static int cmd_cmp(void *data, const char *input) {
ut16 n = (ut16) r_num_math (core->num, input + 2);
if (core->blocksize >= 2 && *(ut16*)block == n) {
r_cons_printf ("0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
break;
}
@ -1454,9 +1454,9 @@ static int cmd_cmp(void *data, const char *input) {
ut32 n = (ut32) r_num_math (core->num, input + 2);
if (core->blocksize >= 4 && *(ut32*)block == n) {
r_cons_printf ("0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
break;
}
@ -1464,14 +1464,14 @@ static int cmd_cmp(void *data, const char *input) {
ut64 n = (ut64) r_num_math (core->num, input + 2);
if (core->blocksize >= 8 && *(ut64*)block == n) {
r_cons_printf ("0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
break;
}
default:
r_core_return_code (core, 1);
r_core_return_value (core, 1);
// fallthrough
case '?':
eprintf ("Usage: cv[1248] [num]\n"
@ -1504,7 +1504,7 @@ static int cmd_cmp(void *data, const char *input) {
ut8 buf[8] = {0};
r_io_read_at (core->io, at, buf, sizeof (buf));
int val = memcmp (buf, core->block, sz)? 1: 0;
r_core_return_code (core, val);
r_core_return_value (core, val);
}
break;
}
@ -1526,7 +1526,7 @@ static int cmd_cmp(void *data, const char *input) {
char **argv = r_str_argv (r_str_trim_head_ro (input + 2), &argc);
if (argc == 2) {
int res = cmd_cmp_posix (core, argv[0], argv[1]);
r_core_return_code (core, res);
r_core_return_value (core, res);
} else {
r_core_cmd_help (core, help_msg_cmp);
}
@ -1538,7 +1538,7 @@ static int cmd_cmp(void *data, const char *input) {
break;
}
if (val != UT64_MAX) {
r_core_return_code (core, val);
r_core_return_value (core, val);
}
return 0;
}

View File

@ -2092,10 +2092,10 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp"
char *r2profile = r_reg_parse_gdb_profile (ptr);
if (r2profile) {
r_cons_println (r2profile);
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
free (r2profile);
} else {
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
eprintf ("Warning: Cannot parse gdb profile.\n");
}
} else {
@ -2562,7 +2562,7 @@ static void cmd_debug_reg(RCore *core, const char *str) {
RRegFlags* rf = r_reg_cond_retrieve (core->dbg->reg, NULL);
if (rf) {
int o = r_reg_cond_bits (core->dbg->reg, id, rf);
r_core_return_code (core, o);
r_core_return_value (core, o);
// orly?
r_cons_printf ("%d\n", o);
free (rf);
@ -5624,7 +5624,7 @@ static int cmd_debug(void *data, const char *input) {
}
break;
case ':': // "d:"
r_core_return_code (core,
r_core_return_value (core,
r_debug_cmd (core->dbg, input + 1)
? R_CMD_RC_FAILURE
: R_CMD_RC_SUCCESS);

View File

@ -1718,7 +1718,7 @@ rep:
if (input[1]) {
const char *arg = r_str_trim_head_ro (input + 1);
RFlagItem *fi = r_flag_get (core->flags, arg);
r_core_return_code (core, fi? 1:0);
r_core_return_value (core, fi? 1:0);
} else {
r_core_cmd_help (core, help_msg_f);
break;

View File

@ -585,7 +585,7 @@ static int cmd_help(void *data, const char *input) {
r_prof_start (&prof);
r_core_cmd (core, input + 1, 0);
r_prof_end (&prof);
r_core_return_code (core, (ut64)(int)prof.result);
r_core_return_value (core, (ut64)(int)prof.result);
eprintf ("%lf\n", prof.result);
break;
}
@ -619,7 +619,7 @@ static int cmd_help(void *data, const char *input) {
r = UT32_MAX >> 1;
}
ut64 n = (ut64)b + r_num_rand (r);
r_core_return_code (core, n);
r_core_return_value (core, n);
r_cons_printf ("0x%"PFMT64x"\n", n);
}
break;
@ -824,7 +824,7 @@ static int cmd_help(void *data, const char *input) {
} else {
n = r_num_math (core->num, "$?");
}
r_core_return_code (core, n); // redundant
r_core_return_value (core, n);
}
break;
case 'v': // "?v"
@ -881,7 +881,7 @@ static int cmd_help(void *data, const char *input) {
default:
r_cons_printf ("0x%"PFMT64x"\n", n);
}
r_core_return_code (core, n); // redundant
r_core_return_value (core, n); // redundant
break;
case '=': // "?=" set num->value
if (input[1] == '=') { // ?==
@ -893,7 +893,7 @@ static int cmd_help(void *data, const char *input) {
*e++ = 0;
e = (char *)r_str_trim_head_ro (e);
int val = strcmp (s, e);
r_core_return_code (core, val);
r_core_return_value (core, val);
} else {
eprintf ("Missing secondary word in expression to compare\n");
}
@ -937,7 +937,7 @@ static int cmd_help(void *data, const char *input) {
return 0;
}
int cmdres = r_core_cmd (core, input + 1, 0);
r_core_return_code (core, cmdres);
r_core_return_value (core, cmdres);
return cmdres;
}
} else {
@ -1045,10 +1045,10 @@ static int cmd_help(void *data, const char *input) {
case 'l': // "?l"
if (input[1] == 'q') {
for (input += 2; input[0] == ' '; input++);
r_core_return_code (core, strlen (input));
r_core_return_value (core, strlen (input));
} else {
for (input++; input[0] == ' '; input++);
r_core_return_code (core, strlen (input));
r_core_return_value (core, strlen (input));
r_cons_printf ("%" PFMT64d "\n", core->num->value);
}
break;
@ -1301,25 +1301,25 @@ static int cmd_help(void *data, const char *input) {
} else {
switch (input[1]) {
case 'f': // "?if"
r_core_return_code (core, !r_num_conditional (core->num, input + 2));
r_core_return_value (core, !r_num_conditional (core->num, input + 2));
eprintf ("%s\n", r_str_bool (!core->num->value));
break;
case 'm': // "?im"
r_cons_message (input + 2);
break;
case 'p': // "?ip"
r_core_return_code (core, r_core_yank_hud_path (core, input + 2, 0) == true);
r_core_return_value (core, r_core_yank_hud_path (core, input + 2, 0) == true);
break;
case 'k': // "?ik"
r_cons_any_key (NULL);
break;
case 'y': // "?iy"
for (input += 2; *input == ' '; input++);
r_core_return_code (core, r_cons_yesno (1, "%s? (Y/n)", input));
r_core_return_value (core, r_cons_yesno (1, "%s? (Y/n)", input));
break;
case 'n': // "?in"
for (input += 2; *input==' '; input++);
r_core_return_code (core, r_cons_yesno (0, "%s? (y/N)", input));
r_core_return_value (core, r_cons_yesno (0, "%s? (y/N)", input));
break;
default: {
char foo[1024];
@ -1331,7 +1331,7 @@ static int cmd_help(void *data, const char *input) {
r_cons_fgets (foo, sizeof (foo), 0, NULL);
foo[sizeof (foo) - 1] = 0;
r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, foo, strlen (foo) + 1);
r_core_return_code (core, r_num_math (core->num, foo));
r_core_return_value (core, r_num_math (core->num, foo));
}
break;
}
@ -1365,7 +1365,7 @@ static int cmd_help(void *data, const char *input) {
return 0;
} else if (input[1]) {
if (core->num->value) {
r_core_return_code (core, r_core_cmd (core, input + 1, 0));
r_core_return_value (core, r_core_cmd (core, input + 1, 0));
}
} else {
if (core->num->dbz) {
@ -1383,4 +1383,3 @@ static int cmd_help(void *data, const char *input) {
}
return 0;
}

View File

@ -75,13 +75,13 @@ static int cmd_macro(void *data, const char *_input) {
r_cmd_macro_call (&core->rcmd->macro, buf);
} else {
eprintf ("Invalid syntax for macro\n");
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
}
}
free (buf);
} break;
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
free (input);
return R_CMD_RC_SUCCESS;
}

View File

@ -35,18 +35,18 @@ static const char *help_msg_mf[] = {
static int cmd_mktemp(RCore *core, const char *input) {
char *res = r_syscmd_mktemp (input);
if (res) {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
r_cons_printf ("%s", res);
free (res);
} else {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
return 0;
}
static int cmd_mkdir(RCore *core, const char *input) {
int rc = r_syscmd_mkdir (input)? 0: 1;
r_core_return_code (core, rc);
r_core_return_value (core, rc);
return 0;
}

View File

@ -1330,7 +1330,7 @@ R_API void r_core_file_reopen_remote_debug(RCore *core, char *uri, ut64 addr) {
if ((file = r_core_file_open (core, uri, R_PERM_RW, addr))) {
fd = file->fd;
r_core_return_code (core, fd);
r_core_return_value (core, fd);
// if no baddr is defined, use the one provided by the file
if (addr == 0) {
desc = r_io_desc_get (core->io, file->fd);
@ -1738,7 +1738,7 @@ static int cmd_open(void *data, const char *input) {
eprintf ("Cannot open file '%s'\n", ptr);
}
r_str_argv_free (argv);
r_core_return_code (core, fd);
r_core_return_value (core, fd);
r_core_block_read (core);
return 0;
// XXX projects use the of command, but i think we should deprecate it... keeping it for now
@ -1755,7 +1755,7 @@ static int cmd_open(void *data, const char *input) {
perms = r_str_rwx (argv[1]);
}
fd = r_io_fd_open (core->io, argv[0], perms, 0);
r_core_return_code (core, fd);
r_core_return_value (core, fd);
r_str_argv_free (argv);
} else {
eprintf ("Usage: of [arg...]\n");
@ -1831,7 +1831,7 @@ static int cmd_open(void *data, const char *input) {
const char *argv0 = argv ? argv[0] : ptr;
if ((file = r_core_file_open (core, argv0, perms, addr))) {
fd = file->fd;
r_core_return_code (core, fd);
r_core_return_value (core, fd);
if (addr == 0) { // if no baddr defined, use the one provided by the file
addr = UT64_MAX;
}
@ -1984,7 +1984,7 @@ static int cmd_open(void *data, const char *input) {
r_io_read_at (core->io, core->offset, data, len);
if ((file = r_core_file_open (core, uri, R_PERM_RWX, 0))) {
fd = file->fd;
r_core_return_code (core, fd);
r_core_return_value (core, fd);
r_core_bin_load (core, uri, 0);
RIODesc *desc = r_io_desc_get (core->io, fd);
if (desc) {

View File

@ -4389,7 +4389,7 @@ static void cmd_print_bars(RCore *core, const char *input) {
if (core->print->cur_enabled) {
if (i == core->print->cur) {
r_cons_printf ("> ");
r_core_return_code (core, off);
r_core_return_value (core, off);
} else {
r_cons_printf (" ");
}
@ -5372,7 +5372,7 @@ static bool cmd_pi(RCore *core, const char *input, int len, int l, ut8 *block) {
func_walk_blocks (core, f, input[2], 'I', input[2] == '.');
} else {
eprintf ("Cannot find function at 0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
}
break;
@ -5383,7 +5383,7 @@ static bool cmd_pi(RCore *core, const char *input, int len, int l, ut8 *block) {
r_core_print_disasm_instructions (core, b->size - (core->offset - b->addr), 0);
} else {
eprintf ("Cannot find function at 0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
}
break;
@ -5617,7 +5617,7 @@ static void cmd_psa(RCore *core, const char *_) {
}
}
RCmdReturnCode rc = found? R_CMD_RC_SUCCESS: R_CMD_RC_FAILURE;
r_core_return_code (core, rc);
r_core_return_value (core, rc);
}
static int cmd_print(void *data, const char *input) {
@ -5647,15 +5647,15 @@ static int cmd_print(void *data, const char *input) {
if (*arg) {
halp = false;
if (r_syscmd_pushd (arg)) {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
}
}
if (halp) {
eprintf ("Usage: pushd [dir]\n");
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
return 0;
}
@ -5664,16 +5664,16 @@ static int cmd_print(void *data, const char *input) {
bool halp = strstr (input, "-h");
if (halp) {
eprintf ("Usage: popd [-a]\n");
r_core_return_code (core, 1);
r_core_return_value (core, 1);
} else {
bool suc = all
? r_syscmd_popalld ()
: r_syscmd_popd ();
if (suc) {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
eprintf ("Cannot popd\n");
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
}
return 0;
@ -5763,12 +5763,12 @@ static int cmd_print(void *data, const char *input) {
}
} else {
eprintf ("p: Cannot find function at 0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
goto beach;
}
}
// TODO figure out why `f eax=33; f test=eax; pa call test` misassembles if len is 0
r_core_return_code (core, len ? len : core->blocksize);
r_core_return_value (core, len ? len : core->blocksize);
if (off != UT64_MAX) {
r_core_seek (core, off, SEEK_SET);
r_core_block_read (core);
@ -6281,14 +6281,14 @@ static int cmd_print(void *data, const char *input) {
core, b->addr, block,
b->size, b->size, 0, NULL, true,
input[2] == 'J', NULL, NULL);
r_core_return_code (core, dislen);
r_core_return_value (core, dislen);
}
free (block);
pd_result = 0;
}
} else {
eprintf ("Cannot find function at 0x%08"PFMT64x "\n", core->offset);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
}
break;
@ -6375,7 +6375,7 @@ static int cmd_print(void *data, const char *input) {
if (buf) {
(void)r_io_read_at (core->io, at, buf, sz);
int dislen = r_core_print_disasm (core, at, buf, sz, sz, 0, NULL, true, false, NULL, f);
r_core_return_code (core, dislen);
r_core_return_value (core, dislen);
free (buf);
// r_core_cmdf (core, "pD %d @ 0x%08" PFMT64x, f->_size > 0 ? f->_size: r_anal_function_realsize (f), f->addr);
}
@ -6384,7 +6384,7 @@ static int cmd_print(void *data, const char *input) {
} else {
eprintf ("pdf: Cannot find function at 0x%08"PFMT64x "\n", core->offset);
processed_cmd = true;
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
if (bsz != core->blocksize) {
r_core_block_size (core, bsz);
@ -6491,7 +6491,7 @@ static int cmd_print(void *data, const char *input) {
}
r_io_read_at (core->io, addr - l, block1, l); // core->blocksize);
int dislen = r_core_print_disasm (core, addr - l, block1, l, l, 0, NULL, true, formatted_json, NULL, NULL);
r_core_return_code (core, dislen);
r_core_return_value (core, dislen);
} else { // pd
int instr_len;
if (!r_core_prevop_addr (core, core->offset, l, &start)) {
@ -6522,7 +6522,7 @@ static int cmd_print(void *data, const char *input) {
R_MAX (bs, bs1), l, 0, NULL,
false, formatted_json, NULL,
NULL);
r_core_return_code (core, dislen);
r_core_return_value (core, dislen);
r_core_seek (core, prevaddr, true);
}
}
@ -6541,7 +6541,7 @@ static int cmd_print(void *data, const char *input) {
addr, block1, addrbytes * l, l,
0, NULL, true, formatted_json,
NULL, NULL);
r_core_return_code (core, dislen);
r_core_return_value (core, dislen);
} else {
eprintf ("Cannot allocate %" PFMT64d " byte(s)\n", addrbytes * l);
}

View File

@ -45,14 +45,12 @@ static int cmd_quit(void *data, const char *input) {
case '!': // "q!"
return cmd_Quit (core, input);
case '\0': // "q"
r_core_return_code (core, R_CMD_RC_QUIT);
r_core_return_code (core, 0);
return R_CMD_RC_QUIT;
default:
while (*input == ' ') {
input++;
}
input = r_str_trim_head_ro (input);
if (*input) {
r_num_math (core->num, input);
r_core_return_code (core, r_num_math (core->num, input));
} else {
core->num->value = 0LL;
r_core_return_code (core, 0);

View File

@ -2623,7 +2623,7 @@ static void do_string_search(RCore *core, RInterval search_itv, struct search_pa
}
print_search_progress (at, to1, search->nhits, param);
r_cons_clear_line (1);
r_core_return_code (core, search->nhits);
r_core_return_value (core, search->nhits);
if (param->outmode != R_MODE_JSON) {
eprintf ("hits: %" PFMT64d "\n", search->nhits - saved_nhits);
}
@ -3705,10 +3705,10 @@ reread:
}
}
free (hashValue);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
} else {
eprintf ("Cannot allocate memory.\n");
r_core_return_code (core, 1);
r_core_return_value (core, 1);
}
} else {
eprintf ("Usage: /cc [hashname] [hexpairhashvalue]\n");
@ -4089,7 +4089,7 @@ reread:
}
if (input[param_offset - 1] != ' ') {
eprintf ("Missing ' ' after /i\n");
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
goto beach;
}
ignorecase = true;
@ -4231,7 +4231,7 @@ reread:
st64 coff = core->offset;
RInterval itv = {core->offset, -coff};
if (!r_itv_overlap (search_itv, itv)) {
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
goto beach;
} else {
search_itv = r_itv_intersect (search_itv, itv);
@ -4435,9 +4435,9 @@ again:
}
beach:
if (errcode != -1) {
r_core_return_code (core, errcode);
r_core_return_value (core, errcode);
} else {
r_core_return_code (core, search->nhits);
r_core_return_value (core, search->nhits);
}
core->in_search = false;
r_flag_space_pop (core->flags);

View File

@ -343,7 +343,7 @@ static void cmd_seek_opcode(RCore *core, const char *input) {
int val = (n < 0)
? cmd_seek_opcode_backward (core, -n)
: cmd_seek_opcode_forward (core, n);
r_core_return_code (core, val);
r_core_return_value (core, val);
}
static int cmd_seek(void *data, const char *input) {
@ -796,7 +796,7 @@ static int cmd_seek(void *data, const char *input) {
char *arg = r_str_trim_dup (input + 1);
if (R_STR_ISNOTEMPTY (arg)) {
int rc = r_sys_tem (arg);
r_core_return_code (core, (rc > 0)? rc: 1);
r_core_return_value (core, (rc > 0)? rc: 1);
} else {
if (r_config_get_b (core->config, "scr.interactive")) {
// open shell
@ -807,7 +807,7 @@ static int cmd_seek(void *data, const char *input) {
break;
}
int rc = r_sys_tem (line);
r_core_return_code (core, (rc > 0)? rc: 1);
r_core_return_value (core, (rc > 0)? rc: 1);
}
} else {
R_LOG_WARN ("enable scr.interactive to use this new shell prompt");

View File

@ -191,7 +191,7 @@ static const char *help_msg_wx[] = {
static void cmd_write_fail(RCore *core) {
R_LOG_ERROR ("Cannot write. Check `omp` or reopen the file with `oo+`");
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
}
R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
@ -208,10 +208,10 @@ R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
buf[len - 1] |= core->block[len - 1] & 0xf;
}
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
if (!r_core_write_at (core, core->offset, buf, len)) {
cmd_write_fail (core);
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
}
// call WSEEK for consistency?
if (r_config_get_b (core->config, "cfg.wseek")) {
@ -220,7 +220,7 @@ R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
r_core_block_read (core);
} else {
R_LOG_ERROR ("Error: invalid hexpair string");
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
}
free (buf);
return len;
@ -450,7 +450,7 @@ static int cmd_wo(void *data, const char *input) {
} else if (input[2] == ' ') {
value = r_num_get (core->num, input + 3);
int offset = r_debruijn_offset (value, r_config_get_i (core->config, "cfg.bigendian"));
r_core_return_code (core, offset);
r_core_return_value (core, offset);
r_cons_printf ("%"PFMT64d"\n", core->num->value);
}
break;
@ -496,7 +496,7 @@ static void cmd_write_value(RCore *core, const char *input) {
ut8 buf[sizeof(ut64)];
bool be = r_config_get_i (core->config, "cfg.bigendian");
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
switch (input[0]) {
case '?': // "wv?"
@ -1412,7 +1412,7 @@ static int cmd_w(RCore *core, const char *input) {
free (str);
WSEEK (core, len);
r_core_block_read (core);
r_core_return_code (core, len);
r_core_return_value (core, len);
return 0;
}
@ -1424,13 +1424,13 @@ static int cmd_wz(RCore *core, const char *input) {
if (*input == '?' || *input != ' ' || len < 1) {
free (str);
r_core_cmd_help_match (core, help_msg_w, "wz", true);
r_core_return_code (core, 0);
r_core_return_value (core, 0);
return 0;
}
if (!r_core_write_at (core, core->offset, (const ut8 *)str, len)) {
cmd_write_fail (core);
}
r_core_return_code (core, len);
r_core_return_value (core, len);
WSEEK (core, len + 1);
r_core_block_read (core);
free (str);
@ -1706,9 +1706,9 @@ static int cmd_wx(void *data, const char *input) {
if (!r_io_write_at (core->io, core->offset, out, len)) {
eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset);
}
r_core_return_code (core, len);
r_core_return_value (core, len);
} else {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
free (out);
}
@ -1718,7 +1718,7 @@ static int cmd_wx(void *data, const char *input) {
if ((buf = r_file_slurp_hexpairs (arg, &size))) {
r_io_use_fd (core->io, core->io->desc->fd);
if (r_io_write_at (core->io, core->offset, buf, size) > 0) {
r_core_return_code (core, size);
r_core_return_value (core, size);
WSEEK (core, size);
} else {
eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset);
@ -1740,9 +1740,9 @@ static int cmd_wx(void *data, const char *input) {
int len = cmd_write_hexpair (core, input + 1);
if (len > 0) {
r_core_seek_delta (core, len);
r_core_return_code (core, len);
r_core_return_value (core, len);
} else {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
}
}
break;
@ -2161,7 +2161,7 @@ static int cmd_write(void *data, const char *input) {
ut64 addr = core->offset;
if (R_STR_ISEMPTY (curcs)) {
r_core_return_code (core, 0);
r_core_return_value (core, 0);
cmd_w (core, str + 1);
addr += core->num->value;
} else {

View File

@ -3457,7 +3457,7 @@ R_API int r_core_prompt(RCore *r, int sync) {
if (r->scr_gadgets && *line && *line != 'q') {
r_core_cmd0 (r, "pg");
}
r->num->value = r->rc;
// r->num->value = r->rc;
return true;
}
@ -3477,11 +3477,9 @@ R_API int r_core_prompt_exec(RCore *r) {
r_core_cmd_queue (r, NULL);
break;
}
r->rc = r->num->value;
// int ret = r_core_cmd (r, cmd, true);
if (r->cons && r->cons->context->use_tts) {
const char *buf = r_cons_get_buffer ();
if (buf && *buf) {
if (R_STR_ISNOTEMPTY (buf)) {
r_sys_tts (buf, true);
}
r->cons->context->use_tts = false;

View File

@ -84,14 +84,14 @@ R_API bool r_core_is_project(RCore *core, const char *name) {
}
R_API void r_core_project_cat(RCore *core, const char *name) {
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
char *path = get_project_script_path (core, name);
if (path) {
char *data = r_file_slurp (path, NULL);
if (data) {
r_cons_println (data);
free (data);
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
}
free (path);
}

View File

@ -801,7 +801,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
return;
}
// eprintf ("Connected to: 'http://%s:%s'\n", host, port);
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
free (str);
}
break;
@ -817,32 +817,32 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
break;
case RTR_PROTOCOL_UNIX:
if (!r_socket_connect_unix (fd, host)) {
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
eprintf ("Error: Cannot connect to 'unix://%s'\n", host);
r_socket_free (fd);
return;
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
eprintf ("Connected to: 'unix://%s'\n", host);
break;
case RTR_PROTOCOL_TCP:
if (!r_socket_connect_tcp (fd, host, port, timeout)) { //TODO: Use rap.ssl
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
eprintf ("Error: Cannot connect to '%s' (%s)\n", host, port);
r_socket_free (fd);
return;
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
eprintf ("Connected to: %s at port %s\n", host, port);
break;
case RTR_PROTOCOL_UDP:
if (!r_socket_connect_udp (fd, host, port, timeout)) { //TODO: Use rap.ssl
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
eprintf ("Error: Cannot connect to '%s' (%s)\n", host, port);
r_socket_free (fd);
return;
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
eprintf ("Connected to: %s at port %s\n", host, port);
break;
}
@ -862,7 +862,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
rtr_n = i;
break;
}
r_core_return_code (core, ret);
r_core_return_value (core, ret);
// double free wtf is freed this here? r_socket_free(fd);
//r_core_rtr_list (core);
}
@ -1026,7 +1026,7 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) {
if (!rtr_host[rtr_n].fd) {
eprintf ("Error: Unknown host\n");
r_core_return_code (core, R_CMD_RC_FAILURE);
r_core_return_value (core, R_CMD_RC_FAILURE);
return;
}
@ -1072,7 +1072,7 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) {
eprintf ("Cannot find '%s'\n", uri);
return;
}
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
str[len] = 0;
r_cons_print (str);
free ((void *)str);
@ -1081,7 +1081,7 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) {
}
if (rtr_host[rtr_n].proto == RTR_PROTOCOL_RAP) {
r_core_return_code (core, R_CMD_RC_SUCCESS);
r_core_return_value (core, R_CMD_RC_SUCCESS);
cmd = r_str_trim_head_ro (cmd);
RSocket *fh = rtr_host[rtr_n].fd;
if (!strlen (cmd)) {

View File

@ -406,7 +406,8 @@ typedef int RCmdReturnCode;
#define R_CMD_RC_SUCCESS 0
#define R_CMD_RC_QUIT -2
#define R_CMD_RC_FASTQUIT -1
#define r_core_return_code(core, val) (core)->num->value = (val)
#define r_core_return_value(core, val) (core)->num->value = (val)
#define r_core_return_code(core, val) (core)->rc = (val)
R_API RList *r_core_list_themes(RCore *core);
R_API char *r_core_get_theme(RCore *core);

View File

@ -270,7 +270,6 @@ static bool run_commands(RCore *r, RList *cmds, RList *files, bool quiet, int do
RListIter *iter;
const char *cmdn;
const char *file;
int ret;
/* -i */
bool has_failed = false;
r_list_foreach (files, iter, file) {
@ -278,7 +277,7 @@ static bool run_commands(RCore *r, RList *cmds, RList *files, bool quiet, int do
eprintf ("Script '%s' not found.\n", file);
goto beach;
}
ret = r_core_run_script (r, file);
int ret = r_core_run_script (r, file);
r_cons_flush ();
if (ret == -2) {
eprintf ("[c] Cannot open '%s'\n", file);
@ -305,7 +304,7 @@ beach:
return true;
}
}
return false;
return has_failed;
}
static bool mustSaveHistory(RConfig *c) {
@ -1491,14 +1490,15 @@ R_API int r_main_radare2(int argc, const char **argv) {
r_list_free (evals);
r_list_free (files);
cmds = evals = files = NULL;
if (forcequit) {
ret = 1;
}
if (ret) {
ret = 0;
if (forcequit || quietLeak) {
ret = r->rc;
goto beach;
}
if (r_config_get_i (r->config, "scr.prompt")) {
if (ret) {
ret = r->rc;
goto beach;
}
if (r_config_get_b (r->config, "scr.prompt")) {
if (run_rc && r_config_get_i (r->config, "cfg.fortunes")) {
r_core_fortune_print_random (r);
r_cons_flush ();
@ -1621,7 +1621,7 @@ R_API int r_main_radare2(int argc, const char **argv) {
ret = r->num->value;
beach:
if (quietLeak) {
exit (ret);
exit (r->rc);
return ret;
}

View File

@ -53,6 +53,16 @@ yara: bins
clean:
rm -rf tmp
rc:
echo q | r2 -c '?V' -
echo q12 | r2 -c '?V' - ; if [ $$? = 12 ]; then echo "Test q12" OK ; exit 0 ; else exit 1 ; fi
echo q2 | r2 - ; if [ $$? = 2 ]; then echo "Test - q2 OK" ; exit 0 ; else exit 1 ; fi
echo q2 | r2 -cq - ; if [ $$? = 2 ]; then echo "Test -cq q2 OK" ; exit 0 ; else exit 1 ; fi
r2 -qcq2 - ; if [ $$? = 2 ]; then echo "Test q2 OK" ; exit 0 ; else exit 1 ; fi
r2 -qcq -
r2 -qqcq -
echo q2 | r2 -qqcq - # input is ignored
symstall:
install:
@ -60,7 +70,7 @@ install:
uninstall:
unit unit_tests: bins
$(MAKE) -C unit
$(MAKE) rc
$(MAKE) -C unit run
.PHONY: all clean unit install uninstall r2r-tests fuzz-tests keystone swf dwarf yara