Improvements in aaa output and initial work towards twice afva checks ##analysis

This commit is contained in:
pancake 2024-06-05 22:47:45 +02:00 committed by GitHub
parent 6ad44b9c74
commit a307e85246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 31 deletions

View File

@ -6760,7 +6760,8 @@ R_API int r_core_esil_step(RCore *core, ut64 until_addr, const char *until_expr,
if (re < 1) {
ret = 0;
} else {
ret = r_anal_op (core->anal, &op, addr, code, sizeof (code), R_ARCH_OP_MASK_BASIC | R_ARCH_OP_MASK_ESIL | R_ARCH_OP_MASK_HINT);
ret = r_anal_op (core->anal, &op, addr, code, sizeof (code),
R_ARCH_OP_MASK_BASIC | R_ARCH_OP_MASK_ESIL | R_ARCH_OP_MASK_HINT);
}
// if type is JMP then we execute the next N instructions
// update the esil pointer because RAnal.op() can change it
@ -13373,7 +13374,7 @@ static bool isSkippable(RBinSymbol *s) {
return false;
}
R_API int r_core_anal_all(RCore *core) {
static bool cmd_aa(RCore *core, bool aaa) {
const RList *list;
RListIter *iter;
RAnalFunction *fcni;
@ -13449,21 +13450,23 @@ R_API int r_core_anal_all(RCore *core) {
}
}
r_core_task_yield (&core->tasks);
// R2_600 - drop this code? we already recover vars later in aaa. should be fine to if 0
if (anal_vars) {
logline (core, 22, "Recovering variables");
/* Set fcn type to R_ANAL_FCN_TYPE_SYM for symbols */
r_list_foreach_prev (core->anal->fcns, iter, fcni) {
if (r_cons_is_breaked ()) {
break;
}
r_core_recover_vars (core, fcni, true);
const char *fname = fcni->name;
if (r_str_startswith (fname, "dbg.")
|| r_str_startswith (fname, "rsym.")
|| r_str_startswith (fname, "sym.")
|| r_str_startswith (fname, "main")) {
fcni->type = R_ANAL_FCN_TYPE_SYM;
if (!aaa) {
// R2_600 - drop this code? we already recover vars later in aaa. should be fine to if 0
if (anal_vars) {
logline (core, 22, "Recovering variables (afva@@@F)");
/* Set fcn type to R_ANAL_FCN_TYPE_SYM for symbols */
r_list_foreach_prev (core->anal->fcns, iter, fcni) {
if (r_cons_is_breaked ()) {
break;
}
r_core_recover_vars (core, fcni, true);
const char *fname = fcni->name;
if (r_str_startswith (fname, "dbg.")
|| r_str_startswith (fname, "rsym.")
|| r_str_startswith (fname, "sym.")
|| r_str_startswith (fname, "main")) {
fcni->type = R_ANAL_FCN_TYPE_SYM;
}
}
}
}
@ -13471,6 +13474,15 @@ R_API int r_core_anal_all(RCore *core) {
return true;
}
#if R2_USE_NEW_ABI
// deprecated call
#else
R_API int r_core_anal_all(RCore *core) {
cmd_aa (core, true);
return true;
}
#endif
static int cmd_anal_all(RCore *core, const char *input) {
switch (*input) {
case '?':
@ -13673,18 +13685,21 @@ static int cmd_anal_all(RCore *core, const char *input) {
anal_imports = true;
}
r_config_set_b (core->config, "anal.imports", false);
r_core_anal_all (core);
cmd_aa (core, input[0] == 'a');
r_config_set_b (core->config, "anal.imports", anal_imports);
r_core_task_yield (&core->tasks);
if (r_cons_is_breaked ()) {
goto jacuzzi;
}
#if 1
// TODO: should not be run sometimes
// Run afvn in all fcns
if (r_config_get_b (core->config, "anal.vars")) {
logline (core, 25, "Analyze all functions arguments/locals (afva@@@F)");
// r_core_cmd0 (core, "afva@@f");
r_core_cmd0 (core, "afva@@@F");
}
#endif
// Run pending analysis immediately after analysis
// Usefull when running commands with ";" or via r2 -c,-i
@ -13754,7 +13769,7 @@ static int cmd_anal_all(RCore *core, const char *input) {
r_core_task_yield (&core->tasks);
logline (core, 60, "Finding and parsing C++ vtables (avrr)");
r_core_cmd_call (core, "avrr");
logline (core, 65, "Analyzing methods");
logline (core, 65, "Analyzing methods (af @@ method.*)");
r_core_cmd0 (core, "af @@ method.*");
r_core_task_yield (&core->tasks);
// r_config_set_b (core->config, "anal.calls", c);
@ -13800,7 +13815,7 @@ static int cmd_anal_all(RCore *core, const char *input) {
r_core_task_yield (&core->tasks);
}
if (core->anal->opt.vars) {
logline (core, 80, "Recovering local variables (afva)");
logline (core, 80, "Recovering local variables (afva@@@F)");
RAnalFunction *fcni;
RListIter *iter;
r_list_foreach (core->anal->fcns, iter, fcni) {

View File

@ -689,7 +689,9 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts);
R_API int r_core_anal_graph_fcn(RCore *core, char *input, int opts);
R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n);
R_API int r_core_anal_ref_list(RCore *core, int rad);
#if !R2_USE_NEW_ABI
R_API int r_core_anal_all(RCore *core);
#endif
R_API RList* r_core_anal_cycles(RCore *core, int ccl);
typedef struct r_vec_RVecAnalRef_t RVecAnalRef;
R_API RVecAnalRef *r_core_anal_fcn_get_calls(RCore *core, RAnalFunction *fcn); // get all calls from a function

View File

@ -110,7 +110,7 @@ INFO: Analyze all flags starting with sym. and entry0 (aa)
INFO: Analyze imports (af@@@i)
INFO: Analyze entrypoint (af@ entry0)
INFO: Analyze symbols (af@@@s)
INFO: Recovering variables
INFO: Recovering variables (afva@@@F)
INFO: Analyze all functions arguments/locals (afva@@@F)
 WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late

View File

@ -60,11 +60,6 @@ EXPECT=<<EOF
"origin": "logline",
"message": "Analyze symbols (af@@@s)"
},
{
"type": "WARN",
"origin": "logline",
"message": "Recovering variables"
},
{
"type": "WARN",
"origin": "logline",
@ -93,7 +88,7 @@ EXPECT=<<EOF
{
"type": "WARN",
"origin": "logline",
"message": "Analyzing methods"
"message": "Analyzing methods (af @@ method.*)"
},
{
"type": "WARN",
@ -108,7 +103,7 @@ EXPECT=<<EOF
{
"type": "WARN",
"origin": "logline",
"message": "Recovering local variables (afva)"
"message": "Recovering local variables (afva@@@F)"
},
{
"type": "WARN",

View File

@ -131221,19 +131221,19 @@ INFO: Analyze all flags starting with sym. and entry0 (aa)
INFO: Analyze imports (af@@@i)
INFO: Analyze entrypoint (af@ entry0)
                               INFO: Analyze symbols (af@@@s)
INFO: Recovering variables
INFO: Recovering variables (afva@@@F)
INFO: Analyze all functions arguments/locals (afva@@@F)
 INFO: Analyze all flags starting with sym. and entry0 (aa)
INFO: Analyze imports (af@@@i)
INFO: Analyze entrypoint (af@ entry0)
INFO: Analyze symbols (af@@@s)
INFO: Recovering variables
INFO: Recovering variables (afva@@@F)
INFO: Analyze all functions arguments/locals (afva@@@F)
 INFO: Analyze all flags starting with sym. and entry0 (aa)
INFO: Analyze imports (af@@@i)
INFO: Analyze entrypoint (af@ entry0)
                               INFO: Analyze symbols (af@@@s)
INFO: Recovering variables
INFO: Recovering variables (afva@@@F)
INFO: Analyze all functions arguments/locals (afva@@@F)
 ERROR: Cannot find basic block
                                                                                      ERROR: Cannot find basic block