2018-04-02 22:34:07 +00:00
|
|
|
|
/* radare - LGPL - Copyright 2009-2018 - pancake */
|
2016-05-03 02:52:41 +00:00
|
|
|
|
|
2016-07-03 19:57:00 +00:00
|
|
|
|
#include <stddef.h>
|
2016-05-03 02:52:41 +00:00
|
|
|
|
#include "r_cons.h"
|
|
|
|
|
#include "r_core.h"
|
2012-02-27 01:40:27 +00:00
|
|
|
|
|
2017-07-26 13:14:06 +00:00
|
|
|
|
static const char *help_msg_f[] = {
|
|
|
|
|
"Usage: f","[?] [flagname]", " # Manage offset-name flags",
|
|
|
|
|
"f","","list flags (will only list flags from selected flagspaces)",
|
|
|
|
|
"f?","flagname","check if flag exists or not, See ?? and ?!",
|
|
|
|
|
"f."," [*[*]]","list local per-function flags (*) as r2 commands",
|
|
|
|
|
"f.","blah=$$+12","set local function label named 'blah'",
|
|
|
|
|
"f*","","list flags in r commands",
|
|
|
|
|
"f"," name 12 @ 33","set flag 'name' with length 12 at offset 33",
|
|
|
|
|
"f"," name = 33","alias for 'f name @ 33' or 'f name 1 33'",
|
|
|
|
|
"f"," name 12 33 [cmt]","same as above + optional comment",
|
|
|
|
|
"f-",".blah@fcn.foo","delete local label from function at current seek (also f.-)",
|
|
|
|
|
"f--","","delete all flags and flagspaces (deinit)",
|
|
|
|
|
"f+","name 12 @ 33","like above but creates new one if doesnt exist",
|
|
|
|
|
"f-","name","remove flag 'name'",
|
|
|
|
|
"f-","@addr","remove flag at address expression",
|
|
|
|
|
"f."," fname","list all local labels for the given function",
|
|
|
|
|
"f="," [glob]","list range bars graphics with flag offsets and sizes",
|
|
|
|
|
"fa"," [name] [alias]","alias a flag to evaluate an expression",
|
|
|
|
|
"fb"," [addr]","set base address for new flags",
|
|
|
|
|
"fb"," [addr] [flag*]","move flags matching 'flag' to relative addr",
|
|
|
|
|
"fc","[?][name] [color]","set color for given flag",
|
|
|
|
|
"fC"," [name] [cmt]","set comment for given flag",
|
|
|
|
|
"fd"," addr","return flag+delta",
|
|
|
|
|
"fe-","","resets the enumerator counter",
|
|
|
|
|
"fe"," [name]","create flag name.#num# enumerated flag. See fe?",
|
2017-11-23 13:34:07 +00:00
|
|
|
|
"ff"," ([glob])","distance in bytes to reach the next flag (see sn/sp)",
|
2017-07-26 13:14:06 +00:00
|
|
|
|
"fi"," [size] | [from] [to]","show flags in current block or range",
|
|
|
|
|
"fg","","bring visual mode to foreground",
|
|
|
|
|
"fj","","list flags in JSON format",
|
|
|
|
|
"fl"," (@[flag]) [size]","show or set flag length (size)",
|
|
|
|
|
"fla"," [glob]","automatically compute the size of all flags matching glob",
|
|
|
|
|
"fm"," addr","move flag at current offset to new address",
|
|
|
|
|
"fn","","list flags displaying the real name (demangled)",
|
|
|
|
|
"fo","","show fortunes",
|
2017-12-02 01:11:22 +00:00
|
|
|
|
"fO", " [glob]", "flag as ordinals (sym.* func.* method.*)",
|
2017-07-26 13:14:06 +00:00
|
|
|
|
//" fc [name] [cmt] ; set execution command for a specific flag"
|
|
|
|
|
"fr"," [old] [[new]]","rename flag (if no new flag current seek one is used)",
|
|
|
|
|
"fR","[?] [f] [t] [m]","relocate all flags matching f&~m 'f'rom, 't'o, 'm'ask",
|
|
|
|
|
"fs","[?]+-*","manage flagspaces",
|
|
|
|
|
"fS","[on]","sort flags by offset or name",
|
2018-05-11 15:18:36 +00:00
|
|
|
|
"ft","[?]*","flag tags, useful to find all flags matching some words",
|
2017-07-26 13:14:06 +00:00
|
|
|
|
"fV","[*-] [nkey] [offset]","dump/restore visual marks (mK/'K)",
|
|
|
|
|
"fx","[d]","show hexdump (or disasm) of flag:flagsize",
|
2017-10-23 10:54:03 +00:00
|
|
|
|
"fq","","list flags in quiet mode",
|
2017-07-26 13:14:06 +00:00
|
|
|
|
"fz","[?][name]","add named flag zone -name to delete. see fz?[name]",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char *help_msg_fc[] = {
|
|
|
|
|
"Usage: fc", "<flagname> [color]", " # List colors with 'ecs'",
|
|
|
|
|
"fc", " flagname", "Get current color for given flagname",
|
|
|
|
|
"fc", " flagname color", "Set color to a flag",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2017-12-19 21:49:30 +00:00
|
|
|
|
static const char *help_msg_fd[] = {
|
|
|
|
|
"Usage: fd[d]", " [offset|flag|expression]", " # Describe flags",
|
|
|
|
|
"fd", " $$" , "# describe flag + delta for given offset",
|
2018-01-12 08:47:42 +00:00
|
|
|
|
"fd.", " $$", "# check flags in current address (no delta)",
|
2017-12-19 21:49:30 +00:00
|
|
|
|
"fdd", " $$", "# describe flag without space restrictions",
|
|
|
|
|
"fdw", " [string]", "# filter closest flag by string for current offset",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2017-07-26 13:14:06 +00:00
|
|
|
|
|
|
|
|
|
static const char *help_msg_fs[] = {
|
|
|
|
|
"Usage: fs","[*] [+-][flagspace|addr]", " # Manage flagspaces",
|
|
|
|
|
"fs","","display flagspaces",
|
|
|
|
|
"fs*","","display flagspaces as r2 commands",
|
|
|
|
|
"fsj","","display flagspaces in JSON",
|
|
|
|
|
"fs"," *","select all flagspaces",
|
|
|
|
|
"fs"," flagspace","select flagspace or create if it doesn't exist",
|
|
|
|
|
"fs","-flagspace","remove flagspace",
|
|
|
|
|
"fs","-*","remove all flagspaces",
|
|
|
|
|
"fs","+foo","push previous flagspace and set",
|
|
|
|
|
"fs","-","pop to the previous flagspace",
|
|
|
|
|
"fs","-.","remove the current flagspace",
|
2017-10-23 10:54:03 +00:00
|
|
|
|
"fsq","", "list flagspaces in quiet mode",
|
2017-07-26 13:14:06 +00:00
|
|
|
|
"fsm"," [addr]","move flags at given address to the current flagspace",
|
|
|
|
|
"fss","","display flagspaces stack",
|
|
|
|
|
"fss*","","display flagspaces stack in r2 commands",
|
|
|
|
|
"fssj","","display flagspaces stack in JSON",
|
|
|
|
|
"fsr"," newname","rename selected flagspace",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char *help_msg_fz[] = {
|
|
|
|
|
"Usage: f", "[?|-name| name] [@addr]", " # Manage flagzones",
|
|
|
|
|
" fz", " math", "add new flagzone named 'math'",
|
|
|
|
|
" fz-", "math", "remove the math flagzone",
|
|
|
|
|
" fz-", "*", "remove all flagzones",
|
|
|
|
|
" fz.", "", "show around flagzone context",
|
|
|
|
|
" fz:", "", "show what's in scr.flagzone for visual",
|
|
|
|
|
" fz*", "", "dump into r2 commands, for projects",
|
2017-09-12 09:05:24 +00:00
|
|
|
|
NULL
|
2017-07-26 13:14:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-07-27 12:52:17 +00:00
|
|
|
|
static void cmd_flag_init(RCore *core) {
|
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, f);
|
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, fc);
|
2017-12-19 21:49:30 +00:00
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, fd);
|
2017-07-27 12:52:17 +00:00
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, fs);
|
|
|
|
|
DEFINE_CMD_DESCRIPTOR (core, fz);
|
2017-07-26 13:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 00:40:26 +00:00
|
|
|
|
static void cmd_fz(RCore *core, const char *input) {
|
|
|
|
|
switch (*input) {
|
|
|
|
|
case '?':
|
2017-07-26 13:14:06 +00:00
|
|
|
|
r_core_cmd_help (core, help_msg_fz);
|
2016-10-06 00:40:26 +00:00
|
|
|
|
break;
|
|
|
|
|
case '.':
|
|
|
|
|
{
|
|
|
|
|
const char *a, *b;
|
|
|
|
|
r_flag_zone_around (core->flags, core->offset, &a, &b);
|
|
|
|
|
r_cons_printf ("%s %s\n", a, b);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ':':
|
|
|
|
|
{
|
|
|
|
|
const char *a, *b;
|
|
|
|
|
int a_len = 0;
|
|
|
|
|
int w = r_cons_get_size (NULL);
|
|
|
|
|
r_flag_zone_around (core->flags, core->offset, &a, &b);
|
|
|
|
|
if (a) {
|
|
|
|
|
r_cons_printf ("[<< %s]", a);
|
|
|
|
|
a_len = strlen (a) + 4;
|
|
|
|
|
}
|
|
|
|
|
int padsize = (w / 2) - a_len;
|
|
|
|
|
int title_size = 12;
|
|
|
|
|
if (a || b) {
|
|
|
|
|
char *title = r_str_newf ("[ 0x%08"PFMT64x" ]", core->offset);
|
|
|
|
|
title_size = strlen (title);
|
|
|
|
|
padsize -= strlen (title) / 2;
|
|
|
|
|
const char *halfpad = r_str_pad (' ', padsize);
|
|
|
|
|
r_cons_printf ("%s%s", halfpad, title);
|
|
|
|
|
free (title);
|
|
|
|
|
}
|
|
|
|
|
if (b) {
|
|
|
|
|
padsize = (w / 2) - title_size - strlen (b) - 4;
|
|
|
|
|
const char *halfpad = padsize > 1? r_str_pad (' ', padsize): "";
|
|
|
|
|
r_cons_printf ("%s[%s >>]", halfpad, b);
|
|
|
|
|
}
|
|
|
|
|
if (a || b) {
|
|
|
|
|
r_cons_newline();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
2018-01-08 02:29:29 +00:00
|
|
|
|
r_flag_zone_add (core->flags, r_str_trim_ro (input + 1), core->offset);
|
2016-10-06 00:40:26 +00:00
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
if (input[1] == '*') {
|
|
|
|
|
r_flag_zone_reset (core->flags);
|
|
|
|
|
} else {
|
|
|
|
|
r_flag_zone_del (core->flags, input + 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '*':
|
|
|
|
|
r_flag_zone_list (core->flags, '*');
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
r_flag_zone_list (core->flags, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 02:39:37 +00:00
|
|
|
|
|
2017-01-23 23:43:57 +00:00
|
|
|
|
static void flagbars(RCore *core, const char *glob) {
|
2014-10-21 02:39:37 +00:00
|
|
|
|
int cols = r_cons_get_size (NULL);
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
RFlagItem *flag;
|
2017-01-23 23:43:57 +00:00
|
|
|
|
cols -= 80;
|
|
|
|
|
if (cols < 0) {
|
|
|
|
|
cols += 80;
|
2014-10-21 02:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
2017-01-23 23:43:57 +00:00
|
|
|
|
ut64 min = 0, max = r_io_size (core->io);
|
|
|
|
|
RIOSection *s = r_io_section_vget (core->io, flag->offset);
|
|
|
|
|
if (s) {
|
|
|
|
|
min = s->vaddr;
|
|
|
|
|
max = s->vaddr + s->size;
|
|
|
|
|
}
|
|
|
|
|
if (r_str_glob (flag->name, glob)) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x" ", flag->offset);
|
|
|
|
|
r_print_rangebar (core->print, flag->offset, flag->offset + flag->size, min, max, cols);
|
|
|
|
|
r_cons_printf (" %s\n", flag->name);
|
|
|
|
|
}
|
2013-09-23 22:43:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 13:34:07 +00:00
|
|
|
|
static int flag_to_flag(RCore *core, const char *glob) {
|
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
ut64 next = UT64_MAX;
|
2018-01-08 02:29:29 +00:00
|
|
|
|
glob = r_str_trim_ro (glob);
|
2017-11-23 13:34:07 +00:00
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
|
if (flag->offset < next && flag->offset > core->offset) {
|
|
|
|
|
if (glob && *glob && !r_str_glob (flag->name, glob)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
next = flag->offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (next != UT64_MAX && next > core->offset) {
|
|
|
|
|
return next - core->offset;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 02:39:08 +00:00
|
|
|
|
static void cmd_flag_tags (RCore *core, const char *input) {
|
2018-05-11 15:18:36 +00:00
|
|
|
|
char mode = input[1];
|
2018-05-14 01:00:36 +00:00
|
|
|
|
for (; *input && !IS_WHITESPACE (*input); input++) {}
|
2018-05-11 15:18:36 +00:00
|
|
|
|
char *inp = strdup (input);
|
|
|
|
|
char *arg = r_str_trim (inp);
|
2018-05-26 16:12:13 +00:00
|
|
|
|
if (!*arg && !mode) {
|
2018-05-11 15:18:36 +00:00
|
|
|
|
const char *tag;
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
RList *list = r_flag_tags_list (core->flags);
|
|
|
|
|
r_list_foreach (list, iter, tag) {
|
|
|
|
|
r_cons_printf ("%s\n", tag);
|
|
|
|
|
}
|
|
|
|
|
r_list_free (list);
|
|
|
|
|
free (inp);
|
2018-05-11 02:39:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-05-26 16:12:13 +00:00
|
|
|
|
if (mode == '?') {
|
2018-05-11 02:39:08 +00:00
|
|
|
|
eprintf ("Usage: ft [k] [v ...]\n");
|
2018-05-11 15:18:36 +00:00
|
|
|
|
eprintf (" ft tag strcpy strlen ... # set words for the 'string' tag\n");
|
|
|
|
|
eprintf (" ft tag # get offsets of all matching flags\n");
|
|
|
|
|
eprintf (" ft # list all tags\n");
|
|
|
|
|
eprintf (" ftn tag # get matching flagnames fot given tag\n");
|
|
|
|
|
free (inp);
|
2018-05-11 02:39:08 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
char *arg1 = strchr (arg, ' ');
|
|
|
|
|
if (arg1) {
|
|
|
|
|
*arg1 = 0;
|
|
|
|
|
const char *a1 = r_str_trim_ro (arg1 + 1);
|
|
|
|
|
r_flag_tags_set (core->flags, arg, a1);
|
|
|
|
|
} else {
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RList *flags = r_flag_tags_get (core->flags, arg);
|
2018-05-11 15:18:36 +00:00
|
|
|
|
switch (mode) {
|
|
|
|
|
case 'n':
|
|
|
|
|
r_list_foreach (flags, iter, flag) {
|
|
|
|
|
// r_cons_printf ("0x%08"PFMT64x"\n", flag->offset);
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x" %s\n", flag->offset, flag->name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
r_list_foreach (flags, iter, flag) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", flag->offset);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-05-11 02:39:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-11 15:18:36 +00:00
|
|
|
|
free (inp);
|
2018-05-11 02:39:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 01:11:22 +00:00
|
|
|
|
static void flag_ordinals(RCore *core, const char *str) {
|
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RListIter *iter;
|
2018-01-08 02:29:29 +00:00
|
|
|
|
const char *glob = r_str_trim_ro (str);
|
2017-12-02 01:11:22 +00:00
|
|
|
|
int count = 0;
|
|
|
|
|
char *pfx = strdup (glob);
|
|
|
|
|
char *p = strchr (pfx, '*');
|
|
|
|
|
if (p) {
|
|
|
|
|
*p = 0;
|
|
|
|
|
}
|
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
|
if (r_str_glob (flag->name, glob)) {
|
|
|
|
|
char *newName = r_str_newf ("%s%d", pfx, count++);
|
|
|
|
|
r_flag_rename (core->flags, flag, newName);
|
|
|
|
|
free (newName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 21:49:30 +00:00
|
|
|
|
static int cmpflag(const void *_a, const void *_b) {
|
|
|
|
|
const RFlagItem *flag1 = _a , *flag2 = _b;
|
|
|
|
|
return (flag1->offset - flag2->offset);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 01:40:27 +00:00
|
|
|
|
static int cmd_flag(void *data, const char *input) {
|
2015-02-03 00:11:33 +00:00
|
|
|
|
static int flagenum = 0;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
RCore *core = (RCore *)data;
|
|
|
|
|
ut64 off = core->offset;
|
2012-11-13 02:25:07 +00:00
|
|
|
|
char *ptr, *str = NULL;
|
2015-07-13 09:21:21 +00:00
|
|
|
|
RFlagItem *item;
|
2014-09-01 00:24:38 +00:00
|
|
|
|
char *name = NULL;
|
2012-11-13 02:25:07 +00:00
|
|
|
|
st64 base;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
|
2013-06-30 00:45:33 +00:00
|
|
|
|
// TODO: off+=cursor
|
2016-07-03 19:57:00 +00:00
|
|
|
|
if (*input) {
|
|
|
|
|
str = strdup (input + 1);
|
|
|
|
|
}
|
2015-04-11 22:44:49 +00:00
|
|
|
|
rep:
|
2012-02-27 01:40:27 +00:00
|
|
|
|
switch (*input) {
|
2017-11-23 13:34:07 +00:00
|
|
|
|
case 'f': // "ff"
|
2017-11-23 16:08:05 +00:00
|
|
|
|
if (input[1] == 's') { // "ffs"
|
|
|
|
|
int delta = flag_to_flag (core, input + 2);
|
|
|
|
|
if (delta > 0) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", core->offset + delta);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
r_cons_printf ("%d\n", flag_to_flag (core, input + 1));
|
|
|
|
|
}
|
2017-11-23 13:34:07 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'e': // "fe"
|
2015-02-03 00:11:33 +00:00
|
|
|
|
switch (input[1]) {
|
|
|
|
|
case ' ':
|
2017-11-23 13:34:07 +00:00
|
|
|
|
ptr = r_str_newf ("%s.%d", input + 2, flagenum);
|
|
|
|
|
(void)r_flag_set (core->flags, ptr, core->offset, 1);
|
2015-02-03 00:11:33 +00:00
|
|
|
|
flagenum++;
|
|
|
|
|
free (ptr);
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
flagenum = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
eprintf ("|Usage: fe[-| name] @@= 1 2 3 4\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-10-21 02:39:37 +00:00
|
|
|
|
case '=': // "f="
|
|
|
|
|
switch (input[1]) {
|
2017-01-23 23:43:57 +00:00
|
|
|
|
case ' ':
|
|
|
|
|
flagbars (core, input + 2);
|
2014-10-21 02:39:37 +00:00
|
|
|
|
break;
|
2017-01-23 23:43:57 +00:00
|
|
|
|
case 0:
|
|
|
|
|
flagbars (core, NULL);
|
2014-10-21 02:39:37 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-01-23 23:43:57 +00:00
|
|
|
|
case '?':
|
|
|
|
|
eprintf ("Usage: f= [glob] to grep for matching flag names\n");
|
2014-10-21 02:39:37 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-23 22:43:31 +00:00
|
|
|
|
break;
|
2014-09-01 00:24:38 +00:00
|
|
|
|
case 'a':
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (input[1] == ' '){
|
2014-09-01 00:24:38 +00:00
|
|
|
|
RFlagItem *fi;
|
2015-02-03 14:53:21 +00:00
|
|
|
|
R_FREE (str);
|
2014-09-01 00:24:38 +00:00
|
|
|
|
str = strdup (input+2);
|
|
|
|
|
ptr = strchr (str, '=');
|
|
|
|
|
if (!ptr)
|
|
|
|
|
ptr = strchr (str, ' ');
|
|
|
|
|
if (ptr) *ptr++ = 0;
|
2018-01-08 02:29:29 +00:00
|
|
|
|
name = (char *)r_str_trim_ro (str);
|
|
|
|
|
ptr = (char *)r_str_trim_ro (ptr);
|
2014-09-01 00:24:38 +00:00
|
|
|
|
fi = r_flag_get (core->flags, name);
|
|
|
|
|
if (!fi)
|
|
|
|
|
fi = r_flag_set (core->flags, name,
|
2016-02-20 14:38:46 +00:00
|
|
|
|
core->offset, 1);
|
2014-09-01 00:24:38 +00:00
|
|
|
|
if (fi) {
|
|
|
|
|
r_flag_item_set_alias (fi, ptr);
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find flag '%s'\n", name);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Usage: fa flagname flagalias\n");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-10-12 12:33:52 +00:00
|
|
|
|
case 'V': // visual marks
|
|
|
|
|
switch(input[1]) {
|
|
|
|
|
case '-':
|
|
|
|
|
r_core_visual_mark_reset (core);
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
|
|
|
|
{
|
|
|
|
|
const char *arg = strchr (input+2, ' ');
|
|
|
|
|
ut64 addr = arg? r_num_math (core->num, arg): core->offset;
|
|
|
|
|
r_core_visual_mark_set (core, atoi (input+1), addr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '?':
|
|
|
|
|
eprintf ("Usage: fV[*-] [nkey] [offset]\n");
|
|
|
|
|
eprintf ("Dump/Restore visual marks (mK/'K)\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
r_core_visual_mark_dump (core);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
case 'm': // "fm"
|
2014-03-02 04:41:45 +00:00
|
|
|
|
r_flag_move (core->flags, core->offset, r_num_math (core->num, input+1));
|
|
|
|
|
break;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
case '2': // "f2"
|
2013-09-03 20:45:43 +00:00
|
|
|
|
r_flag_get_i2 (core->flags, r_num_math (core->num, input+1));
|
|
|
|
|
break;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
case 'R': // "fR"
|
2017-05-22 00:54:26 +00:00
|
|
|
|
switch(*str) {
|
|
|
|
|
case '\0':
|
2015-06-20 11:57:11 +00:00
|
|
|
|
eprintf ("Usage: fR [from] [to] ([mask])\n");
|
|
|
|
|
eprintf ("Example to relocate PIE flags on debugger:\n"
|
|
|
|
|
" > fR entry0 `dm~:1[1]`\n");
|
|
|
|
|
break;
|
2017-05-22 00:54:26 +00:00
|
|
|
|
case '?':
|
|
|
|
|
r_cons_println ("Usage: fR [from] [to] ([mask])");
|
|
|
|
|
r_cons_println ("Example to relocate PIE flags on debugger:\n"
|
|
|
|
|
" > fR entry0 `dm~:1[1]`");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
char *p = strchr (str+1, ' ');
|
|
|
|
|
ut64 from, to, mask = 0xffff;
|
|
|
|
|
int ret;
|
|
|
|
|
if (p) {
|
|
|
|
|
char *q = strchr (p+1, ' ');
|
|
|
|
|
*p = 0;
|
|
|
|
|
if (q) {
|
|
|
|
|
*q = 0;
|
|
|
|
|
mask = r_num_math (core->num, q+1);
|
|
|
|
|
}
|
|
|
|
|
from = r_num_math (core->num, str+1);
|
|
|
|
|
to = r_num_math (core->num, p+1);
|
|
|
|
|
ret = r_flag_relocate (core->flags, from, mask, to);
|
|
|
|
|
eprintf ("Relocated %d flags\n", ret);
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Usage: fR [from] [to] ([mask])\n");
|
|
|
|
|
eprintf ("Example to relocate PIE flags on debugger:\n"
|
|
|
|
|
" > fR entry0 `dm~:1[1]`\n");
|
|
|
|
|
}
|
2013-08-29 01:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
case 'b': // "fb"
|
2012-11-13 02:25:07 +00:00
|
|
|
|
switch (input[1]) {
|
|
|
|
|
case ' ':
|
2016-07-03 19:57:00 +00:00
|
|
|
|
free (str);
|
|
|
|
|
str = strdup (input + 2);
|
2012-11-13 02:25:07 +00:00
|
|
|
|
ptr = strchr (str, ' ');
|
|
|
|
|
if (ptr) {
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RFlag *f = core->flags;
|
|
|
|
|
*ptr = 0;
|
|
|
|
|
base = r_num_math (core->num, str);
|
|
|
|
|
r_list_foreach (f->flags, iter, flag) {
|
|
|
|
|
if (r_str_glob (flag->name, ptr+1))
|
|
|
|
|
flag->offset += base;
|
|
|
|
|
}
|
2016-07-03 19:57:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
core->flags->base = r_num_math (core->num, input+1);
|
|
|
|
|
}
|
2012-11-13 02:25:07 +00:00
|
|
|
|
free (str);
|
|
|
|
|
str = NULL;
|
|
|
|
|
break;
|
|
|
|
|
case '\0':
|
|
|
|
|
r_cons_printf ("%"PFMT64d" 0x%"PFMT64x"\n",
|
|
|
|
|
core->flags->base,
|
|
|
|
|
core->flags->base);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
eprintf ("Usage: fb [addr] [[flags*]]\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-12-10 11:53:06 +00:00
|
|
|
|
case '+': // "f+'
|
2012-02-27 01:40:27 +00:00
|
|
|
|
case ' ': {
|
2018-01-08 02:29:29 +00:00
|
|
|
|
const char *cstr = r_str_trim_ro (str);
|
2016-10-28 10:19:44 +00:00
|
|
|
|
char* eq = strchr (cstr, '=');
|
|
|
|
|
char* s = strchr (cstr, ' ');
|
2015-09-04 13:12:42 +00:00
|
|
|
|
char* s2 = NULL;
|
2012-11-13 02:25:07 +00:00
|
|
|
|
ut32 bsze = 1; //core->blocksize;
|
|
|
|
|
if (eq) {
|
|
|
|
|
// TODO: add support for '=' char in flag comments
|
|
|
|
|
*eq = 0;
|
2016-10-28 10:19:44 +00:00
|
|
|
|
off = r_num_math (core->num, eq + 1);
|
2012-11-13 02:25:07 +00:00
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
if (s) {
|
|
|
|
|
*s = '\0';
|
2016-10-28 10:19:44 +00:00
|
|
|
|
s2 = strchr (s + 1, ' ');
|
2012-02-27 01:40:27 +00:00
|
|
|
|
if (s2) {
|
|
|
|
|
*s2 = '\0';
|
2016-07-03 19:57:00 +00:00
|
|
|
|
if (s2[1] && s2[2]) {
|
|
|
|
|
off = r_num_math (core->num, s2 + 1);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
}
|
2016-07-03 19:57:00 +00:00
|
|
|
|
bsze = r_num_math (core->num, s + 1);
|
2012-02-27 01:40:27 +00:00
|
|
|
|
}
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (*cstr == '.') {
|
2016-04-11 22:54:45 +00:00
|
|
|
|
input++;
|
|
|
|
|
goto rep;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
} else {
|
2017-03-28 12:07:26 +00:00
|
|
|
|
bool addFlag = true;
|
|
|
|
|
if (input[0] == '+') {
|
|
|
|
|
if (r_flag_get_at (core->flags, off, false)) {
|
|
|
|
|
addFlag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (addFlag) {
|
|
|
|
|
r_flag_set (core->flags, cstr, off, bsze);
|
|
|
|
|
}
|
2016-07-03 19:57:00 +00:00
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (input[1] == '-') {
|
2015-01-22 01:22:29 +00:00
|
|
|
|
r_flag_unset_all (core->flags);
|
|
|
|
|
} else if (input[1]) {
|
2018-01-08 02:29:29 +00:00
|
|
|
|
const char *flagname = r_str_trim_ro (input + 1);
|
2016-10-28 10:19:44 +00:00
|
|
|
|
while (*flagname==' ') {
|
|
|
|
|
flagname++;
|
|
|
|
|
}
|
2018-08-03 13:33:27 +00:00
|
|
|
|
if (*flagname == '.') {
|
2014-09-26 13:40:17 +00:00
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (fcn) {
|
|
|
|
|
eprintf ("TODO: local_del_name has been deprecated\n");
|
|
|
|
|
//;r_anal_fcn_local_del_name (core->anal, fcn, flagname+1);
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find function at 0x%08"PFMT64x"\n", off);
|
|
|
|
|
}
|
2013-06-30 00:45:33 +00:00
|
|
|
|
} else {
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (strchr (flagname, '*')) {
|
2013-06-30 00:45:33 +00:00
|
|
|
|
r_flag_unset_glob (core->flags, flagname);
|
2016-10-28 10:19:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
r_flag_unset_name (core->flags, flagname);
|
|
|
|
|
}
|
2013-06-30 00:45:33 +00:00
|
|
|
|
}
|
2016-10-28 10:19:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
r_flag_unset_off (core->flags, off);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
2013-06-25 21:44:21 +00:00
|
|
|
|
case '.':
|
2018-01-08 02:29:29 +00:00
|
|
|
|
input = r_str_trim_ro (input + 1) - 1;
|
2013-06-30 00:45:33 +00:00
|
|
|
|
if (input[1]) {
|
|
|
|
|
if (input[1] == '*') {
|
|
|
|
|
if (input[2] == '*') {
|
2014-09-23 07:35:37 +00:00
|
|
|
|
r_anal_fcn_labels (core->anal, NULL, 1);
|
2013-06-30 00:45:33 +00:00
|
|
|
|
} else {
|
2014-09-26 13:40:17 +00:00
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
2014-09-23 07:35:37 +00:00
|
|
|
|
if (fcn) r_anal_fcn_labels (core->anal, fcn, 1);
|
2013-06-30 00:45:33 +00:00
|
|
|
|
else eprintf ("Cannot find function at 0x%08"PFMT64x"\n", off);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-04-11 22:54:45 +00:00
|
|
|
|
char *name = strdup (input + ((input[2] == ' ')? 2: 1));
|
2014-09-26 13:40:17 +00:00
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
2016-04-11 22:54:45 +00:00
|
|
|
|
if (name) {
|
|
|
|
|
char *eq = strchr (name, '=');
|
|
|
|
|
if (eq) {
|
|
|
|
|
*eq ++ = 0;
|
|
|
|
|
off = r_num_math (core->num, eq);
|
|
|
|
|
}
|
2018-01-08 02:22:26 +00:00
|
|
|
|
r_str_trim (name);
|
2016-10-20 13:02:25 +00:00
|
|
|
|
if (fcn) {
|
|
|
|
|
if (*name=='-') {
|
|
|
|
|
r_anal_fcn_label_del (core->anal, fcn, name + 1, off);
|
|
|
|
|
} else {
|
|
|
|
|
r_anal_fcn_label_set (core->anal, fcn, name, off);
|
|
|
|
|
}
|
2018-08-03 13:33:27 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find function at 0x%08"PFMT64x"\n", off);
|
|
|
|
|
}
|
2016-10-20 13:02:25 +00:00
|
|
|
|
free (name);
|
2016-04-11 22:54:45 +00:00
|
|
|
|
}
|
2013-06-30 00:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-09-26 13:40:17 +00:00
|
|
|
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0);
|
2018-08-03 13:33:27 +00:00
|
|
|
|
if (fcn) {
|
|
|
|
|
r_anal_fcn_labels (core->anal, fcn, 0);
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Local flags require a function to work.");
|
|
|
|
|
}
|
2013-06-25 21:44:21 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2015-07-09 20:20:02 +00:00
|
|
|
|
case 'l': // "fl"
|
2017-01-09 02:44:52 +00:00
|
|
|
|
if (input[1] == '?') { // "fl?"
|
|
|
|
|
eprintf ("Usage: fl[a] [flagname] [flagsize]\n");
|
|
|
|
|
} else
|
2016-12-14 23:12:40 +00:00
|
|
|
|
if (input[1] == 'a') { // "fla"
|
|
|
|
|
// TODO: we can optimize this if core->flags->flags is sorted by flagitem->offset
|
|
|
|
|
char *glob = strchr (input, ' ');
|
|
|
|
|
if (glob) {
|
|
|
|
|
glob++;
|
|
|
|
|
}
|
|
|
|
|
RListIter *iter, *iter2;
|
|
|
|
|
RFlagItem *flag, *flag2;
|
|
|
|
|
r_list_foreach (core->flags->flags, iter, flag) {
|
|
|
|
|
if (flag->size == 0 && (!glob || r_str_glob (flag->name, glob))) {
|
|
|
|
|
RFlagItem *win = NULL;
|
|
|
|
|
ut64 at = flag->offset;
|
|
|
|
|
r_list_foreach (core->flags->flags, iter2, flag2) {
|
|
|
|
|
if (flag2->offset > at) {
|
|
|
|
|
if (!win || flag2->offset < win->offset) {
|
|
|
|
|
win = flag2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (win) {
|
|
|
|
|
flag->size = win->offset - flag->offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (input[1] == ' ') { // "fl ..."
|
|
|
|
|
char *p, *arg = strdup (input + 2);
|
2015-07-09 20:20:02 +00:00
|
|
|
|
r_str_trim_head_tail (arg);
|
|
|
|
|
p = strchr (arg, ' ');
|
|
|
|
|
if (p) {
|
|
|
|
|
*p++ = 0;
|
2015-07-13 09:21:21 +00:00
|
|
|
|
item = r_flag_get_i (core->flags,
|
2017-01-09 02:38:55 +00:00
|
|
|
|
r_num_math (core->num, arg));
|
2015-07-09 20:20:02 +00:00
|
|
|
|
if (item)
|
|
|
|
|
item->size = r_num_math (core->num, p);
|
|
|
|
|
} else {
|
2017-01-09 02:44:52 +00:00
|
|
|
|
if (*arg) {
|
|
|
|
|
item = r_flag_get_i (core->flags, core->offset);
|
|
|
|
|
if (item) {
|
|
|
|
|
item->size = r_num_math (core->num, arg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
item = r_flag_get_i (core->flags, r_num_math (core->num, arg));
|
|
|
|
|
if (item) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", item->size);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-09 20:20:02 +00:00
|
|
|
|
}
|
2015-07-13 09:21:21 +00:00
|
|
|
|
free (arg);
|
2016-12-14 23:12:40 +00:00
|
|
|
|
} else { // "fl"
|
2015-07-13 09:21:21 +00:00
|
|
|
|
item = r_flag_get_i (core->flags, core->offset);
|
2012-09-06 01:12:54 +00:00
|
|
|
|
if (item)
|
2015-03-13 20:18:25 +00:00
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", item->size);
|
2015-07-09 20:20:02 +00:00
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
2012-09-28 00:20:52 +00:00
|
|
|
|
#if 0
|
|
|
|
|
case 'd':
|
|
|
|
|
if (input[1] == ' ') {
|
|
|
|
|
char cmd[128];
|
|
|
|
|
RFlagItem *item = r_flag_get_i (core->flags,
|
|
|
|
|
r_num_math (core->num, input+2));
|
|
|
|
|
if (item) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", item->offset);
|
|
|
|
|
snprintf (cmd, sizeof (cmd), "pD@%"PFMT64d":%"PFMT64d,
|
|
|
|
|
item->offset, item->size);
|
|
|
|
|
r_core_cmd0 (core, cmd);
|
|
|
|
|
}
|
|
|
|
|
} else eprintf ("Missing arguments\n");
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
2016-10-06 00:40:26 +00:00
|
|
|
|
case 'z':
|
|
|
|
|
cmd_fz (core, input + 1);
|
|
|
|
|
break;
|
2012-09-28 00:20:52 +00:00
|
|
|
|
case 'x':
|
|
|
|
|
if (input[1] == ' ') {
|
|
|
|
|
char cmd[128];
|
|
|
|
|
RFlagItem *item = r_flag_get_i (core->flags,
|
|
|
|
|
r_num_math (core->num, input+2));
|
|
|
|
|
if (item) {
|
|
|
|
|
r_cons_printf ("0x%08"PFMT64x"\n", item->offset);
|
|
|
|
|
snprintf (cmd, sizeof (cmd), "px@%"PFMT64d":%"PFMT64d,
|
|
|
|
|
item->offset, item->size);
|
|
|
|
|
r_core_cmd0 (core, cmd);
|
|
|
|
|
}
|
2016-10-06 00:40:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Missing arguments\n");
|
|
|
|
|
}
|
2012-09-28 00:20:52 +00:00
|
|
|
|
break;
|
2018-05-11 15:18:36 +00:00
|
|
|
|
case 't': // "ft"
|
2018-05-11 02:39:08 +00:00
|
|
|
|
cmd_flag_tags (core, input);
|
|
|
|
|
break;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
case 'S':
|
|
|
|
|
r_flag_sort (core->flags, (input[1]=='n'));
|
|
|
|
|
break;
|
2017-10-23 10:54:03 +00:00
|
|
|
|
case 's': // "fs"
|
2012-11-13 02:25:07 +00:00
|
|
|
|
switch (input[1]) {
|
2015-04-12 19:37:21 +00:00
|
|
|
|
case '?':
|
2017-07-26 13:14:06 +00:00
|
|
|
|
r_core_cmd_help (core, help_msg_fs);
|
2015-04-13 04:43:42 +00:00
|
|
|
|
break;
|
2015-04-03 18:38:34 +00:00
|
|
|
|
case '+':
|
|
|
|
|
r_flag_space_push (core->flags, input+2);
|
|
|
|
|
break;
|
2013-03-07 22:47:41 +00:00
|
|
|
|
case 'r':
|
2016-08-23 22:23:14 +00:00
|
|
|
|
if (input[2] ==' ') {
|
|
|
|
|
r_flag_space_rename (core->flags, NULL, input + 2);
|
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Usage: fsr [newname]\n");
|
|
|
|
|
}
|
2013-03-07 22:47:41 +00:00
|
|
|
|
break;
|
2017-05-02 03:46:43 +00:00
|
|
|
|
case 's':
|
|
|
|
|
r_flag_space_stack_list (core->flags, input[2]);
|
|
|
|
|
break;
|
2015-01-22 01:22:29 +00:00
|
|
|
|
case '-':
|
2015-07-17 09:10:28 +00:00
|
|
|
|
switch (input[2]) {
|
|
|
|
|
case '*':
|
|
|
|
|
r_flag_space_unset (core->flags, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case '.':
|
|
|
|
|
{
|
|
|
|
|
const char *curfs = r_flag_space_cur (core->flags);
|
|
|
|
|
r_flag_space_unset (core->flags, curfs);
|
2015-04-03 18:38:34 +00:00
|
|
|
|
}
|
2015-07-17 09:10:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0:
|
2015-04-03 18:38:34 +00:00
|
|
|
|
r_flag_space_pop (core->flags);
|
2015-07-17 09:10:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
r_flag_space_unset (core->flags, input+2);
|
|
|
|
|
break;
|
2015-01-22 01:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-01-17 02:29:46 +00:00
|
|
|
|
case 'j':
|
|
|
|
|
case '\0':
|
|
|
|
|
case '*':
|
2017-10-23 10:54:03 +00:00
|
|
|
|
case 'q':
|
2013-01-17 02:29:46 +00:00
|
|
|
|
r_flag_space_list (core->flags, input[1]);
|
|
|
|
|
break;
|
2012-11-13 02:25:07 +00:00
|
|
|
|
case ' ':
|
2012-09-06 01:12:54 +00:00
|
|
|
|
r_flag_space_set (core->flags, input+2);
|
2012-11-13 02:25:07 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
{ RFlagItem *f;
|
|
|
|
|
ut64 off = core->offset;
|
2016-08-23 22:23:14 +00:00
|
|
|
|
if (input[2] == ' ') {
|
2012-11-13 02:25:07 +00:00
|
|
|
|
off = r_num_math (core->num, input+2);
|
2016-08-23 22:23:14 +00:00
|
|
|
|
}
|
2012-11-13 02:25:07 +00:00
|
|
|
|
f = r_flag_get_i (core->flags, off);
|
|
|
|
|
if (f) {
|
|
|
|
|
f->space = core->flags->space_idx;
|
2016-08-23 22:23:14 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find any flag at 0x%"PFMT64x".\n", off);
|
|
|
|
|
}
|
2012-11-13 02:25:07 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: {
|
2012-09-06 01:12:54 +00:00
|
|
|
|
int i, j = 0;
|
2016-08-23 22:23:14 +00:00
|
|
|
|
for (i = 0; i < R_FLAG_SPACES_MAX; i++) {
|
2012-09-06 01:12:54 +00:00
|
|
|
|
if (core->flags->spaces[i])
|
|
|
|
|
r_cons_printf ("%02d %c %s\n", j++,
|
2016-08-23 22:23:14 +00:00
|
|
|
|
(i == core->flags->space_idx)?'*':' ',
|
2012-09-06 01:12:54 +00:00
|
|
|
|
core->flags->spaces[i]);
|
|
|
|
|
}
|
2012-11-13 02:25:07 +00:00
|
|
|
|
} break;
|
2012-09-06 01:12:54 +00:00
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
2012-08-09 16:19:00 +00:00
|
|
|
|
case 'g':
|
2013-10-16 23:04:05 +00:00
|
|
|
|
r_core_cmd0 (core, "V");
|
2012-08-09 16:19:00 +00:00
|
|
|
|
break;
|
2012-10-26 08:00:22 +00:00
|
|
|
|
case 'c':
|
2016-06-17 21:17:24 +00:00
|
|
|
|
if (input[1]=='?' || input[1] != ' ') {
|
2017-07-26 13:14:06 +00:00
|
|
|
|
r_core_cmd_help (core, help_msg_fc);
|
2014-08-18 23:47:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
RFlagItem *fi;
|
|
|
|
|
const char *ret;
|
2018-01-08 02:22:26 +00:00
|
|
|
|
char *arg = r_str_trim (strdup (input+2));
|
2014-08-18 23:47:02 +00:00
|
|
|
|
char *color = strchr (arg, ' ');
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (color && color[1]) {
|
2014-08-18 23:47:02 +00:00
|
|
|
|
*color++ = 0;
|
2016-10-28 10:19:44 +00:00
|
|
|
|
}
|
2014-08-18 23:47:02 +00:00
|
|
|
|
fi = r_flag_get (core->flags, arg);
|
|
|
|
|
if (fi) {
|
|
|
|
|
ret = r_flag_color (core->flags, fi, color);
|
|
|
|
|
if (!color && ret)
|
2016-06-26 04:51:17 +00:00
|
|
|
|
r_cons_println (ret);
|
2014-08-18 23:47:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Unknown flag '%s'\n", arg);
|
|
|
|
|
}
|
|
|
|
|
free (arg);
|
|
|
|
|
}
|
2012-10-26 08:00:22 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
2016-10-28 10:19:44 +00:00
|
|
|
|
if (input[1] == ' ') {
|
2012-10-26 08:00:22 +00:00
|
|
|
|
RFlagItem *item;
|
2016-10-28 10:19:44 +00:00
|
|
|
|
char *q, *p = strdup (input + 2);
|
2012-10-26 08:00:22 +00:00
|
|
|
|
q = strchr (p, ' ');
|
|
|
|
|
if (q) {
|
|
|
|
|
*q = 0;
|
|
|
|
|
item = r_flag_get (core->flags, p);
|
|
|
|
|
if (item) {
|
|
|
|
|
r_flag_item_set_comment (item, q+1);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find flag with name '%s'\n", p);
|
|
|
|
|
}
|
2012-10-26 08:00:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
item = r_flag_get_i (core->flags, r_num_math (core->num, p));
|
|
|
|
|
if (item && item->comment) {
|
2016-06-26 04:51:17 +00:00
|
|
|
|
r_cons_println (item->comment);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find item\n");
|
|
|
|
|
}
|
2012-10-26 08:00:22 +00:00
|
|
|
|
}
|
|
|
|
|
free (p);
|
|
|
|
|
} else eprintf ("Usage: fC [name] [comment]\n");
|
|
|
|
|
break;
|
2017-05-12 01:44:53 +00:00
|
|
|
|
case 'o': // "fo"
|
2017-09-11 22:41:07 +00:00
|
|
|
|
r_core_fortune_print_random (core);
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
2017-12-02 01:11:22 +00:00
|
|
|
|
case 'O': // "fO"
|
|
|
|
|
flag_ordinals (core, input + 1);
|
|
|
|
|
break;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
case 'r':
|
2013-02-11 03:08:21 +00:00
|
|
|
|
if (input[1]==' ' && input[2]) {
|
2012-02-27 01:40:27 +00:00
|
|
|
|
char *old, *new;
|
|
|
|
|
RFlagItem *item;
|
2016-10-28 10:19:44 +00:00
|
|
|
|
old = str + 1;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
new = strchr (old, ' ');
|
|
|
|
|
if (new) {
|
|
|
|
|
*new = 0;
|
|
|
|
|
new++;
|
|
|
|
|
item = r_flag_get (core->flags, old);
|
2015-01-29 23:22:48 +00:00
|
|
|
|
if (!item && !strncmp (old, "fcn.", 4)) {
|
|
|
|
|
item = r_flag_get (core->flags, old+4);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
} else {
|
|
|
|
|
new = old;
|
|
|
|
|
item = r_flag_get_i (core->flags, core->offset);
|
|
|
|
|
}
|
2012-11-13 02:25:07 +00:00
|
|
|
|
if (item) {
|
2016-07-03 19:57:00 +00:00
|
|
|
|
if (!r_flag_rename (core->flags, item, new)) {
|
2012-11-13 02:25:07 +00:00
|
|
|
|
eprintf ("Invalid name\n");
|
2016-07-03 19:57:00 +00:00
|
|
|
|
}
|
2015-01-29 23:22:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
eprintf ("Cannot find flag (%s)\n", old);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2016-07-03 19:57:00 +00:00
|
|
|
|
case '\0':
|
2015-08-17 08:34:47 +00:00
|
|
|
|
case 'n': // "fn"
|
|
|
|
|
case '*': // "f*"
|
|
|
|
|
case 'j': // "fj"
|
2017-10-23 10:54:03 +00:00
|
|
|
|
case 'q': // "fq"
|
2018-07-02 18:06:09 +00:00
|
|
|
|
r_flag_list (core->flags, *input, input[0]? input + 1: "");
|
2016-07-03 19:57:00 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'i': // "fi"
|
2018-08-03 13:33:27 +00:00
|
|
|
|
if (input[1] == ' ' || (input[1] && input[2] == ' ')) {
|
2018-01-08 02:29:29 +00:00
|
|
|
|
char *arg = strdup (r_str_trim_ro (input + 2));
|
2016-07-03 19:57:00 +00:00
|
|
|
|
if (*arg) {
|
2018-01-08 02:29:29 +00:00
|
|
|
|
arg = strdup (r_str_trim_ro (input + 2));
|
2016-07-03 19:57:00 +00:00
|
|
|
|
char *sp = strchr (arg, ' ');
|
|
|
|
|
if (!sp) {
|
|
|
|
|
char *newarg = r_str_newf ("%c0x%"PFMT64x" %s+0x%"PFMT64x,
|
|
|
|
|
input[1], core->offset, arg, core->offset);
|
|
|
|
|
free (arg);
|
|
|
|
|
arg = newarg;
|
|
|
|
|
} else {
|
|
|
|
|
char *newarg = r_str_newf ("%c%s", input[1], arg);
|
|
|
|
|
free (arg);
|
|
|
|
|
arg = newarg;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
free (arg);
|
|
|
|
|
arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x,
|
|
|
|
|
core->offset, core->offset + core->blocksize);
|
|
|
|
|
}
|
2018-07-02 18:06:09 +00:00
|
|
|
|
r_flag_list (core->flags, 'i', arg);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
free (arg);
|
|
|
|
|
} else {
|
|
|
|
|
// XXX dupe for prev case
|
|
|
|
|
char *arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x,
|
|
|
|
|
core->offset, core->offset + core->blocksize);
|
2018-07-02 18:06:09 +00:00
|
|
|
|
r_flag_list (core->flags, 'i', arg);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
free (arg);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
2015-08-17 08:34:47 +00:00
|
|
|
|
case 'd': // "fd"
|
2012-02-27 01:40:27 +00:00
|
|
|
|
{
|
2017-01-24 00:41:12 +00:00
|
|
|
|
ut64 addr = core->offset;
|
2018-01-12 08:47:42 +00:00
|
|
|
|
char *arg = NULL;
|
2017-01-15 20:17:59 +00:00
|
|
|
|
RFlagItem *f = NULL;
|
2017-01-24 00:41:12 +00:00
|
|
|
|
bool space_strict = true;
|
2017-04-14 08:06:06 +00:00
|
|
|
|
bool strict_offset = false;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
switch (input[1]) {
|
|
|
|
|
case '?':
|
2017-12-19 21:49:30 +00:00
|
|
|
|
r_core_cmd_help (core, help_msg_fd);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
if (str) {
|
2014-04-29 22:57:51 +00:00
|
|
|
|
free (str);
|
2016-07-03 19:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
case '\0':
|
|
|
|
|
addr = core->offset;
|
|
|
|
|
break;
|
2017-01-24 00:41:12 +00:00
|
|
|
|
case 'd':
|
|
|
|
|
space_strict = false;
|
2018-01-12 08:47:42 +00:00
|
|
|
|
arg = strchr (input, ' ');
|
|
|
|
|
if (arg) {
|
|
|
|
|
addr = r_num_math (core->num, arg + 1);
|
2017-01-24 00:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2018-02-25 09:31:33 +00:00
|
|
|
|
case '.': // list all flags at given offset
|
|
|
|
|
{
|
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
const RList *flaglist;
|
2018-01-12 08:47:42 +00:00
|
|
|
|
arg = strchr (input, ' ');
|
|
|
|
|
if (arg) {
|
|
|
|
|
addr = r_num_math (core->num, arg + 1);
|
2017-04-14 08:06:06 +00:00
|
|
|
|
}
|
2018-02-25 09:31:33 +00:00
|
|
|
|
flaglist = r_flag_get_list (core->flags, addr);
|
|
|
|
|
r_list_foreach (flaglist, iter, flag) {
|
|
|
|
|
if (flag) {
|
|
|
|
|
r_cons_println (flag->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2017-12-19 21:49:30 +00:00
|
|
|
|
case 'w':
|
|
|
|
|
{
|
2018-01-12 08:47:42 +00:00
|
|
|
|
arg = strchr (input, ' ');
|
2017-12-19 21:49:30 +00:00
|
|
|
|
if (arg) {
|
2018-01-12 08:47:42 +00:00
|
|
|
|
arg++;
|
2017-12-19 21:49:30 +00:00
|
|
|
|
if (*arg) {
|
|
|
|
|
RFlag *f = core->flags;
|
|
|
|
|
RList *temp = r_list_new ();
|
|
|
|
|
ut64 loff = 0;
|
|
|
|
|
ut64 uoff = 0;
|
|
|
|
|
ut64 curseek = core->offset;
|
2018-02-21 15:11:05 +00:00
|
|
|
|
char *lmatch = NULL , *umatch = NULL;
|
2017-12-19 21:49:30 +00:00
|
|
|
|
RFlagItem *flag;
|
|
|
|
|
RListIter *iter;
|
|
|
|
|
r_list_foreach (f->flags, iter, flag) { // creating a local copy
|
|
|
|
|
r_list_append (temp, flag);
|
|
|
|
|
}
|
|
|
|
|
r_list_sort (temp, &cmpflag);
|
|
|
|
|
r_list_foreach (temp, iter, flag) {
|
|
|
|
|
if ((f->space_idx != -1) && (flag->space != f->space_idx)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (strstr (flag->name , arg) != NULL) {
|
|
|
|
|
if (flag->offset < core->offset) {
|
|
|
|
|
loff = flag->offset;
|
|
|
|
|
lmatch = flag->name;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
uoff = flag->offset;
|
|
|
|
|
umatch = flag->name;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
char *match = (curseek - loff) < (uoff - curseek) ? lmatch : umatch ;
|
|
|
|
|
if (match) {
|
|
|
|
|
if (*match) {
|
|
|
|
|
r_cons_println (match);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
r_list_free (temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
default:
|
2018-01-12 08:47:42 +00:00
|
|
|
|
arg = strchr (input, ' ');
|
|
|
|
|
if (arg) {
|
|
|
|
|
addr = r_num_math (core->num, arg + 1);
|
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-24 00:41:12 +00:00
|
|
|
|
core->flags->space_strict = space_strict;
|
2017-04-14 08:06:06 +00:00
|
|
|
|
f = r_flag_get_at (core->flags, addr, !strict_offset);
|
2016-01-09 22:55:18 +00:00
|
|
|
|
core->flags->space_strict = false;
|
2012-02-27 01:40:27 +00:00
|
|
|
|
if (f) {
|
|
|
|
|
if (f->offset != addr) {
|
2018-01-11 21:22:32 +00:00
|
|
|
|
// if input contains 'j' print json
|
|
|
|
|
if (strchr (input, 'j')) {
|
|
|
|
|
r_cons_printf ("{\"name\":\"%s\",\"offset\":%d}\n",
|
|
|
|
|
f->name, (int)(addr - f->offset));
|
|
|
|
|
} else {
|
|
|
|
|
r_cons_printf ("%s + %d\n", f->name,
|
|
|
|
|
(int)(addr - f->offset));
|
|
|
|
|
}
|
2015-08-11 09:49:56 +00:00
|
|
|
|
} else {
|
2018-01-12 08:47:42 +00:00
|
|
|
|
if (strchr (input, 'j')) {
|
2018-01-11 21:22:32 +00:00
|
|
|
|
r_cons_printf ("{\"name\":\"%s\"}\n",
|
|
|
|
|
f->name);
|
|
|
|
|
} else {
|
|
|
|
|
r_cons_println (f->name);
|
|
|
|
|
}
|
2015-08-11 09:49:56 +00:00
|
|
|
|
}
|
2012-02-27 01:40:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '?':
|
2018-09-17 07:50:31 +00:00
|
|
|
|
default:
|
2017-04-07 02:11:32 +00:00
|
|
|
|
if (input[1]) {
|
|
|
|
|
core->num->value = r_flag_get (core->flags, input + 1)? 1: 0;
|
|
|
|
|
} else {
|
2018-09-17 07:50:31 +00:00
|
|
|
|
r_core_cmd_help (core, help_msg_f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-11 09:49:56 +00:00
|
|
|
|
}
|
2017-11-23 13:34:07 +00:00
|
|
|
|
free (str);
|
2012-02-27 01:40:27 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|