Exemple #1
0
    def test_stc(self):
        asm = ["stc"]

        x86_instrs = map(self.x86_parser.parse, asm)
        x86_instrs[0].address = 0xdeadbeef

        reil_instrs = map(self.x86_translator.translate, x86_instrs)

        ctx_init = self.__init_context()

        x86_rv, x86_ctx_out = pyasmjit.execute("\n".join(asm), ctx_init)

        reil_ctx_out, reil_mem_out = self.reil_emulator.execute(
            reil_instrs,
            0xdeadbeef << 8,
            context=ctx_init
        )

        reil_ctx_out = self.__fix_reil_flags(reil_ctx_out, x86_ctx_out)

        self.assertTrue(self.__compare_contexts(
            ctx_init,
            x86_ctx_out,
            reil_ctx_out
        ))
Exemple #2
0
    def test_div(self):
        asm = ["div ebx"]

        x86_instrs = map(self.x86_parser.parse, asm)

        reil_instrs = map(self.x86_translator.translate, x86_instrs)

        ctx_init = {
            'rax'    : 0x10,
            'rbx'    : 0x2,
            'rdx'    : 0x0,
            'rflags' : 0x202,
        }

        x86_rv, x86_ctx_out = pyasmjit.execute("\n".join(asm), ctx_init)
        reil_ctx_out, reil_mem_out = self.reil_emulator.execute(
            reil_instrs,
            0xdeadbeef << 8,
            context=ctx_init
        )

        reil_ctx_out = self.__fix_reil_flags(reil_ctx_out, x86_ctx_out)

        self.assertTrue(self.__compare_contexts(
            ctx_init,
            x86_ctx_out,
            reil_ctx_out
        ))
Exemple #3
0
    def test_sal(self):
        asm = ["sal eax, 3"]

        x86_instrs = map(self.x86_parser.parse, asm)

        reil_instrs = map(self.x86_translator.translate, x86_instrs)

        context_init = self.__init_context()

        x86_rv, x86_context_out  = pyasmjit.execute("\n".join(asm), context_init)
        reil_context_out, reil_memory_out = self.reil_emulator.execute(reil_instrs, 0xdeadbeef << 8, context=self.__update_flags_from_rflags(context_init))

        self.assertTrue(self.__compare_contexts(context_init, x86_context_out, reil_context_out))
#! /usr/bin/env python

import pyasmjit

code = """\
add rax, rbx
"""

# code = """\
# mov rax, 0x3
# mov rbx, 0x4
# imul rax, rbx
# """

context_in = {
    'rax': 0x1,
    'rbx': 0x2,
    'rcx': 0x1,
    'rdx': 0x1,
    'rdi': 0x1,
    'rsi': 0x1,
    'rflags': 0x202,
}

print code
print context_in

rv, context_out = pyasmjit.execute(code, context_in)

print context_out
#! /usr/bin/env python

import pyasmjit

code = """\
add rax, rbx
"""

# code = """\
# mov rax, 0x3
# mov rbx, 0x4
# imul rax, rbx
# """

context_in = {
    'rax' : 0x1,
    'rbx' : 0x2,
    'rcx' : 0x1,
    'rdx' : 0x1,
    'rdi' : 0x1,
    'rsi' : 0x1,
    'rflags' : 0x202,
}

print code
print context_in

rv, context_out = pyasmjit.execute(code, context_in)

print context_out