def test_graphutil_getcodepaths(self): ''' In this function, order doesn't matter ''' vw = self.gcc_vw g = v_t_graphutil.buildFunctionGraph(vw, 0x456190) paths = [ set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x45621c, 0x456240, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x45621c, 0x40aa97, 0x4561ea, 0x4561ef, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x45621c, 0x40aa97, 0x4561ea, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x4561c2, 0x4561d0, 0x4561ea, 0x4561ef, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x4561c2, 0x4561d0, 0x4561ea, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x4561c2, 0x40aa85, 0x40aa8d, 0x4561d0, 0x4561ea, 0x4561ef, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x4561c2, 0x40aa85, 0x40aa8d, 0x4561d0, 0x4561ea, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x456216, 0x4561c2, 0x40aa85, 0x40aab9, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x45621c, 0x456240, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x45621c, 0x40aa97, 0x4561ea, 0x4561ef, 0x4561fa, 0x456242]), set([0x456190, 0x4561ba, 0x456202, 0x45621c, 0x40aa97, 0x4561ea, 0x4561fa, 0x456242]), set([0x456190, 0x456242]), ] pathcount = 0 genr = v_t_graphutil.getCodePaths(g, loopcnt=0, maxpath=None) for path in genr: p = set(map(lambda k: k[0], path)) self.assertIn(p, paths) pathcount += 1 self.assertEqual(12, pathcount) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x0041a766)) thruCnt = glen(v_t_graphutil.getCodePathsThru(g, 0x0041a766)) self.assertEqual(2, thruCnt) thruCnt = glen(v_t_graphutil.getCodePathsThru(g, 0x0041a766, maxpath=1)) self.assertEqual(1, thruCnt) # this will not be true for all examples, but for this function it is g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x0041a77d)) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x0041a77d)) self.assertEqual(2, toCnt) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x0041a77d, maxpath=99)) self.assertEqual(2, toCnt) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x004042eb)) fromCnt = glen(v_t_graphutil.getCodePathsFrom(g, 0x004042eb)) self.assertEqual(8, fromCnt) fromCnt = glen(v_t_graphutil.getCodePathsFrom(g, 0x004042eb, maxpath=3)) self.assertEqual(3, fromCnt)
def test_graphutil_getcodepaths(self): ''' In this function, order doesn't matter ''' vw = self.firefox_vw g = v_t_graphutil.buildFunctionGraph(vw, 0x140010e60) paths = [ set([5368778336, 5368778350, 5368778362, 5368778366, 5368778394, 5368778400]), set([5368778336, 5368778350, 5368778362, 5368778366, 5368778498, 5368778515, 5368778394, 5368778400]), set([5368778336, 5368778350, 5368778362, 5368778366, 5368778498, 5368778520, 5368778544, 5368778549]), set([5368778336, 5368778350, 5368778362, 5368778366, 5368778498, 5368778520, 5368778544, 5368778601, 5368778603]), set([5368778336, 5368778350, 5368778362, 5368778366, 5368778498, 5368778520, 5368778560, 5368778603]), set([5368778336, 5368778350, 5368778482, 5368778366, 5368778394, 5368778400]), set([5368778336, 5368778350, 5368778482, 5368778366, 5368778498, 5368778515, 5368778394, 5368778400]), set([5368778336, 5368778350, 5368778482, 5368778366, 5368778498, 5368778520, 5368778544, 5368778549]), set([5368778336, 5368778350, 5368778482, 5368778366, 5368778498, 5368778520, 5368778544, 5368778601, 5368778603]), set([5368778336, 5368778350, 5368778482, 5368778366, 5368778498, 5368778520, 5368778560, 5368778603]), set([5368778336, 5368778400]), ] pathcount = 0 genr = v_t_graphutil.getCodePaths(g, loopcnt=0, maxpath=None) for path in genr: p = set([k[0] for k in path]) self.assertIn(p, paths) pathcount += 1 self.assertEqual(11, pathcount) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x1400110a0)) thruCnt = glen(v_t_graphutil.getCodePathsThru(g, 0x1400110a0)) self.assertEqual(23, thruCnt) thruCnt = glen(v_t_graphutil.getCodePathsThru(g, 0x1400110a0, maxpath=2)) self.assertEqual(2, thruCnt) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x14001ead0)) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x14001ec2a)) self.assertEqual(2, toCnt) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x14001ec2a, maxpath=99)) self.assertEqual(2, toCnt) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x1400019ab)) fromCnt = glen(v_t_graphutil.getCodePathsFrom(g, 0x1400019ab)) self.assertEqual(2, fromCnt) fromCnt = glen(v_t_graphutil.getCodePathsFrom(g, 0x1400019ab, maxpath=1)) self.assertEqual(1, fromCnt)
def renderSymbolikPaths(self): try: self.memcanvas.clearCanvas() exprtxt = str(self.exprtext.text()) if not exprtxt: return exprparts = exprtxt.split(';') expr = exprparts[0] preeff = [] precons = [] for e in exprparts[1:]: s = self.symexpr.parseExpression(e) if isinstance(s, viv_sym_constraints.Constraint): precons.append(s) continue if isinstance(s, viv_sym_effects.SymbolikEffect): preeff.append(s) continue raise Exception('Unhandled Symbolik Expression: %s' % e) self.symctx.setSymPreEffects(preeff) self.symctx.setSymPreConstraints(precons) va = self.vw.parseExpression(expr) self.fva = self.vw.getFunction(va) if self.fva is None: raise Exception('Invalid Address: 0x%.8x' % va) # check the constraints # FIXME: add ability to page through more than just the first 100 paths. requires # storing the codegraph and codepaths codepaths = None codegraph = self.symctx.getSymbolikGraph(self.fva) cexpr = str(self.constraintext.text()) if cexpr: cva = self.vw.parseExpression(cexpr) ccb = self.vw.getCodeBlock(cva) if ccb is not None and ccb in self.vw.getFunctionBlocks(self.fva): # FIXME: allow the GUI-setting of loopcnt, instead of hard-coding loopcnt = self.loop_count.value() codepaths = viv_graph.getCodePathsThru(codegraph, ccb[0], loopcnt=loopcnt) paths = self.symctx.getSymbolikPaths(self.fva, paths=codepaths, graph=codegraph, maxpath=100) if codepaths is None: paths = self.symctx.walkSymbolikPaths(self.fva, maxpath=100) self.pathview.loadSymbolikPaths(paths) except Exception as e: traceback.print_exc() self.memcanvas.addText('ERROR: %s' % e)
def renderSymbolikPaths(self): try: self.memcanvas.clearCanvas() exprtxt = str(self.exprtext.text()) if not exprtxt: return exprparts = exprtxt.split(';') expr = exprparts[0] preeff = [] precons = [] for e in exprparts[1:]: s = self.symexpr.parseExpression(e) if isinstance(s, viv_sym_common.Constraint): precons.append(s) continue if isinstance(s, viv_sym_effects.SymbolikEffect): preeff.append(s) continue raise Exception('Unhandled Symbolik Expression: %s' % e) self.symctx.setSymPreEffects(preeff) self.symctx.setSymPreConstraints(precons) va = self.vw.parseExpression(expr) self.fva = self.vw.getFunction(va) if self.fva is None: raise Exception('QTSymboliks: Invalid Address: 0x%.8x' % va) # check the constraints # FIXME: add ability to page through more than just the first 100 paths. requires # storing the codegraph and codepaths codepaths = None codegraph = self.symctx.getSymbolikGraph(self.fva) cexpr = str(self.constraintext.text()) if cexpr: cva = self.vw.parseExpression(cexpr) ccb = self.vw.getCodeBlock(cva) if ccb is not None and ccb in self.vw.getFunctionBlocks(self.fva): loopcnt = self.loop_count.value() codepaths = viv_graph.getCodePathsThru(codegraph, ccb[0], loopcnt=loopcnt) paths = self.symctx.getSymbolikPaths(self.fva, paths=codepaths, graph=codegraph, maxpath=100) if codepaths is None: loopcnt = self.loop_count.value() paths = self.symctx.walkSymbolikPaths(self.fva, maxpath=100, loopcnt=loopcnt) if not self.pathview.loadSymbolikPaths(paths): self.memcanvas.addText('No valid symbolik paths found for %s' % expr) except Exception as e: self.memcanvas.addText('ERROR: %s' % e)
def checkGetCodePathsThru(self, vw, fva, cbva): graph = viv_graph.buildFunctionGraph(vw, fva) paths = [path for path in viv_graph.getCodePathsThru(graph, cbva)] self.codepathsthru = paths self.assertGreater(len(self.codepaths), len(self.codepathsthru)) paths = [path for path in graph.getHierPathsThru((cbva, ))] self.hiercodepathsthru = paths self.assertGreater(len(self.codepaths), len(self.hiercodepathsthru))
def checkGetCodePathsThru(self, vw, fva, cbva): graph = viv_graph.buildFunctionGraph(vw, fva ) paths = [ path for path in viv_graph.getCodePathsThru(graph, cbva) ] self.codepathsthru = paths self.assertGreater(len(self.codepaths), len(self.codepathsthru)) paths = [ path for path in graph.getHierPathsThru((cbva,)) ] self.hiercodepathsthru = paths self.assertGreater(len(self.codepaths), len(self.hiercodepathsthru))
def renderSymbolikPaths(self): try: self.memcanvas.clearCanvas() exprtxt = str(self.exprtext.text()) if not exprtxt: return exprparts = exprtxt.split(';') expr = exprparts[0] preeff = [] precons = [] for e in exprparts[1:]: s = self.symexpr.parseExpression(e) if isinstance(s, viv_sym_constraints.Constraint): precons.append(s) continue if isinstance(s, viv_sym_effects.SymbolikEffect): preeff.append(s) continue raise Exception('Unhandled Symbolik Expression: %s' % e) self.symctx.setSymPreEffects(preeff) self.symctx.setSymPreConstraints(precons) va = self.vw.parseExpression(expr) self.fva = self.vw.getFunction(va) if self.fva == None: raise Exception('Invalid Address: 0x%.8x' % va) # check the constraints codepaths = None codegraph = self.symctx.getSymbolikGraph(self.fva) cexpr = str(self.constraintext.text()) if cexpr: cva = self.vw.parseExpression(cexpr) ccb = self.vw.getCodeBlock(cva) if ccb != None and ccb in self.vw.getFunctionBlocks(self.fva): codepaths = viv_graph.getCodePathsThru( codegraph, ccb[0], loopcnt=3 ) #FIXME: allow the GUI-setting of loopcnt, instead of hard-coding if codepaths == None: codepaths = viv_graph.getCodePaths(codegraph, 3) #paths = self.symctx.getSymbolikPaths(self.fva, paths=codepaths, maxpath=100) paths = self.symctx.walkSymbolikPaths(self.fva, maxpath=100) self.pathview.loadSymbolikPaths(paths) except Exception, e: traceback.print_exc() self.memcanvas.addText('ERROR: %s' % e)
def checkPathGenGetCodePaths(self, vw, fva): graph = viv_graph.buildFunctionGraph(vw, fva) paths = [path for path in viv_graph.getCodePathsThru(graph)] self.codepaths = paths self.assertGreater(len(self.codepaths), 150)
def test_graphutil_getcodepaths(self): ''' In this function, order doesn't matter ''' vw = self.firefox_vw g = v_t_graphutil.buildFunctionGraph(vw, 0x140010e60) paths = [ set([ 0x140010e60, 0x140010e6e, 0x140010e7a, 0x140010e7e, 0x140010e9a, 0x140010ea0 ]), set([ 0x140010e60, 0x140010e6e, 0x140010e7a, 0x140010e7e, 0x140010e9a, 0x140010ea0, 0x140010f02, 0x140010f13 ]), set([ 0x140010e60, 0x140010e6e, 0x140010e7a, 0x140010e7e, 0x140010f02, 0x140010f18 ]), set([ 0x140010e60, 0x140010e6e, 0x140010e7e, 0x140010e9a, 0x140010ea0, 0x140010ef2 ]), set([ 0x140010e60, 0x140010e6e, 0x140010e7e, 0x140010e9a, 0x140010ea0, 0x140010ef2, 0x140010f02, 0x140010f13 ]), set([ 0x140010e60, 0x140010e6e, 0x140010e7e, 0x140010ef2, 0x140010f02, 0x140010f18 ]), set([0x140010e60, 0x140010ea0]), ] pathcount = 0 genr = v_t_graphutil.getCodePaths(g, loopcnt=0, maxpath=None) for path in genr: p = set([k[0] for k in path]) self.assertIn(p, paths) pathcount += 1 self.assertEqual(7, pathcount) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x1400110a0)) thruCnt = glen(v_t_graphutil.getCodePathsThru(g, 0x1400110a0)) self.assertEqual(21, thruCnt) thruCnt = glen( v_t_graphutil.getCodePathsThru(g, 0x1400110a0, maxpath=2)) self.assertEqual(2, thruCnt) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x14001ead0)) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x14001ec2a)) self.assertEqual(2, toCnt) toCnt = glen(v_t_graphutil.getCodePathsTo(g, 0x14001ec2a, maxpath=99)) self.assertEqual(2, toCnt) g = v_t_graphutil.buildFunctionGraph(vw, vw.getFunction(0x1400019ab)) fromCnt = glen(v_t_graphutil.getCodePathsFrom(g, 0x1400019ab)) self.assertEqual(2, fromCnt) fromCnt = glen( v_t_graphutil.getCodePathsFrom(g, 0x1400019ab, maxpath=1)) self.assertEqual(1, fromCnt)
def checkPathGenGetCodePaths(self, vw, fva): graph = viv_graph.buildFunctionGraph(vw, fva) paths = [ path for path in viv_graph.getCodePathsThru(graph) ] self.codepaths = paths self.assertGreater(len(self.codepaths), 150)