mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
Five less globals in agraph
This commit is contained in:
parent
db798cf402
commit
f1ae08a813
@ -1,14 +1,9 @@
|
|||||||
/* Copyright radare2 - 2014-2023 - pancake, ret2libc */
|
/* Copyright radare2 - 2014-2024 - pancake, ret2libc */
|
||||||
|
|
||||||
#include <r_core.h>
|
#include <r_core.h>
|
||||||
#include <r_vec.h>
|
#include <r_vec.h>
|
||||||
|
|
||||||
R_IPI void visual_refresh(RCore *core);
|
R_IPI void visual_refresh(RCore *core);
|
||||||
static R_TH_LOCAL int mousemode = 0;
|
|
||||||
static R_TH_LOCAL int disMode = 0;
|
|
||||||
static R_TH_LOCAL int discroll = 0;
|
|
||||||
static R_TH_LOCAL bool graphCursor = false;
|
|
||||||
static R_TH_LOCAL bool coming_from_vmark = false;
|
|
||||||
|
|
||||||
static RCoreHelpMessage help_msg_visual_graph = {
|
static RCoreHelpMessage help_msg_visual_graph = {
|
||||||
":e cmd.gprompt=agft", "show tinygraph in one side",
|
":e cmd.gprompt=agft", "show tinygraph in one side",
|
||||||
@ -357,8 +352,8 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool d
|
|||||||
(void) G (-g->can->sx, -g->can->sy + 2);
|
(void) G (-g->can->sx, -g->can->sy + 2);
|
||||||
snprintf (title, sizeof (title) - 1, "[ %s ]", n->title);
|
snprintf (title, sizeof (title) - 1, "[ %s ]", n->title);
|
||||||
W (title);
|
W (title);
|
||||||
if (discroll > 0) {
|
if (g->discroll > 0) {
|
||||||
char *body = r_str_ansi_crop (n->body, 0, discroll, -1, -1);
|
char *body = r_str_ansi_crop (n->body, 0, g->discroll, -1, -1);
|
||||||
(void) G (-g->can->sx, -g->can->sy + 3);
|
(void) G (-g->can->sx, -g->can->sy + 3);
|
||||||
W (body);
|
W (body);
|
||||||
free (body);
|
free (body);
|
||||||
@ -3476,7 +3471,7 @@ static void agraph_update_title(RCore *core, RAGraph *g, RAnalFunction *fcn) {
|
|||||||
char *sig = r_core_cmd_str (core, "afcf");
|
char *sig = r_core_cmd_str (core, "afcf");
|
||||||
char *new_title = r_str_newf (
|
char *new_title = r_str_newf (
|
||||||
"%s[0x%08"PFMT64x "]> %s # %s ",
|
"%s[0x%08"PFMT64x "]> %s # %s ",
|
||||||
graphCursor? "(cursor)": "",
|
core->visual.graphCursor? "(cursor)": "",
|
||||||
fcn->addr, a? a->title: "", sig);
|
fcn->addr, a? a->title: "", sig);
|
||||||
r_agraph_set_title (g, new_title);
|
r_agraph_set_title (g, new_title);
|
||||||
free (new_title);
|
free (new_title);
|
||||||
@ -3727,9 +3722,9 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
|
|||||||
*fcn = f;
|
*fcn = f;
|
||||||
check_function_modified (core, *fcn);
|
check_function_modified (core, *fcn);
|
||||||
g->need_reload_nodes = true;
|
g->need_reload_nodes = true;
|
||||||
if (!coming_from_vmark) {
|
if (!core->visual.coming_from_vmark) {
|
||||||
g->force_update_seek = true;
|
g->force_update_seek = true;
|
||||||
coming_from_vmark = false;
|
core->visual.coming_from_vmark = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -3786,21 +3781,22 @@ static void graphNodeMove(RAGraph *g, int dir, int speed) {
|
|||||||
if (dir == 'h' || dir == 'l') {
|
if (dir == 'h' || dir == 'l') {
|
||||||
// horizontal scroll
|
// horizontal scroll
|
||||||
if (is_mini (g)) {
|
if (is_mini (g)) {
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
} else {
|
} else {
|
||||||
int delta = (dir == 'l')? 1: -1;
|
int delta = (dir == 'l')? 1: -1;
|
||||||
move_current_node (g, speed * delta, 0);
|
move_current_node (g, speed * delta, 0);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
RCore *core = NULL;
|
|
||||||
// vertical scroll
|
|
||||||
if (is_mini (g)) {
|
|
||||||
discroll += (delta * speed);
|
|
||||||
} else if (g->is_dis) {
|
|
||||||
r_core_cmdf (core, "so %d", (delta * 4) * speed);
|
|
||||||
} else {
|
} else {
|
||||||
move_current_node (g, 0, delta * speed);
|
// vertical scroll
|
||||||
|
if (is_mini (g)) {
|
||||||
|
g->discroll += (delta * speed);
|
||||||
|
} else if (g->is_dis) {
|
||||||
|
// XXX core is null here cant work
|
||||||
|
// RCore *core = NULL;
|
||||||
|
// r_core_cmdf (core, "so %d", (delta * 4) * speed);
|
||||||
|
} else {
|
||||||
|
move_current_node (g, 0, delta * speed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4331,7 +4327,7 @@ static void graph_continue(RCore *core) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void applyDisMode(RCore *core) {
|
static void applyDisMode(RCore *core) {
|
||||||
switch (disMode) {
|
switch (core->visual.disMode) {
|
||||||
case 0:
|
case 0:
|
||||||
r_config_set_b (core->config, "asm.pseudo", false);
|
r_config_set_b (core->config, "asm.pseudo", false);
|
||||||
r_config_set_b (core->config, "asm.esil", false);
|
r_config_set_b (core->config, "asm.esil", false);
|
||||||
@ -4586,7 +4582,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
switch (key) {
|
switch (key) {
|
||||||
case 'j':
|
case 'j':
|
||||||
case 'k':
|
case 'k':
|
||||||
switch (mousemode) {
|
switch (core->visual.mousemode) {
|
||||||
case 0: break;
|
case 0: break;
|
||||||
case 1: key = key == 'k'? 'h': 'l'; break;
|
case 1: key = key == 'k'? 'h': 'l'; break;
|
||||||
case 2: key = key == 'k'? 'J': 'K'; break;
|
case 2: key = key == 'k'? 'J': 'K'; break;
|
||||||
@ -4642,7 +4638,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
g->need_update_dim = true;
|
g->need_update_dim = true;
|
||||||
g->need_set_layout = true;
|
g->need_set_layout = true;
|
||||||
}
|
}
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
@ -4728,7 +4724,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
} else {
|
} else {
|
||||||
graph_single_step_in (core, g);
|
graph_single_step_in (core, g);
|
||||||
}
|
}
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
@ -4754,7 +4750,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
case '@': // tab
|
case '@': // tab
|
||||||
r_config_set_i (core->config, "graph.layout",
|
r_config_set_i (core->config, "graph.layout",
|
||||||
r_config_get_i (core->config, "graph.layout")? 0: 1);
|
r_config_get_i (core->config, "graph.layout")? 0: 1);
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
g->layout = r_config_get_i (core->config, "graph.layout");
|
g->layout = r_config_get_i (core->config, "graph.layout");
|
||||||
g->need_reload_nodes = true;
|
g->need_reload_nodes = true;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
@ -4766,7 +4762,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
break;
|
break;
|
||||||
case 9: // tab
|
case 9: // tab
|
||||||
agraph_next_node (g);
|
agraph_next_node (g);
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
r_cons_clear00 ();
|
r_cons_clear00 ();
|
||||||
@ -4785,7 +4781,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
g->mode = R_AGRAPH_MODE_COMMENTS;
|
g->mode = R_AGRAPH_MODE_COMMENTS;
|
||||||
}
|
}
|
||||||
g->need_reload_nodes = true;
|
g->need_reload_nodes = true;
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
// r_config_toggle (core->config, "graph.hints");
|
// r_config_toggle (core->config, "graph.hints");
|
||||||
break;
|
break;
|
||||||
@ -4814,7 +4810,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
if (!fcn) {
|
if (!fcn) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
disMode = (disMode + 1) % 3;
|
core->visual.disMode = (core->visual.disMode + 1) % 3;
|
||||||
applyDisMode (core);
|
applyDisMode (core);
|
||||||
g->need_reload_nodes = true;
|
g->need_reload_nodes = true;
|
||||||
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0);
|
||||||
@ -4967,7 +4963,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
r_cons_flush ();
|
r_cons_flush ();
|
||||||
const int ch = r_cons_readchar ();
|
const int ch = r_cons_readchar ();
|
||||||
r_core_vmark_seek (core, ch, g);
|
r_core_vmark_seek (core, ch, g);
|
||||||
coming_from_vmark = true;
|
core->visual.coming_from_vmark = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -4979,9 +4975,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
mousemode--;
|
core->visual.mousemode--;
|
||||||
if (mousemode < 0) {
|
if (core->visual.mousemode < 0) {
|
||||||
mousemode = 3;
|
core->visual.mousemode = 3;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
@ -5025,7 +5021,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
agraph_toggle_mini (g);
|
agraph_toggle_mini (g);
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@ -5033,7 +5029,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
break;
|
break;
|
||||||
case 'J':
|
case 'J':
|
||||||
// copypaste from 'j'
|
// copypaste from 'j'
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'j', speed * 2);
|
graphNodeMove (g, 'j', speed * 2);
|
||||||
} else {
|
} else {
|
||||||
@ -5041,7 +5037,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'K':
|
case 'K':
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'k', speed * 2);
|
graphNodeMove (g, 'k', speed * 2);
|
||||||
} else {
|
} else {
|
||||||
@ -5049,7 +5045,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
// move node canvas faster
|
// move node canvas faster
|
||||||
graphNodeMove (g, 'h', movspeed * 2);
|
graphNodeMove (g, 'h', movspeed * 2);
|
||||||
} else {
|
} else {
|
||||||
@ -5064,20 +5060,20 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
graphNodeMove (g, 'l', movspeed * 2);
|
graphNodeMove (g, 'l', movspeed * 2);
|
||||||
} else {
|
} else {
|
||||||
can->sx -= (5 * movspeed) * (invscroll? -1: 1);
|
can->sx -= (5 * movspeed) * (invscroll? -1: 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
graphCursor = !graphCursor;
|
core->visual.graphCursor = !core->visual.graphCursor;
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
if (g->is_dis) {
|
if (g->is_dis) {
|
||||||
r_core_cmd_call (core, "so 1");
|
r_core_cmd_call (core, "so 1");
|
||||||
} else {
|
} else {
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'j', speed);
|
graphNodeMove (g, 'j', speed);
|
||||||
} else {
|
} else {
|
||||||
@ -5090,7 +5086,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
if (g->is_dis) {
|
if (g->is_dis) {
|
||||||
r_core_cmd_call (core, "so -1");
|
r_core_cmd_call (core, "so -1");
|
||||||
} else {
|
} else {
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'k', speed);
|
graphNodeMove (g, 'k', speed);
|
||||||
} else {
|
} else {
|
||||||
@ -5100,7 +5096,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'l', speed);
|
graphNodeMove (g, 'l', speed);
|
||||||
} else {
|
} else {
|
||||||
@ -5108,7 +5104,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
if (graphCursor) {
|
if (core->visual.graphCursor) {
|
||||||
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
int speed = (okey == 27)? PAGEKEY_SPEED: movspeed;
|
||||||
graphNodeMove (g, 'h', speed);
|
graphNodeMove (g, 'h', speed);
|
||||||
} else {
|
} else {
|
||||||
@ -5130,7 +5126,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int
|
|||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
discroll = 0;
|
g->discroll = 0;
|
||||||
agraph_update_seek (g, get_anode (g->curnode), true);
|
agraph_update_seek (g, get_anode (g->curnode), true);
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* radare - LGPL - Copyright 2009-2023 // pancake */
|
/* radare - LGPL - Copyright 2009-2024 // pancake */
|
||||||
|
|
||||||
#if R_INCLUDE_BEGIN
|
#if R_INCLUDE_BEGIN
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ static int cmd_mount(void *data, const char *_input) {
|
|||||||
break;
|
break;
|
||||||
case 'd': // "md"
|
case 'd': // "md"
|
||||||
if (input[1] == '?') { // "md?"
|
if (input[1] == '?') { // "md?"
|
||||||
r_core_cmd_help_match (core, help_msg_m, "md");
|
r_core_cmd_help_contains (core, help_msg_m, "md");
|
||||||
} else {
|
} else {
|
||||||
cmd_mount_ls (core, input + 1);
|
cmd_mount_ls (core, input + 1);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ typedef struct r_ascii_graph_t {
|
|||||||
bool is_interactive;
|
bool is_interactive;
|
||||||
int zoom;
|
int zoom;
|
||||||
int movspeed;
|
int movspeed;
|
||||||
|
int discroll;
|
||||||
bool hints;
|
bool hints;
|
||||||
|
|
||||||
RANode *update_seek_on;
|
RANode *update_seek_on;
|
||||||
|
@ -250,6 +250,10 @@ typedef struct r_core_visual_t {
|
|||||||
bool firstRun;
|
bool firstRun;
|
||||||
bool fromVisual;
|
bool fromVisual;
|
||||||
char *menus_Colors[128];
|
char *menus_Colors[128];
|
||||||
|
int discroll;
|
||||||
|
int mousemode;
|
||||||
|
bool graphCursor;
|
||||||
|
bool coming_from_vmark;
|
||||||
} RCoreVisual;
|
} RCoreVisual;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user