Esempio n. 1
0
class Instruction_IMAGINARY(Instruction):
    bin_format = bin(0x0f0b)[2:].zfill(16)
    name = 'IMAGINARY'

    def compute_result(self):
        a = self.constant(10, Type.int_27)
        b = self.constant(20, Type.int_27)
        a + b


class ImaginarySpotter(GymratLifter):
    instrs = [Instruction_IMAGINARY]


register(ImaginarySpotter, 'X86')

basic_goal = """
IRSB {
   t0:Ity_I27

   00 | ------ IMark(0x1, 2, 0) ------
   01 | t0 = Add27((0xa :: Ity_I27),(0x14 :: Ity_I27))
   NEXT: PUT(eip) = 0x00000003; Ijk_Boring
}
"""


def test_basic():
    b = pyvex.block.IRSB(b'\x0f\x0b', 1, archinfo.ArchX86())
    nose.tools.assert_equal(str(b).strip(), basic_goal.strip())
Esempio n. 2
0

# The instrs are in this order so we try NOP last.
all_instrs = [
    Instruction_INCPTR, Instruction_DECPTR, Instruction_INC, Instruction_DEC,
    Instruction_SKZ, Instruction_SKNZ, Instruction_IN, Instruction_OUT,
    Instruction_NOP
]


class LifterBF(GymratLifter):
    instrs = all_instrs


# Tell PyVEX that this lifter exists.
register(LifterBF, 'BF')

if __name__ == '__main__':
    sys.path.append(
        os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    import logging
    logging.getLogger('pyvex').setLevel(logging.DEBUG)
    logging.basicConfig()

    irsb_ = pyvex.IRSB(None, 0, arch=archinfo.arch_from_id('bf'))
    test1 = '<>+-[].,'
    test2 = '<>+-[].,'
    lifter = LifterBF(irsb_, test1, len(test1), len(test1), 0, None)
    lifter.lift()
    lifter.irsb.pp()
Esempio n. 3
0
    #Inst_FANCYXOR,
    #Inst_FANCYITE,
    Inst_LDDATA,
    Inst_LDCONST,
    Inst_LDXCONST,
    Inst_LDTEMP,
    Inst_LDXTEMP,
    Inst_SDTEMP,
    Inst_SDXTEMP,
    Inst_JEQ,
    Inst_RET,
    Inst_TAX,
    Inst_TXA,
    Inst_ADD,
    Inst_ADDX,
    Inst_MUL,
    Inst_DIV,
    Inst_AND,
    Inst_XORX,
    Inst_NEG,
    Inst_RSH,
]


class LifterBPF(GymratLifter):
    instrs = all_instrs


# Tell PyVEX that this lifter exists.
register(LifterBPF, 'BPF')
Esempio n. 4
0
from .arch_riscv import ArchRISCV64
from . import instrs_riscv as instrs
from pyvex.lifting import register
from pyvex.lifting.util import GymratLifter


class LifterRISCV64(GymratLifter):
    # The default behavior of GymratLifter works here.
    # We just grab all the instruction classes out of the other file.
    instrs = [instrs.__dict__[x] for x in filter(lambda x: x.startswith("Instruction_"), instrs.__dict__.keys())]

register(LifterRISCV64, 'RISCV')
Esempio n. 5
0
import logging
log = logging.getLogger(__name__)

from .arch_gameboy import ArchGameboy
from . import instrs_00_gameboy as instrs1
from . import instrs_80_gameboy as instrs2
from . import instrs_cb_gameboy as instrs3
from pyvex.lifting import register
from itertools import chain
from pyvex.lifting.util import GymratLifter


class LifterGameboy(GymratLifter):
    # The default behavior of GymratLifter works here.
    # We just grab all the instruction classes out of the other file.

    instr_classes = chain(
        instrs1.__dict__.items(),
        instrs2.__dict__.items(),
        instrs3.__dict__.items(),
    )
    instrs = [v for k, v in instr_classes if k.startswith('Instruction_')]


register(LifterGameboy, 'Gameboy')
Esempio n. 6
0
test_location = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../binaries/tests'))

class Instruction_IMAGINARY(Instruction):
    bin_format = bin(0x0f0b)[2:].zfill(16)
    name = 'IMAGINARY'

    def compute_result(self):
        a = self.constant(10, Type.int_27)
        b = self.constant(20, Type.int_27)
        a + b

class ImaginarySpotter(GymratLifter):
    instrs = [Instruction_IMAGINARY]

register(ImaginarySpotter, 'X86')

basic_goal = """
IRSB {
   t0:Ity_I27

   00 | ------ IMark(0x1, 2, 0) ------
   01 | t0 = Add27((0xa :: Ity_I27),(0x14 :: Ity_I27))
   NEXT: PUT(eip) = 0x00000003; Ijk_Boring
}
"""

def test_basic():
    b = pyvex.block.IRSB(b'\x0f\x0b', 1, archinfo.ArchX86())
    nose.tools.assert_equal(str(b).strip(), basic_goal.strip())
Esempio n. 7
0
from .arch_msp430 import ArchMSP430
from . import instrs_msp430 as instrs
from pyvex.lifting import register
from pyvex.lifting.util import GymratLifter


class LifterMSP430(GymratLifter):
    # The default behavior of GymratLifter works here.
    # We just grab all the instruction classes out of the other file.
    instrs = [
        instrs.__dict__[x] for x in filter(
            lambda x: x.startswith("Instruction_"), instrs.__dict__.keys())
    ]


register(LifterMSP430, 'MSP430')
Esempio n. 8
0
from .arch_riscv import ArchRISCV
from . import instrs_riscv as instrs
from pyvex.lifting import register
from pyvex.lifting.util import GymratLifter


class LifterRISCV32(GymratLifter):
    # The default behavior of GymratLifter works here.
    # We just grab all the instruction classes out of the other file.
    instrs = [
        instrs.__dict__[x] for x in filter(
            lambda x: x.startswith("Instruction_"), instrs.__dict__.keys())
    ]


register(LifterRISCV32, 'RISCV')
Esempio n. 9
0
class Instruction_IMAGINARY(Instruction):
    bin_format = bin(0x0F0B)[2:].zfill(16)
    name = "IMAGINARY"

    def compute_result(self):
        a = self.constant(10, Type.int_27)
        b = self.constant(20, Type.int_27)
        a + b


class ImaginarySpotter(GymratLifter):
    instrs = [Instruction_IMAGINARY]


register(ImaginarySpotter, "X86")

basic_goal = """
IRSB {
   t0:Ity_I27

   00 | ------ IMark(0x1, 2, 0) ------
   01 | t0 = Add27((0xa :: Ity_I27),(0x14 :: Ity_I27))
   NEXT: PUT(eip) = 0x00000003; Ijk_Boring
}
"""


def test_basic():
    b = pyvex.block.IRSB(b"\x0f\x0b", 1, archinfo.ArchX86())
    assert str(b).strip() == basic_goal.strip()