IDA SDK
Classes | Functions | Macros | Typedefs | Enumerations | Variables
graph.hpp File Reference

Detailed Description

Graph view management.

Classes

struct  node_info_t
 Information about a node in a graph. More...
 
class  node_ordering_t
 Node ordering in a graph. More...
 
struct  edge_t
 Edge connecting two graph nodes. More...
 
class  graph_node_visitor_t
 Node visitor - see abstract_graph_t::visit_nodes() More...
 
struct  graph_path_visitor_t
 Path visitor - see abstract_graph_t::visit_paths() More...
 
struct  point_t
 Coordinate in a graph view. More...
 
class  pointseq_t
 Ordered sequence of points. More...
 
struct  rect_t
 A rectangle in a graph view. More...
 
struct  TPointDouble
 Coordinate in a graph view (double precision) More...
 
struct  edge_info_t
 Attributes of a graph edge. More...
 
struct  edge_layout_point_t
 Edge layout point. More...
 
struct  selection_item_t
 Element of a graph selection - could be a node or edge layout point. More...
 
struct  screen_graph_selection_t
 Selection in a graph. More...
 
struct  edge_segment_t
 Sub-segment of a graph edge. More...
 
class  graph_item_t
 Describes a sub-item of a graph. More...
 
struct  interval_t
 One dimensional range. More...
 
struct  row_info_t
 Organize graph nodes by row. More...
 
class  abstract_graph_t
 Abstract graph interface. More...
 
struct  edge_infos_wrapper_t
 
class  mutable_graph_t
 Base class used by graphs in IDA. More...
 
class  graph_visitor_t
 Visit all nodes and edges in a graph. More...
 
struct  group_crinfo_t
 
struct  user_graph_place_t
 Structure returned by get_custom_viewer_place() if the first parameter is a graph viewer. More...
 

Functions

idaman bool ida_export get_node_info (node_info_t *out, graph_id_t gid, int node)
 Get node info. More...
 
idaman void ida_export set_node_info (graph_id_t gid, int node, const node_info_t &ni, uint32 flags)
 Set node info. More...
 
idaman void ida_export del_node_info (graph_id_t gid, int node)
 Delete the node_info_t for the given node.
 
idaman void ida_export clr_node_info (graph_id_t gid, int node, uint32 flags)
 Clear node info for the given node. More...
 
double calc_dist (point_t p, point_t q)
 Calculate distance between p and q.
 
graph_viewer_t *idaapi create_graph_viewer (const char *title, uval_t id, hook_cb_t *callback, void *ud, int title_height, TWidget *parent=NULL)
 Create a custom graph viewer. More...
 
graph_viewer_t *idaapi get_graph_viewer (TWidget *parent)
 Get custom graph viewer for given form.
 
mutable_graph_t *idaapi create_mutable_graph (uval_t id)
 Create a new empty graph with given id.
 
mutable_graph_t *idaapi create_disasm_graph (ea_t ea)
 Create a graph for the function that contains 'ea'.
 
mutable_graph_t *idaapi create_disasm_graph (const rangevec_t &ranges)
 Create a graph using an arbitrary set of ranges.
 
mutable_graph_t *idaapi get_viewer_graph (graph_viewer_t *gv)
 Get graph object for given custom graph viewer.
 
void idaapi set_viewer_graph (graph_viewer_t *gv, mutable_graph_t *g)
 Set the underlying graph object for the given viewer.
 
void idaapi refresh_viewer (graph_viewer_t *gv)
 Redraw the graph in the given view.
 
void idaapi viewer_fit_window (graph_viewer_t *gv)
 Fit graph viewer to its parent form.
 
int idaapi viewer_get_curnode (graph_viewer_t *gv)
 Get number of currently selected node (-1 if none)
 
void idaapi viewer_center_on (graph_viewer_t *gv, int node)
 Center the graph view on the given node.
 
void idaapi viewer_set_gli (graph_viewer_t *gv, const graph_location_info_t *gli, uint32 flags=0)
 Set location info for given graph view If flags contains GLICTL_CENTER, then the gli will be set to be the center of the view. More...
 
bool idaapi viewer_get_gli (graph_location_info_t *out, graph_viewer_t *gv, uint32 flags=0)
 Get location info for given graph view If flags contains GLICTL_CENTER, then the gli that will be retrieved, will be the one at the center of the view. More...
 
void idaapi viewer_set_node_info (graph_viewer_t *gv, int n, const node_info_t &ni, uint32 flags)
 Set node info for node in given viewer (see set_node_info())
 
bool idaapi viewer_get_node_info (graph_viewer_t *gv, node_info_t *out, int n)
 Get node info for node in given viewer (see get_node_info())
 
void idaapi viewer_del_node_info (graph_viewer_t *gv, int n)
 Delete node info for node in given viewer (see del_node_info())
 
bool idaapi viewer_create_groups (graph_viewer_t *gv, intvec_t *out_group_nodes, const groups_crinfos_t &gi)
 This will perform an operation similar to what happens when a user manually selects a set of nodes, right-clicks and selects "Create group". More...
 
bool idaapi viewer_delete_groups (graph_viewer_t *gv, const intvec_t &groups, int new_current=-1)
 Wrapper around mutable_graph_t::delete_group. More...
 
bool idaapi viewer_set_groups_visibility (graph_viewer_t *gv, const intvec_t &groups, bool expand, int new_current=-1)
 Wrapper around mutable_graph_t::change_visibility. More...
 
bool idaapi viewer_attach_menu_item (graph_viewer_t *g, const char *name)
 Attach a previously-registered action to the view's context menu. More...
 
bool idaapi viewer_get_selection (graph_viewer_t *gv, screen_graph_selection_t *sgs)
 Get currently selected items for graph viewer.
 
int idaapi viewer_set_titlebar_height (graph_viewer_t *gv, int height)
 Set height of node title bars (grcode_set_titlebar_height)
 
void idaapi delete_mutable_graph (mutable_graph_t *g)
 Delete graph object. More...
 
user_graph_place_tcreate_user_graph_place (int node, int lnnum)
 Get a copy of a user_graph_place_t (returns a pointer to static storage)
 
grentry

IDA designates a function for handling graph operations (::grentry).

This function accepts a notification code (graph_notification_t), along with a list of relevant arguments, and handles the action appropriately (similar to callui in kernwin.hpp).

ssize_t grentry (graph_notification_t event_code,...)
 

Macros

#define NIF_BG_COLOR   (1 << 0)
 node_info_t::bg_color
 
#define NIF_FRAME_COLOR   (1 << 1)
 node_info_t::frame_color
 
#define NIF_EA   (1 << 2)
 node_info_t::ea
 
#define NIF_TEXT   (1 << 3)
 node_info_t::text
 
#define NIF_FLAGS   (1 << 4)
 node_info_t::flags
 
#define NIF_ALL   (NIF_BG_COLOR | NIF_FRAME_COLOR | NIF_EA | NIF_TEXT | NIF_FLAGS)
 
#define GLICTL_CENTER   (1 << 0)
 the gli should be set/get as center
 
#define NIFF_SHOW_CONTENTS   (1 << 0)
 
#define GCC_PUREVIRT
 For some reason GCC insists on putting the vtable into object files, even though we only use mutable_graph_t by pointer. More...
 
#define CHKNODEIDX(n)
 
#define MTG_GROUP_NODE   0x01
 is group node?
 
#define MTG_DOT_NODE   0x02
 is dot node?
 
#define MTG_NON_DISPLAYABLE_NODE   0x08
 for disassembly graphs - non-displayable nodes have a visible More...
 
#define COLLAPSED_NODE   0x80000000
 

Typedefs

typedef ea_t graph_id_t
 Graph instances have a unique id (see mutable_graph_t::gid)
 
typedef qvector< edge_tedgevec_t
 vector of graph edges
 
typedef int layout_type_t
 see Proximity view layouts
 
typedef qvector< row_info_tgraph_row_info_t
 vector of row infos
 
typedef qvector< group_crinfo_tgroups_crinfos_t
 
typedef TWidget graph_viewer_t
 graph view opaque structure
 

Enumerations

enum  edge_type_t {
  edge_error = 0, edge_tree = 1, edge_forward = 2, edge_back = 3,
  edge_cross = 4, edge_subgraph = 5
}
 
enum  graph_item_type_t {
  git_none, git_edge, git_node, git_tool,
  git_text, git_elp
}
 See graph_item_t. More...
 
enum  graph_notification_t {
  grcode_calculating_layout, grcode_layout_calculated, grcode_changed_graph, grcode_changed_current,
  grcode_clicked, grcode_dblclicked, grcode_creating_group, grcode_deleting_group,
  grcode_group_visibility, grcode_gotfocus, grcode_lostfocus, grcode_user_refresh,
  grcode_user_gentext, grcode_user_text, grcode_user_size, grcode_user_title,
  grcode_user_draw, grcode_user_hint, grcode_destroyed, grcode_create_graph_viewer = 256,
  grcode_get_graph_viewer, grcode_get_viewer_graph, grcode_create_mutable_graph, grcode_set_viewer_graph,
  grcode_refresh_viewer, grcode_fit_window, grcode_get_curnode, grcode_center_on,
  grcode_get_selection, grcode_del_custom_layout, grcode_set_custom_layout, grcode_set_graph_groups,
  grcode_clear, grcode_create_digraph_layout, grcode_create_tree_layout, grcode_create_circle_layout,
  grcode_get_node_representative, grcode_find_subgraph_node, grcode_create_group, grcode_get_custom_layout,
  grcode_get_graph_groups, grcode_empty, grcode_is_visible_node, grcode_delete_group,
  grcode_change_group_visibility, grcode_set_edge, grcode_node_qty, grcode_nrect,
  grcode_set_titlebar_height, grcode_create_user_graph_place, grcode_create_disasm_graph1, grcode_create_disasm_graph2,
  grcode_set_node_info, grcode_get_node_info, grcode_del_node_info, grcode_viewer_create_groups,
  grcode_viewer_delete_groups, grcode_viewer_groups_visibility, grcode_viewer_create_groups_vec, grcode_viewer_delete_groups_vec,
  grcode_viewer_groups_visibility_vec, grcode_delete_mutable_graph, grcode_edge_infos_wrapper_copy, grcode_edge_infos_wrapper_clear,
  grcode_attach_menu_item, grcode_set_gli, grcode_get_gli
}
 Graph notification codes. More...
 

Variables

const layout_type_t layout_none = 0
 
const layout_type_t layout_digraph = 1
 
const layout_type_t layout_tree = 2
 
const layout_type_t layout_circle = 3
 
const layout_type_t layout_polar_tree = 4
 
const layout_type_t layout_orthogonal = 5
 
const layout_type_t layout_radial_tree = 6
 

Macro Definition Documentation

#define GCC_PUREVIRT

For some reason GCC insists on putting the vtable into object files, even though we only use mutable_graph_t by pointer.

This looks like a linker bug. We fix it by declaring functions as pure virtual when plugins are compiled.

#define MTG_NON_DISPLAYABLE_NODE   0x08

for disassembly graphs - non-displayable nodes have a visible

area that is too large to generate disassembly lines for without IDA slowing down significantly (see MAX_VISIBLE_NODE_AREA)

Enumeration Type Documentation

See graph_item_t.

Enumerator
git_none 

nothing

git_edge 

edge (graph_item_t::e, graph_item_t::n. n is farthest edge endpoint)

git_node 

node title (graph_item_t::n)

git_tool 

node title button (graph_item_t::n, graph_item_t::b)

git_text 

node text (graph_item_t::n, graph_item_t::p)

git_elp 

edge layout point (graph_item_t::elp)

Graph notification codes.

Enumerator
grcode_calculating_layout 

calculating user-defined graph layout.

Parameters
g(mutable_graph_t *)
Return values
0not implemented
1graph layout calculated by the plugin
grcode_layout_calculated 

graph layout calculated.

Parameters
g(mutable_graph_t *)
layout_succeeded(bool)
Return values
0must return 0
grcode_changed_graph 

new graph has been set.

Parameters
g(mutable_graph_t *)
Return values
0must return 0
grcode_changed_current 

a new graph node became the current node.

Parameters
gv(graph_viewer_t *)
curnode(int)
Return values
0ok
1forbid to change the current node
grcode_clicked 

graph is being clicked.

this callback allows you to ignore some clicks. it occurs too early, internal graph variables are not updated yet. current_item1, current_item2 point to the same thing. item2 has more information. see also: custom_viewer_click_t

Parameters
gv(graph_viewer_t *)
current_item1(selection_item_t *)
current_item2(graph_item_t *)
Return values
0ok
1ignore click
grcode_dblclicked 

a graph node has been double clicked.

Parameters
gv(graph_viewer_t *)
current_item(selection_item_t *)
Return values
0ok
1ignore click
grcode_creating_group 

a group is being created.

Parameters
g(mutable_graph_t *)
nodes(intvec_t *)
Return values
0ok
1forbid group creation
grcode_deleting_group 

a group is being deleted.

Parameters
g(mutable_graph_t *)
old_group(int)
Return values
0ok
1forbid group deletion
grcode_group_visibility 

a group is being collapsed/uncollapsed

Parameters
g(mutable_graph_t *)
group(int)
expand(bool)
Return values
0ok
1forbid group modification
grcode_gotfocus 

a graph viewer got focus.

Parameters
gv(graph_viewer_t *)
Return values
0must return 0
grcode_lostfocus 

a graph viewer lost focus.

Parameters
gv(graph_viewer_t *)
Return values
0must return 0
grcode_user_refresh 

refresh user-defined graph node number and edges.

Parameters
g(mutable_graph_t *)
Returns
success
grcode_user_gentext 

generate text for user-defined graph nodes.

Parameters
g(mutable_graph_t *)
Returns
success
grcode_user_text 

retrieve text for user-defined graph node.

NB: do not use anything calling GDI!

Parameters
g(mutable_graph_t *)
node(int)
result(const char **)
bg_color(bgcolor_t *) may be NULL
Returns
success, result must be filled
grcode_user_size 

calculate node size for user-defined graph.

Parameters
g(mutable_graph_t *)
node(int)
cx(int *)
cy(int *)
Return values
0did not calculate. ida will use node text size
1calculated. ida will add node title to the size
grcode_user_title 

render node title of a user-defined graph.

Parameters
g(mutable_graph_t *)
node(int)
title_rect(rect_t *)
title_bg_color(int)
dc(HDC)
Return values
0did not render, ida will fill it with title_bg_color
1rendered node title
grcode_user_draw 

render node of a user-defined graph.

NB: draw only on the specified DC and nowhere else!

Parameters
g(mutable_graph_t *)
node(int)
node_rect(rect_t *)
dc(HDC)
Return values
0not rendered
1rendered
grcode_user_hint 

retrieve hint for the user-defined graph.

Parameters
g(mutable_graph_t *)
mousenode(int)
mouseedge_src(int)
mouseedge_dst(int)
hint(char **) must be allocated by qalloc() or qstrdup()
Return values
0use default hint
1use proposed hint
grcode_destroyed 

graph is being destroyed.

Note that this doesn't mean the graph viewer is being destroyed; this only means that the graph that is being displayed by it is being destroyed, and that, e.g., any possibly cached data should be invalidated (this event can happen when, for example, the user decides to group nodes together: that operation will effectively create a new graph, that will replace the old one.) To be notified when the graph viewer itself is being destroyed, please see notification 'view_close', in kernwin.hpp

Parameters
g(mutable_graph_t *)
Return values
0must return 0
grcode_create_graph_viewer 

use create_graph_viewer()

grcode_get_graph_viewer 

use get_graph_viewer()

grcode_get_viewer_graph 

use get_viewer_graph()

grcode_create_mutable_graph 

use create_mutable_graph()

grcode_set_viewer_graph 

use set_viewer_graph()

grcode_refresh_viewer 

use refresh_viewer()

grcode_fit_window 

use viewer_fit_window()

grcode_get_curnode 

use viewer_get_curnode()

grcode_center_on 

use viewer_center_on()

grcode_get_selection 

use viewer_get_selection()

grcode_del_custom_layout 

use mutable_graph_t::del_custom_layout()

grcode_set_custom_layout 

use mutable_graph_t::set_custom_layout()

grcode_set_graph_groups 

use mutable_graph_t::set_graph_groups()

grcode_clear 

use mutable_graph_t::clear()

grcode_create_digraph_layout 

use mutable_graph_t::create_digraph_layout()

grcode_create_tree_layout 

use abstract_graph_t::create_tree_layout()

grcode_create_circle_layout 

use abstract_graph_t::create_circle_layout()

grcode_get_node_representative 

use mutable_graph_t::get_node_representative()

grcode_find_subgraph_node 

use mutable_graph_t::_find_subgraph_node()

grcode_create_group 

use mutable_graph_t::create_group()

grcode_get_custom_layout 

use mutable_graph_t::get_custom_layout()

grcode_get_graph_groups 

use mutable_graph_t::get_graph_groups()

grcode_empty 

use mutable_graph_t::empty()

grcode_is_visible_node 

use mutable_graph_t::is_visible_node()

grcode_delete_group 

use mutable_graph_t::delete_group()

grcode_change_group_visibility 

use mutable_graph_t::change_group_visibility()

grcode_set_edge 

use mutable_graph_t::set_edge()

grcode_node_qty 

use mutable_graph_t::node_qty()

grcode_nrect 

use mutable_graph_t::nrect()

grcode_set_titlebar_height 

use viewer_set_titlebar_height()

grcode_create_user_graph_place 

use create_user_graph_place()

grcode_create_disasm_graph1 

use create_disasm_graph(ea_t ea)

grcode_create_disasm_graph2 

use create_disasm_graph(const rangevec_t &ranges)

grcode_set_node_info 

use viewer_set_node_info()

grcode_get_node_info 

use viewer_get_node_info()

grcode_del_node_info 

use viewer_del_node_info()

grcode_viewer_create_groups_vec 

use viewer_create_groups()

grcode_viewer_delete_groups_vec 

use viewer_delete_groups()

grcode_viewer_groups_visibility_vec 

use viewer_set_groups_visibility()

grcode_delete_mutable_graph 

use delete_mutable_graph()

grcode_edge_infos_wrapper_copy 

use edge_infos_wrapper_t::operator=()

grcode_edge_infos_wrapper_clear 

use edge_infos_wrapper_t::clear()

grcode_set_gli 

use viewer_set_gli()

grcode_get_gli 

use viewer_get_gli()

Function Documentation

idaman bool ida_export get_node_info ( node_info_t out,
graph_id_t  gid,
int  node 
)

Get node info.

Parameters
outresult
gidid of desired graph
nodenode number
Returns
success
idaman void ida_export set_node_info ( graph_id_t  gid,
int  node,
const node_info_t ni,
uint32  flags 
)

Set node info.

Parameters
gidid of desired graph
nodenode number
ninode info to use
flagscombination of Node info flags, identifying which fields of 'ni' will be used
idaman void ida_export clr_node_info ( graph_id_t  gid,
int  node,
uint32  flags 
)

Clear node info for the given node.

Parameters
gidid of desired graph
nodenode number
flagscombination of Node info flags, identifying which fields of node_info_t will be cleared
graph_viewer_t* idaapi create_graph_viewer ( const char *  title,
uval_t  id,
hook_cb_t callback,
void *  ud,
int  title_height,
TWidget *  parent = NULL 
)
inline

Create a custom graph viewer.

Parameters
titlethe widget title
idgraph id
callbackcallback to handle graph notifications (graph_notification_t)
uduser data passed to callback
title_heightnode title height
Returns
new viewer
void idaapi viewer_set_gli ( graph_viewer_t gv,
const graph_location_info_t *  gli,
uint32  flags = 0 
)
inline

Set location info for given graph view If flags contains GLICTL_CENTER, then the gli will be set to be the center of the view.

Otherwise it will be the top-left.

bool idaapi viewer_get_gli ( graph_location_info_t *  out,
graph_viewer_t gv,
uint32  flags = 0 
)
inline

Get location info for given graph view If flags contains GLICTL_CENTER, then the gli that will be retrieved, will be the one at the center of the view.

Otherwise it will be the top-left.

bool idaapi viewer_create_groups ( graph_viewer_t gv,
intvec_t out_group_nodes,
const groups_crinfos_t gi 
)
inline

This will perform an operation similar to what happens when a user manually selects a set of nodes, right-clicks and selects "Create group".

This is a wrapper around mutable_graph_t::create_group that will, in essence:

  • clone the current graph
  • for each group_crinfo_t, attempt creating group in that new graph
  • if all were successful, animate to that new graph.
    Note
    this accepts parameters that allow creating of multiple groups at once; which means only one graph animation will be triggered.
bool idaapi viewer_delete_groups ( graph_viewer_t gv,
const intvec_t groups,
int  new_current = -1 
)
inline

Wrapper around mutable_graph_t::delete_group.

This function will:

  • clone the current graph
  • attempt deleting the groups in that new graph
  • if successful, animate to that new graph.
bool idaapi viewer_set_groups_visibility ( graph_viewer_t gv,
const intvec_t groups,
bool  expand,
int  new_current = -1 
)
inline

Wrapper around mutable_graph_t::change_visibility.

This function will:

  • clone the current graph
  • attempt changing visibility of the groups in that new graph
  • if successful, animate to that new graph.
bool idaapi viewer_attach_menu_item ( graph_viewer_t g,
const char *  name 
)
inline

Attach a previously-registered action to the view's context menu.

See kernwin.hpp for how to register actions.

Parameters
nameaction name
Returns
success
void idaapi delete_mutable_graph ( mutable_graph_t g)
inline

Delete graph object.

Warning
use this only if you are dealing with mutable_graph_t instances that have not been used together with a graph_viewer_t. If you have called set_viewer_graph() with your graph, the graph's lifecycle will be managed by the viewer, and you shouldn't interfere with it