diff options
Diffstat (limited to 'test/arch')
| -rw-r--r-- | test/arch/aarch64/arch.py | 6 | ||||
| -rw-r--r-- | test/arch/aarch64/unit/asm_test.py | 1 | ||||
| -rw-r--r-- | test/arch/arm/arch.py | 7 | ||||
| -rwxr-xr-x | test/arch/arm/sem.py | 4 | ||||
| -rw-r--r-- | test/arch/mips32/arch.py | 5 | ||||
| -rw-r--r-- | test/arch/mips32/unit/asm_test.py | 3 | ||||
| -rw-r--r-- | test/arch/msp430/arch.py | 5 | ||||
| -rw-r--r-- | test/arch/sh4/arch.py | 6 | ||||
| -rw-r--r-- | test/arch/x86/arch.py | 60 | ||||
| -rwxr-xr-x | test/arch/x86/sem.py | 5 | ||||
| -rw-r--r-- | test/arch/x86/unit/asm_test.py | 1 |
11 files changed, 36 insertions, 67 deletions
diff --git a/test/arch/aarch64/arch.py b/test/arch/aarch64/arch.py index 8364fcf1..a6aa7ba5 100644 --- a/test/arch/aarch64/arch.py +++ b/test/arch/aarch64/arch.py @@ -1,6 +1,10 @@ import sys import time +from pdb import pm from miasm2.arch.aarch64.arch import * +from miasm2.core.asmblock import AsmSymbolPool + +symbol_pool = AsmSymbolPool() reg_tests_aarch64 = [ ("XXXXXXXX MOV W1, WZR", @@ -1810,7 +1814,7 @@ for s, l in reg_tests_aarch64[:]: print s print mn assert(str(mn) == s) - l = mn_aarch64.fromstring(s, 'l') + l = mn_aarch64.fromstring(s, symbol_pool, 'l') assert(str(l) == s) a = mn_aarch64.asm(l) print [x for x in a] diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index ddb8a08c..ca27ef9d 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -1,7 +1,6 @@ import sys import os -from miasm2.core.cpu import ParseAst from miasm2.arch.aarch64.arch import mn_aarch64, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * diff --git a/test/arch/arm/arch.py b/test/arch/arm/arch.py index 7f3b321e..90d137d0 100644 --- a/test/arch/arm/arch.py +++ b/test/arch/arm/arch.py @@ -1,7 +1,10 @@ import time from miasm2.arch.arm.arch import * +from miasm2.core.asmblock import AsmSymbolPool from pdb import pm + +symbol_pool = AsmSymbolPool() if 0: a = bs('00') b = bs('01') @@ -267,7 +270,7 @@ for s, l in reg_tests_arm: assert(str(mn) == s) # print hex(b) # print [str(x.get()) for x in mn.args] - l = mn_arm.fromstring(s, 'l') + l = mn_arm.fromstring(s, symbol_pool, 'l') # print l assert(str(l) == s) a = mn_arm.asm(l) @@ -719,7 +722,7 @@ for s, l in reg_tests_armt: assert(str(mn) == s) # print hex(b) # print [str(x.get()) for x in mn.args] - l = mn_armt.fromstring(s, 'l') + l = mn_armt.fromstring(s, symbol_pool, 'l') # print l assert(str(l) == s) print 'Asm..', l diff --git a/test/arch/arm/sem.py b/test/arch/arm/sem.py index 1b14214e..d9e6aa76 100755 --- a/test/arch/arm/sem.py +++ b/test/arch/arm/sem.py @@ -9,11 +9,13 @@ from miasm2.arch.arm.arch import mn_arm as mn from miasm2.arch.arm.sem import ir_arml as ir_arch from miasm2.arch.arm.regs import * from miasm2.expression.expression import * +from miasm2.core.asmblock import AsmSymbolPool from pdb import pm logging.getLogger('cpuhelper').setLevel(logging.ERROR) EXCLUDE_REGS = set([ir_arch().IRDst]) +symbol_pool = AsmSymbolPool() def M(addr): return ExprMem(ExprInt(addr, 16), 16) @@ -24,7 +26,7 @@ def compute(asm, inputstate={}, debug=False): sympool.update({k: ExprInt(v, k.size) for k, v in inputstate.iteritems()}) interm = ir_arch() symexec = SymbolicExecutionEngine(interm, sympool) - instr = mn.fromstring(asm, "l") + instr = mn.fromstring(asm, symbol_pool, "l") code = mn.asm(instr)[0] instr = mn.dis(code, "l") instr.offset = inputstate.get(PC, 0) diff --git a/test/arch/mips32/arch.py b/test/arch/mips32/arch.py index b28e2583..c6b68c0c 100644 --- a/test/arch/mips32/arch.py +++ b/test/arch/mips32/arch.py @@ -1,8 +1,11 @@ import time from pdb import pm +from miasm2.core.asmblock import AsmSymbolPool from miasm2.arch.mips32.arch import * +symbol_pool = AsmSymbolPool() + reg_tests_mips32 = [ ("004496D8 ADDU GP, GP, T9", "0399E021"), @@ -227,7 +230,7 @@ for s, l in reg_tests_mips32: assert(str(mn) == s) # print hex(b) # print [str(x.get()) for x in mn.args] - l = mn_mips32.fromstring(s, 'b') + l = mn_mips32.fromstring(s, symbol_pool, 'b') # print l assert(str(l) == s) a = mn_mips32.asm(l, 'b') diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index 9281f1b6..f03a32d7 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -1,8 +1,7 @@ import sys import os -from miasm2.core.cpu import ParseAst -from miasm2.arch.mips32.arch import mn_mips32, base_expr, variable +from miasm2.arch.mips32.arch import mn_mips32 from miasm2.core import parse_asm from miasm2.expression.expression import * from miasm2.core import asmblock diff --git a/test/arch/msp430/arch.py b/test/arch/msp430/arch.py index b3dbac82..3df2becb 100644 --- a/test/arch/msp430/arch.py +++ b/test/arch/msp430/arch.py @@ -1,6 +1,9 @@ import time +from pdb import pm from miasm2.arch.msp430.arch import * +from miasm2.core.asmblock import AsmSymbolPool +symbol_pool = AsmSymbolPool() def h2i(s): return s.replace(' ', '').decode('hex') @@ -94,7 +97,7 @@ for s, l in reg_tests_msp: assert(str(mn) == s) # print hex(b) # print [str(x.get()) for x in mn.args] - l = mn_msp430.fromstring(s, None) + l = mn_msp430.fromstring(s, symbol_pool, None) # print l assert(str(l) == s) a = mn_msp430.asm(l) diff --git a/test/arch/sh4/arch.py b/test/arch/sh4/arch.py index 4d173add..574dcf49 100644 --- a/test/arch/sh4/arch.py +++ b/test/arch/sh4/arch.py @@ -1,6 +1,10 @@ import time +from pdb import pm from sys import stderr from miasm2.arch.sh4.arch import * +from miasm2.core.asmblock import AsmSymbolPool + +symbol_pool = AsmSymbolPool() def h2i(s): return s.replace(' ', '').decode('hex') @@ -396,7 +400,7 @@ for s, l in reg_tests_sh4: assert(str(mn) == s) # print hex(b) # print [str(x.get()) for x in mn.args] - l = mn_sh4.fromstring(s, None) + l = mn_sh4.fromstring(s, symbol_pool, None) # print l assert(str(l) == s) a = mn_sh4.asm(l) diff --git a/test/arch/x86/arch.py b/test/arch/x86/arch.py index 7b834e2c..05b31815 100644 --- a/test/arch/x86/arch.py +++ b/test/arch/x86/arch.py @@ -1,19 +1,13 @@ import time +from pdb import pm import miasm2.expression.expression as m2_expr -from miasm2.arch.x86.arch import mn_x86, deref_mem_ad, ParseAst, ast_int2expr, \ +from miasm2.arch.x86.arch import mn_x86, deref_mem_ad, \ base_expr, rmarg, print_size from miasm2.arch.x86.sem import ir_x86_16, ir_x86_32, ir_x86_64 from miasm2.core.bin_stream import bin_stream_str +from miasm2.core.asmblock import AsmSymbolPool -for s in ["[EAX]", - "[0x10]", - "[EBX + 0x10]", - "[EBX + ECX*0x10]", - "[EBX + ECX*0x10 + 0x1337]"]: - (e, a, b) = deref_mem_ad.scanString(s).next() - print 'expr', e[0] - -print '---' +symbol_pool = AsmSymbolPool() mylabel16 = m2_expr.ExprId('mylabel16', 16) mylabel32 = m2_expr.ExprId('mylabel32', 32) @@ -26,32 +20,6 @@ reg_and_id.update({'mylabel16': mylabel16, }) -def my_ast_id2expr(t): - r = reg_and_id.get(t, m2_expr.ExprId(t, size=32)) - return r - -my_var_parser = ParseAst(my_ast_id2expr, ast_int2expr) -base_expr.setParseAction(my_var_parser) - -for s in ['EAX', - "BYTE PTR [EAX]", - "WORD PTR [EAX]", - "DWORD PTR [ECX+0x1337]", - "QWORD PTR [RAX+4*RCX + 0x1337]", - "DWORD PTR [EAX+EBX]", - "QWORD PTR [RAX+RBX+0x55667788]", - "BYTE PTR CS:[EAX]", - "QWORD PTR [RAX+RBX+mylabel64]", - "BYTE PTR [RAX+RBX+mylabel64]", - "BYTE PTR [AX+BX+mylabel16]", - "BYTE PTR [mylabel32]", - ]: - print '*' * 80 - print s - (e, a, b) = rmarg.scanString(s).next() - print 'expr', e[0] - e[0].visit(print_size) - def h2i(s): return int(s.replace(' ', '').decode('hex')[::].encode('hex'), 16) @@ -3080,27 +3048,9 @@ reg_tests = [ ] - # mode = 64 - # l = mn_x86.dis('\x4D\x11\x7c\x18\x00', mode) - # print l - #""" - # mode = 64 - # l = mn_x86.fromstring("ADC DWORD PTR [RAX], 0x11223344", mode) - # print 'xx' - # t= time.time() - # import cProfile - # def f(): - # x = l.asm(mode) - # print x - # cProfile.run('f()') - # l.asm(mode) - # print time.time()-t -# reg_tests = reg_tests[-1:] - test_file = {16: open('regression_test16_ia32.bin', 'w'), 32: open('regression_test32_ia32.bin', 'w'), 64: open('regression_test64_ia32.bin', 'w')} - # 64: open('testmnemo', 'r+')} ts = time.time() for mode, s, l, in reg_tests: print "-" * 80 @@ -3115,7 +3065,7 @@ for mode, s, l, in reg_tests: # print hex(b) # print [str(x.get()) for x in mn.args] print 'fromstring', repr(s) - l = mn_x86.fromstring(s, mode) + l = mn_x86.fromstring(s, symbol_pool, mode) # print l print 'str args', [(str(x), x.size) for x in l.args] assert(str(l).strip(' ') == s) diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index eb3c15c0..b3b7e940 100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -14,11 +14,14 @@ from miasm2.arch.x86.regs import * from miasm2.expression.expression import * from miasm2.expression.simplifications import expr_simp from miasm2.core import parse_asm, asmblock +from miasm2.core.asmblock import AsmSymbolPool logging.getLogger('cpuhelper').setLevel(logging.ERROR) EXCLUDE_REGS = set([ir_32().IRDst, ir_64().IRDst]) +symbol_pool = AsmSymbolPool() + m32 = 32 m64 = 64 @@ -35,7 +38,7 @@ def symb_exec(interm, inputstate, debug): if k not in EXCLUDE_REGS and regs_init.get(k, None) != v} def compute(ir, mode, asm, inputstate={}, debug=False): - instr = mn.fromstring(asm, mode) + instr = mn.fromstring(asm, symbol_pool, mode) code = mn.asm(instr)[0] instr = mn.dis(code, mode) instr.offset = inputstate.get(EIP, 0) diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index 8a6b215c..961967f9 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -1,7 +1,6 @@ import sys import os -from miasm2.core.cpu import ParseAst from miasm2.arch.x86.arch import mn_x86, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * |