Dont enable debug tracing from type propagation ##analysis

This commit is contained in:
pancake 2023-06-05 21:03:57 +02:00
parent 0c90170ced
commit 4a53f2b2c0
5 changed files with 95 additions and 60 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2016-2021 - oddcoder, sivaramaaa, pancake */
/* radare - LGPL - Copyright 2016-2023 - oddcoder, sivaramaaa, pancake */
/* type matching - type propagation */
#include <r_anal.h>
@ -22,8 +22,7 @@ static bool anal_emul_init(RCore *core, RConfigHold *hc, RDebugTrace **dt, REsil
const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP);
const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP);
if ((bp && !r_reg_getv (core->anal->reg, bp)) && (sp && !r_reg_getv (core->anal->reg, sp))) {
eprintf ("Stack isn't initialized.\n");
eprintf ("Try running aei and aeim commands before aft for default stack initialization\n");
R_LOG_WARN ("The virtual stack is not yet available. Run aeim or aei and try again");
return false;
}
return (core->dbg->trace && core->anal->esil->trace);

View File

@ -491,6 +491,15 @@ static const char *avatar_orangg[] = {
" `-----'`-----'\n"
};
static const char *avatar_croco[] = {
" __ __ .-%s-.\n"
"(o |_| o)_____ | %s |\n"
"| ___________) < %s |\n"
"\\ / | %s |\n"
" \\ / `-%s-'\n"
" \\________/\n"
};
static const char *avatar_clippy[] = {
" .--. .-%s-.\n"
" | _| | %s |\n"
@ -560,36 +569,53 @@ static const char *avatar_cybcat[] = {
enum {
R_AVATAR_ORANGG,
R_AVATAR_CYBCAT,
R_AVATAR_CROCO,
R_AVATAR_CLIPPY,
};
R_API void r_core_clippy(RCore *core, const char *msg) {
int type = R_AVATAR_CLIPPY;
if (*msg == '+' || *msg == '3') {
char *space = strchr (msg, ' ');
if (!space) {
return;
switch (*msg) {
case '+':
case '3':
case 'C':
{
char *space = strchr (msg, ' ');
if (!space) {
return;
}
type = (*msg == '+')? R_AVATAR_ORANGG: (*msg == 'C')? R_AVATAR_CROCO: R_AVATAR_CYBCAT;
msg = space + 1;
}
type = (*msg == '+')? R_AVATAR_ORANGG: R_AVATAR_CYBCAT;
msg = space + 1;
break;
}
const char *f;
int msglen = r_str_len_utf8 (msg);
char *s = strdup (r_str_pad (' ', msglen));
char *l;
if (type == R_AVATAR_ORANGG) {
switch (type) {
case R_AVATAR_ORANGG:
l = strdup (r_str_pad ('-', msglen));
f = avatar_orangg[0];
} else if (type == R_AVATAR_CYBCAT) {
break;
case R_AVATAR_CROCO:
l = strdup (r_str_pad ('-', msglen));
f = avatar_croco[0];
break;
case R_AVATAR_CYBCAT:
l = strdup (r_str_pad ('-', msglen));
f = avatar_cybcat[r_num_rand (R_ARRAY_SIZE (avatar_cybcat))];
} else if (r_config_get_i (core->config, "scr.utf8")) {
l = (char *)r_str_repeat ("", msglen);
f = avatar_clippy_utf8[r_num_rand (R_ARRAY_SIZE (avatar_clippy_utf8))];
} else {
l = strdup (r_str_pad ('-', msglen));
f = avatar_clippy[r_num_rand (R_ARRAY_SIZE (avatar_clippy))];
break;
default:
if (r_config_get_b (core->config, "scr.utf8")) {
l = (char *)r_str_repeat ("", msglen);
f = avatar_clippy_utf8[r_num_rand (R_ARRAY_SIZE (avatar_clippy_utf8))];
} else {
l = strdup (r_str_pad ('-', msglen));
f = avatar_clippy[r_num_rand (R_ARRAY_SIZE (avatar_clippy))];
}
break;
}
r_cons_printf (f, l, s, msg, s, l);

View File

@ -1,10 +1,11 @@
/* radare - LGPL - Copyright 2010-2022 - pancake, rhl */
/* radare - LGPL - Copyright 2010-2023 - pancake, rhl */
#define USE_R2 1
#define PROJECT_EXPERIMENTAL 0
#include <r_core.h>
#include <rvc.h>
// required to make spp use RStrBuf instead of SStrBuf
#define USE_R2 1
#include <spp/spp.h>
// project apis to be used from cmd_project.c
@ -101,13 +102,12 @@ R_API void r_core_project_cat(RCore *core, const char *name) {
R_API int r_core_project_list(RCore *core, int mode) {
PJ *pj = NULL;
RListIter *iter;
RList *list;
char *foo, *path = r_file_abspath (r_config_get (core->config, "dir.projects"));
if (!path) {
return 0;
}
list = r_sys_dir (path);
RList *list = r_sys_dir (path);
switch (mode) {
case 'j':
pj = pj_new ();
@ -169,7 +169,7 @@ R_API int r_core_project_delete(RCore *core, const char *prjfile) {
}
static bool load_project_rop(RCore *core, const char *prjfile) {
r_return_val_if_fail (core && !R_STR_ISEMPTY (prjfile), false);
r_return_val_if_fail (core && R_STR_ISNOTEMPTY (prjfile), false);
char *path, *db = NULL, *path_ns;
bool found = 0;
SdbListIter *it;
@ -288,9 +288,10 @@ typedef struct {
RCore *core;
char *prj_name;
char *rc_path;
} projectState;
} ProjectState;
static bool r_core_project_load(RCore *core, const char *prj_name, const char *rcpath) {
r_return_val_if_fail (core, false);
if (R_STR_ISEMPTY (prj_name)) {
prj_name = r_core_project_name (core, rcpath);
}
@ -337,7 +338,7 @@ static bool r_core_project_load(RCore *core, const char *prj_name, const char *r
}
static RThreadFunctionRet project_load_background(RThread *th) {
projectState *ps = th->user;
ProjectState *ps = th->user;
r_core_project_load (ps->core, ps->prj_name, ps->rc_path);
free (ps->prj_name);
free (ps->rc_path);
@ -346,7 +347,7 @@ static RThreadFunctionRet project_load_background(RThread *th) {
}
R_API RThread *r_core_project_load_bg(RCore *core, const char *prj_name, const char *rc_path) {
projectState *ps = R_NEW0 (projectState);
ProjectState *ps = R_NEW0 (ProjectState);
ps->core = core;
ps->prj_name = strdup (prj_name);
ps->rc_path = strdup (rc_path);
@ -370,13 +371,12 @@ R_API bool r_core_project_open(RCore *core, const char *prj_path) {
R_LOG_ERROR ("There's a project already opened");
ask_for_closing = false;
bool ccs = interactive? r_cons_yesno ('y', "Close current session? (Y/n)"): true;
if (ccs) {
r_core_cmd0 (core, "o--");
r_core_cmd0 (core, "P-");
} else {
if (!ccs) {
R_LOG_ERROR ("Project not loaded");
return false;
}
r_core_cmd0 (core, "o--");
r_core_cmd0 (core, "P-");
}
char *prj_name = r_core_project_name (core, prj_path);
char *prj_script = get_project_script_path (core, prj_path);
@ -417,9 +417,14 @@ static char *get_project_name(const char *prj_script) {
if (feof (fd)) {
break;
}
if (!strncmp (buf, "\"e prj.name = ", 14)) {
buf[strlen (buf) - 2] = 0;
file = r_str_new (buf + 14);
if (r_str_startswith (buf, "\"\"e prj.name = ")) {
file = strdup (buf + strlen ("\"\"e prj.name"));
break;
}
if (r_str_startswith (buf, "\"e prj.name = ")) {
// if (!strncmp (buf, "\"e prj.name = ", 14))
buf[strlen (buf) - 2] = 0; // remove trailing '"'
file = strdup (buf + 14);
break;
}
}

View File

@ -2,8 +2,6 @@
#include <r_debug.h>
// DO IT WITH SDB
R_API RDebugTrace *r_debug_trace_new(void) {
RDebugTrace *t = R_NEW0 (RDebugTrace);
if (!t) {
@ -12,12 +10,11 @@ R_API RDebugTrace *r_debug_trace_new(void) {
t->tag = 1; // UT32_MAX;
t->addresses = NULL;
t->enabled = false;
t->traces = r_list_new ();
t->traces = r_list_newf ((RListFree)free);
if (!t->traces) {
r_debug_trace_free (t);
return NULL;
}
t->traces->free = free;
t->ht = ht_pp_new0 ();
if (!t->ht) {
r_debug_trace_free (t);
@ -28,18 +25,19 @@ R_API RDebugTrace *r_debug_trace_new(void) {
R_API void r_debug_trace_free(RDebugTrace *trace) {
if (trace) {
r_list_purge (trace->traces);
free (trace->traces);
r_list_free (trace->traces);
ht_pp_free (trace->ht);
R_FREE (trace);
free (trace);
}
}
// TODO: added overlap/mask support here... wtf?
// TODO: think about tagged traces
// TODO: think about tagged traces .. must return 0 or ntag :?
R_API int r_debug_trace_tag(RDebug *dbg, int tag) {
//if (tag>0 && tag<31) core->dbg->trace->tag = 1<<(sz-1);
return (dbg->trace->tag = (tag>0)? tag: UT32_MAX);
r_return_val_if_fail (dbg && dbg->trace, 0);
ut32 ntag = (tag > 0)? (ut32)tag: UT32_MAX;
dbg->trace->tag = ntag;
return ntag;
}
R_API bool r_debug_trace_ins_before(RDebug *dbg) {
@ -157,7 +155,9 @@ R_API bool r_debug_trace_ins_after(RDebug *dbg) {
/*
* something happened at the given pc that we need to trace
*/
// R2_590 -> must be bool
R_API int r_debug_trace_pc(RDebug *dbg, ut64 pc) {
r_return_val_if_fail (dbg && dbg->trace, false);
ut8 buf[32];
RAnalOp op = {0};
if (!dbg->iob.is_valid_offset (dbg->iob.io, pc, 0)) {
@ -175,6 +175,7 @@ R_API int r_debug_trace_pc(RDebug *dbg, ut64 pc) {
}
R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) {
r_return_if_fail (dbg && dbg->trace);
static ut64 oldpc = UT64_MAX; // Must trace the previously traced instruction
if (dbg->trace->enabled) {
if (dbg->anal->esil) {
@ -192,12 +193,14 @@ R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) {
}
R_API void r_debug_trace_at(RDebug *dbg, const char *str) {
r_return_if_fail (dbg && dbg->trace);
// TODO: parse offsets and so use ut64 instead of strstr()
free (dbg->trace->addresses);
dbg->trace->addresses = (str&&*str)? strdup (str): NULL;
dbg->trace->addresses = R_STR_ISNOTEMPTY (str)? strdup (str): NULL;
}
R_API RDebugTracepoint *r_debug_trace_get(RDebug *dbg, ut64 addr) {
r_return_val_if_fail (dbg && dbg->trace, NULL);
int tag = dbg->trace->tag;
r_strf_var (key, 64, "trace.%d.%"PFMT64x, tag, addr);
return ht_pp_find (dbg->trace->ht, key, NULL);
@ -210,6 +213,7 @@ static int cmpaddr(const void *_a, const void *_b) {
}
R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset) {
r_return_if_fail (dbg && dbg->trace);
int tag = dbg->trace->tag;
RListIter *iter;
bool flag = false;
@ -298,33 +302,32 @@ static bool r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
}
R_API RDebugTracepoint *r_debug_trace_add(RDebug *dbg, ut64 addr, int size) {
RDebugTracepoint *tp;
r_return_val_if_fail (dbg, NULL);
int tag = dbg->trace->tag;
if (!r_debug_trace_is_traceable (dbg, addr)) {
return NULL;
}
r_anal_trace_bb (dbg->anal, addr);
tp = R_NEW0 (RDebugTracepoint);
if (!tp) {
return NULL;
RDebugTracepoint *tp = R_NEW0 (RDebugTracepoint);
if (tp) {
tp->stamp = r_time_now ();
tp->addr = addr;
tp->tags = tag;
tp->size = size;
tp->count = ++dbg->trace->count;
tp->times = 1;
r_list_append (dbg->trace->traces, tp);
r_strf_var (key, 64, "trace.%d.%"PFMT64x, tag, addr);
ht_pp_update (dbg->trace->ht, key, tp);
}
tp->stamp = r_time_now ();
tp->addr = addr;
tp->tags = tag;
tp->size = size;
tp->count = ++dbg->trace->count;
tp->times = 1;
r_list_append (dbg->trace->traces, tp);
r_strf_var (key, 64, "trace.%d.%"PFMT64x, tag, addr);
ht_pp_update (dbg->trace->ht, key, tp);
return tp;
}
R_API void r_debug_trace_reset(RDebug *dbg) {
r_return_if_fail (dbg);
RDebugTrace *t = dbg->trace;
r_list_purge (t->traces);
ht_pp_free (t->ht);
t->ht = ht_pp_new0 ();
t->traces = r_list_new ();
t->traces->free = free;
r_list_free (t->traces);
t->traces = r_list_newf ((RListFree)free);
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2022 - pancake */
/* radare - LGPL - Copyright 2009-2023 - pancake */
#ifndef R2_DEBUG_H
#define R2_DEBUG_H
@ -234,6 +234,8 @@ typedef struct r_debug_trace_t {
HtPP *ht; // use rbtree like the iocache?
} RDebugTrace;
// R2_590 rename to traceitem for consistency?
#define r_debug_tracepoint_free(x) free((x))
typedef struct r_debug_tracepoint_t {
ut64 addr;
ut64 tags; // XXX