Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_modify_arch2(self):
"""Check we can change arch at anytime."""
for _ in range(10):
self.ctx = TritonContext(random.choice((ARCH.X86_64, ARCH.X86, ARCH.AARCH64)))
def test_known_issues(self):
"""Check tainting result after processing."""
Triton = TritonContext()
Triton.setArchitecture(ARCH.X86)
Triton.taintRegister(Triton.registers.eax)
inst = Instruction()
# lea eax,[esi+eax*1]
inst.setOpcode(b"\x8D\x04\x06")
Triton.processing(inst)
self.assertTrue(Triton.isRegisterTainted(Triton.registers.eax))
self.assertFalse(Triton.isRegisterTainted(Triton.registers.ebx))
def test_pop(self):
"""Check the pop instruction processing."""
self.Triton = TritonContext()
self.Triton.setArchitecture(ARCH.X86)
# mov esp, 0x19fe00
inst1 = Instruction(b'\xBC\x00\xFE\x19\x00')
# mov edi, 0x19fe00
inst2 = Instruction(b'\xBF\x00\xFE\x19\x00')
# mov dword ptr [esp], 0x11111111
inst3 = Instruction(b'\xC7\x04\x24\x11\x11\x11\x11')
# pop dword ptr [edi]
inst4 = Instruction(b'\x8F\x07')
self.Triton.processing(inst1)
self.Triton.processing(inst2)
self.Triton.processing(inst3)
self.Triton.processing(inst4)
self.assertEqual(inst4.getOperands()[0].getAddress(), 0x19fe00, "poping edi doesn't change it")
self.assertEqual(inst4.getStoreAccess()[0][0].getAddress(), 0x19fe00, "inst4 store the new value in 0x19fe00 (edi value)")
def setUp(self):
"""Define the arch."""
self.Triton = TritonContext()
self.Triton.setArchitecture(ARCH.X86)
def setUp(self):
"""Define the arch."""
self.ctx = TritonContext()
self.assertFalse(self.ctx.isArchitectureValid())
self.ctx.setArchitecture(ARCH.X86)
self.assertTrue(self.ctx.isArchitectureValid())
def test_trace(trace):
Triton.setArchitecture(ARCH.X86)
symbolization_init()
astCtxt = Triton.getAstContext()
for opcode in trace:
instruction = Instruction()
instruction.setOpcode(opcode)
Triton.processing(instruction)
print(instruction.getDisassembly())
if instruction.isBranch():
# Opaque Predicate AST
op_ast = Triton.getPathConstraintsAst()
# Try another model
model = Triton.getModel(astCtxt.lnot(op_ast))
if model:
flags = self.get_flags()
if s in regs:
v = regs[s]
elif s in flags:
v = flags[s]
elif s in self.exports:
v = self.exports[s]
elif s.startswith("0x"):
v = int(s, 16)
else:
v = int(s)
return v
tritonarch = {
"x86": {
32: triton.ARCH.X86,
64: triton.ARCH.X86_64
}
}
class Pimp(object):
CMD_HANDLED = 1
CMD_NOT_HANDLED = 0
def __init__(self, context=None):
self.r2p = None
self.comments = {}
self.arch = None
self.inputs = collections.OrderedDict()
self.regs = {}
self.triton_regs = {}
self.commands = {}
self.last_symjump = None
def test2():
Triton = TritonContext()
Triton.setArchitecture(ARCH.X86)
astCtxt = Triton.getAstContext()
x = Triton.newSymbolicVariable(32)
c = ((astCtxt.variable(x) ^ 0x40) - 1 == 0x10)
print('Test 2:', Triton.getModel(c)[0])
return
self.r2p = R2("pimp")
arch = self.r2p.arch
bits = self.r2p.bits
self.arch = tritonarch[arch][bits]
self.trace = collections.Counter()
self.triton = triton.TritonContext()
self.triton.setArchitecture(self.arch)
self.triton.setAstRepresentationMode(triton.AST_REPRESENTATION.PYTHON)
# Hack in order to be able to get triton register ids by name
for r in self.triton.getAllRegisters():
self.triton_regs[r.getName()] = r
if self.arch == triton.ARCH.X86:
self.pcreg = self.triton.registers.eip
elif self.arch == triton.ARCH.X86_64:
self.pcreg = self.triton.registers.rip
else:
raise(ValueError("Architecture not implemented"))
setattr(self.memoryCaching, "memsolver", self.r2p)
def test3():
Triton = TritonContext()
Triton.setArchitecture(ARCH.X86)
astCtxt = Triton.getAstContext()
x = Triton.newSymbolicVariable(8)
c = astCtxt.land([
astCtxt.variable(x) * astCtxt.variable(x) - 1 == 0x20,
astCtxt.variable(x) != 0x11
])
print('Test 3:', Triton.getModel(c)[0])
return