diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2015-06-29 12:29:41 +0200 |
|---|---|---|
| committer | serpilliere <serpilliere@users.noreply.github.com> | 2015-06-29 12:29:41 +0200 |
| commit | 5e5dc1f12bed5fb8b8e2ac01392a236f02ea6250 (patch) | |
| tree | 0495661f91edce5d899d07053b152b73e92e1171 /miasm2/os_dep/common.py | |
| parent | a1cb2ec2ffcc0146964a376b5645ba0373712143 (diff) | |
| parent | 5055ac3ae8c6c2a7a65d44d1a46ff964d63e8b41 (diff) | |
| download | miasm-5e5dc1f12bed5fb8b8e2ac01392a236f02ea6250.tar.gz miasm-5e5dc1f12bed5fb8b8e2ac01392a236f02ea6250.zip | |
Merge pull request #185 from p-l-/feature-sbpaths
Factorize code to handle sandboxed files
Diffstat (limited to 'miasm2/os_dep/common.py')
| -rw-r--r-- | miasm2/os_dep/common.py | 30 |
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) |