From 81f71828002fc0e555051700bfa2dfb91d38813f Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 11 May 2018 17:18:36 +0200 Subject: [PATCH] Initial import of the flag tags registry and minor fixes for 'ft' --- libr/core/cmd_flag.c | 42 ++++++++++++++++++++++++++++++++---------- libr/flag/d/Makefile | 8 ++++++++ libr/flag/d/alloc | 5 +++++ libr/flag/d/env | 7 +++++++ libr/flag/d/fs | 4 ++++ libr/flag/d/network | 10 ++++++++++ libr/flag/d/process | 2 ++ libr/flag/d/stdout | 2 ++ libr/flag/d/string | 7 +++++++ libr/flag/tags.c | 10 ++++++++-- libr/include/r_flag.h | 1 + 11 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 libr/flag/d/Makefile create mode 100644 libr/flag/d/alloc create mode 100644 libr/flag/d/env create mode 100644 libr/flag/d/fs create mode 100644 libr/flag/d/network create mode 100644 libr/flag/d/process create mode 100644 libr/flag/d/stdout create mode 100644 libr/flag/d/string diff --git a/libr/core/cmd_flag.c b/libr/core/cmd_flag.c index aaa85527c3..e2b46ad05c 100644 --- a/libr/core/cmd_flag.c +++ b/libr/core/cmd_flag.c @@ -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': diff --git a/libr/flag/d/Makefile b/libr/flag/d/Makefile new file mode 100644 index 0000000000..0ac3fc03d0 --- /dev/null +++ b/libr/flag/d/Makefile @@ -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 diff --git a/libr/flag/d/alloc b/libr/flag/d/alloc new file mode 100644 index 0000000000..3e7ec3cc6f --- /dev/null +++ b/libr/flag/d/alloc @@ -0,0 +1,5 @@ +malloc +free +calloc +kalloc +realloc diff --git a/libr/flag/d/env b/libr/flag/d/env new file mode 100644 index 0000000000..0b6bf44509 --- /dev/null +++ b/libr/flag/d/env @@ -0,0 +1,7 @@ +getenv +putenv +unsetenv +setenv +GetEnvironmentVariable +SetEnvironmentVariable +ExpandEnvironmentStrings diff --git a/libr/flag/d/fs b/libr/flag/d/fs new file mode 100644 index 0000000000..406e2735f2 --- /dev/null +++ b/libr/flag/d/fs @@ -0,0 +1,4 @@ +open +close +read$ +write diff --git a/libr/flag/d/network b/libr/flag/d/network new file mode 100644 index 0000000000..01bf4733d4 --- /dev/null +++ b/libr/flag/d/network @@ -0,0 +1,10 @@ +socket +connect +bind$ +listen +accept +sendto +recvfrom +gethostbyname +htons +ntohs diff --git a/libr/flag/d/process b/libr/flag/d/process new file mode 100644 index 0000000000..b7b1b166dd --- /dev/null +++ b/libr/flag/d/process @@ -0,0 +1,2 @@ +getpid +kill diff --git a/libr/flag/d/stdout b/libr/flag/d/stdout new file mode 100644 index 0000000000..2dd2515c46 --- /dev/null +++ b/libr/flag/d/stdout @@ -0,0 +1,2 @@ +printf +puts diff --git a/libr/flag/d/string b/libr/flag/d/string new file mode 100644 index 0000000000..1d3e871d44 --- /dev/null +++ b/libr/flag/d/string @@ -0,0 +1,7 @@ +strcat +strcpy +strncpy +strlen +strtok +strstr +strlcpy diff --git a/libr/flag/tags.c b/libr/flag/tags.c index c2fee156ae..2d3097abe2 100644 --- a/libr/flag/tags.c +++ b/libr/flag/tags.c @@ -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; diff --git a/libr/include/r_flag.h b/libr/include/r_flag.h index 4ec03f3243..0da53c3f32 100644 --- a/libr/include/r_flag.h +++ b/libr/include/r_flag.h @@ -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);