diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-11-02 22:24:23 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2019-11-12 15:10:44 +0100 |
| commit | 4dc802e3544e669cfea1d6be8a01ca2a2600dfef (patch) | |
| tree | 96a79b40469c1db9201ca46b210503d4dcf378c5 /miasm/os_dep/common.py | |
| parent | 83e54bd2de945a36ab5ccd4cc5b94817d7cb0112 (diff) | |
| download | focaccia-miasm-4dc802e3544e669cfea1d6be8a01ca2a2600dfef.tar.gz focaccia-miasm-4dc802e3544e669cfea1d6be8a01ca2a2600dfef.zip | |
Clear get_str_* API
get_str_ansi decoded strings using utf8 and was blindly used for pure windows function (LoadLibraryA) and for stdlib functions (printf, strlen, ...) even if strlen does not use utf8... New API is: get_win_str_a/get_win_str_w and set_win_str_a/set_win_str_w for windows (respectively codepage1252/windows utf16) .Those functions should only be used in windows strings manipulations, so there are taken out of the jitter. get_c_str/set_c_str: as those functions are "classic" in OSes, they are keeped in the jitter.
Diffstat (limited to 'miasm/os_dep/common.py')
| -rw-r--r-- | miasm/os_dep/common.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/miasm/os_dep/common.py b/miasm/os_dep/common.py index 0b4d7e11..4a92ef2a 100644 --- a/miasm/os_dep/common.py +++ b/miasm/os_dep/common.py @@ -2,25 +2,27 @@ import os from future.utils import viewitems -from miasm.core.utils import force_bytes +from miasm.core.utils import force_bytes, force_str from miasm.jitter.csts import PAGE_READ, PAGE_WRITE from miasm.core.utils import get_caller_name from miasm.core.utils import pck64, upck64 BASE_SB_PATH = "file_sb" +WIN_CODEPAGE = "cp1252" - -def get_str_ansi(jitter, ad_str, max_char=None): +def get_win_str_a(jitter, ad_str, max_char=None): l = 0 tmp = ad_str while ((max_char is None or l < max_char) and jitter.vm.get_mem(tmp, 1) != b"\x00"): tmp += 1 l += 1 - return jitter.vm.get_mem(ad_str, l) + data = jitter.vm.get_mem(ad_str, l) + ret = data.decode(WIN_CODEPAGE) + return ret -def get_str_unic(jitter, ad_str, max_char=None): +def get_win_str_w(jitter, ad_str, max_char=None): l = 0 tmp = ad_str while ((max_char is None or l < max_char) and @@ -31,18 +33,23 @@ def get_str_unic(jitter, ad_str, max_char=None): s = s.decode("utf-16le") return s +def encode_win_str_a(value): + value = value.encode(WIN_CODEPAGE) + b"\x00" + return value + +def encode_win_str_w(value): + value = value.encode("utf-16le") + b'\x00' * 2 + return value + -def set_str_ansi(value): - value = force_bytes(value) - return value + b"\x00" +def set_win_str_a(jitter, addr, value): + value = encode_win_str_a(value) + jitter.vm.set_mem(addr, value) -def set_str_unic(value): - try: - value = value.decode() - except AttributeError: - pass - return value.encode("utf-16le") + b'\x00' * 2 +def set_win_str_w(jitter, addr, value): + value = encode_win_str_w(value) + jitter.vm.set_mem(addr, value) class heap(object): |