From 583be01f32d7bdca1afa6ccd01feeff8c8448ade Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 14 May 2014 23:24:46 +0200 Subject: [PATCH] Handle ^C in /p --- libr/cons/cons.c | 2 ++ libr/core/cmd_search.c | 2 ++ libr/include/r_print.h | 5 +++++ libr/search/bytepat.c | 5 ++++- libr/util/print.c | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libr/cons/cons.c b/libr/cons/cons.c index f5ff49ff59..bbc3bc2290 100644 --- a/libr/cons/cons.c +++ b/libr/cons/cons.c @@ -16,6 +16,7 @@ static RCons r_cons_instance; static void break_signal(int sig) { I.breaked = R_TRUE; + r_print_set_interrupted (I.breaked); if (I.event_interrupt) I.event_interrupt (I.data); } @@ -116,6 +117,7 @@ R_API void r_cons_break(void (*cb)(void *u), void *user) { R_API void r_cons_break_end() { I.breaked = R_FALSE; + r_print_set_interrupted (I.breaked); #if __UNIX__ signal (SIGINT, SIG_IGN); #endif diff --git a/libr/core/cmd_search.c b/libr/core/cmd_search.c index c79857aaff..cac0666df6 100644 --- a/libr/core/cmd_search.c +++ b/libr/core/cmd_search.c @@ -476,8 +476,10 @@ static int cmd_search(void *data, const char *input) { { int ps = atoi (input+1); if (ps>1) { + r_cons_break (NULL, NULL); r_search_pattern_size (core->search, ps); r_search_pattern (core->search, from, to); + r_cons_break_end (); } else eprintf ("Invalid pattern size (must be >0)\n"); } break; diff --git a/libr/include/r_print.h b/libr/include/r_print.h index 3f82a4b672..404550dfff 100644 --- a/libr/include/r_print.h +++ b/libr/include/r_print.h @@ -59,6 +59,11 @@ typedef struct r_print_t { } RPrint; #ifdef R_API +/* RConsBreak handlers */ +R_API int r_print_is_interrupted(); +R_API void r_print_set_interrupt(int i); + +/* ... */ R_API char *r_print_hexpair(RPrint *p, const char *str, int idx); R_API RPrint *r_print_new(); R_API RPrint *r_print_free(RPrint *p); diff --git a/libr/search/bytepat.c b/libr/search/bytepat.c index 0362ac4a74..b458ae167d 100644 --- a/libr/search/bytepat.c +++ b/libr/search/bytepat.c @@ -58,7 +58,7 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) { int patlen = s->pattern_size; fnditem* root; -eprintf ("Searching patterns between 0x%llx and 0x%llx\n", from, to); + eprintf ("Searching patterns between 0x%llx and 0x%llx\n", from, to); if (patlen < 1 || patlen > MAX_PATLEN) { eprintf ("Invalid pattern length (must be > 1 and < %d)\n", MAX_PATLEN); return R_FALSE; @@ -74,6 +74,9 @@ eprintf ("Searching patterns between 0x%llx and 0x%llx\n", from, to); // bproc = from2 while (bact < bytes) { addr = bact; + if (r_print_is_interrupted ()) { + break; + } bproc = bact + patlen ; // read ( fd, sblk, patlen ); diff --git a/libr/util/print.c b/libr/util/print.c index f3bfb86b8f..0f1167599c 100644 --- a/libr/util/print.c +++ b/libr/util/print.c @@ -6,6 +6,15 @@ #include "r_util.h" static int nullprinter(const char* a, ...) { return 0; } +static int IsInterrupted = 0; + +R_API int r_print_is_interrupted() { + return IsInterrupted; +} + +R_API void r_print_set_interrupted(int i) { + IsInterrupted = i; +} R_API int r_print_mute(RPrint *p, int x) { if (x) {