diff options
| author | Camille Mougey <commial@gmail.com> | 2015-08-10 16:10:55 +0200 |
|---|---|---|
| committer | Camille Mougey <commial@gmail.com> | 2015-08-10 16:10:55 +0200 |
| commit | bd47054b59077cc6b0aa91b3a542bc5bf2c12ff8 (patch) | |
| tree | f75283277ee1ec555a37dd817c41bb695092370f /test/arch/aarch64/unit/asm_test.py | |
| parent | dcc488ec39d9a96b70c728ccdbcd43e62b25ae99 (diff) | |
| parent | 6c9e46d8d2c2f0b34f025ec2381015bbfa9eb34e (diff) | |
| download | miasm-bd47054b59077cc6b0aa91b3a542bc5bf2c12ff8.tar.gz miasm-bd47054b59077cc6b0aa91b3a542bc5bf2c12ff8.zip | |
Merge pull request #206 from serpilliere/aarch64
Aarch64
Diffstat (limited to 'test/arch/aarch64/unit/asm_test.py')
| -rw-r--r-- | test/arch/aarch64/unit/asm_test.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py new file mode 100644 index 00000000..60ed418e --- /dev/null +++ b/test/arch/aarch64/unit/asm_test.py @@ -0,0 +1,64 @@ +#! /usr/bin/env python +import sys +import os + +from miasm2.core.cpu import parse_ast +from miasm2.arch.aarch64.arch import mn_aarch64, base_expr, variable +from miasm2.core import parse_asm +from miasm2.expression.expression import * +from miasm2.core import asmbloc +from elfesteem.strpatchwork import StrPatchwork +from miasm2.analysis.machine import Machine +from miasm2.jitter.csts import * +from pdb import pm + + +filename = os.environ.get('PYTHONSTARTUP') +if filename and os.path.isfile(filename): + execfile(filename) + + +reg_and_id = dict(mn_aarch64.regs.all_regs_ids_byname) + +class Asm_Test(object): + def __init__(self): + self.myjit = Machine("aarch64l").jitter() + self.myjit.init_stack() + + self.myjit.jit.log_regs = False + self.myjit.jit.log_mn = False + + + def __call__(self): + self.asm() + self.run() + self.check() + + + def asm(self): + blocs, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, + symbol_pool = self.myjit.ir_arch.symbol_pool) + # fix shellcode addr + symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) + s = StrPatchwork() + patches = asmbloc.asm_resolve_final(mn_aarch64, blocs[0], symbol_pool) + for offset, raw in patches.items(): + s[offset] = raw + + self.assembly = str(s) + + def run(self): + run_addr = 0 + self.myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, self.assembly) + + self.myjit.cpu.LR = 0x1337beef + + self.myjit.add_breakpoint(0x1337beef, lambda x:False) + + self.myjit.init_run(run_addr) + self.myjit.continue_run() + + assert(self.myjit.pc == 0x1337beef) + + def check(self): + raise NotImplementedError('abstract method') |