Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afva #23001

Merged
merged 4 commits into from
Jun 5, 2024
Merged

Afva #23001

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -13449,28 +13450,39 @@ 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;
}
}
}
}
r_cons_break_pop ();
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 '?':
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions libr/include/r_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/cmd_afl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions test/db/cmd/r2pipe2
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ EXPECT=<<EOF
"origin": "logline",
"message": "Analyze symbols (af@@@s)"
},
{
"type": "WARN",
"origin": "logline",
"message": "Recovering variables"
},
{
"type": "WARN",
"origin": "logline",
Expand Down Expand Up @@ -93,7 +88,7 @@ EXPECT=<<EOF
{
"type": "WARN",
"origin": "logline",
"message": "Analyzing methods"
"message": "Analyzing methods (af @@ method.*)"
},
{
"type": "WARN",
Expand All @@ -108,7 +103,7 @@ EXPECT=<<EOF
{
"type": "WARN",
"origin": "logline",
"message": "Recovering local variables (afva)"
"message": "Recovering local variables (afva@@@F)"
},
{
"type": "WARN",
Expand Down
6 changes: 3 additions & 3 deletions test/db/cmd/slow
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading