| 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 | graph_node_visitor_t
| Node visitor - see drawable_graph_t::visit_nodes() More...
struct | graph_path_visitor_t
| Path visitor - see drawable_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
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 | drawable_graph_t
struct | edge_infos_wrapper_t
class | interactive_graph_t
| The base class used to display 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...
THREAD_SAFE 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=nullptr)
| Create a custom graph viewer. More...
graph_viewer_t *idaapi | get_graph_viewer (TWidget *parent)
| Get custom graph viewer for given form.
interactive_graph_t *idaapi | create_interactive_graph (uval_t id)
| Create a new empty graph with given id.
interactive_graph_t *idaapi | create_disasm_graph (ea_t ea)
| Create a graph for the function that contains 'ea'.
interactive_graph_t *idaapi | create_disasm_graph (const rangevec_t &ranges)
| Create a graph using an arbitrary set of ranges.
interactive_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, interactive_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 interactive_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 interactive_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_interactive_graph (interactive_graph_t *g)
| Delete graph object. More...
user_graph_place_t * | create_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 interactive_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 area that is too large to generate disassembly lines for without IDA slowing down significantly (see MAX_VISIBLE_NODE_AREA)
#define | COLLAPSED_NODE 0x80000000

## Typedefs
typedef ea_t | graph_id_t
| Graph instances have a unique id (see interactive_graph_t::gid)
typedef qvector< point_t > | pointvec_t
typedef int | layout_type_t
| see Proximity view layouts
typedef qvector< selection_item_t > | screen_graph_selection_base_t
| Selection in a graph. More...
typedef qvector< row_info_t > | graph_row_info_t
| vector of row infos
typedef qvector< group_crinfo_t > | groups_crinfos_t
typedef TWidget | graph_viewer_t
| graph view opaque structure

## Enumerations
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_reserved , grcode_clicked , grcode_dblclicked , grcode_creating_group , grcode_deleting_group , grcode_group_visibility , grcode_gotfocus , grcode_lostfocus , grcode_user_refresh , grcode_reserved2 , 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_interactive_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_interactive_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

## ◆ GCC_PUREVIRT

#define GCC_PUREVIRT

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

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

## Typedef Documentation

## ◆ screen_graph_selection_base_t

typedef qvector<selection_item_t> screen_graph_selection_base_t

Selection in a graph.

(A list of nodes and edge layout points). This selection is used to move a subgraph on the screen.

## Enumeration Type Documentation

## ◆ graph_item_type_t

enum graph_item_type_t

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_t

enum graph_notification_t

Graph notification codes.

Enumerator
  grcode_calculating_layout | calculating user-defined graph layout. Parameters
  g | (interactive_graph_t *)
  Return values
  0 | not implemented
  1 | graph layout calculated by the plugin
  grcode_layout_calculated | graph layout calculated. Parameters
  g | (interactive_graph_t *)
  layout_succeeded | (bool)
  Return values
  0 | must return 0
  grcode_changed_graph | new graph has been set. Parameters
  g | (interactive_graph_t *)
  Return values
  0 | must return 0
  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
  0 | ok
  1 | ignore click
  grcode_dblclicked | a graph node has been double clicked. Parameters
  gv | (graph_viewer_t *)
  current_item | (selection_item_t *)
  Return values
  0 | ok
  1 | ignore click
  grcode_creating_group | a group is being created. this provides an opportunity for the graph to forbid creation of the group. Note that groups management is done by the interactive_graph_t instance itself: there is no need to modify the graph in this callback. Parameters
  g | (interactive_graph_t *)
  nodes | (intvec_t *)
  Return values
  0 | ok
  1 | forbid group creation
  grcode_deleting_group | a group is being deleted. this provides an opportunity for the graph to forbid deletion of the group. Note that groups management is done by the interactive_graph_t instance itself: there is no need to modify the graph in this callback. Parameters
  g | (interactive_graph_t *)
  old_group | (int)
  Return values
  0 | ok
  1 | forbid group deletion
  grcode_group_visibility | a group is being collapsed/uncollapsed this provides an opportunity for the graph to forbid changing the visibility of the group. Note that groups management is done by the interactive_graph_t instance itself: there is no need to modify the graph in this callback. Parameters
  g | (interactive_graph_t *)
  group | (int)
  expand | (bool)
  Return values
  0 | ok
  1 | forbid group modification
  grcode_gotfocus | a graph viewer got focus. Parameters
  gv | (graph_viewer_t *)
  Return values
  0 | must return 0
  grcode_lostfocus | a graph viewer lost focus. Parameters
  gv | (graph_viewer_t *)
  Return values
  0 | must return 0
-   grcode_user_refresh | refresh user-defined graph nodes and edges This is called when the UI considers that it is necessary to recreate the graph layout, and thus has to ensure that the 'interactive_graph_t' instance it is using, is up-to-date. For example: at graph creation-time if a refresh_viewer() call was made Parameters
    g | (interactive_graph_t *)
Returns success
  grcode_user_text | retrieve text for user-defined graph node. NB: do not use anything calling GDI! Parameters
  g | (interactive_graph_t *)
  node | (int)
  result | (const char **)
  bg_color | (bgcolor_t *) may be nullptr
Returns success, result must be filled
  grcode_user_size | calculate node size for user-defined graph. Parameters
  g | (interactive_graph_t *)
  node | (int)
  cx | (int *)
  cy | (int *)
  Return values
  0 | did not calculate. ida will use node text size
  1 | calculated. ida will add node title to the size
  grcode_user_title | render node title of a user-defined graph. Parameters
  g | (interactive_graph_t *)
  node | (int)
  title_rect | (rect_t *)
  title_bg_color | (int)
  dc | (HDC)
  Return values
  0 | did not render, ida will fill it with title_bg_color
  1 | rendered node title
  grcode_user_draw | render node of a user-defined graph. NB: draw only on the specified DC and nowhere else! Parameters
  g | (interactive_graph_t *)
  node | (int)
  node_rect | (rect_t *)
  dc | (HDC)
  Return values
  0 | not rendered
  1 | rendered
  grcode_user_hint | retrieve hint for the user-defined graph. Parameters
  g | (interactive_graph_t *)
  mousenode | (int)
  mouseedge_src | (int)
  mouseedge_dst | (int)
  hint | (char **) must be allocated by qalloc() or qstrdup()
  Return values
  0 | use default hint
  1 | use 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 | (interactive_graph_t *)
  Return values
  0 | must 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_interactive_graph | use create_interactive_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 interactive_graph_t::del_custom_layout()
grcode_set_custom_layout | use interactive_graph_t::set_custom_layout()
grcode_set_graph_groups | use interactive_graph_t::set_graph_groups()
grcode_clear | use interactive_graph_t::clear()
grcode_create_digraph_layout | use interactive_graph_t::create_digraph_layout()
grcode_create_tree_layout | use drawable_graph_t::create_tree_layout()
grcode_create_circle_layout | use drawable_graph_t::create_circle_layout()
grcode_get_node_representative | use interactive_graph_t::get_node_representative()
grcode_find_subgraph_node | use interactive_graph_t::_find_subgraph_node()
grcode_create_group | use interactive_graph_t::create_group()
grcode_get_custom_layout | use interactive_graph_t::get_custom_layout()
grcode_get_graph_groups | use interactive_graph_t::get_graph_groups()
grcode_empty | use interactive_graph_t::empty()
grcode_is_visible_node | use interactive_graph_t::is_visible_node()
grcode_delete_group | use interactive_graph_t::delete_group()
grcode_change_group_visibility | use interactive_graph_t::change_group_visibility()
grcode_set_edge | use interactive_graph_t::set_edge()
grcode_node_qty | use interactive_graph_t::node_qty()
grcode_nrect | use interactive_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_interactive_graph | use delete_interactive_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

## ◆ get_node_info()

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

Get node info.

Parameters

  out | result
  gid | id of desired graph
  node | node number

Returns
  success

## ◆ set_node_info()

idaman void ida_export set_node_info | ( | graph_id_t | gid,
|  | int | node,
|  | const node_info_t & | ni,
|  | uint32 | flags
| ) |  |

Set node info.

Parameters

  gid | id of desired graph
  node | node number
  ni | node info to use
  flags | combination of Node info flags, identifying which fields of 'ni' will be used

## ◆ clr_node_info()

idaman void ida_export clr_node_info | ( | graph_id_t | gid,
|  | int | node,
|  | uint32 | flags
| ) |  |

Clear node info for the given node.

Parameters

  gid | id of desired graph
  node | node number
  flags | combination of Node info flags, identifying which fields of node_info_t will be cleared

## ◆ create_graph_viewer()

graph_viewer_t *idaapi create_graph_viewer | ( | const char * | title,
|  | uval_t | id,
|  | hook_cb_t * | callback,
|  | void * | ud,
|  | int | title_height,
|  | TWidget * | parent = `nullptr`
| ) |  |
| inline

Create a custom graph viewer.

Parameters

  title | the widget title
  id | graph id
  callback | callback to handle graph notifications (graph_notification_t)
  ud | user data passed to callback
  title_height | node title height
  parent | the parent widget of the graph viewer

Returns
  new viewer

## ◆ viewer_set_gli()

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.

## ◆ viewer_get_gli()

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.

## ◆ viewer_create_groups()

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 interactive_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.

## ◆ viewer_delete_groups()

bool idaapi viewer_delete_groups | ( | graph_viewer_t * | gv,
|  | const intvec_t & | groups,
|  | int | new_current = `-1`
| ) |  |
| inline

Wrapper around interactive_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.

## ◆ viewer_set_groups_visibility()

bool idaapi viewer_set_groups_visibility | ( | graph_viewer_t * | gv,
|  | const intvec_t & | groups,
|  | bool | expand,
|  | int | new_current = `-1`
| ) |  |
| inline

Wrapper around interactive_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.

## ◆ viewer_attach_menu_item()

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

  g | graph viewer
  name | action name

Returns
  success

## ◆ delete_interactive_graph()

void idaapi delete_interactive_graph | ( | interactive_graph_t * | g | ) |
| inline

Delete graph object.

Warning
  use this only if you are dealing with interactive_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