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/jitter/jitload.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/jitter/jitload.py')
| -rw-r--r-- | miasm/jitter/jitload.py | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/miasm/jitter/jitload.py b/miasm/jitter/jitload.py index 9fcb0b0a..e8277e34 100644 --- a/miasm/jitter/jitload.py +++ b/miasm/jitter/jitload.py @@ -429,8 +429,8 @@ class Jitter(object): return self.cpu.get_exception() | self.vm.get_exception() # commun functions - def get_str_ansi(self, addr, max_char=None): - """Get ansi str from vm. + def get_c_str(self, addr, max_char=None): + """Get C str from vm. @addr: address in memory @max_char: maximum len""" l = 0 @@ -440,31 +440,21 @@ class Jitter(object): tmp += 1 l += 1 value = self.vm.get_mem(addr, l) - return value.decode('utf8') + value = force_str(value) + return value - def get_str_unic(self, addr, max_char=None): - """Get unicode str from vm. + def set_c_str(self, addr, value): + """Set C str str from vm. @addr: address in memory - @max_char: maximum len""" - l = 0 - tmp = addr - while ((max_char is None or l < max_char) and - self.vm.get_mem(tmp, 2) != b"\x00\x00"): - tmp += 2 - l += 2 - s = self.vm.get_mem(addr, l) - s = s.decode("utf-16le") - return s - - def set_str_ansi(self, addr, string): - """Set an ansi string in memory""" - string = (string + "\x00").encode('utf8') - self.vm.set_mem(addr, string) - - def set_str_unic(self, addr, string): - """Set an unicode string in memory""" - s = (string + "\x00").encode('utf-16le') - self.vm.set_mem(addr, s) + @value: str""" + value = force_bytes(value) + self.vm.set_mem(addr, value + b'\x00') + + def get_str_ansi(self, addr, max_char=None): + raise NotImplementedError("Deprecated: use os_dep.win_api_x86_32.get_win_str_a") + + def get_str_unic(self, addr, max_char=None): + raise NotImplementedError("Deprecated: use os_dep.win_api_x86_32.get_win_str_a") @staticmethod def handle_lib(jitter): @@ -501,7 +491,6 @@ class Jitter(object): self.libs = libs out = {} for name, func in viewitems(user_globals): - name = force_bytes(name) out[name] = func self.user_globals = out |