diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/arch/x86/unit/mn_seh.py | 106 | ||||
| -rw-r--r-- | test/test_all.py | 10 |
2 files changed, 114 insertions, 2 deletions
diff --git a/test/arch/x86/unit/mn_seh.py b/test/arch/x86/unit/mn_seh.py new file mode 100644 index 00000000..cc8b5cc2 --- /dev/null +++ b/test/arch/x86/unit/mn_seh.py @@ -0,0 +1,106 @@ +#! /usr/bin/env python +import sys + +from miasm2.os_dep.win_api_x86_32_seh import fake_seh_handler, build_teb, \ + set_win_fs_0, return_from_exception, EXCEPTION_PRIV_INSTRUCTION, \ + return_from_seh, FS_0_AD, DEFAULT_SEH +from miasm2.os_dep.win_32_structs import ContextException + +from asm_test import Asm_Test_32 + +from pdb import pm + +class Test_SEH(Asm_Test_32): + """SEH Handling""" + + @staticmethod + def deal_exception_priv(jitter): + print 'Exception Priv', hex(jitter.cpu.ESP) + pc = fake_seh_handler(jitter, EXCEPTION_PRIV_INSTRUCTION) + jitter.pc = pc + jitter.cpu.EIP = pc + return True + + def init_machine(self): + super(Test_SEH, self).init_machine() + build_teb(self.myjit, FS_0_AD) + set_win_fs_0(self.myjit) + self.myjit.add_exception_handler((1 << 17), + Test_SEH.deal_exception_priv) + self.myjit.add_breakpoint(return_from_exception, return_from_seh) + + +class Test_SEH_simple(Test_SEH): + TXT = ''' + main: + XOR EAX, EAX + XOR EDX, EDX + + PUSH handler + PUSH DWORD PTR FS:[EDX] + MOV DWORD PTR FS:[EDX], ESP + + STI + + MOV EBX, DWORD PTR [ESP] + MOV DWORD PTR FS:[EDX], EBX + ADD ESP, 0x8 + + RET + + handler: + MOV ECX, DWORD PTR [ESP+0xC] + INC DWORD PTR [ECX+0x%08x] + MOV DWORD PTR [ECX+0x%08x], 0xcafebabe + XOR EAX, EAX + RET + ''' % (ContextException.get_offset("eip"), + ContextException.get_offset("eax")) + + def check(self): + assert(self.myjit.cpu.EAX == 0xcafebabe) + assert(self.myjit.cpu.EBX == DEFAULT_SEH) + + +class Test_SEH_double(Test_SEH_simple): + TXT = ''' + main: + XOR EAX, EAX + XOR EDX, EDX + + PUSH handler1 + PUSH DWORD PTR FS:[EDX] + MOV DWORD PTR FS:[EDX], ESP + + PUSH handler2 + PUSH DWORD PTR FS:[EDX] + MOV DWORD PTR FS:[EDX], ESP + + STI + + MOV EBX, DWORD PTR [ESP] + MOV DWORD PTR FS:[EDX], EBX + ADD ESP, 0x8 + + MOV EBX, DWORD PTR [ESP] + MOV DWORD PTR FS:[EDX], EBX + ADD ESP, 0x8 + + RET + + handler1: + MOV EAX, 0x1 + RET + + handler2: + MOV ECX, DWORD PTR [ESP+0xC] + INC DWORD PTR [ECX+0x%08x] + MOV DWORD PTR [ECX+0x%08x], 0xcafebabe + XOR EAX, EAX + RET + ''' % (ContextException.get_offset("eip"), + ContextException.get_offset("eax")) + + +if __name__ == "__main__": + [test(*sys.argv[1:])() for test in [Test_SEH_simple, Test_SEH_double]] diff --git a/test/test_all.py b/test/test_all.py index c3e3c1fb..7b878c89 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -48,12 +48,15 @@ testset += RegressionTest(["x86/arch.py"], base_dir="arch", class ArchUnitTest(RegressionTest): """Test against arch unit regression tests""" - jitter_engines = ["tcc", "llvm", "gcc"] + jitter_engines = ["tcc", "llvm", "gcc", "python"] def __init__(self, script, jitter ,*args, **kwargs): super(ArchUnitTest, self).__init__([script, jitter], *args, **kwargs) - +# script -> blacklisted jitter +blacklist = { + "x86/unit/mn_float.py": ["python"], +} for script in ["x86/sem.py", "x86/unit/mn_strings.py", "x86/unit/mn_float.py", @@ -71,6 +74,7 @@ for script in ["x86/sem.py", "x86/unit/mn_pextr.py", "x86/unit/mn_pmovmskb.py", "x86/unit/mn_pushpop.py", + "x86/unit/mn_seh.py", "arm/arch.py", "arm/sem.py", "aarch64/unit/mn_ubfm.py", @@ -82,6 +86,8 @@ for script in ["x86/sem.py", "mips32/unit/mn_bcc.py", ]: for jitter in ArchUnitTest.jitter_engines: + if jitter in blacklist.get(script, []): + continue tags = [TAGS[jitter]] if jitter in TAGS else [] testset += ArchUnitTest(script, jitter, base_dir="arch", tags=tags) |