?%? must be the same as %? Fix #10866 (#10894)

This commit is contained in:
Maijin 2018-08-02 13:18:48 +02:00 committed by GitHub
parent 20cacc39a0
commit 096d5eed00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 53 deletions

View File

@ -108,14 +108,6 @@ static const char *help_msg_dollar[] = {
NULL
};
static const char *help_msg_percent[] = {
"Usage:", "%[name[=value]]", "Set each NAME to VALUE in the environment",
"%", "", "list all environment variables",
"%", "SHELL", "prints SHELL value",
"%", "TMPDIR=/tmp", "sets TMPDIR value to \"/tmp\"",
NULL
};
static const char *help_msg_star[] = {
"Usage:", "*<addr>[=[0x]value]", "Pointer read/write data/values",
"*", "entry0=cc", "write trap in entrypoint",
@ -1448,7 +1440,7 @@ static int cmd_env(void *data, const char *input) {
int ret = true;
switch (*input) {
case '?':
r_core_cmd_help (core, help_msg_percent);
cmd_help_percent (core);
break;
default:
ret = r_core_cmdf (core, "env %s", input);
@ -1615,7 +1607,7 @@ static int cmd_system(void *data, const char *input) {
if (input[1] == '!') { // !!! & !!!-
cmd_autocomplete (core, input + 2);
} else if (input[1] == '?') {
r_core_sysenv_help (core);
cmd_help_exclamation (core);
} else {
if (r_sandbox_enable (0)) {
eprintf ("This command is disabled in sandbox mode\n");
@ -1642,7 +1634,7 @@ static int cmd_system(void *data, const char *input) {
r_line_hist_list ();
break;
case '?': //!?
r_core_sysenv_help (core);
cmd_help_exclamation (core);
break;
default:
n = atoi (input);

View File

@ -20,6 +20,55 @@ static ut32 vernum(const char *s) {
return res;
}
static const char *help_msg_percent[] = {
"Usage:", "%[name[=value]]", "Set each NAME to VALUE in the environment",
"%", "", "list all environment variables",
"%", "SHELL", "prints SHELL value",
"%", "TMPDIR=/tmp", "sets TMPDIR value to \"/tmp\"",
NULL
};
// NOTE: probably not all environment vars takes sesnse
// because they can be replaced by commands in the given
// command.. we should only expose the most essential and
// unidirectional ones.
static const char *help_msg_env[] = {
"\nEnvironment:", "", "",
"R2_FILE", "", "file name",
"R2_OFFSET", "", "10base offset 64bit value",
"R2_BYTES", "", "TODO: variable with bytes in curblock",
"R2_XOFFSET", "", "same as above, but in 16 base",
"R2_BSIZE", "", "block size",
"R2_ENDIAN", "", "'big' or 'little'",
"R2_IOVA", "", "is io.va true? virtual addressing (1,0)",
"R2_DEBUG", "", "debug mode enabled? (1,0)",
"R2_BLOCK", "", "TODO: dump current block to tmp file",
"R2_SIZE", "","file size",
"R2_ARCH", "", "value of asm.arch",
"R2_BITS", "", "arch reg size (8, 16, 32, 64)",
"RABIN2_LANG", "", "assume this lang to demangle",
"RABIN2_DEMANGLE", "", "demangle or not",
"RABIN2_PDBSERVER", "", "e pdb.server",
NULL
};
static const char *help_msg_exclamation[] = {
"Usage:", "!<cmd>", " Run given command as in system(3)",
"!", "", "list all historic commands",
"!", "ls", "execute 'ls' in shell",
"!!", "", "save command history to hist file",
"!!", "ls~txt", "print output of 'ls' and grep for 'txt'",
"!!!", "cmd [args|$type]", "adds the autocomplete value",
"!!!-", "cmd [args]", "removes the autocomplete value",
".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd",
"!", "echo $SIZE", "display file size",
"!-", "", "clear history in current session",
"!-*", "", "clear and save empty history log",
"!=!", "", "enable remotecmd mode",
"=!=", "", "disable remotecmd mode",
NULL
};
static const char *help_msg_root[] = {
"%var", "=value", "alias for 'env' command",
"*", "[?] off[=[0x]value]", "pointer read/write data/values (see ?v, wx, wv)",
@ -180,6 +229,16 @@ static const char *help_msg_greater_sign[] = {
NULL
};
static void cmd_help_exclamation(RCore *core) {
r_core_cmd_help (core, help_msg_exclamation);
r_core_cmd_help (core, help_msg_env);
}
static void cmd_help_percent(RCore *core) {
r_core_cmd_help (core, help_msg_percent);
r_core_cmd_help (core, help_msg_env);
}
static void cmd_help_init(RCore *core) {
DEFINE_CMD_DESCRIPTOR_SPECIAL (core, ?, question);
DEFINE_CMD_DESCRIPTOR_SPECIAL (core, ?v, question_v);
@ -623,7 +682,7 @@ static int cmd_help(void *data, const char *input) {
if (input[1]) {
if (!core->num->value) {
if (input[1] == '?') {
r_core_sysenv_help (core);
cmd_help_exclamation (core);
return 0;
} else {
return core->num->value = r_core_cmd (core, input+1, 0);
@ -647,6 +706,11 @@ static int cmd_help(void *data, const char *input) {
case '&': // "?&"
helpCmdTasks (core);
break;
case '%': // "?%"
if (input[1] == '?') {
cmd_help_percent (core);
}
break;
case '$': // "?$"
if (input[1] == '?') {
r_core_cmd_help (core, help_msg_question_v);

View File

@ -160,46 +160,6 @@ R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbi
return ret;
}
// NOTE: probably not all environment vars takes sesnse
// because they can be replaced by commands in the given
// command.. we should only expose the most essential and
// unidirectional ones.
R_API void r_core_sysenv_help(const RCore *core) {
const char *help_msg[] = {
"Usage:", "!<cmd>", " Run given command as in system(3)",
"!", "", "list all historic commands",
"!", "ls", "execute 'ls' in shell",
"!!", "", "save command history to hist file",
"!!", "ls~txt", "print output of 'ls' and grep for 'txt'",
"!!!", "cmd [args|$type]", "adds the autocomplete value",
"!!!-", "cmd [args]", "removes the autocomplete value",
".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd",
"!", "echo $SIZE", "display file size",
"!-", "", "clear history in current session",
"!-*", "", "clear and save empty history log",
"!=!", "", "enable remotecmd mode",
"=!=", "", "disable remotecmd mode",
"\nEnvironment:", "", "",
"R2_FILE", "", "file name",
"R2_OFFSET", "", "10base offset 64bit value",
"R2_BYTES", "", "TODO: variable with bytes in curblock",
"R2_XOFFSET", "", "same as above, but in 16 base",
"R2_BSIZE", "", "block size",
"R2_ENDIAN", "", "'big' or 'little'",
"R2_IOVA", "", "is io.va true? virtual addressing (1,0)",
"R2_DEBUG", "", "debug mode enabled? (1,0)",
"R2_BLOCK", "", "TODO: dump current block to tmp file",
"R2_SIZE", "","file size",
"R2_ARCH", "", "value of asm.arch",
"R2_BITS", "", "arch reg size (8, 16, 32, 64)",
"RABIN2_LANG", "", "assume this lang to demangle",
"RABIN2_DEMANGLE", "", "demangle or not",
"RABIN2_PDBSERVER", "", "e pdb.server",
NULL
};
r_core_cmd_help (core, help_msg);
}
R_API void r_core_sysenv_end(RCore *core, const char *cmd) {
// TODO: remove tmpfilez
if (strstr (cmd, "R2_BLOCK")) {

View File

@ -556,7 +556,6 @@ R_API char *r_core_project_notes_file (RCore *core, const char *file);
R_API char *r_core_sysenv_begin(RCore *core, const char *cmd);
R_API void r_core_sysenv_end(RCore *core, const char *cmd);
R_API void r_core_sysenv_help(const RCore* core);
R_API void r_core_recover_vars(RCore *core, RAnalFunction *fcn, bool argonly);
/* bin.c */