diff options
| author | _Frky <3105926+Frky@users.noreply.github.com> | 2020-06-03 16:16:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-03 16:16:24 +0200 |
| commit | e3fb39a01d9ff8b508cb60e6129bacdbbf74bbc8 (patch) | |
| tree | bb406f6e0784b973bb856880d8ff7b5eda289f94 | |
| parent | a5f4ba4774838c48b27ee863e756a84e913d2917 (diff) | |
| download | miasm-e3fb39a01d9ff8b508cb60e6129bacdbbf74bbc8.tar.gz miasm-e3fb39a01d9ff8b508cb60e6129bacdbbf74bbc8.zip | |
Fix MultiByteToWideChar when cbMultiByte = -1
When cbMultiByte = -1, the MultiByteStr input string is null-terminated.
| -rw-r--r-- | miasm/os_dep/win_api_x86_32.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/miasm/os_dep/win_api_x86_32.py b/miasm/os_dep/win_api_x86_32.py index e83a3993..090865df 100644 --- a/miasm/os_dep/win_api_x86_32.py +++ b/miasm/os_dep/win_api_x86_32.py @@ -1681,7 +1681,20 @@ def kernel32_MultiByteToWideChar(jitter): "cchwidechar"]) if args.codepage != CP_ACP and args.codepage != CP_1252: raise NotImplementedError - src = jitter.vm.get_mem(args.lpmultibytestr, args.cbmultibyte) + # according to MSDN: + # "Note that, if cbMultiByte is 0, the function fails." + if args.cbmultibyte == 0: + raise ValueError + # according to MSDN: + # "Alternatively, this parameter can be set to -1 if the string is + # null-terminated." + if args.cbmultibyte == 0xffffffff: + src_len = 0 + while jitter.vm.get_mem(args.lpmultibytestr + src_len, 1) != b'\0': + src_len += 1 + src = jitter.vm.get_mem(args.lpmultibytestr, src_len) + else: + src = jitter.vm.get_mem(args.lpmultibytestr, args.cbmultibyte) if args.dwflags & MB_ERR_INVALID_CHARS: # will raise an exception if decoding fails s = src.decode("cp1252", errors="replace").encode("utf-16le") |