about summary refs log tree commit diff stats
path: root/miasm/analysis/sandbox.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/analysis/sandbox.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/analysis/sandbox.py')
-rw-r--r--miasm/analysis/sandbox.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/miasm/analysis/sandbox.py b/miasm/analysis/sandbox.py
index b8aaf788..3040a1a8 100644
--- a/miasm/analysis/sandbox.py
+++ b/miasm/analysis/sandbox.py
@@ -6,13 +6,13 @@ import logging
 from argparse import ArgumentParser
 
 from future.utils import viewitems, viewvalues
+from past.builtins import basestring
 
-from miasm.core.utils import force_bytes
 from miasm.analysis.machine import Machine
 from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
 from miasm.analysis import debugging
 from miasm.jitter.jitload import log_func
-
+from miasm.core.utils import force_bytes
 
 
 class Sandbox(object):
@@ -51,8 +51,7 @@ class Sandbox(object):
         """
 
         # Initialize
-        if not isinstance(fname, bytes):
-            fname = fname.encode('utf8')
+        assert isinstance(fname, basestring)
         self.fname = fname
         self.options = options
         if custom_methods is None:
@@ -183,17 +182,18 @@ class Arch(object):
 
 class OS_Win(OS):
     # DLL to import
-    ALL_IMP_DLL = ["ntdll.dll", "kernel32.dll", "user32.dll",
-                   "ole32.dll", "urlmon.dll",
-                   "ws2_32.dll", 'advapi32.dll', "psapi.dll",
-                   ]
-    modules_path = b"win_dll"
+    ALL_IMP_DLL = [
+        "ntdll.dll", "kernel32.dll", "user32.dll",
+        "ole32.dll", "urlmon.dll",
+        "ws2_32.dll", 'advapi32.dll', "psapi.dll",
+    ]
+    modules_path = "win_dll"
 
     def __init__(self, custom_methods, *args, **kwargs):
         from miasm.jitter.loader.pe import vm_load_pe, vm_load_pe_libs,\
             preload_pe, libimp_pe, vm_load_pe_and_dependencies
         from miasm.os_dep import win_api_x86_32, win_api_x86_32_seh
-        methods = dict((name.encode(),func) for name, func in viewitems(win_api_x86_32.__dict__))
+        methods = dict((name, func) for name, func in viewitems(win_api_x86_32.__dict__))
         methods.update(custom_methods)
 
         super(OS_Win, self).__init__(methods, *args, **kwargs)