Initial import of the flag tags registry and minor fixes for 'ft'

This commit is contained in:
pancake 2018-05-11 17:18:36 +02:00
parent b4dd6530fe
commit 81f7182800
11 changed files with 86 additions and 12 deletions

View File

@ -44,7 +44,7 @@ static const char *help_msg_f[] = {
"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",
"ft","[?]+-*","flag tags, useful to find all flags matching some words",
"ft","[?]*","flag tags, useful to find all flags matching some words",
"fV","[*-] [nkey] [offset]","dump/restore visual marks (mK/'K)",
"fx","[d]","show hexdump (or disasm) of flag:flagsize",
"fq","","list flags in quiet mode",
@ -212,16 +212,28 @@ static int flag_to_flag(RCore *core, const char *glob) {
}
static void cmd_flag_tags (RCore *core, const char *input) {
const char *arg = r_str_trim_ro (input + 2);
char mode = input[1];
for (input; *input && !IS_WHITESPACE (*input); input++) {}
char *inp = strdup (input);
char *arg = r_str_trim (inp);
if (!*arg) {
eprintf ("list tags\n");
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);
return;
}
if (*arg == '?') {
eprintf ("Usage: ft [k] [v ...]\n");
eprintf (" ft string strcpy strlen ... # set words for the 'string' tag\n");
eprintf (" ft string # get offsets of all matching flags\n");
eprintf (" ft # list all tags\n");
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);
return;
}
char *arg1 = strchr (arg, ' ');
@ -233,11 +245,21 @@ static void cmd_flag_tags (RCore *core, const char *input) {
RListIter *iter;
RFlagItem *flag;
RList *flags = r_flag_tags_get (core->flags, arg);
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);
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;
}
}
free (inp);
}
static void flag_ordinals(RCore *core, const char *str) {
@ -632,7 +654,7 @@ rep:
eprintf ("Missing arguments\n");
}
break;
case 't':
case 't': // "ft"
cmd_flag_tags (core, input);
break;
case 'S':

8
libr/flag/d/Makefile Normal file
View File

@ -0,0 +1,8 @@
#TODO: this makefile is not called yet. we need to test and improve that for the next release
FILES:=$(filter-out ft.r2,$(filter-out Makefile,$(shell ls)))
all: ft.r2
ft.r2: $(FILES)
for a in $(FILES) ; do b=$$(echo `cat $$a`); echo "ft $$a $$b" ; done > ft.r2

5
libr/flag/d/alloc Normal file
View File

@ -0,0 +1,5 @@
malloc
free
calloc
kalloc
realloc

7
libr/flag/d/env Normal file
View File

@ -0,0 +1,7 @@
getenv
putenv
unsetenv
setenv
GetEnvironmentVariable
SetEnvironmentVariable
ExpandEnvironmentStrings

4
libr/flag/d/fs Normal file
View File

@ -0,0 +1,4 @@
open
close
read$
write

10
libr/flag/d/network Normal file
View File

@ -0,0 +1,10 @@
socket
connect
bind$
listen
accept
sendto
recvfrom
gethostbyname
htons
ntohs

2
libr/flag/d/process Normal file
View File

@ -0,0 +1,2 @@
getpid
kill

2
libr/flag/d/stdout Normal file
View File

@ -0,0 +1,2 @@
printf
puts

7
libr/flag/d/string Normal file
View File

@ -0,0 +1,7 @@
strcat
strcpy
strncpy
strlen
strtok
strstr
strlcpy

View File

@ -13,8 +13,14 @@ R_API RList *r_flag_tags_list(RFlag *f) {
SdbList *o = sdb_foreach_list (f->tags, false);
SdbListIter *iter;
const char *tag;
ls_foreach (o, iter, tag) {
r_list_append (res, (void *)tag);
SdbKv *kv;
ls_foreach (o, iter, kv) {
const char *tag = kv->key;
if (strlen (tag) < 5) {
continue;
}
char *tagName = strdup (tag + 4);
r_list_append (res, (void *)strdup (tagName));
}
ls_free (o);
return res;

View File

@ -132,6 +132,7 @@ R_API int r_flag_space_push(RFlag *f, const char *name);
R_API int r_flag_space_stack_list(RFlag *f, int mode);
/* tags */
R_API RList *r_flag_tags_list(RFlag *f);
R_API RList *r_flag_tags_set(RFlag *f, const char *name, const char *words);
R_API void r_flag_tags_reset(RFlag *f, const char *name);
R_API RList *r_flag_tags_get(RFlag *f, const char *name);