diff options
| author | Ajax <commial@gmail.com> | 2016-06-29 08:26:28 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2016-09-01 17:34:50 +0200 |
| commit | bb3433682f92fe5a74a89d8984561cd4f2de2120 (patch) | |
| tree | cd62b3b53e8f2dd8b4175a59367661f2a47f5f99 | |
| parent | 48e3279683c16cb00d7c006b4716781a44d39798 (diff) | |
| download | miasm-bb3433682f92fe5a74a89d8984561cd4f2de2120.tar.gz miasm-bb3433682f92fe5a74a89d8984561cd4f2de2120.zip | |
Add a regression test for SEH handling
XOR EDX, EDX is used to obtain a 32bits 0 in FS:[0x0], because this is an ambiguity in Intel representation
Diffstat (limited to '')
| -rw-r--r-- | test/arch/x86/unit/mn_seh.py | 66 | ||||
| -rw-r--r-- | test/test_all.py | 1 |
2 files changed, 67 insertions, 0 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..12750b05 --- /dev/null +++ b/test/arch/x86/unit/mn_seh.py @@ -0,0 +1,66 @@ +#! /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) + + +if __name__ == "__main__": + [test(*sys.argv[1:])() for test in [Test_SEH_simple]] diff --git a/test/test_all.py b/test/test_all.py index c3e3c1fb..72975801 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -71,6 +71,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", |