Skip to content

Commit

Permalink
Remove hackish r_core.h include in print.c and use callbacks instead
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanpencil committed Jul 20, 2018
1 parent 1ca11ba commit 6e04a55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions libr/core/core.c
Expand Up @@ -1867,6 +1867,14 @@ static int mywrite(const ut8 *buf, int len) {
return r_cons_memcat ((const char *)buf, len);
}

static bool exists_var(RPrint *print, ut64 func_addr, char *str) {
char *name_key = sdb_fmt ("var.0x%"PFMT64x ".%d.%s", func_addr, 1, str);
if (sdb_const_get_len (((RCore*)(print->user))->anal->sdb_fcns, name_key, NULL, 0)) {
return true;
}
return false;
}

static bool r_core_anal_log(struct r_anal_t *anal, const char *msg) {
RCore *core = anal->user;
if (core->cfglog) {
Expand Down Expand Up @@ -2028,6 +2036,7 @@ R_API bool r_core_init(RCore *core) {
core->print->cb_printf = r_cons_printf;
core->print->cb_color = r_cons_rainbow_get;
core->print->write = mywrite;
core->print->exists_var = exists_var;
core->print->disasm = __disasm;
core->print->colorfor = (RPrintColorFor)r_core_anal_optype_colorfor;
core->print->hasrefs = (RPrintColorFor)r_core_anal_hasrefs;
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_print.h
Expand Up @@ -85,6 +85,7 @@ typedef struct r_print_t {
RReg *reg;
RRegItem* (*get_register)(RReg *reg, const char *name, int type);
ut64 (*get_register_value)(RReg *reg, RRegItem *item);
bool (*exists_var)(struct RPrint *print, ut64 func_addr, char *str);
ut64* lines_cache;
int lines_cache_sz;
int lines_abs;
Expand Down
9 changes: 3 additions & 6 deletions libr/util/print.c
@@ -1,6 +1,5 @@
/* radare - LGPL - Copyright 2007-2018 - pancake */

#include "r_core.h"
#include "r_anal.h"
#include "r_cons.h"
#include "r_print.h"
Expand Down Expand Up @@ -1633,16 +1632,14 @@ static bool issymbol(char c) {
}

static bool check_arg_name (RPrint *print, char *p, ut64 func_addr) {
if (func_addr) {
if (func_addr && print->exists_var) {
int z;
for (z = 0; p[z] && (IS_ALPHA (p[z]) || IS_DIGIT (p[z]) || p[z] == '_'); z++);
char tmp = p[z];
p[z] = '\0';
char *name_key = sdb_fmt ("var.0x%"PFMT64x ".%d.%s", func_addr, 1, p);
bool ret = print->exists_var (print, func_addr, p);
p[z] = tmp;
if (sdb_const_get_len (((RCore*)(print->user))->anal->sdb_fcns, name_key, NULL, 0)) {
return true;
}
return ret;
}
return false;
}
Expand Down

0 comments on commit 6e04a55

Please sign in to comment.