本文整理汇总了Python中triton.TritonContext.addCallback方法的典型用法代码示例。如果您正苦于以下问题:Python TritonContext.addCallback方法的具体用法?Python TritonContext.addCallback怎么用?Python TritonContext.addCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类triton.TritonContext
的用法示例。
在下文中一共展示了TritonContext.addCallback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
# 需要导入模块: from triton import TritonContext [as 别名]
# 或者: from triton.TritonContext import addCallback [as 别名]
def initialize():
Triton = TritonContext()
# Define the target architecture
Triton.setArchitecture(ARCH.X86_64)
# Define symbolic optimizations
Triton.enableMode(MODE.ALIGNED_MEMORY, True)
Triton.enableMode(MODE.ONLY_ON_SYMBOLIZED, True)
# Define internal callbacks.
Triton.addCallback(memoryCaching, CALLBACK.GET_CONCRETE_MEMORY_VALUE)
Triton.addCallback(constantFolding, CALLBACK.SYMBOLIC_SIMPLIFICATION)
# Load the meory dump
load_dump(Triton, os.path.join(os.path.dirname(__file__), "baby-re.dump"))
# Symbolize user inputs
symbolizeInputs(Triton)
return Triton
示例2: TestCallback
# 需要导入模块: from triton import TritonContext [as 别名]
# 或者: from triton.TritonContext import addCallback [as 别名]
class TestCallback(unittest.TestCase):
"""Testing callbacks."""
def test_get_concrete_memory_value(self):
global flag
self.Triton = TritonContext()
self.Triton.setArchitecture(ARCH.X86_64)
flag = False
self.Triton.addCallback(self.cb_flag, CALLBACK.GET_CONCRETE_MEMORY_VALUE)
# movabs rax, qword ptr [0x1000]
self.Triton.processing(Instruction("\x48\xa1\x00\x10\x00\x00\x00\x00\x00\x00"))
self.assertTrue(flag)
flag = False
self.Triton.removeCallback(self.cb_flag, CALLBACK.GET_CONCRETE_MEMORY_VALUE)
# movabs rax, qword ptr [0x1000]
self.Triton.processing(Instruction("\x48\xa1\x00\x10\x00\x00\x00\x00\x00\x00"))
self.assertFalse(flag)
def test_get_concrete_register_value(self):
global flag
self.Triton = TritonContext()
self.Triton.setArchitecture(ARCH.X86_64)
flag = False
self.Triton.addCallback(self.cb_flag, CALLBACK.GET_CONCRETE_REGISTER_VALUE)
self.Triton.processing(Instruction("\x48\x89\xd8")) # mov rax, rbx
self.assertTrue(flag)
flag = False
self.Triton.removeCallback(self.cb_flag, CALLBACK.GET_CONCRETE_REGISTER_VALUE)
self.Triton.processing(Instruction("\x48\x89\xd8")) # mov rax, rbx
self.assertFalse(flag)
# Remove all callbacks
flag = False
self.Triton.addCallback(self.cb_flag, CALLBACK.GET_CONCRETE_REGISTER_VALUE)
self.Triton.processing(Instruction("\x48\x89\xd8")) # mov rax, rbx
self.assertTrue(flag)
flag = False
self.Triton.removeAllCallbacks()
self.Triton.processing(Instruction("\x48\x89\xd8")) # mov rax, rbx
self.assertFalse(flag)
@staticmethod
def cb_flag(api, x):
global flag
flag = True
示例3: TestAstSimplification
# 需要导入模块: from triton import TritonContext [as 别名]
# 或者: from triton.TritonContext import addCallback [as 别名]
class TestAstSimplification(unittest.TestCase):
"""Testing AST simplification."""
def setUp(self):
self.Triton = TritonContext()
self.Triton.setArchitecture(ARCH.X86_64)
self.Triton.addCallback(self.xor_1, CALLBACK.SYMBOLIC_SIMPLIFICATION)
self.Triton.addCallback(self.xor_2, CALLBACK.SYMBOLIC_SIMPLIFICATION)
self.astCtxt = self.Triton.getAstContext()
def test_simplification(self):
a = self.astCtxt.bv(1, 8)
b = self.astCtxt.bv(2, 8)
# Example 1
c = a ^ a
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(_ bv0 8)")
c = a ^ b
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(bvxor (_ bv1 8) (_ bv2 8))")
c = (a & ~b) | (~a & b)
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(bvxor (_ bv1 8) (_ bv2 8))")
# Example 2 - forme B
c = (~b & a) | (~a & b)
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(bvxor (_ bv1 8) (_ bv2 8))")
# Example 2 - forme C
c = (~b & a) | (b & ~a)
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(bvxor (_ bv1 8) (_ bv2 8))")
# Example 2 - forme D
c = (b & ~a) | (~b & a)
c = self.Triton.simplify(c)
self.assertEqual(str(c), "(bvxor (_ bv2 8) (_ bv1 8))")
return
# a ^ a -> a = 0
@staticmethod
def xor_1(api, node):
if node.getKind() == AST_NODE.BVXOR:
if node.getChildren()[0].equalTo(node.getChildren()[1]):
return api.getAstContext().bv(0, node.getBitvectorSize())
return node
# ((a & ~b) | (~a & b)) -> (a ^ b)
@staticmethod
def xor_2(api, node):
def getNot(node):
a = node.getChildren()[0]
b = node.getChildren()[1]
if a.getKind() == AST_NODE.BVNOT and b.getKind() != AST_NODE.BVNOT:
return a
if b.getKind() == AST_NODE.BVNOT and a.getKind() != AST_NODE.BVNOT:
return b
return None
def getNonNot(node):
a = node.getChildren()[0]
b = node.getChildren()[1]
if a.getKind() != AST_NODE.BVNOT and b.getKind() == AST_NODE.BVNOT:
return a
if b.getKind() != AST_NODE.BVNOT and a.getKind() == AST_NODE.BVNOT:
return b
return None
if node.getKind() == AST_NODE.BVOR:
c1 = node.getChildren()[0]
c2 = node.getChildren()[1]
if c1.getKind() == AST_NODE.BVAND and c2.getKind() == AST_NODE.BVAND:
c1_not = getNot(c1)
c2_not = getNot(c2)
c1_nonNot = getNonNot(c1)
c2_nonNot = getNonNot(c2)
if c1_not.equalTo(~c2_nonNot) and c2_not.equalTo(~c1_nonNot):
return c1_nonNot ^ c2_nonNot
return node
示例4: getNot
# 需要导入模块: from triton import TritonContext [as 别名]
# 或者: from triton.TritonContext import addCallback [as 别名]
c2_not = getNot(c2)
c1_nonNot = getNonNot(c1)
c2_nonNot = getNonNot(c2)
if c1_not.equalTo(~c2_nonNot) and c2_not.equalTo(~c1_nonNot):
return c1_nonNot ^ c2_nonNot
return node
if __name__ == "__main__":
# Set arch to init engines
Triton.setArchitecture(ARCH.X86_64)
# Record simplifications
Triton.addCallback(xor_1, CALLBACK.SYMBOLIC_SIMPLIFICATION)
Triton.addCallback(xor_2, CALLBACK.SYMBOLIC_SIMPLIFICATION)
astCtxt = Triton.getAstContext()
a = astCtxt.bv(1, 8)
b = astCtxt.bv(2, 8)
# Example 1
c = a ^ a
print 'Expr: ', c
c = Triton.simplify(c)
print 'Simp: ', c
print