from
triton
import
*
import
idc
import
ida_bytes
from
capstone
import
*
from
capstone.arm64
import
*
cs
=
Cs(CS_ARCH_ARM64, CS_MODE_LITTLE_ENDIAN)
cs.detail
=
True
def
get_insn2(opcode0, addr):
insns
=
cs.disasm(opcode0, addr)
for
i
in
insns:
return
i
def
taint_analysis2(start, end):
Triton
=
TritonContext()
with
open
(
'C:\\Users\\lj\\Desktop\\junks\\test1\\CoreBook2'
,
'rb'
) as f:
bin1
=
f.read()
Triton.setArchitecture(ARCH.AARCH64)
Triton.setConcreteMemoryAreaValue(
0
, bin1)
sp
=
0x100000000
Triton.setConcreteRegisterValue(Triton.registers.x29, sp)
Triton.setConcreteRegisterValue(Triton.registers.sp, sp)
pc
=
start
nop_addrs
=
[]
while
pc:
inst
=
Instruction()
opcode0
=
ida_bytes.get_bytes(pc,
4
)
cs_insn: CsInsn
=
get_insn2(opcode0, pc)
if
cs_insn
is
None
or
cs_insn.mnemonic
in
[
'br'
,
'bl'
,
'b'
]:
pc
=
pc
+
4
continue
inst.setOpcode(opcode0)
inst.setAddress(pc)
Triton.processing(inst)
print
(
str
(inst))
if
pc
=
=
0x1E7D00
:
Triton.taintRegister(Triton.registers.w8)
if
pc
=
=
0x1E7D08
:
Triton.taintRegister(Triton.registers.w9)
if
pc
=
=
0x1E7D10
:
Triton.taintRegister(Triton.registers.w10)
if
pc
=
=
0x1E7D18
:
Triton.taintRegister(Triton.registers.w11)
if
pc
=
=
0x1E7D20
:
Triton.taintRegister(Triton.registers.w12)
if
pc
=
=
0x1E4DB8
:
Triton.taintRegister(Triton.registers.x4)
Triton.taintMemory(Triton.getConcreteRegisterValue(Triton.registers.x4))
if
pc
=
=
0x1e7d90
:
Triton.taintMemory(Triton.getConcreteRegisterValue(Triton.registers.x8))
if
inst.isTainted():
idc.set_color(pc, idc.CIC_ITEM,
0xffe699
)
nop_addrs.append(pc)
if
pc >
=
end:
break
pc
=
pc
+
4
if
__name__
=
=
'__main__'
:
taint_analysis2(
0x1E4D28
,
0x1E7D98
)