Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 611 lines (594 sloc) 22.3 KB
diff -crBN ../mynav-1.1/mybrowser.py ./mynav-1.1-ubigraph/mybrowser.py
*** ../mynav-1.1/mybrowser.py Fri Sep 3 20:20:14 2010
--- ./mynav-1.1-ubigraph/mybrowser.py Sun Jun 19 05:17:41 2011
***************
*** 32,37 ****
--- 32,79 ----
from idaapi import GraphViewer, Choose2
+ # ---------------------------------------
+
+ import ubiconfig, xmlrpclib
+
+ def UbiConnect():
+
+ try:
+
+ # connect to the UbiGraph XMLRPC server
+ ubi_server = xmlrpclib.Server(ubiconfig.ubi_server_url)
+ ubiconfig.ubi_graph = ubi_server.ubigraph
+
+ # clear the graph
+ ubiconfig.ubi_graph.clear()
+
+ print "[+] Connected to the ubigraph server \"%s\"" % (ubiconfig.ubi_server_url)
+
+ ubiconfig.ubi_is_initialized = True
+
+ return False
+
+ except Exception, why:
+
+ print "[!] Can't connect to the ubigraph server \"%s\"" % (ubiconfig.ubi_server_url)
+ print "[!] " + str(why)
+
+ return True
+
+ # def end
+
+ def UbiDispatchVertexCallback(id):
+
+ print "UbiDispatchVertexCallback() %d" % (id)
+
+ # jump to the clicked graph vertex address in disasm window
+ idc.Jump(id)
+
+ # if end
+ # def end
+
+ # ---------------------------------------
+
def GetCodeRefsFrom(ea):
name = idc.GetFunctionName(ea)
ea = idc.LocByName(name)
***************
*** 293,298 ****
--- 335,341 ----
if n == 1:
return [0xFF0000, 0]
+
class FunctionsBrowser(GraphViewer):
def __init__(self, title, father, session):
GraphViewer.__init__(self, title, False)
***************
*** 311,316 ****
--- 354,477 ----
self.hidden = []
self.mynav = None
+ # initialize ubigraph
+
+ self.ubi_vertex = []
+ self.ubi_callback_srv_addr = "http://" + ubiconfig.ubi_local_addr + ":11631/RPC2/vertex_callback"
+
+ print "[+] FunctionsBrowser.__init__()"
+
+ UbiConnect()
+
+ # if end
+
+ # ---------------------------------------
+
+ def __del__(self):
+
+ print "[+] FunctionsBrowser.__del__()"
+
+ ubiconfig.ubi_browser = None
+
+ # def end
+
+ def UbiNewVertex(self, id):
+
+ if not ubiconfig.ubi_is_initialized:
+
+ # ubigrapt is not available
+ return
+
+ addr = self.GetNodeAddress(id)
+
+ G = ubiconfig.ubi_graph
+
+ # create new ubigraph vertex
+ G.new_vertex_w_id(addr)
+
+ # set vertex label properties
+ G.set_vertex_attribute(addr, "fontcolor", "#fdd70f")
+ G.set_vertex_attribute(addr, "fontfamily", "Helvetica")
+ G.set_vertex_attribute(addr, "fontsize", "12")
+
+ # set vertex shape properties
+ G.set_vertex_attribute(addr, "shape", "cube")
+ G.set_vertex_attribute(addr, "shapedetail", "40")
+ G.set_vertex_attribute(addr, "size", "0.5")
+
+ # set vertex color and label
+ attrs = self.OnGetText(id)
+ if type(attrs) == str:
+
+ G.set_vertex_attribute(addr, "label", attrs.split("@")[0])
+ G.set_vertex_attribute(addr, "color", "#ff0000")
+
+ else:
+
+ G.set_vertex_attribute(addr, "label", attrs[0].split("@")[0])
+ G.set_vertex_attribute(addr, "color", "#%.6x" % attrs[1])
+
+ # set vertex callback
+ G.set_vertex_attribute(addr, "callback_left_doubleclick", self.ubi_callback_srv_addr)
+
+ # save vertex id into the list
+ self.ubi_vertex.append(id)
+
+ def GetNodeAddress(self, id):
+
+ try:
+
+ for item in self.nodes.items():
+
+ if item[1] == id:
+
+ return item[0]
+
+ # for end
+
+ except:
+
+ pass
+
+ return id
+
+ # def end
+
+ def AddEdge(self, one, two):
+
+ GraphViewer.AddEdge(self, one, two)
+
+ if not ubiconfig.ubi_is_initialized:
+
+ return
+
+ if not one in self.ubi_vertex:
+
+ # create a first vertex
+ self.UbiNewVertex(one)
+
+ # if end
+
+ if not two in self.ubi_vertex:
+
+ # create the second vertex
+ self.UbiNewVertex(two)
+
+ # if end
+
+ G = ubiconfig.ubi_graph
+
+ # create edge between vertexes
+ e = G.new_edge(self.GetNodeAddress(one), self.GetNodeAddress(two))
+ G.set_edge_attribute(e, "width", "1.5")
+ G.set_edge_attribute(e, "oriented", "true")
+ G.set_edge_attribute(e, "showstrain", "true")
+ G.set_edge_attribute(e, "arrow", "true")
+ G.set_edge_attribute(e, "arrow_position", "0.5")
+ G.set_edge_attribute(e, "arrow_radius", "0.5")
+
+ # ---------------------------------------
+
def addChildNodes(self, father):
self.addRequiredNodes(father, 0)
self.addEdges()
***************
*** 368,373 ****
--- 529,542 ----
self.nodes = {}
self.totals = {}
self.last_level = []
+
+ # clear ubigraph
+ self.ubi_vertex = []
+
+ if ubiconfig.ubi_is_initialized:
+
+ ubiconfig.ubi_graph.clear()
+
self.nodes[self.father] = self.AddNode((self.father, idc.GetFunctionName(self.father)))
self.addChildNodes(self.father)
***************
*** 419,425 ****
def OnSelect(self, node_id):
return True
! def Show(self):
if not GraphViewer.Show(self):
return False
"""
--- 588,595 ----
def OnSelect(self, node_id):
return True
! def Show(self):
!
if not GraphViewer.Show(self):
return False
"""
***************
*** 514,520 ****
except:
print "OnCommand:", sys.exc_info()[1]
! return True
class PathsBrowser(GraphViewer):
def __init__(self, title, nodes, start, target, hits = []):
--- 684,690 ----
except:
print "OnCommand:", sys.exc_info()[1]
! return True
class PathsBrowser(GraphViewer):
def __init__(self, title, nodes, start, target, hits = []):
***************
*** 527,539 ****
if type(target) is not type([]):
self.target = [target]
else:
! self.target = target
self.result = nodes
self.nodes = {}
self.added = []
self.hits = []
def addNodes(self):
for node in self.result:
name = idc.GetFunctionName(node)
--- 697,711 ----
if type(target) is not type([]):
self.target = [target]
else:
! self.target = target
self.result = nodes
self.nodes = {}
self.added = []
self.hits = []
+ print "[+] PathsBrowser.__init__()"
+
def addNodes(self):
for node in self.result:
name = idc.GetFunctionName(node)
diff -crBN ../mynav-1.1/ubiconfig.py ./mynav-1.1-ubigraph/ubiconfig.py
*** ../mynav-1.1/ubiconfig.py Thu Jan 1 03:00:00 1970
--- ./mynav-1.1-ubigraph/ubiconfig.py Sun Jun 19 04:55:32 2011
***************
*** 0 ****
--- 1,30 ----
+
+ ubi_graph = None
+ ubi_is_initialized = False
+
+ # ubigraph server XMLRPC URL
+ ubi_server_url = "http://192.168.254.100:20738/RPC2"
+
+ # ubigraph client IP address
+ # i.e., host that runs IDA
+ ubi_local_addr = "192.168.254.1"
+
+ #
+ # If you're using IDA and UbiGraph server on the
+ # same machine - just write 127.0.0.1 in both of
+ # ubi_server_url and ubi_local_addr
+ #
+
+ ##############################################
+ # variables and other stuff for internal use
+ ##############################################
+
+ try:
+
+ # initialize XMLRPC server for UbiGraph vertex callbacks
+ import ubicallback
+ ubicallback.init()
+
+ except:
+
+ pass
diff -crBN ../mynav-1.1/ubigraph.py ./mynav-1.1-ubigraph/ubigraph.py
*** ../mynav-1.1/ubigraph.py Thu Jan 1 03:00:00 1970
--- ./mynav-1.1-ubigraph/ubigraph.py Thu May 29 05:43:22 2008
***************
*** 0 ****
--- 1,293 ----
+ import xmlrpclib
+
+ class Ubigraph:
+ def __init__(self, URL='http://127.0.0.1:20738/RPC2'):
+ self.server = xmlrpclib.Server(URL)
+ self.server_backup = self.server
+ self.defaultVertexStyle = VertexStyle(self, None, id=0)
+ self.defaultEdgeStyle = EdgeStyle(self, None, id=0)
+
+ def clear(self):
+ self.server.ubigraph.clear()
+
+ def beginMultiCall(self):
+ self.server = xmlrpclib.MultiCall(self.server)
+
+ def endMultiCall(self):
+ for result in self.server():
+ print result
+ self.server = self.server_backup
+
+ def newVertex(self, id=None, style=None, color=None, shape=None,
+ label=None, size=None, fontcolor=None, fontfamily=None,
+ fontsize=None, visible=None):
+ return Vertex(self, id=id, style=style, color=color, shape=shape,
+ label=label, size=size, fontcolor=fontcolor, fontfamily=fontfamily,
+ fontsize=fontsize, visible=visible)
+
+ def newEdge(self, x, y, id=None, style=None, arrow=None, arrow_position=None,
+ arrow_length=None, arrow_radius=None, arrow_reverse=None,
+ color=None, label=None, fontcolor=None, fontfamily=None,
+ fontsize=None, oriented=None, spline=None, showstrain=None,
+ stroke=None, strength=None, visible=None, width=None):
+ return Edge(self, x, y, id=id, style=style, arrow=arrow,
+ arrow_position=arrow_position, arrow_length=arrow_length,
+ arrow_radius=arrow_radius, arrow_reverse=arrow_reverse, color=color,
+ label=label, fontcolor=fontcolor, fontfamily=fontfamily,
+ fontsize=fontsize, oriented=oriented, spline=spline,
+ showstrain=showstrain, stroke=stroke, strength=strength,
+ visible=visible, width=width)
+
+ def newVertexStyle(self, parentStyle=None, id=None, color=None, shape=None,
+ label=None, size=None, fontcolor=None, fontfamily=None,
+ fontsize=None, visible=None):
+ return VertexStyle(self, parentStyle=parentStyle, id=id,
+ color=color, shape=shape, label=label, size=size, fontcolor=fontcolor,
+ fontfamily=fontfamily, fontsize=fontsize, visible=visible)
+
+ def newEdgeStyle(self, parentStyle=None, id=None, arrow=None,
+ arrow_position=None, arrow_length=None, arrow_radius=None,
+ arrow_reverse=None, color=None,
+ label=None, fontcolor=None, fontfamily=None, fontsize=None,
+ oriented=None, spline=None, showstrain=None, stroke=None,
+ strength=None, visible=None, width=None):
+ return EdgeStyle(self, parentStyle=parentStyle, id=id, arrow=arrow,
+ arrow_position=arrow_position, arrow_length=arrow_length,
+ arrow_radius=arrow_radius, color=color, label=label,
+ fontcolor=fontcolor, fontfamily=fontfamily,
+ fontsize=fontsize, oriented=oriented, spline=spline,
+ showstrain=showstrain, stroke=stroke, strength=strength,
+ visible=visible, width=width)
+
+
+
+ class Vertex:
+ def __init__(self, U, id=None, style=None, color=None, shape=None,
+ label=None, size=None, fontcolor=None, fontfamily=None, fontsize=None,
+ visible=None, callback=None):
+ self.U = U
+ if id == None:
+ self.id = U.server.ubigraph.new_vertex()
+ else:
+ U.server.ubigraph.new_vertex_w_id(id)
+ self.id = id
+ self.set(style=style, color=color, shape=shape, label=label,
+ size=size, fontcolor=fontcolor, fontfamily=fontfamily,
+ fontsize=fontsize, visible=visible, callback=callback)
+
+ def set(self, style=None, color=None, shape=None,
+ label=None, size=None, fontcolor=None, fontfamily=None, fontsize=None,
+ visible=None, callback=None):
+ if style != None:
+ self.U.server.ubigraph.change_vertex_style(self.id, style.id)
+ if color != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "color", color)
+ if shape != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "shape", shape)
+ if label != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "label", label)
+ if size != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "size", str(size))
+ if fontcolor != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "fontcolor", fontcolor)
+ if fontfamily != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "fontfamily", fontfamily)
+ if fontsize != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "fontsize", str(fontsize))
+ if visible != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "visible", str(visible))
+ if callback != None:
+ self.U.server.ubigraph.set_vertex_attribute(self.id, "callback_left_doubleclick",
+ callback)
+
+ def destroy(self):
+ self.U.server.ubigraph.remove_vertex(self.id)
+
+
+
+ class Edge:
+ def __init__(self, U, x, y, id=None, style=None, arrow=None,
+ arrow_position=None, arrow_length=None, arrow_radius=None,
+ arrow_reverse=None, color=None,
+ label=None, fontcolor=None, fontfamily=None, fontsize=None,
+ oriented=None, spline=None, showstrain=None, stroke=None,
+ strength=None, visible=None, width=None):
+ self.U = U
+ if id == None:
+ self.id = U.server.ubigraph.new_edge(x.id,y.id)
+ else:
+ U.server.ubigraph.new_edge_w_id(id,x.id,y.id)
+ self.id = id
+ self.set(style=style, arrow=arrow, arrow_position=arrow_position,
+ arrow_length=arrow_length, arrow_radius=arrow_radius, color=color,
+ label=label, fontcolor=fontcolor, fontfamily=fontfamily,
+ fontsize=fontsize, oriented=oriented, spline=spline,
+ showstrain=showstrain, stroke=stroke, strength=strength,
+ visible=visible, width=width)
+
+ def set(self, style=None, arrow=None, arrow_position=None,
+ arrow_length=None, arrow_radius=None, arrow_reverse=None,
+ color=None, label=None, fontcolor=None, fontfamily=None,
+ fontsize=None, oriented=None, spline=None, showstrain=None,
+ stroke=None, strength=None, visible=None, width=None):
+ if style != None:
+ self.U.server.ubigraph.change_edge_style(self.id, style.id)
+ if arrow != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "arrow", str(arrow))
+ if arrow_position != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "arrow_position",
+ str(arrow_position))
+ if arrow_length != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "arrow_length",
+ str(arrow_length))
+ if arrow_radius != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "arrow_radius",
+ str(arrow_radius))
+ if arrow_reverse != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "arrow_reverse",
+ str(arrow_reverse))
+ if color != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "color", color)
+ if label != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "label", label)
+ if fontcolor != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "fontcolor", fontcolor)
+ if fontfamily != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "fontfamily", fontfamily)
+ if fontsize != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "fontsize", str(fontsize))
+ if oriented != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "oriented", str(oriented))
+ if spline != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "spline", str(spline))
+ if showstrain != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "showstrain", str(showstrain))
+ if stroke != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "stroke", stroke)
+ if strength != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "strength", str(strength))
+ if visible != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "visible", str(visible))
+ if width != None:
+ self.U.server.ubigraph.set_edge_attribute(self.id, "width", str(width))
+
+ def destroy(self):
+ self.U.server.ubigraph.remove_edge(self.id)
+
+
+ class VertexStyle:
+ def __init__(self, U, parentStyle=None, id=None, color=None, shape=None,
+ label=None, size=None, fontcolor=None, fontfamily=None,
+ fontsize=None, visible=None):
+ self.U = U
+ parentStyle2 = parentStyle
+ if parentStyle == None:
+ if id == 0:
+ # Represent the global default style
+ self.id = 0
+ return
+ else:
+ parentStyle2 = U.defaultVertexStyle
+
+ if id == None:
+ self.id = U.server.ubigraph.new_vertex_style(parentStyle2.id)
+ else:
+ U.server.ubigraph.new_vertex_style_w_id(id, parentStyle2.id)
+ self.id = id
+ self.set(color=color, shape=shape, label=label, size=size,
+ fontcolor=fontcolor, fontfamily=fontfamily, fontsize=fontsize,
+ visible=visible)
+
+ def set(self, color=None, shape=None, label=None, size=None,
+ fontcolor=None, fontfamily=None, fontsize=None, visible=None,
+ callback=None):
+ if color != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "color", color)
+ if shape != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "shape", shape)
+ if label != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "label", label)
+ if size != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "size", str(size))
+ if fontcolor != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "fontcolor", fontcolor)
+ if fontfamily != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "fontfamily", fontfamily)
+ if fontsize != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "fontsize", str(fontsize))
+ if visible != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "visible", str(visible))
+ if callback != None:
+ self.U.server.ubigraph.set_vertex_style_attribute(self.id, "callback_left_doubleclick",
+ callback)
+
+
+
+ class EdgeStyle:
+ def __init__(self, U, parentStyle=None, id=None, arrow=None, color=None,
+ label=None, fontcolor=None, fontfamily=None, fontsize=None,
+ oriented=None, spline=None, showstrain=None, stroke=None,
+ strength=None, visible=None, width=None):
+ self.U = U
+ parentStyle2 = parentStyle
+ if parentStyle2 == None:
+ if id == 0:
+ # Represent the global default style
+ self.id = 0
+ return
+ else:
+ parentStyle2 = U.defaultEdgeStyle
+
+ if id == None:
+ self.id = U.server.ubigraph.new_edge_style(parentStyle2.id)
+ else:
+ U.server.ubigraph.new_edge_style_w_id(id, parentStyle2.id)
+ self.id = id
+ self.set(arrow=arrow, color=color, label=label, fontcolor=fontcolor,
+ fontfamily=fontfamily, fontsize=fontsize, oriented=oriented,
+ spline=spline, showstrain=showstrain, stroke=stroke, strength=strength,
+ visible=visible, width=width)
+
+ def set(self, arrow=None, color=None,
+ label=None, fontcolor=None, fontfamily=None, fontsize=None,
+ oriented=None, spline=None, showstrain=None, stroke=None,
+ strength=None, visible=None, width=None):
+ if arrow != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "arrow", str(arrow))
+ if arrow_position != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "arrow_position",
+ str(arrow_position))
+ if arrow_length != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "arrow_length",
+ str(arrow_length))
+ if arrow_radius != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "arrow_radius",
+ str(arrow_radius))
+ if arrow_reverse != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "arrow_reverse",
+ str(arrow_reverse))
+ if color != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "color", color)
+ if label != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "label", label)
+ if fontcolor != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "fontcolor", fontcolor)
+ if fontfamily != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "fontfamily", fontfamily)
+ if fontsize != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "fontsize", str(fontsize))
+ if oriented != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "oriented", str(oriented))
+ if spline != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "spline", str(spline))
+ if showstrain != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "showstrain", str(showstrain))
+ if stroke != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "stroke", stroke)
+ if strength != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "strength", str(strength))
+ if visible != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "visible", str(visible))
+ if width != None:
+ self.U.server.ubigraph.set_edge_style_attribute(self.id, "width", str(width))
+