From d97c6fb7f5ace4eba25efbad332b0cd647899334 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 9 May 2017 02:58:39 +0200 Subject: [PATCH] Implement cfg.log and cmd.log --- libr/core/cconfig.c | 13 ++++++++++++- libr/core/log.c | 10 ++++++++++ libr/include/r_core.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 05f6e43010..296ee7862b 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -784,7 +784,9 @@ static int cb_timezone(void *user, void *data) { } static int cb_cfglog(void *user, void *data) { - // TODO do something here + RCore *core = (RCore *) user; + RConfigNode *node = (RConfigNode *) data; + core->cfglog = node->i_value; return true; } @@ -837,6 +839,14 @@ static int cb_cfgsanbox(void *user, void *data) { return (!node->i_value && ret)? 0: 1; } +static int cb_cmdlog(void *user, void *data) { + RCore *core = (RCore *) user; + RConfigNode *node = (RConfigNode *) data; + R_FREE (core->cmdlog); + core->cmdlog = strdup (node->value); + return true; +} + static int cb_cmdrepeat(void *user, void *data) { RCore *core = (RCore *) user; RConfigNode *node = (RConfigNode *) data; @@ -2196,6 +2206,7 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("cmd.gprompt", "", "Graph visual prompt commands"); SETPREF ("cmd.hit", "", "Run when a search hit is found"); SETPREF ("cmd.open", "", "Run when file is opened"); + SETCB ("cmd.log", "", &cb_cmdlog, "Every time a new T log is added run this command"); SETPREF ("cmd.prompt", "", "Prompt commands"); SETCB ("cmd.repeat", "false", &cb_cmdrepeat, "Empty command an alias for '..' (repeat last command)"); SETPREF ("cmd.fcn.new", "", "Run when new function is analyzed"); diff --git a/libr/core/log.c b/libr/core/log.c index 32fe425b58..f6bd53caa4 100644 --- a/libr/core/log.c +++ b/libr/core/log.c @@ -59,8 +59,18 @@ R_API void r_core_log_free(RCoreLog *log) { } R_API void r_core_log_add(RCore *core, const char *msg) { + static bool inProcess = false; r_strpool_append (core->log->sp, msg); core->log->last++; + if (core->cmdlog && *core->cmdlog) { + if (inProcess) { + // avoid infinite recursive calls + return; + } + inProcess = true; + r_core_cmd0 (core, core->cmdlog); + inProcess = false; + } } R_API void r_core_log_del(RCore *core, int n) { diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 73f8e0932e..396a9695f5 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -140,6 +140,8 @@ typedef struct r_core_t { RAGraph *graph; char *cmdqueue; char *lastcmd; + char *cmdlog; + bool cfglog; int cmdrepeat; ut64 inc; int rtr_n;