def test_wipeAstArch_wipeva(self): vw = viv.VivWorkspace() vw.addMemoryMap(0x410000, e_mem.MM_RWX, 'code', [0 for x in range(0x10000)]) vw.addLocation(0x41b2ac, 47, viv_const.LOC_POINTER) vw.addLocation(0x4149b3, 28, viv_const.LOC_POINTER) vw.addLocation(0x41ac93, 83, viv_const.LOC_POINTER) vw.setMeta('Architecture', 'i386') symctx = vsym_analysis.SymbolikAnalysisContext(vw) cons = vsc.Const(0x41b2ac, 4) func1 = vsc.Call(cons, 4, argsyms=[vsc.Var('edx', 4)]) func2 = vsc.Call( vsc.Const(0x4149b3, 4), 4, argsyms=[vsc.Const(0, 4), vsc.Const(1, 4), vsc.Const(0x41b2ac, 4)]) func3 = vsc.Call(vsc.Const(0x41ac93, 4), 4, argsyms=[vsc.Const(0, 4), vsc.Var('ecx', 4)]) wiped = vsym_archind.wipeAstArch(symctx, [func1 + func2, func3], wipeva=True) self.assertEqual(2, len(wiped)) self.assertEqual('(2archindva(1indreg) + 1archindva(0,1,2archindva))', str(wiped[0])) self.assertEqual('0archindva(0,0indreg)', str(wiped[1]))
def test_coverage(self): ''' ((mem[piva_global(0xbfbfee08):1] | (mem[(arg0 + 72):4] & 0xffffff00)) + piva_global()) ''' ids = [] piva1 = vsc.Var('piva_global', 4) ids.append(piva1._sym_id) arg = vsc.Const(0xbfbfee08, 4) ids.append(arg._sym_id) call = vsc.Call(piva1, 4, argsyms=[arg]) ids.append(call._sym_id) con = vsc.Const(1, 4) ids.append(con._sym_id) mem1 = vsc.Mem(call, con) ids.append(mem1._sym_id) arg = vsc.Arg(0, 4) ids.append(arg._sym_id) addop = vsc.Const(72, 4) ids.append(addop._sym_id) add = vsc.o_add(arg, addop, 4) ids.append(add._sym_id) con = vsc.Const(4, 4) ids.append(con._sym_id) memac = vsc.Mem(add, con) ids.append(memac._sym_id) andop = vsc.Const(0xffffff00, 4) ids.append(andop._sym_id) mem2 = vsc.o_and(memac, andop, 4) ids.append(mem2._sym_id) memor = vsc.o_or(mem1, mem2, 4) ids.append(memor._sym_id) piva2 = vsc.Var('piva_global', 4) ids.append(piva2._sym_id) call2 = vsc.Call(piva2, 4, argsyms=[]) ids.append(call2._sym_id) add = vsc.o_add(memor, call2, 4) ids.append(add._sym_id) traveled_ids = [] def walkerTest(path, symobj, ctx): traveled_ids.append(symobj._sym_id) add.walkTree(walkerTest) self.assertEqual(traveled_ids, ids) self.assertEqual( '((mem[piva_global(0xbfbfee08):1] | (mem[(arg0 + 72):4] & 0xffffff00)) + piva_global())', str(add))
def test_wipeAstArch(self): vw = viv.VivWorkspace() vw.addMemoryMap(0x00, e_mem.MM_RWX, 'code', [0 for x in range(256)]) vw.addLocation(0x40, 47, viv_const.LOC_POINTER) vw.setMeta('Architecture', 'i386') symctx = vsym_analysis.SymbolikAnalysisContext(vw) func = vsc.Var('eax', 4) call = vsc.Call(func, 4) addr = vsc.Var('arg0', 4) + call mem = vsc.Mem(addr, vsc.Const(4, 4)) op = mem + vsc.Var('edx', 4) final = op * vsc.Var('edx', 4) wiped = vsym_archind.wipeAstArch(symctx, [final]) self.assertEquals(1, len(wiped)) self.assertEquals('((mem[(arg0 + 1indreg()):4] + 0indreg) * 0indreg)', str(wiped[0]))