Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return
def reg_hit(ctxt, reg):
print('Need concrete register value:', reg)
return
def mem_hit(ctxt, mem):
print('Need concrete memory value:', mem)
return
if __name__ == '__main__':
# Start JIT at the entry point
startAnalysisFromEntry()
getTritonContext().addCallback(mem_hit, CALLBACK.GET_CONCRETE_MEMORY_VALUE)
getTritonContext().addCallback(reg_hit, CALLBACK.GET_CONCRETE_REGISTER_VALUE)
# Add callback
insertCall(mycb, INSERT_POINT.BEFORE)
# Run Program
runProgram()
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
def reset(self):
self.triton.reset()
self.triton.clearPathConstraints()
self.triton.setArchitecture(self.arch)
self.triton.enableMode(triton.MODE.ALIGNED_MEMORY, True)
self.triton.enableMode(triton.MODE.ONLY_ON_SYMBOLIZED, True)
self.triton.addCallback(self.memoryCaching,
triton.CALLBACK.GET_CONCRETE_MEMORY_VALUE)
self.triton.addCallback(self.constantFolding,
triton.CALLBACK.SYMBOLIC_SIMPLIFICATION)
for r in self.triton_regs:
if r in self.regs:
self.triton.setConcreteRegisterValue(
self.triton_regs[r], self.regs[r] & 0xffffffffffffffff
)
for m in cache:
self.write_mem(m['start'], m["data"])
for address in self.inputs:
self.inputs[address] = self.triton.convertMemoryToSymbolicVariable(
triton.MemoryAccess(
address,
triton.CPUSIZE.BYTE
)
def reset(self):
triton.resetEngines()
triton.clearPathConstraints()
triton.setArchitecture(self.arch)
triton.enableMode(triton.MODE.ALIGNED_MEMORY, True)
triton.enableMode(triton.MODE.ONLY_ON_SYMBOLIZED, True)
triton.addCallback(self.memoryCaching,
triton.CALLBACK.GET_CONCRETE_MEMORY_VALUE)
triton.addCallback(self.constantFolding,
triton.CALLBACK.SYMBOLIC_SIMPLIFICATION)
for r in self.regs:
if r in self.triton_regs:
triton.setConcreteRegisterValue(
triton.Register(self.triton_regs[r], self.regs[r] & ((1 << self.triton_regs[r].getBitSize()) - 1))
)
for m in cache:
self.write_mem(m['start'], m["data"])
for address in self.inputs:
self.inputs[address] = triton.convertMemoryToSymbolicVariable(
triton.MemoryAccess(
address,
triton.CPUSIZE.BYTE
)
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
# Example 2 - forme A
c = (a & ~b) | (~a & b)
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
# Example 2 - forme A