diff options
Diffstat (limited to 'test')
39 files changed, 149 insertions, 59 deletions
diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index a9e6cfc6..cfb2a81c 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import sys import os @@ -10,13 +9,6 @@ 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) diff --git a/test/arch/aarch64/unit/mn_ubfm.py b/test/arch/aarch64/unit/mn_ubfm.py index 6f1857fb..25d1cde7 100644..100755 --- a/test/arch/aarch64/unit/mn_ubfm.py +++ b/test/arch/aarch64/unit/mn_ubfm.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test diff --git a/test/arch/arm/sem.py b/test/arch/arm/sem.py index 922642d3..3695fd29 100644..100755 --- a/test/arch/arm/sem.py +++ b/test/arch/arm/sem.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index 7272c15e..35d87d85 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import sys import os @@ -10,17 +9,10 @@ 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_mips32.regs.all_regs_ids_byname) - class Asm_Test(object): def __init__(self, jitter): diff --git a/test/arch/mips32/unit/mn_bcc.py b/test/arch/mips32/unit/mn_bcc.py index 4818c171..e9b28e77 100644..100755 --- a/test/arch/mips32/unit/mn_bcc.py +++ b/test/arch/mips32/unit/mn_bcc.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test diff --git a/test/arch/msp430/sem.py b/test/arch/msp430/sem.py index 4d39d357..433055e0 100644..100755 --- a/test/arch/msp430/sem.py +++ b/test/arch/msp430/sem.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index 93d2ff83..d2198847 100644..100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- # Loosely based on ARM's sem.py diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index 4e1d03b8..bf97dbe4 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python import sys import os @@ -10,13 +9,6 @@ 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_x86.regs.all_regs_ids_byname) diff --git a/test/arch/x86/unit/mn_daa.py b/test/arch/x86/unit/mn_daa.py index d07bf849..21d609e4 100644..100755 --- a/test/arch/x86/unit/mn_daa.py +++ b/test/arch/x86/unit/mn_daa.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_das.py b/test/arch/x86/unit/mn_das.py index 2d8102d9..08df1a7a 100644..100755 --- a/test/arch/x86/unit/mn_das.py +++ b/test/arch/x86/unit/mn_das.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_float.py b/test/arch/x86/unit/mn_float.py index d704de73..f31a25e3 100644..100755 --- a/test/arch/x86/unit/mn_float.py +++ b/test/arch/x86/unit/mn_float.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_int.py b/test/arch/x86/unit/mn_int.py index 9d964220..09792371 100644..100755 --- a/test/arch/x86/unit/mn_int.py +++ b/test/arch/x86/unit/mn_int.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from miasm2.jitter.csts import EXCEPT_INT_XX diff --git a/test/arch/x86/unit/mn_pcmpeq.py b/test/arch/x86/unit/mn_pcmpeq.py index 5d0a59c6..22760db4 100644..100755 --- a/test/arch/x86/unit/mn_pcmpeq.py +++ b/test/arch/x86/unit/mn_pcmpeq.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pextr.py b/test/arch/x86/unit/mn_pextr.py index 696f077b..c4548d67 100644..100755 --- a/test/arch/x86/unit/mn_pextr.py +++ b/test/arch/x86/unit/mn_pextr.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pinsr.py b/test/arch/x86/unit/mn_pinsr.py index 74120e5c..4beaba13 100644..100755 --- a/test/arch/x86/unit/mn_pinsr.py +++ b/test/arch/x86/unit/mn_pinsr.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pmaxu.py b/test/arch/x86/unit/mn_pmaxu.py index 527b966f..752b9132 100644..100755 --- a/test/arch/x86/unit/mn_pmaxu.py +++ b/test/arch/x86/unit/mn_pmaxu.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pminu.py b/test/arch/x86/unit/mn_pminu.py index d667df4e..3be95a9a 100644..100755 --- a/test/arch/x86/unit/mn_pminu.py +++ b/test/arch/x86/unit/mn_pminu.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pmovmskb.py b/test/arch/x86/unit/mn_pmovmskb.py index b7e7b897..a3eb65f5 100644..100755 --- a/test/arch/x86/unit/mn_pmovmskb.py +++ b/test/arch/x86/unit/mn_pmovmskb.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pshufb.py b/test/arch/x86/unit/mn_pshufb.py index 5f4c7370..d10c18e3 100644..100755 --- a/test/arch/x86/unit/mn_pshufb.py +++ b/test/arch/x86/unit/mn_pshufb.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_psrl_psll.py b/test/arch/x86/unit/mn_psrl_psll.py index 44126b96..a5428dab 100644..100755 --- a/test/arch/x86/unit/mn_psrl_psll.py +++ b/test/arch/x86/unit/mn_psrl_psll.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_punpck.py b/test/arch/x86/unit/mn_punpck.py index f6a4772e..b519b4c3 100644..100755 --- a/test/arch/x86/unit/mn_punpck.py +++ b/test/arch/x86/unit/mn_punpck.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_pushpop.py b/test/arch/x86/unit/mn_pushpop.py index 1a3f5517..ffcc3fa5 100644..100755 --- a/test/arch/x86/unit/mn_pushpop.py +++ b/test/arch/x86/unit/mn_pushpop.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_16, Asm_Test_32 diff --git a/test/arch/x86/unit/mn_seh.py b/test/arch/x86/unit/mn_seh.py index d6fc56ca..dd3fd4ef 100644..100755 --- a/test/arch/x86/unit/mn_seh.py +++ b/test/arch/x86/unit/mn_seh.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from miasm2.os_dep.win_api_x86_32_seh import fake_seh_handler, build_teb, \ diff --git a/test/arch/x86/unit/mn_stack.py b/test/arch/x86/unit/mn_stack.py index 3bce3979..f9cfc60a 100644..100755 --- a/test/arch/x86/unit/mn_stack.py +++ b/test/arch/x86/unit/mn_stack.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 + import sys from asm_test import Asm_Test_32 diff --git a/test/arch/x86/unit/mn_strings.py b/test/arch/x86/unit/mn_strings.py index 5e7269f7..3cb70e2a 100644..100755 --- a/test/arch/x86/unit/mn_strings.py +++ b/test/arch/x86/unit/mn_strings.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python2 import sys from asm_test import Asm_Test_32 diff --git a/test/core/interval.py b/test/core/interval.py index 4572ac50..ab18e567 100644..100755 --- a/test/core/interval.py +++ b/test/core/interval.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- from miasm2.core.interval import * diff --git a/test/core/parse_asm.py b/test/core/parse_asm.py index a488d075..e91c8c8c 100644..100755 --- a/test/core/parse_asm.py +++ b/test/core/parse_asm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/core/test_types.py b/test/core/test_types.py index f6e5cb13..ab1d47c4 100644..100755 --- a/test/core/test_types.py +++ b/test/core/test_types.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 # miasm2.core.types tests diff --git a/test/core/utils.py b/test/core/utils.py index f7de6565..b506f904 100644..100755 --- a/test/core/utils.py +++ b/test/core/utils.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 + #-*- coding:utf-8 -*- import unittest diff --git a/test/expression/expression_helper.py b/test/expression/expression_helper.py index a3a8fba4..6c800020 100644..100755 --- a/test/expression/expression_helper.py +++ b/test/expression/expression_helper.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/expression/stp.py b/test/expression/stp.py index fe09e865..b911a2a4 100644..100755 --- a/test/expression/stp.py +++ b/test/expression/stp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/ir/analysis.py b/test/ir/analysis.py index 913d9c56..913d9c56 100755..100644 --- a/test/ir/analysis.py +++ b/test/ir/analysis.py diff --git a/test/ir/ir2C.py b/test/ir/ir2C.py index 36683904..395703ed 100644..100755 --- a/test/ir/ir2C.py +++ b/test/ir/ir2C.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/ir/symbexec.py b/test/ir/symbexec.py index 24b02341..2e776f74 100644..100755 --- a/test/ir/symbexec.py +++ b/test/ir/symbexec.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/jitter/jit_options.py b/test/jitter/jit_options.py new file mode 100644 index 00000000..cc955c64 --- /dev/null +++ b/test/jitter/jit_options.py @@ -0,0 +1,97 @@ +import os +import sys +from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE +from miasm2.analysis.machine import Machine +from pdb import pm + +# Shellcode + +# main: +# MOV EAX, 0x1 +# loop_main: +# CMP EAX, 0x10 +# JZ loop_end +# loop_inc: +# INC EAX +# JMP loop_main +# loop_end: +# RET +data = "b80100000083f810740340ebf8c3".decode("hex") +run_addr = 0x40000000 + +def code_sentinelle(jitter): + jitter.run = False + jitter.pc = 0 + return True + +def init_jitter(): + global data, run_addr + # Create jitter + myjit = Machine("x86_32").jitter(sys.argv[1]) + + myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, data) + + # Init jitter + myjit.init_stack() + myjit.jit.log_regs = True + myjit.jit.log_mn = True + myjit.push_uint32_t(0x1337beef) + + myjit.add_breakpoint(0x1337beef, code_sentinelle) + return myjit + +# Test 'max_exec_per_call' +print "[+] First run, to jit blocks" +myjit = init_jitter() +myjit.init_run(run_addr) +myjit.continue_run() + +assert myjit.run is False +assert myjit.cpu.EAX == 0x10 + +## Let's specify a max_exec_per_call +## 5: main, loop_main, loop_inc, loop_main, loop_inc +myjit.jit.options["max_exec_per_call"] = 5 + +first_call = True +def cb(jitter): + global first_call + if first_call: + # Avoid breaking on the first pass (before any execution) + first_call = False + return True + return False + +## Second run +print "[+] Second run" +myjit.push_uint32_t(0x1337beef) +myjit.cpu.EAX = 0 +myjit.init_run(run_addr) +myjit.exec_cb = cb +myjit.continue_run() + +assert myjit.run is True +# Use a '<=' because it's a 'max_...' +assert myjit.cpu.EAX <= 3 + +# Test 'jit_maxline' +print "[+] Run instr one by one" +myjit = init_jitter() +myjit.jit.options["jit_maxline"] = 1 +myjit.jit.options["max_exec_per_call"] = 1 + +counter = 0 +def cb(jitter): + global counter + counter += 1 + return True + +myjit.init_run(run_addr) +myjit.exec_cb = cb +myjit.continue_run() + +assert myjit.run is False +assert myjit.cpu.EAX == 0x10 +## dry(1) + main(1) + (loop_main(2) + loop_inc(2))*(0x10 - 1) + loop_main(2) + +## loop_end(1) = 65 +assert counter == 65 diff --git a/test/jitter/jitload.py b/test/jitter/jitload.py index 283298db..544e9d18 100644 --- a/test/jitter/jitload.py +++ b/test/jitter/jitload.py @@ -1,3 +1,4 @@ +import sys from pdb import pm from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE @@ -9,7 +10,7 @@ from miasm2.expression.expression import ExprId, ExprInt32, ExprInt64, ExprAff, data = "8d49048d5b0180f90174058d5bffeb038d5b0189d8c3".decode("hex") # Init jitter -myjit = Machine("x86_32").jitter() +myjit = Machine("x86_32").jitter(sys.argv[1]) myjit.init_stack() run_addr = 0x40000000 diff --git a/test/jitter/vm_mngr.py b/test/jitter/vm_mngr.py index b2b7336b..87bc6f8f 100644 --- a/test/jitter/vm_mngr.py +++ b/test/jitter/vm_mngr.py @@ -1,7 +1,8 @@ +import sys from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE from miasm2.analysis.machine import Machine -myjit = Machine("x86_32").jitter() +myjit = Machine("x86_32").jitter(sys.argv[1]) base_addr = 0x13371337 page_size = 0x1000 diff --git a/test/os_dep/win_api_x86_32.py b/test/os_dep/win_api_x86_32.py index bb13138f..2e22ccea 100644..100755 --- a/test/os_dep/win_api_x86_32.py +++ b/test/os_dep/win_api_x86_32.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#! /usr/bin/env python2 #-*- coding:utf-8 -*- import unittest diff --git a/test/test_all.py b/test/test_all.py index 7cc8f6eb..59624832 100644..100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -1,3 +1,5 @@ +#! /usr/bin/env python2 + import argparse import time import os @@ -55,7 +57,7 @@ class ArchUnitTest(RegressionTest): # script -> blacklisted jitter blacklist = { - "x86/unit/mn_float.py": ["python", "llvm"], + "x86/unit/mn_float.py": ["python"], } for script in ["x86/sem.py", "x86/unit/mn_strings.py", @@ -323,8 +325,11 @@ for i, test_args in enumerate(test_args): ## Jitter for script in ["jitload.py", "vm_mngr.py", + "jit_options.py", ]: - testset += RegressionTest([script], base_dir="jitter", tags=[TAGS["tcc"]]) + for engine in ArchUnitTest.jitter_engines: + testset += RegressionTest([script, engine], base_dir="jitter", + tags=[TAGS.get(engine,None)]) # Examples |