Introduce anal.verbose and set http.verbose and bin.verbose to false ##core

This commit is contained in:
radare 2019-03-06 11:26:37 +01:00 committed by GitHub
parent da6ec135dc
commit d7191b9aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 24 deletions

View File

@ -95,7 +95,9 @@ R_API int r_anal_bb(RAnal *anal, RAnalBlock *bb, ut64 addr, ut8 *buf, ut64 len,
r_anal_op_free (op);
op = NULL;
if (idx == 0) {
VERBOSE_ANAL eprintf ("Unknown opcode at 0x%08"PFMT64x"\n", addr+idx);
if (anal->verbose) {
eprintf ("Unknown opcode at 0x%08"PFMT64x"\n", addr+idx);
}
return R_ANAL_RET_END;
}
break;
@ -118,7 +120,11 @@ R_API int r_anal_bb(RAnal *anal, RAnalBlock *bb, ut64 addr, ut8 *buf, ut64 len,
if (bb->cond) {
// TODO: get values from anal backend
bb->cond->type = R_ANAL_COND_EQ;
} else VERBOSE_ANAL eprintf ("Unknown conditional for block 0x%"PFMT64x"\n", bb->addr);
} else {
if (anal->verbose) {
eprintf ("Unknown conditional for block 0x%"PFMT64x"\n", bb->addr);
}
}
bb->conditional = 1;
bb->fail = op->fail;
bb->jump = op->jump;

View File

@ -736,7 +736,9 @@ static bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAna
}
// predecessor must be a conditional jump
if (!prev_bb || !prev_bb->jump || !prev_bb->fail) {
eprintf ("[anal.jmp.tbl] Missing predecesessor cjmp bb at 0x%08"PFMT64x"\n", addr);
if (anal->verbose) {
eprintf ("Warning: [anal.jmp.tbl] Missing predecesessor cjmp bb at 0x%08"PFMT64x"\n", addr);
}
return false;
}
@ -934,7 +936,9 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut6
// check if address is readable //:
if (!anal->iob.is_valid_offset (anal->iob.io, addr, 0)) {
if (addr != UT64_MAX && !anal->iob.io->va) {
eprintf ("Invalid address 0x%"PFMT64x ". Try with io.va=true\n", addr);
if (anal->verbose) {
eprintf ("Invalid address 0x%"PFMT64x ". Try with io.va=true\n", addr);
}
}
return R_ANAL_RET_ERROR; // MUST BE TOO DEEP
}
@ -954,7 +958,9 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut6
bb = appendBasicBlock (anal, fcn, addr);
VERBOSE_ANAL eprintf ("Append bb at 0x%08"PFMT64x" (fcn 0x%08"PFMT64x ")\n", addr, fcn->addr);
if (anal->verbose) {
eprintf ("Append bb at 0x%08"PFMT64x" (fcn 0x%08"PFMT64x ")\n", addr, fcn->addr);
}
ut64 leaddr = UT64_MAX;
bool last_is_push = false;
@ -988,7 +994,9 @@ repeat:
r_anal_op_fini (&op);
if (isInvalidMemory (buf + addrbytes * idx, len - addrbytes * idx)) {
FITFCNSZ ();
VERBOSE_ANAL eprintf ("FFFF opcode at 0x%08"PFMT64x "\n", addr + idx);
if (anal->verbose) {
eprintf ("Warning: FFFF opcode at 0x%08"PFMT64x "\n", addr + idx);
}
return R_ANAL_RET_ERROR;
}
if ((oplen = r_anal_op (anal, &op, addr + idx, buf + (addrbytes * idx), len - (addrbytes * idx), R_ANAL_OP_MASK_ALL)) < 1) {
@ -1021,7 +1029,9 @@ repeat:
r_anal_fcn_split_bb (anal, fcn, bbg, addr + idx);
}
overlapped = 1;
VERBOSE_ANAL eprintf ("Overlapped at 0x%08"PFMT64x "\n", addr + idx);
if (anal->verbose) {
eprintf ("Overlapped at 0x%08"PFMT64x "\n", addr + idx);
}
// return R_ANAL_RET_END;
}
}
@ -1524,9 +1534,11 @@ analopfinish:
gotoBeachRet ();
} else {
if (!op.cond) {
VERBOSE_ANAL eprintf("RET 0x%08"PFMT64x ". %d %d %d\n",
addr + delay.un_idx - oplen, overlapped,
bb->size, r_anal_fcn_size (fcn));
if (anal->verbose) {
eprintf ("RET 0x%08"PFMT64x ". %d %d %d\n",
addr + delay.un_idx - oplen, overlapped,
bb->size, r_anal_fcn_size (fcn));
}
gotoBeach (R_ANAL_RET_END);
}
}
@ -2047,7 +2059,7 @@ R_API int r_anal_fcn_loops(RAnalFunction *fcn) {
return loops;
}
R_API int r_anal_fcn_cc(RAnalFunction *fcn) {
R_API int r_anal_fcn_cc(RAnal *anal, RAnalFunction *fcn) {
/*
CC = E - N + 2P
E = the number of edges of the graph.
@ -2060,7 +2072,7 @@ R_API int r_anal_fcn_cc(RAnalFunction *fcn) {
r_list_foreach (fcn->bbs, iter, bb) {
N++; // nodes
if (bb->jump == UT64_MAX && bb->fail != UT64_MAX) {
if ((anal && anal->verbose) && bb->jump == UT64_MAX && bb->fail != UT64_MAX) {
eprintf ("Warning: invalid bb jump/fail pair at 0x%08"PFMT64x" (fcn 0x%08"PFMT64x"\n", bb->addr, fcn->addr);
}
if (bb->jump == UT64_MAX && bb->fail == UT64_MAX) {

View File

@ -1261,7 +1261,7 @@ static bool fcnMetricsCmp(RSignItem *it, RAnalFunction *fcn) {
RSignGraph *graph = it->graph;
int ebbs = -1;
if (graph->cc != -1 && graph->cc != r_anal_fcn_cc (fcn)) {
if (graph->cc != -1 && graph->cc != r_anal_fcn_cc (NULL, fcn)) {
return false;
}
if (graph->nbbs != -1 && graph->nbbs != r_list_length (fcn->bbs)) {

View File

@ -11,7 +11,7 @@
#define PE_IMAGE_FILE_MACHINE_RPI2 452
#define MAX_METADATA_STRING_LENGTH 256
#define bprintf if(bin->verbose) eprintf
#define bprintf if (bin->verbose) eprintf
#define COFF_SYMBOL_SIZE 18
struct SCV_NB10_HEADER;

View File

@ -2278,7 +2278,7 @@ static int fcn_print_verbose(RCore *core, RAnalFunction *fcn, bool use_color) {
r_anal_fcn_realsize (fcn),
r_list_length (fcn->bbs),
r_anal_fcn_count_edges (fcn, &ebbs),
r_anal_fcn_cc (fcn),
r_anal_fcn_cc (core->anal, fcn),
r_anal_fcn_cost (core->anal, fcn),
addrwidth, fcn->meta.min,
r_anal_fcn_size (fcn),
@ -2465,7 +2465,7 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) {
pj_ki (pj, "stackframe", fcn->maxstack);
pj_ks (pj, "calltype", fcn->cc);
pj_ki (pj, "cost", r_anal_fcn_cost (core->anal, fcn));
pj_ki (pj, "cc", r_anal_fcn_cc (fcn));
pj_ki (pj, "cc", r_anal_fcn_cc (core->anal, fcn));
pj_ki (pj, "bits", fcn->bits);
pj_ks (pj, "type", r_anal_fcn_type_tostring (fcn->type));
pj_ki (pj, "nbbs", r_list_length (fcn->bbs));
@ -2674,7 +2674,7 @@ static int fcn_print_legacy(RCore *core, RAnalFunction *fcn) {
r_cons_printf ("\nstackframe: %d", fcn->maxstack);
r_cons_printf ("\ncall-convention: %s", fcn->cc);
r_cons_printf ("\ncyclomatic-cost : %d", r_anal_fcn_cost (core->anal, fcn));
r_cons_printf ("\ncyclomatic-complexity: %d", r_anal_fcn_cc (fcn));
r_cons_printf ("\ncyclomatic-complexity: %d", r_anal_fcn_cc (core->anal, fcn));
r_cons_printf ("\nbits: %d", fcn->bits);
r_cons_printf ("\ntype: %s", r_anal_fcn_type_tostring (fcn->type));
if (fcn->type == R_ANAL_FCN_TYPE_FCN || fcn->type == R_ANAL_FCN_TYPE_SYM) {

View File

@ -2109,6 +2109,13 @@ static int cb_zoombyte(void *user, void *data) {
return true;
}
static int cb_analverbose(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
core->anal->verbose = node->i_value;
return true;
}
static int cb_binverbose(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
@ -2589,6 +2596,7 @@ R_API int r_core_config_init(RCore *core) {
/* anal */
SETPREF ("anal.fcnprefix", "fcn", "Prefix new function names with this");
SETCB ("anal.verbose", "false", &cb_analverbose, "Show RAnal warnings when analyzing code");
SETPREF ("anal.a2f", "false", "Use the new WIP analysis algorithm (core/p/a2f), anal.depth ignored atm");
SETICB ("anal.gp", 0, (RConfigCallback)&cb_anal_gp, "Set the value of the GP register (MIPS)");
SETI ("anal.gp2", 0, "Set anal.gp before emulating each instruction (workaround)");
@ -2866,7 +2874,7 @@ R_API int r_core_config_init(RCore *core) {
SETCB ("bin.strings", "true", &cb_binstrings, "Load strings from rbin on startup");
SETCB ("bin.debase64", "false", &cb_debase64, "Try to debase64 all strings");
SETPREF ("bin.classes", "true", "Load classes from rbin on startup");
SETCB ("bin.verbose", "true", &cb_binverbose, "Show RBin warnings when loading binaries");
SETCB ("bin.verbose", "false", &cb_binverbose, "Show RBin warnings when loading binaries");
/* prj */
SETPREF ("prj.name", "", "Name of current project");

View File

@ -2636,7 +2636,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
if (input[2] == 'c') {
RAnalFunction *fcn;
if ((fcn = r_anal_get_fcn_in (core->anal, core->offset, 0)) != NULL) {
r_cons_printf ("%i\n", r_anal_fcn_cc (fcn));
r_cons_printf ("%i\n", r_anal_fcn_cc (core->anal, fcn));
} else {
eprintf ("Error: Cannot find function at 0x08%" PFMT64x "\n", core->offset);
}

View File

@ -118,7 +118,7 @@ out:
static bool addFcnGraph(RCore *core, RAnalFunction *fcn, const char *name) {
RSignGraph graph = {
.cc = r_anal_fcn_cc (fcn),
.cc = r_anal_fcn_cc (core->anal, fcn),
.nbbs = r_list_length (fcn->bbs)
};
// XXX ebbs doesnt gets initialized if calling this from inside the struct

View File

@ -36,9 +36,6 @@ R_LIB_VERSION_HEADER(r_anal);
bb_has_ops=0 -> 350MB
*/
// TODO: Remove this define? /cc @nibble_ds
#define VERBOSE_ANAL if(0)
/* meta */
typedef struct r_anal_meta_item_t {
ut64 from;
@ -708,6 +705,7 @@ typedef struct r_anal_t {
bool fillval;
bool (*log)(struct r_anal_t *anal, const char *msg);
bool (*read_at)(struct r_anal_t *anal, ut64 addr, ut8 *buf, int len);
bool verbose;
char *cmdtail;
int seggrn;
RFlagGetAtAddr flag_get;
@ -1476,7 +1474,7 @@ R_API ut32 r_anal_fcn_size(const RAnalFunction *fcn);
R_API void r_anal_fcn_set_size(RAnal *anal, RAnalFunction *fcn, ut32 size);
R_API ut32 r_anal_fcn_contsize(const RAnalFunction *fcn);
R_API ut32 r_anal_fcn_realsize(const RAnalFunction *fcn);
R_API int r_anal_fcn_cc(RAnalFunction *fcn);
R_API int r_anal_fcn_cc(RAnal *anal, RAnalFunction *fcn);
R_API int r_anal_fcn_loops(RAnalFunction *fcn);
R_API int r_anal_fcn_split_bb(RAnal *anal, RAnalFunction *fcn, RAnalBlock *bbi, ut64 addr);
R_API int r_anal_fcn_bb_overlaps(RAnalFunction *fcn, RAnalBlock *bb);