예제 #1
0
파일: pcode.py 프로젝트: SamL98/MyDeco
    def fromjson(cls, j):
        inputs = [Varnode.fromjson(ij) for ij in j['inputs']]
        output = None

        if 'output' in j:
            output = Varnode.fromjson(j['output'])

        pcop = cls(j['addr'], j['mnemonic'], inputs, output)

        if pcop.is_call():
            pcop = CallOp.frompcop(pcop)
        elif pcop.is_ret():
            pcop = RetOp.frompcop(pcop)

        return pcop
예제 #2
0
파일: pcode.py 프로젝트: SamL98/MyDeco
    def fromstring(cls, s):
        comps = s.split(': ')
        addr = int(comps[0], 16)
        s = comps[1]

        comps = s.split(' = ')
        output = None

        if len(comps) == 2:
            output = Varnode.fromstring(comps[0])
            s = comps[1]

        mnem_idx = s.index(' ')
        mnemonic = s[:mnem_idx]
        inputs = [Varnode.fromstring(comp) for comp in s[mnem_idx+1:].split(', ')]

        pcop = cls(addr, mnemonic, inputs, output)

        if pcop.is_call():
            pcop = CallOp.frompcop(pcop)
        elif pcop.is_ret():
            pcop = RetOp.frompcop(pcop)

        return pcop
예제 #3
0
파일: test_ssa.py 프로젝트: SamL98/MyDeco
import sys
sys.path.insert(0, '..')

import unittest

from blocks import Block
from cfg import CFG
from insn import Instruction
from pcode import PcodeOp
from varnode import Varnode

insn_addr = 0
insn_len = 4
reg_size = 4

r1 = Varnode('register', 0, reg_size)
r2 = Varnode('register', reg_size, reg_size)
r3 = Varnode('register', reg_size * 2, reg_size)
u0 = Varnode('unique', 0, reg_size)
insn1 = Instruction(insn_addr, insn_len,
                    [PcodeOp(insn_addr, 'INT_ADD', [r1, r2], u0)])
insn2 = Instruction(insn_addr, insn_len,
                    [PcodeOp(insn_addr, 'COPY', [u0], r3)])
insn3 = Instruction(insn_addr, insn_len,
                    [PcodeOp(insn_addr, 'COPY', [u0], r1)])

# Simple test CFG
s_block1 = Block([insn1.copy()], name='s_block_1')
s_block2 = Block([insn1.copy()], predecessor=s_block1, name='s_block_2')
s_block3 = Block([insn1.copy()], predecessor=s_block1, name='s_block_3')
s_block4 = Block([insn1.copy()], predecessor=s_block3, name='s_block_4')
예제 #4
0
파일: cpu.py 프로젝트: SamL98/MyDeco
from varnode import Varnode


class CPU(object):
    def __init__(self, registers):
        self.registers = registers


cpu = CPU({
    Varnode.reg(0, 8): 'RAX',
    Varnode.reg(0, 4): 'EAX',
})
예제 #5
0
 def input_loc(self, idx, dt=None):
     if idx >= len(self.input_locs):
         stack_off = 8 * (idx - len(self.input_locs))
         return Varnode()
     else:
         return super().input_loc(idx, dt)
예제 #6
0
파일: pcode.py 프로젝트: SamL98/MyDeco
 def frompcop(cls, pcop):
     # TODO: Read cspecs to get varnodes killedbycall.
     killed_varnodes = [Varnode('register', off, 8) for off in [0x0, 0x10, 0x1200]]
     return cls(pcop.addr, pcop.mnemonic, pcop.inputs, pcop.output, killed_varnodes)