Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove oldshell version of s commands #1895

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion librz/core/cmd/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6041,7 +6041,6 @@ RZ_API void rz_core_cmd_init(RzCore *core) {
{ "o", "open or map file", rz_cmd_open },
{ "p", "print current block", rz_cmd_print },
{ "q", "exit program session", rz_cmd_quit },
{ "s", "seek to an offset", rz_cmd_seek },
{ "V", "enter visual mode", rz_cmd_visual },
{ "v", "enter visual mode", rz_cmd_panels },
{ "w", "write bytes", rz_cmd_write },
Expand Down
364 changes: 0 additions & 364 deletions librz/core/cmd/cmd_seek.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,6 @@
#include "rz_debug.h"
#include "rz_io.h"

static const char *help_msg_s[] = {
"Usage: s", "", " # Help for the seek commands. See ?$? to see all variables",
"s", "", "Print current address",
"s.", "hexoff", "Seek honoring a base from core->offset",
"s:", "pad", "Print current address with N padded zeros (defaults to 8)",
"s", " addr", "Seek to address",
"s-", "", "Undo seek",
"s-*", "", "Reset undo seek history",
"s-", " n", "Seek n bytes backward",
"s--", "[n]", "Seek blocksize bytes backward (/=n)",
"s+", "", "Redo seek",
"s+", " n", "Seek n bytes forward",
"s++", "[n]", "Seek blocksize bytes forward (/=n)",
"s[j*=!]", "", "List undo seek history (JSON, =list, *rz, !=names, s==)",
"s/", " DATA", "Search for next occurrence of 'DATA'",
"s/x", " 9091", "Search for next occurrence of \\x90\\x91",
"sa", " [[+-]a] [asz]", "Seek asz (or bsize) aligned to addr",
"sb", "", "Seek aligned to bb start",
"sC", "[?] string", "Seek to comment matching given string",
"sf", "", "Seek to next function (f->addr+f->size)",
"sf", " function", "Seek to address of specified function",
"sf.", "", "Seek to the beginning of current function",
"sg/sG", "", "Seek begin (sg) or end (sG) of section or file",
"sn/sp", " ([nkey])", "Seek to next/prev location, as specified by scr.nkey",
"so", " [N]", "Seek to N next opcode(s)",
"sr", " pc", "Seek to register",
"ss", "", "Seek silently (without adding an entry to the seek history)",
// "sp [page] seek page N (page = block)",
NULL
};

static const char *help_msg_sC[] = {
"Usage:", "sC", "Comment grep",
"sC", "*", "List all comments",
"sC", " str", "Seek to the first comment matching 'str'",
NULL
};

static const char *help_msg_ss[] = {
"Usage: ss", "", " # Seek silently (not recorded in the seek history)",
"s?", "", "Works with all s subcommands",
NULL
};

static void printPadded(RzCore *core, int pad) {
if (pad < 1) {
pad = 8;
Expand Down Expand Up @@ -203,326 +159,6 @@ RZ_IPI int rz_seek_search(void *data, const char *input) {
return 0;
}

RZ_IPI int rz_cmd_seek(void *data, const char *input) {
RzCore *core = (RzCore *)data;
char *cmd, *p;
ut64 off = core->offset;

if (!*input) {
rz_cons_printf("0x%" PFMT64x "\n", core->offset);
return 0;
}
char *ptr;
if ((ptr = strstr(input, "+.")) != NULL) {
char *dup = strdup(input);
dup[ptr - input] = '\x00';
off = rz_num_math(core->num, dup + 1);
core->offset = off;
free(dup);
}
const char *inputnum = strchr(input, ' ');
if (rz_str_cmp(input, "ort", 3)) { // hack to handle Invalid Argument for sort
const char *u_num = inputnum ? inputnum + 1 : input + 1;
off = rz_num_math(core->num, u_num);
if (*u_num == '-') {
off = -(st64)off;
}
}
#if 1
// int sign = 1;
if (input[0] == ' ') {
switch (input[1]) {
case '-':
// sign = -1;
/* pass thru */
case '+':
input++;
break;
}
}
#endif
bool silent = false;
if (*input == 's') {
silent = true;
input++;
if (*input == '?') {
rz_core_cmd_help(core, help_msg_ss);
return 0;
}
}

switch (*input) {
case 'r': // "sr"
if (input[1] && input[2]) {
rz_core_seek_to_register(core, input + 2, silent);
} else {
eprintf("|Usage| 'sr PC' seek to program counter register\n");
}
break;
case 'C': // "sC"
if (input[1] == '*') { // "sC*"
rz_core_cmd0(core, "C*~^\"CC");
} else if (input[1] == ' ') {
RzIntervalTreeIter it;
RzAnalysisMetaItem *meta;
bool seeked = false;
rz_interval_tree_foreach (&core->analysis->meta, it, meta) {
if (meta->type == RZ_META_TYPE_COMMENT && !strcmp(meta->str, input + 2)) {
rz_core_seek_opt(core, off, true, !silent);
seeked = true;
break;
}
}
if (!seeked) {
eprintf("No matching comment.\n");
}
} else {
rz_core_cmd_help(core, help_msg_sC);
}
break;
case ' ': // "s "
{
ut64 addr = rz_num_math(core->num, input + 1);
if (core->num->nc.errors) {
if (rz_cons_singleton()->context->is_interactive) {
eprintf("Cannot seek to unknown address '%s'\n", core->num->nc.calc_buf);
}
break;
}
rz_core_seek_opt(core, addr, true, !silent);
} break;
case '/': // "s/"
rz_seek_search(core, input + 1);
break;
case '.': // "s." "s.."
for (input++; *input == '.'; input++) {
;
}
rz_core_seek_base(core, input, !silent);
break;
case 'j': // "sj"
case '*': // "s*"
case '=': // "s="
case '!': // "s!"
{
int mode = input[0];
RzList *list = rz_core_seek_list(core);
RzListIter *iter;
RzCoreSeekItem *undo;
PJ *pj = NULL;
if (mode == 'j') {
pj = pj_new();
pj_a(pj);
}
bool current_met = false;
rz_list_foreach (list, iter, undo) {
RzFlagItem *f = rz_flag_get_at(core->flags, undo->offset, true);
char *name = NULL;
if (f) {
if (f->offset != undo->offset) {
name = rz_str_newf("%s+%" PFMT64d, f->name, undo->offset - f->offset);
} else {
name = strdup(f->name);
}
}
current_met |= undo->is_current;
if (mode == 'j') {
pj_o(pj);
pj_kn(pj, "offset", undo->offset);
pj_kn(pj, "cursor", undo->cursor);
if (name) {
pj_ks(pj, "name", name);
}
pj_kb(pj, "current", undo->is_current);
pj_end(pj);
} else if (mode == '=') {
if (!name) {
name = rz_str_newf("0x%" PFMT64x, undo->offset);
}
const char *sep = "";
if (iter->n && current_met) {
sep = " < ";
} else if (iter->n) {
sep = " > ";
} else {
sep = "\n";
}
rz_cons_printf("%s%s", name, sep);
} else if (mode == '!') {
const char *comment = "";
if (undo->is_current) {
comment = " # current seek";
} else if (current_met) {
comment = " # redo";
}
rz_cons_printf("0x%" PFMT64x " %s%s\n", undo->offset, name ? name : "", comment);
} else if (mode == '*') {
if (undo->is_current) {
rz_cons_printf("# Current seek @ 0x%" PFMT64x "\n", undo->offset);
} else if (current_met) {
rz_cons_printf("f redo_%d @ 0x%" PFMT64x "\n", RZ_ABS(undo->idx - 1), undo->offset);
} else {
rz_cons_printf("f undo_%d @ 0x%" PFMT64x "\n", RZ_ABS(undo->idx + 1), undo->offset);
}
}
free(name);
}
if (mode == 'j') {
pj_end(pj);
char *s = pj_drain(pj);
rz_cons_printf("%s\n", s);
free(s);
}
break;
}
case '+': // "s+"
if (input[1] != '\0') {
int delta = off;
if (input[1] == '+') {
delta = core->blocksize;
int mult = rz_num_math(core->num, input + 2);
if (mult > 0) {
delta /= mult;
}
}
rz_core_seek_delta(core, delta, !silent);
} else {
rz_core_seek_redo(core);
}
break;
case '-': // "s-"
switch (input[1]) {
case '*': // "s-*"
rz_core_seek_reset(core);
break;
case 0: // "s-"
rz_core_seek_undo(core);
break;
case '-': // "s--"
default: {
int delta = -off;
if (input[1] == '-') {
delta = -core->blocksize;
int mult = rz_num_math(core->num, input + 2);
if (mult > 0) {
delta /= mult;
}
}
rz_core_seek_delta(core, delta, !silent);
} break;
}
break;
case 'n': // "sn"
{
const char *nkey = (input[1] == ' ')
? input + 2
: rz_config_get(core->config, "scr.nkey");
rz_core_seek_next(core, nkey, !silent);
} break;
case 'p': // "sp"
{
const char *nkey = (input[1] == ' ')
? input + 2
: rz_config_get(core->config, "scr.nkey");
rz_core_seek_prev(core, nkey, !silent);
} break;
case 'a': // "sa"
off = core->blocksize;
if (input[1] && input[2]) {
cmd = strdup(input);
p = strchr(cmd + 2, ' ');
if (p) {
off = rz_num_math(core->num, p + 1);
;
*p = '\0';
}
cmd[0] = 's';
// perform real seek if provided
rz_cmd_call(core->rcmd, cmd);
free(cmd);
}
rz_core_seek_align(core, off, !silent);
break;
case 'b': // "sb"
if (off == 0) {
off = core->offset;
}
rz_core_seek_analysis_bb(core, off, !silent);
break;
case 'f': { // "sf"
RzAnalysisFunction *fcn;
switch (input[1]) {
case '\0': // "sf"
fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
if (fcn) {
rz_core_seek_opt(core, rz_analysis_function_max_addr(fcn), true, !silent);
}
break;
case ' ': // "sf "
fcn = rz_analysis_get_function_byname(core->analysis, input + 2);
if (fcn) {
rz_core_seek_opt(core, fcn->addr, true, !silent);
}
break;
case '.': // "sf."
fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
if (fcn) {
rz_core_seek_opt(core, fcn->addr, true, !silent);
}
break;
}
break;
}
case 'o': // "so"
switch (input[1]) {
case ' ':
case '\0':
case '+':
case '-':
cmd_seek_opcode(core, input + 1, silent);
break;
default:
return -1; // invalid command
}
break;
case 'g': // "sg"
{
RzIOMap *map = rz_io_map_get(core->io, core->offset);
if (map) {
rz_core_seek_opt(core, map->itv.addr, true, !silent);
} else {
rz_core_seek_opt(core, 0, true, !silent);
}
} break;
case 'G': // "sG"
{
if (!core->file) {
break;
}
RzIOMap *map = rz_io_map_get(core->io, core->offset);
// XXX: this +2 is a hack. must fix gap between sections
if (map) {
rz_core_seek_opt(core, map->itv.addr + map->itv.size + 2, true, !silent);
} else {
rz_core_seek_opt(core, rz_io_fd_size(core->io, core->file->fd), true, !silent);
}
} break;
case ':': // "s:"
printPadded(core, atoi(input + 1));
break;
case '?': // "s?"
rz_core_cmd_help(core, help_msg_s);
break;
default: {
ut64 n = rz_num_math(core->num, input);
if (n) {
rz_core_seek_opt(core, n, true, !silent);
}
} break;
}
return 0;
}

static RzCmdStatus bool2cmdstatus(bool res) {
return res ? RZ_CMD_STATUS_OK : RZ_CMD_STATUS_ERROR;
}
Expand Down