diff options
| author | Adrien Guinet <adrien@guinet.me> | 2017-10-31 08:16:17 +0100 |
|---|---|---|
| committer | Camille Mougey <commial@gmail.com> | 2017-10-31 08:16:17 +0100 |
| commit | 33dccf7012673882bef35b9afd9fb986881a8168 (patch) | |
| tree | d3f31c219a4ed5227c3a08d0003bc4b9a4494e37 /test/os_dep/linux/stdlib.py | |
| parent | 1e1b3282704700328d23a96d4da402715f554f9e (diff) | |
| download | miasm-33dccf7012673882bef35b9afd9fb986881a8168.tar.gz miasm-33dccf7012673882bef35b9afd9fb986881a8168.zip | |
Various Win32 API additions/fixes (#616)
Various Win32 API additions/fixes
* add a get_size method to Miasm heap object, which allows the
implementation of mscvrt_realloc
* add the concept of "current directory", with the default value being
arbitrary set to "c:\tmp", which allows the implementation of
{Get,Set}CurrentDirecrtory
* various other methods implemented:
- advapi32_RegCloseKey
- advapi32_RegCreateKeyW
- advapi32_RegSetValueExA
- advapi32_RegSetValueExW
- kernel32_GetProcessHeap
- msvcrt_delete
- msvcrt_fprintf
- msvcrt_fwrite
- msvcrt__mbscpy
- msvcrt_new
- msvcrt_realloc
- msvcrt_sprintf
- msvcrt_srand
- msvcrt_strrchr
- msvcrt_swprintf
- msvcrt_wcscat
- msvcrt_wcscmp
- msvcrt_wcscpy
- msvcrt__wcsicmp
- msvcrt_wcslen
- msvcrt_wcsncpy
- msvcrt__wcsnicmp
- msvcrt_wcsrchr
Diffstat (limited to 'test/os_dep/linux/stdlib.py')
| -rwxr-xr-x | test/os_dep/linux/stdlib.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/os_dep/linux/stdlib.py b/test/os_dep/linux/stdlib.py new file mode 100755 index 00000000..ab39a487 --- /dev/null +++ b/test/os_dep/linux/stdlib.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python2 +#-*- coding:utf-8 -*- + +import unittest +import logging +from miasm2.analysis.machine import Machine +import miasm2.os_dep.linux_stdlib as stdlib +from miasm2.core.utils import pck32 +from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE + +machine = Machine("x86_32") + +jit = machine.jitter() +jit.init_stack() + +heap = stdlib.linobjs.heap + +class TestLinuxStdlib(unittest.TestCase): + + def test_xxx_sprintf(self): + def alloc_str(s): + s += "\x00" + ptr = heap.alloc(jit, len(s)) + jit.vm.set_mem(ptr, s) + return ptr + fmt = alloc_str("'%s' %d") + str_ = alloc_str("coucou") + buf = heap.alloc(jit,1024) + + jit.push_uint32_t(1111) + jit.push_uint32_t(str_) + jit.push_uint32_t(fmt) + jit.push_uint32_t(buf) + jit.push_uint32_t(0) # ret_ad + stdlib.xxx_sprintf(jit) + ret = jit.get_str_ansi(buf) + self.assertEqual(ret, "'coucou' 1111") + + +if __name__ == '__main__': + testsuite = unittest.TestLoader().loadTestsFromTestCase(TestLinuxStdlib) + report = unittest.TextTestRunner(verbosity=2).run(testsuite) + exit(len(report.errors + report.failures)) |