Add colors in afll and fix max stack

This commit is contained in:
pancake 2016-05-16 03:46:23 +02:00
parent dad8b434c4
commit c627fb3bec
3 changed files with 35 additions and 16 deletions

View File

@ -471,6 +471,9 @@ repeat:
switch (op.stackop) {
case R_ANAL_STACK_INC:
fcn->stack += op.val;
if (fcn->stack > 0 && (int)op.val > 0) {
fcn->maxstack = fcn->stack;
}
break;
// TODO: use fcn->stack to know our stackframe
case R_ANAL_STACK_SET:
@ -882,6 +885,7 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut8 *buf, ut64
int result = anal->cur->fcn (anal, fcn, addr, buf, len, reftype);
if (anal->cur->custom_fn_anal) return result;
}
fcn->maxstack = 0;
ret = fcn_recurse (anal, fcn, addr, buf, len, FCN_DEPTH);
if (ret == R_ANAL_RET_END && fcn->size) { // cfg analysis completed

View File

@ -1377,6 +1377,7 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
const char *lang;
bool demangle = r_config_get_i (core->config, "bin.demangle");
lang = demangle ? r_config_get (core->config, "bin.lang") : NULL;
bool use_color = r_config_get_i (core->config, "scr.color");
if (input && *input)
addr = r_num_math (core->num, input + 1);
@ -1407,12 +1408,14 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
r_cons_printf ("[");
}
if (rad == 'l') {
r_cons_printf ("%-11s %4s %5s %4s %11s %-11s %s %s %s %s %s %s\n",
"address", "size", "nbbs", "cc", "min bound", "max bound",
"calls", "vars", "args", "xref", "frame", "name");
r_cons_printf ("%-11s %-4s %-5s %-4s %-11s %-11s %s %s %s %s %s %s\n",
"===========", "====", "=====", "====", "===========", "===========",
"=====", "====", "====", "====", "=====", "====");
if (!r_list_empty (core->anal->fcns)) {
r_cons_printf ("%-11s %4s %5s %4s %11s range %-11s %s %s %s %s %s %s\n",
"address", "size", "nbbs", "cc", "min bound", "max bound",
"calls", "vars", "args", "xref", "frame", "name");
r_cons_printf ("%-11s %-4s %-5s %-4s %-11s ===== %-11s %s %s %s %s %s %s\n",
"===========", "====", "=====", "====", "===========", "===========",
"=====", "====", "====", "====", "=====", "====");
}
}
r_list_sort (core->anal->fcns, &cmpfcn);
r_list_foreach (core->anal->fcns, iter, fcn) {
@ -1442,8 +1445,8 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
if (rad == 'o' || rad == 'l') {
RListIter *callrefiter, *bbsiter;
RAnalBlock *bbi;
long long max = UT64_MIN;
long long min = UT64_MAX;
ut64 max = UT64_MIN;
ut64 min = UT64_MAX;
int noofCallRef = 0;
int noofRef = 0;
r_list_foreach (fcn->refs, callrefiter, refi) {
@ -1461,18 +1464,29 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
}
}
if (rad == 'l') {
r_cons_printf ("0x%08"PFMT64x" %4d %5d %4d 0x%08"PFMT64x" .. 0x%08"PFMT64x" %5d %4d %4d %4d %5d %s\n",
fcn->addr,
const char *color = "";
const char *color_end = use_color? Color_RESET: "";
if (use_color) {
if (strstr (name, "sym.imp.")) {
color = Color_YELLOW;
} else if (strstr (name, "sym.")) {
color = Color_GREEN;
} else if (strstr (name, "sub.")) {
color = Color_MAGENTA;
}
}
r_cons_printf ("%s0x%08"PFMT64x" %4d %5d %4d 0x%08"PFMT64x" %5d 0x%08"PFMT64x" %5d %4d %4d %4d %5d %s%s\n",
color, fcn->addr,
r_anal_fcn_cc (fcn),
r_anal_fcn_size (fcn), r_list_length (fcn->bbs), min, max, noofCallRef,
r_anal_fcn_size (fcn), r_list_length (fcn->bbs), min, fcn->size, max, noofCallRef,
r_anal_var_count (core->anal, fcn, 'v'),
r_anal_var_count (core->anal, fcn, 'a'), noofRef, fcn->stack, name);
r_anal_var_count (core->anal, fcn, 'a'), noofRef, fcn->maxstack, name, color_end);
} else {
r_cons_printf ("0x%08"PFMT64x" %-4d %-4d %s\n",
fcn->addr, r_anal_fcn_size (fcn), r_list_length (fcn->bbs), name);
r_cons_printf ("0x%08"PFMT64x" %4d %4d %4d %s\n",
fcn->addr, fcn->size, r_anal_fcn_size (fcn),
r_list_length (fcn->bbs), name);
}
free (callrefiter);
free (bbsiter);
} else if (rad == 'q') {
r_cons_printf ("0x%08"PFMT64x" ", fcn->addr);
//fcn->addr, fcn->size, r_list_length (fcn->bbs), fcn->name);
@ -1563,7 +1577,7 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
r_cons_printf ("#\n offset: 0x%08"PFMT64x"\n name: %s\n size: %"PFMT64d,
fcn->addr, name, (ut64)fcn->size);
r_cons_printf ("\n realsz: %d", r_anal_fcn_size (fcn));
r_cons_printf ("\n stackframe: %d", fcn->stack);
r_cons_printf ("\n stackframe: %d", fcn->maxstack);
r_cons_printf ("\n call-convention: %s", r_anal_cc_type2str (fcn->call));
r_cons_printf ("\n cyclomatic-complexity: %d", r_anal_fcn_cc (fcn));
r_cons_printf ("\n type: %s",

View File

@ -293,6 +293,7 @@ typedef struct r_anal_type_function_t {
char* attr; // __attribute__(()) list
ut64 addr;
int stack;
int maxstack;
int ninstr;
int nargs; // Function arguments counter
int depth;