Code cleanup

This commit is contained in:
pancake 2019-08-21 00:24:33 +02:00 committed by radare
parent 1224127c27
commit bd520474d7
7 changed files with 39 additions and 37 deletions

View File

@ -893,7 +893,6 @@ static int var_comparator(const RAnalVar *a, const RAnalVar *b){
R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int mode, PJ *pj) {
RList *list = r_anal_var_list (anal, fcn, kind);
r_list_sort (list, (RListComparator) var_comparator);
RAnalVar *var;
RListIter *iter;
if (!pj && mode == 'j') {
@ -902,6 +901,13 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m
if (mode == 'j') {
pj_a (pj);
}
if (!list) {
if (mode == 'j') {
pj_end (pj);
}
return;
}
r_list_sort (list, (RListComparator) var_comparator);
r_list_foreach (list, iter, var) {
if (var->kind != kind) {
continue;

View File

@ -453,12 +453,17 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) {
RAnalBlock *bb;
RListIter *it;
RAnalOp aop = {0};
RAnal *anal = core->anal;
Sdb *TDB = anal->sdb_types;
bool resolved = false;
r_return_if_fail (core && fcn && core->anal && core->anal->esil);
r_return_if_fail (core && core->anal && fcn);
if (!core->anal->esil) {
eprintf ("Please run aeim\n");
return;
}
RAnal *anal = core->anal;
Sdb *TDB = anal->sdb_types;
bool chk_constraint = r_config_get_i (core->config, "anal.types.constraint");
int ret, bsize = R_MAX (64, core->blocksize);
const int mininstrsz = r_anal_archinfo (anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
@ -474,7 +479,6 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) {
}
ut8 *buf = malloc (bsize);
if (!buf) {
free (buf);
r_anal_emul_restore (core, hc);
return;
}
@ -500,7 +504,7 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) {
if (i >= (bsize - 32)) {
i = 0;
}
ut64 pcval = r_reg_getv (core->anal->reg, pc);
ut64 pcval = r_reg_getv (anal->reg, pc);
if ((addr >= bb->addr + bb->size) || (addr < bb->addr) || pcval != addr) {
break;
}

View File

@ -563,15 +563,15 @@ R_API void r_core_anal_cc_init(RCore *core) {
RListIter *it;
RAnalFunction *fcn;
r_list_foreach (core->anal->fcns, it, fcn) {
const char *cc = NULL;
if (fcn->cc) {
char *ptr = sdb_fmt ("%p", fcn->cc);
const char *cc = sdb_const_get (sdbs[0], ptr, 0);
if (cc) {
fcn->cc = cc;
cc = sdb_const_get (sdbs[0], ptr, 0);
}
if (!fcn->cc) {
fcn->cc = r_anal_cc_default (core->anal);
if (!cc) {
cc = r_anal_cc_default (core->anal);
}
fcn->cc = r_str_const (fcn->cc);
fcn->cc = r_str_const (cc);
}
sdb_close (sdbs[0]);
sdb_free (sdbs[0]);

View File

@ -643,16 +643,15 @@ static bool cb_dbgbtdepth(void *user, void *data) {
}
static bool cb_asmbits(void *user, void *data) {
const char *asmos, *asmarch, *asmcpu;
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
int ret = 0, bits;
int ret = 0;
if (!core) {
eprintf ("user can't be NULL\n");
return false;
}
bits = node->i_value;
int bits = node->i_value;
#if 0
// TODO: pretty good optimization, but breaks many tests when arch is different i think
if (bits == core->assembler->bits && bits == core->anal->bits && bits == core->dbg->bits) {
@ -697,9 +696,10 @@ static bool cb_asmbits(void *user, void *data) {
(void)r_anal_set_reg_profile (core->anal);
}
}
asmos = r_config_get (core->config, "asm.os");
asmarch = r_config_get (core->config, "asm.arch");
asmcpu = r_config_get (core->config, "asm.cpu");
r_core_anal_cc_init (core);
const char *asmos = r_config_get (core->config, "asm.os");
const char *asmarch = r_config_get (core->config, "asm.arch");
const char *asmcpu = r_config_get (core->config, "asm.cpu");
if (core->anal) {
if (!r_syscall_setup (core->anal->syscall, asmarch, bits, asmcpu, asmos)) {
//eprintf ("asm.arch: Cannot setup syscall '%s/%s' from '%s'\n",
@ -729,8 +729,10 @@ static void update_asmfeatures_options(RCore *core, RConfigNode *node) {
for (i = 0; i < argc; i++) {
node->options->free = free;
const char *feature = r_str_word_get0 (features, i);
if (feature) {
r_list_append (node->options, strdup (feature));
}
}
free (features);
}
}

View File

@ -108,7 +108,6 @@ R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int
static bool __endian_swap(ut8 *buf, ut32 blocksize, ut8 len) {
ut32 i;
ut8 tmp;
ut16 v16;
ut32 v32;
ut64 v64;
@ -261,7 +260,7 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op) {
} else {
bool be = r_config_get_i (core->config, "cfg.bigendian");
if (!be) {
if (!__endian_swap (str, len, len)) {
if (!__endian_swap ((ut8*)str, len, len)) {
goto beach;
}
}
@ -272,7 +271,7 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op) {
case 's': buf[i] -= str[j]; break;
case 'm': buf[i] *= str[j]; break;
case 'w': buf[i] = str[j]; break;
case 'd': buf[i] = (str[j])? buf[i] / str[j]: 0; break;
case 'd': buf[i] = (str[j])? (buf[i] / str[j]): 0; break;
case 'r': buf[i] >>= str[j]; break;
case 'l': buf[i] <<= str[j]; break;
case 'o': buf[i] |= str[j]; break;

View File

@ -3438,7 +3438,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
}
free (name);
}
r_core_anal_propagate_noreturn(core);
r_core_anal_propagate_noreturn (core);
#if 0
// XXX THIS IS VERY SLOW
if (core->anal->opt.vars) {
@ -8488,7 +8488,7 @@ static int cmd_anal_all(RCore *core, const char *input) {
oldstr = r_print_rowlog (core->print, "Propagate noreturn information");
r_print_rowlog_done (core->print, oldstr);
r_core_anal_propagate_noreturn(core);
r_core_anal_propagate_noreturn (core);
oldstr = r_print_rowlog (core->print, "Use -AA or aaaa to perform additional experimental analysis.");
r_print_rowlog_done (core->print, oldstr);

View File

@ -839,18 +839,6 @@ R_API char *r_str_dup(char *ptr, const char *string) {
return r_str_new (string);
}
R_API void r_str_writef(int fd, const char *fmt, ...) {
char *buf;
va_list ap;
va_start (ap, fmt);
if ((buf = malloc (4096)) != NULL) {
vsnprintf (buf, 4096, fmt, ap);
r_str_write (fd, buf);
free (buf);
}
va_end (ap);
}
R_API char *r_str_prepend(char *ptr, const char *string) {
int slen, plen;
if (!ptr) {
@ -3006,6 +2994,9 @@ R_API const char *r_str_const_at(char ***consts, const char *ptr) {
}
R_API const char *r_str_const(const char *ptr) {
if (!ptr) {
return NULL;
}
return r_str_const_at (&__consts, ptr);
}