about summary refs log tree commit diff stats
path: root/miasm/jitter/loader/utils.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2019-11-02 22:24:23 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2019-11-12 15:10:44 +0100
commit4dc802e3544e669cfea1d6be8a01ca2a2600dfef (patch)
tree96a79b40469c1db9201ca46b210503d4dcf378c5 /miasm/jitter/loader/utils.py
parent83e54bd2de945a36ab5ccd4cc5b94817d7cb0112 (diff)
downloadfocaccia-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/loader/utils.py')
-rw-r--r--miasm/jitter/loader/utils.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/miasm/jitter/loader/utils.py b/miasm/jitter/loader/utils.py
index 375424e6..d03adc8a 100644
--- a/miasm/jitter/loader/utils.py
+++ b/miasm/jitter/loader/utils.py
@@ -2,24 +2,23 @@ from builtins import int as int_types
 import logging
 
 from future.utils import viewitems, viewvalues
-
-from miasm.core.utils import force_bytes
+from past.builtins import basestring
 
 log = logging.getLogger('loader_common')
 hnd = logging.StreamHandler()
 hnd.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s"))
 log.addHandler(hnd)
-log.setLevel(logging.INFO)
+log.setLevel(logging.DEBUG)
 
 
 def canon_libname_libfunc(libname, libfunc):
-    libname = force_bytes(libname)
-    dn = libname.split(b'.')[0]
+    assert isinstance(libname, basestring)
+    assert isinstance(libfunc, basestring) or isinstance(libfunc, int)
+    dn = libname.split('.')[0]
     if isinstance(libfunc, int_types):
         return str(dn), libfunc
     else:
-        libfunc = force_bytes(libfunc)
-        return b"%s_%s" % (dn, libfunc)
+        return "%s_%s" % (dn, libfunc)
 
 
 class libimp(object):
@@ -37,11 +36,11 @@ class libimp(object):
         self.fake_libs = set()
 
     def lib_get_add_base(self, name):
-        name = force_bytes(name)
-        name = name.lower().strip(b' ')
-        if not b"." in name:
+        assert isinstance(name, basestring)
+        name = name.lower().strip(' ')
+        if not "." in name:
             log.debug('warning adding .dll to modulename')
-            name += b'.dll'
+            name += '.dll'
             log.debug(name)
 
         if name in self.name2off:
@@ -74,7 +73,7 @@ class libimp(object):
 
         if imp_ord_or_name in self.lib_imp2ad[libad]:
             return self.lib_imp2ad[libad][imp_ord_or_name]
-        # log.debug('new imp %s %s' % (imp_ord_or_name, dst_ad))
+        log.debug('new imp %s %s' % (imp_ord_or_name, dst_ad))
         ad = self.libbase2lastad[libad]
         self.libbase2lastad[libad] += 0x10  # arbitrary
         self.lib_imp2ad[libad][imp_ord_or_name] = ad