From 4371215033dd4d76e2adf29b8a1f01dd6b1d3e46 Mon Sep 17 00:00:00 2001 From: elicn Date: Wed, 21 Feb 2024 03:20:25 +0200 Subject: [PATCH] Fixes related to latest changes --- qiling/os/posix/syscall/resource.py | 10 ++++------ qiling/os/windows/dlls/kernel32/fileapi.py | 3 ++- tests/test_pe_sys.py | 7 ++++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/qiling/os/posix/syscall/resource.py b/qiling/os/posix/syscall/resource.py index f0152c043..4841758d7 100644 --- a/qiling/os/posix/syscall/resource.py +++ b/qiling/os/posix/syscall/resource.py @@ -28,9 +28,8 @@ def __getrlimit_common(ql: Qiling, res: int, rlim: int) -> int: else: rlimit = resource.getrlimit(res) - # FIXME: not sure whether these should be pointersize values or always 32 bits - ql.mem.write_ptr(rlim + 0 * 4, rlimit[0], 4, signed=True) - ql.mem.write_ptr(rlim + 1 * 4, rlimit[1], 4, signed=True) + ql.mem.write_ptr(rlim + 0 * ql.arch.pointersize, rlimit[0], signed=True) + ql.mem.write_ptr(rlim + 1 * ql.arch.pointersize, rlimit[1], signed=True) return 0 @@ -57,9 +56,8 @@ def ql_syscall_prlimit64(ql: Qiling, pid: int, res: int, new_limit: int, old_lim try: rlim = resource.getrlimit(res) - # FIXME: not sure whether these should be pointersize values or always 32 bits - ql.mem.write_ptr(old_limit + 0 * 4, rlim[0], 4, signed=True) - ql.mem.write_ptr(old_limit + 1 * 4, rlim[1], 4, signed=True) + ql.mem.write_ptr(old_limit + 0 * ql.arch.pointersize, rlim[0], signed=True) + ql.mem.write_ptr(old_limit + 1 * ql.arch.pointersize, rlim[1], signed=True) return 0 except: diff --git a/qiling/os/windows/dlls/kernel32/fileapi.py b/qiling/os/windows/dlls/kernel32/fileapi.py index 1ea43e316..c737fc9e8 100644 --- a/qiling/os/windows/dlls/kernel32/fileapi.py +++ b/qiling/os/windows/dlls/kernel32/fileapi.py @@ -696,9 +696,10 @@ def _CreateFileMapping(ql: Qiling, address: int, params): dwMaximumSizeLow = params['dwMaximumSizeLow'] lpName = params['lpName'] + hFile = ql.os.utils.as_signed(hFile, ql.arch.bits) req_size = (dwMaximumSizeHigh << 32) | dwMaximumSizeLow - if hFile == ql.os.utils.as_signed(INVALID_HANDLE_VALUE, ql.arch.bits): + if hFile == INVALID_HANDLE_VALUE: fmobj = FileMappingMem() else: diff --git a/tests/test_pe_sys.py b/tests/test_pe_sys.py index 08a5b97d8..ec4fb6f03 100644 --- a/tests/test_pe_sys.py +++ b/tests/test_pe_sys.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# +# # Cross Platform and Multi Architecture Advanced Binary Emulation Framework # @@ -8,6 +8,8 @@ from unicorn import UcError +from qiling.os.stats import QlWinNullStats + sys.path.append("..") from qiling import Qiling from qiling.const import QL_STOP, QL_VERBOSE @@ -181,6 +183,9 @@ def hook_third_stop_address(ql: Qiling, stops: List[bool]): ql = Qiling(["../examples/rootfs/x86_windows/bin/sality.dll"], "../examples/rootfs/x86_windows", verbose=QL_VERBOSE.DEBUG) + # discard strings and api calls stats to gain a bit of speedup + ql.os.stats = QlWinNullStats() + # emulate some Windows API ql.os.set_api("CreateThread", hook_CreateThread) ql.os.set_api("CreateFileA", hook_CreateFileA)