about summary refs log tree commit diff stats
path: root/miasm2/os_dep/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/os_dep/common.py')
-rw-r--r--miasm2/os_dep/common.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/miasm2/os_dep/common.py b/miasm2/os_dep/common.py
index 41d24405..7f8caed1 100644
--- a/miasm2/os_dep/common.py
+++ b/miasm2/os_dep/common.py
@@ -1,10 +1,15 @@
+import os
+
 from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
 
+BASE_SB_PATH = "file_sb"
+
+
 def get_str_ansi(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) != "\x00"):
+           jitter.vm.get_mem(tmp, 1) != "\x00"):
         tmp += 1
         l += 1
     return jitter.vm.get_mem(ad_str, l)
@@ -14,7 +19,7 @@ def get_str_unic(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, 2) != "\x00\x00"):
+           jitter.vm.get_mem(tmp, 2) != "\x00\x00"):
         tmp += 2
         l += 2
     s = jitter.vm.get_mem(ad_str, l)
@@ -32,14 +37,13 @@ def set_str_unic(s):
     return "\x00".join(list(s)) + '\x00' * 3
 
 
-
 class heap(object):
     "Light heap simulation"
 
     addr = 0x20000000
     align = 0x1000
     size = 32
-    mask = (1<< size) - 1
+    mask = (1 << size) - 1
 
     def next_addr(self, size):
         """
@@ -51,7 +55,6 @@ class heap(object):
         self.addr &= self.mask ^ (self.align - 1)
         return ret
 
-
     def alloc(self, jitter, size):
         """
         @jitter: a jitter instance
@@ -62,3 +65,20 @@ class heap(object):
         jitter.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * size)
         return addr
 
+
+def windows_to_sbpath(path):
+    """Convert a Windows path to a valid filename within the sandbox
+    base directory.
+
+    """
+    path = [elt for elt in path.lower().replace('/', '_').split('\\') if elt]
+    return os.path.join(BASE_SB_PATH, *path)
+
+
+def unix_to_sbpath(path):
+    """Convert a POSIX path to a valid filename within the sandbox
+    base directory.
+
+    """
+    path = [elt for elt in path.split('/') if elt]
+    return os.path.join(BASE_SB_PATH, *path)