Rizin
unix-like reverse engineering framework and cli tools
cagraph.c File Reference
#include <rz_core.h>
#include "core_private.h"

Go to the source code of this file.

Functions

RZ_IPI void rz_core_agraph_reset (RzCore *core)
 
RZ_IPI void rz_core_agraph_add_node (RzCore *core, const char *title, const char *body, int color)
 
RZ_IPI void rz_core_agraph_del_node (RzCore *core, const char *title)
 
RZ_IPI void rz_core_agraph_add_edge (RzCore *core, const char *un, const char *vn)
 
RZ_IPI void rz_core_agraph_del_edge (RzCore *core, const char *un, const char *vn)
 
RZ_IPI void rz_core_agraph_print_ascii (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_tiny (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_sdb (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_interactive (RzCore *core)
 
static void agraph_print_node_dot (RzANode *n, void *user)
 
static void agraph_print_edge_dot (RzANode *from, RzANode *to, void *user)
 
static void agraph_print_edge (RzANode *from, RzANode *to, void *user)
 
static void agraph_print_node (RzANode *n, void *user)
 
RZ_IPI void rz_core_agraph_print_dot (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_rizin (RzCore *core)
 
RZ_IPI void rz_core_agraph_print_json (RzCore *core)
 
static void agraph_print_node_gml (RzANode *n, void *user)
 
static void agraph_print_edge_gml (RzANode *from, RzANode *to, void *user)
 
RZ_IPI void rz_core_agraph_print_gml (RzCore *core)
 

Function Documentation

◆ agraph_print_edge()

static void agraph_print_edge ( RzANode from,
RzANode to,
void *  user 
)
static

Definition at line 129 of file cagraph.c.

129  {
130  rz_cons_printf("age \"%s\" \"%s\"\n", from->title, to->title);
131 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125

References from, rz_cons_printf(), and to.

Referenced by rz_core_agraph_print_rizin().

◆ agraph_print_edge_dot()

static void agraph_print_edge_dot ( RzANode from,
RzANode to,
void *  user 
)
static

Definition at line 125 of file cagraph.c.

125  {
126  rz_cons_printf("\"%s\" -> \"%s\"\n", from->title, to->title);
127 }

References from, rz_cons_printf(), and to.

Referenced by rz_core_agraph_print_dot().

◆ agraph_print_edge_gml()

static void agraph_print_edge_gml ( RzANode from,
RzANode to,
void *  user 
)
static

Definition at line 187 of file cagraph.c.

187  {
188  rz_cons_printf(" edge [\n"
189  " source %d\n"
190  " target %d\n"
191  " ]\n",
192  from->gnode->idx, to->gnode->idx);
193 }

References from, rz_cons_printf(), and to.

Referenced by rz_core_agraph_print_gml().

◆ agraph_print_node()

static void agraph_print_node ( RzANode n,
void *  user 
)
static

Definition at line 133 of file cagraph.c.

133  {
134  char *encbody, *cmd;
135  int len = strlen(n->body);
136 
137  if (len > 0 && n->body[len - 1] == '\n') {
138  len--;
139  }
140  encbody = rz_base64_encode_dyn((const ut8 *)n->body, len);
141  cmd = rz_str_newf("agn \"%s\" base64:%s\n", n->title, encbody);
142  rz_cons_print(cmd);
143  free(cmd);
144  free(encbody);
145 }
size_t len
Definition: 6502dis.c:15
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
int n
Definition: mipsasm.c:19
RZ_API char * rz_base64_encode_dyn(const ut8 *bin, size_t sz)
Definition: ubase64.c:92
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References cmd, free(), len, n, rz_base64_encode_dyn(), and rz_str_newf().

Referenced by rz_core_agraph_print_rizin().

◆ agraph_print_node_dot()

static void agraph_print_node_dot ( RzANode n,
void *  user 
)
static

Definition at line 112 of file cagraph.c.

112  {
113  char *label = strdup(n->body);
114  // label = rz_str_replace (label, "\n", "\\l", 1);
115  if (!label || !*label) {
116  rz_cons_printf("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\"]\n",
117  n->title, n->title, n->title);
118  } else {
119  rz_cons_printf("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\\n%s\"]\n",
120  n->title, n->title, n->title, label);
121  }
122  free(label);
123 }
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
Definition: dis.h:35

References free(), n, rz_cons_printf(), and strdup().

Referenced by rz_core_agraph_print_dot().

◆ agraph_print_node_gml()

static void agraph_print_node_gml ( RzANode n,
void *  user 
)
static

Definition at line 179 of file cagraph.c.

179  {
180  rz_cons_printf(" node [\n"
181  " id %d\n"
182  " label \"%s\"\n"
183  " ]\n",
184  n->gnode->idx, n->title);
185 }

References n, and rz_cons_printf().

Referenced by rz_core_agraph_print_gml().

◆ rz_core_agraph_add_edge()

RZ_IPI void rz_core_agraph_add_edge ( RzCore core,
const char *  un,
const char *  vn 
)

Definition at line 39 of file cagraph.c.

39  {
40  RzANode *u = rz_agraph_get_node(core->graph, un);
41  RzANode *v = rz_agraph_get_node(core->graph, vn);
42  if (!u) {
43  rz_cons_printf("Node %s not found!\n", un);
44  return;
45  } else if (!v) {
46  rz_cons_printf("Node %s not found!\n", vn);
47  return;
48  }
49  rz_agraph_add_edge(core->graph, u, v);
50 }
RZ_API RzANode * rz_agraph_get_node(const RzAGraph *g, const char *title)
Definition: agraph.c:3852
RZ_API void rz_agraph_add_edge(const RzAGraph *g, RzANode *a, RzANode *b)
Definition: agraph.c:3862
const char * v
Definition: dsignal.c:12
RzAGraph * graph
Definition: rz_core.h:333

References rz_core_t::graph, rz_agraph_add_edge(), rz_agraph_get_node(), rz_cons_printf(), and v.

Referenced by cmd_agraph_edge().

◆ rz_core_agraph_add_node()

RZ_IPI void rz_core_agraph_add_node ( RzCore core,
const char *  title,
const char *  body,
int  color 
)

Definition at line 12 of file cagraph.c.

12  {
13  char *b = strdup(body);
14  if (rz_str_startswith(b, "base64:")) {
15  char *newbody = strdup(b);
16  if (!newbody) {
17  free(b);
18  return;
19  }
20  b = rz_str_replace(newbody, "\\n", "", true);
21  newbody = (char *)rz_base64_decode_dyn(b + strlen("base64:"), -1);
22  free(b);
23  if (!newbody) {
24  return;
25  }
26  b = newbody;
27  }
28  if (!RZ_STR_ISEMPTY(b)) {
29  b = rz_str_append(b, "\n");
30  }
32  free(b);
33 }
RZ_API RzANode * rz_agraph_add_node_with_color(const RzAGraph *g, const char *title, const char *body, int color)
Definition: agraph.c:3726
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
#define b(i)
Definition: sha256.c:42
static int color
Definition: visual.c:20

References b, color, free(), rz_core_t::graph, rz_agraph_add_node_with_color(), rz_base64_decode_dyn(), rz_str_append(), RZ_STR_ISEMPTY, rz_str_replace(), rz_str_startswith(), and strdup().

Referenced by cmd_agraph_node().

◆ rz_core_agraph_del_edge()

RZ_IPI void rz_core_agraph_del_edge ( RzCore core,
const char *  un,
const char *  vn 
)

Definition at line 52 of file cagraph.c.

52  {
53  RzANode *u = rz_agraph_get_node(core->graph, un);
54  RzANode *v = rz_agraph_get_node(core->graph, vn);
55  if (!u) {
56  rz_cons_printf("Node %s not found!\n", un);
57  return;
58  } else if (!v) {
59  rz_cons_printf("Node %s not found!\n", vn);
60  return;
61  }
62  rz_agraph_del_edge(core->graph, u, v);
63 }
RZ_API void rz_agraph_del_edge(const RzAGraph *g, RzANode *a, RzANode *b)
Definition: agraph.c:3880

References rz_core_t::graph, rz_agraph_del_edge(), rz_agraph_get_node(), rz_cons_printf(), and v.

Referenced by cmd_agraph_edge().

◆ rz_core_agraph_del_node()

RZ_IPI void rz_core_agraph_del_node ( RzCore core,
const char *  title 
)

Definition at line 35 of file cagraph.c.

35  {
36  rz_agraph_del_node(core->graph, title);
37 }
RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title)
Definition: agraph.c:3769

References rz_core_t::graph, and rz_agraph_del_node().

Referenced by cmd_agraph_node().

◆ rz_core_agraph_print_ascii()

RZ_IPI void rz_core_agraph_print_ascii ( RzCore core)

Definition at line 65 of file cagraph.c.

65  {
66  core->graph->can->linemode = rz_config_get_i(core->config, "graph.linemode");
67  core->graph->can->color = rz_config_get_i(core->config, "scr.color");
68  rz_agraph_set_title(core->graph, rz_config_get(core->config, "graph.title"));
69  rz_agraph_print(core->graph);
70 }
RZ_API void rz_agraph_set_title(RzAGraph *g, const char *title)
Definition: agraph.c:3720
RZ_API void rz_agraph_print(RzAGraph *g)
Definition: agraph.c:3687
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RzConsCanvas * can
Definition: rz_agraph.h:47
RzConfig * config
Definition: rz_core.h:300

References rz_ascii_graph_t::can, rz_cons_canvas_t::color, rz_core_t::config, rz_core_t::graph, rz_cons_canvas_t::linemode, rz_agraph_print(), rz_agraph_set_title(), rz_config_get(), and rz_config_get_i().

Referenced by cmd_analysis_graph(), and rz_core_agraph_print().

◆ rz_core_agraph_print_dot()

RZ_IPI void rz_core_agraph_print_dot ( RzCore core)

Definition at line 147 of file cagraph.c.

147  {
148  const char *font = rz_config_get(core->config, "graph.font");
149  rz_cons_printf("digraph code {\nrankdir=LR;\noutputorder=edgesfirst\ngraph [bgcolor=azure];\n"
150  "edge [arrowhead=normal, color=\"#3030c0\" style=bold weight=2];\n"
151  "node [fillcolor=white, style=filled shape=box "
152  "fontname=\"%s\" fontsize=\"8\"];\n",
153  font);
156  rz_cons_printf("}\n");
157 }
RZ_API void rz_agraph_foreach_edge(RzAGraph *g, RAEdgeCallback cb, void *user)
Definition: agraph.c:3837
RZ_API void rz_agraph_foreach(RzAGraph *g, RzANodeCallback cb, void *user)
Definition: agraph.c:3829
static void agraph_print_edge_dot(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:125
static void agraph_print_node_dot(RzANode *n, void *user)
Definition: cagraph.c:112
#define NULL
Definition: cris-opc.c:27

References agraph_print_edge_dot(), agraph_print_node_dot(), rz_core_t::config, rz_core_t::graph, NULL, rz_agraph_foreach(), rz_agraph_foreach_edge(), rz_config_get(), and rz_cons_printf().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_gml()

RZ_IPI void rz_core_agraph_print_gml ( RzCore core)

Definition at line 195 of file cagraph.c.

195  {
196  rz_cons_printf("graph\n[\n"
197  "hierarchic 1\n"
198  "label \"\"\n"
199  "directed 1\n");
202  rz_cons_print("]\n");
203 }
static void agraph_print_edge_gml(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:187
static void agraph_print_node_gml(RzANode *n, void *user)
Definition: cagraph.c:179

References agraph_print_edge_gml(), agraph_print_node_gml(), rz_core_t::graph, NULL, rz_agraph_foreach(), rz_agraph_foreach_edge(), and rz_cons_printf().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_interactive()

RZ_IPI void rz_core_agraph_print_interactive ( RzCore core)

Definition at line 88 of file cagraph.c.

88  {
90  if (!ran) {
91  eprintf("This graph contains no nodes\n");
92  return;
93  }
94 
95  ut64 oseek = core->offset;
96  rz_agraph_set_title(core->graph, rz_config_get(core->config, "graph.title"));
97  rz_agraph_set_curnode(core->graph, ran);
98  core->graph->force_update_seek = true;
99  core->graph->need_set_layout = true;
100  core->graph->layout = rz_config_get_i(core->config, "graph.layout");
101  bool ov = rz_cons_is_interactive();
102  core->graph->need_update_dim = true;
103  int update_seek = rz_core_visual_graph(core, core->graph, NULL, true);
104  rz_config_set_i(core->config, "scr.interactive", ov);
105  rz_cons_show_cursor(true);
106  rz_cons_enable_mouse(false);
107  if (update_seek != -1) {
108  rz_core_seek(core, oseek, false);
109  }
110 }
RZ_API int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_fcn, int is_interactive)
Definition: agraph.c:4114
RZ_API RzANode * rz_agraph_get_first_node(const RzAGraph *g)
Definition: agraph.c:3846
RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *a)
Definition: agraph.c:2696
static void update_seek(RzConsCanvas *can, RzANode *n, int force)
Definition: agraph.c:2511
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API bool rz_cons_enable_mouse(const bool enable)
Definition: cons.c:500
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
RZ_API void rz_cons_show_cursor(int cursor)
Definition: cons.c:1581
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
int force_update_seek
Definition: rz_agraph.h:71
bool need_set_layout
Definition: rz_agraph.h:69
ut64 offset
Definition: rz_core.h:301
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::config, eprintf, rz_ascii_graph_t::force_update_seek, rz_core_t::graph, rz_ascii_graph_t::layout, rz_ascii_graph_t::need_set_layout, rz_ascii_graph_t::need_update_dim, NULL, rz_core_t::offset, rz_agraph_get_first_node(), rz_agraph_set_curnode(), rz_agraph_set_title(), rz_config_get(), rz_config_get_i(), rz_config_set_i(), rz_cons_enable_mouse(), rz_cons_is_interactive(), rz_cons_show_cursor(), rz_core_seek(), rz_core_visual_graph(), update_seek(), and ut64().

Referenced by dot_trace_traverse(), rz_core_agraph_print(), and rz_core_visual_graph().

◆ rz_core_agraph_print_json()

RZ_IPI void rz_core_agraph_print_json ( RzCore core)

Definition at line 164 of file cagraph.c.

164  {
165  PJ *pj = pj_new();
166  if (!pj) {
167  return;
168  }
169  pj_o(pj);
170  pj_k(pj, "nodes");
171  pj_a(pj);
172  rz_agraph_print_json(core->graph, pj);
173  pj_end(pj);
174  pj_end(pj);
176  pj_free(pj);
177 }
RZ_API void rz_agraph_print_json(RzAGraph *g, PJ *pj)
Definition: agraph.c:3694
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
Definition: rz_pj.h:12

References rz_core_t::graph, pj_a(), pj_end(), pj_free(), pj_k(), pj_new(), pj_o(), pj_string(), rz_agraph_print_json(), and rz_cons_println().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_rizin()

RZ_IPI void rz_core_agraph_print_rizin ( RzCore core)

Definition at line 159 of file cagraph.c.

159  {
162 }
static void agraph_print_node(RzANode *n, void *user)
Definition: cagraph.c:133
static void agraph_print_edge(RzANode *from, RzANode *to, void *user)
Definition: cagraph.c:129

References agraph_print_edge(), agraph_print_node(), rz_core_t::graph, NULL, rz_agraph_foreach(), and rz_agraph_foreach_edge().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_print_sdb()

RZ_IPI void rz_core_agraph_print_sdb ( RzCore core)

Definition at line 81 of file cagraph.c.

81  {
82  Sdb *db = rz_agraph_get_sdb(core->graph);
83  char *o = sdb_querys(db, "null", 0, "*");
84  rz_cons_print(o);
85  free(o);
86 }
RZ_API Sdb * rz_agraph_get_sdb(RzAGraph *g)
Definition: agraph.c:3679
RZ_API char * sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd)
Definition: query.c:164
Definition: sdb.h:63

References free(), rz_core_t::graph, rz_agraph_get_sdb(), and sdb_querys().

Referenced by cmd_analysis_graph(), and rz_core_agraph_print().

◆ rz_core_agraph_print_tiny()

RZ_IPI void rz_core_agraph_print_tiny ( RzCore core)

Definition at line 72 of file cagraph.c.

72  {
73  core->graph->is_tiny = true;
74  int e = rz_config_get_i(core->config, "graph.edges");
75  rz_config_set_i(core->config, "graph.edges", 0);
76  rz_core_visual_graph(core, core->graph, NULL, false);
77  rz_config_set_i(core->config, "graph.edges", e);
78  core->graph->is_tiny = false;
79 }
#define e(frag)

References rz_core_t::config, e, rz_core_t::graph, rz_ascii_graph_t::is_tiny, NULL, rz_config_get_i(), rz_config_set_i(), and rz_core_visual_graph().

Referenced by rz_core_agraph_print().

◆ rz_core_agraph_reset()

RZ_IPI void rz_core_agraph_reset ( RzCore core)

Definition at line 8 of file cagraph.c.

8  {
9  rz_agraph_reset(core->graph);
10 }
RZ_API void rz_agraph_reset(RzAGraph *g)
Definition: agraph.c:3889

References rz_core_t::graph, and rz_agraph_reset().

Referenced by cmd_analysis_graph(), dot_trace_traverse(), and rz_core_visual_graph().