Sark provides some basic utilities and wrappers for IDA's UI.
A natural extension to creating and analyzing graphs, is plotting them.
IDA provides a generic API via the
idaapi.GraphViewer interface. As
Sark mainly uses NetworkX digraphs, the
sark.ui.NXGraph class has
been created to provide an easy plotting solution.
>>> viewer = sark.ui.NXGraph(graph, title="My Graph", handler=sark.ui.AddressNodeHandler()) >>> viewer.Show()
NXGraph constructor takes several arguments:
|graph||the graph to plot|
|title||(opt.) title for the graph|
|handler||(opt.) a default handler for nodes|
|padding||(opt.) visual padding of nodes|
NXGraph is created, use
.Show() to display it.
To allow different types of node data,
NXGraph uses node handlers.
Node handlers inherit from
sark.ui.BasicNodeHandler and implement
the callbacks required for them (all are optional).
|on_get_text||returns the text to display for the node|
|on_click||handles a click on the node. Return
|on_hint||the hint to show|
|on_bg_color||returns the background color for the node|
|on_frame_color||returns the frame (border) color for the node|
There are 2 existing handlers you can use.
||The most basic handler. Calls
||Assumes all nodes are IDB addresses. For node text, it shows the address' name if it exists, or a hex address otherwise. On double click, it jumps to the clicked address.|
Sark provides a menu-manager class to allow the addition of top-level menus to IDA's GUI. This is done by abusing QT to find the top level menu, but you don't need to worry about that.
>>> # Use the manager to add top-level menus >>> menu_manager = sark.ui.MenuManager() >>> menu_manager.add_menu("My Menu") >>> # Use the standard API to add menu items >>> # Assume the action's text is "My Action" >>> idaapi.attach_action_to_menu("My Menu/", "SomeActionName", idaapi.SETMENU_APP) >>> # When a menu is not needed, remove it >>> menu_manager.remove_menu("My Menu") >>> # When you are done with the manager (and want to remove all menus you added.) >>> # clear it before deleting. >>> menu_manager.clear()
As you can see in the above code, the MenuManager class only handles the addition of a top-level menu. After that, IDA's own APIs can be used freely with the created menu to add or remove menu items