diff options
| author | Pierre LALET <pierre.lalet@cea.fr> | 2015-06-28 14:46:51 +0200 |
|---|---|---|
| committer | Pierre LALET <pierre.lalet@cea.fr> | 2015-06-28 18:14:23 +0200 |
| commit | 1bb328a8922f8b2220529f0a61c1f50f94bbc367 (patch) | |
| tree | ce8ee4745811f7fff2ab2005cc850c75d8cd83d6 /miasm2/os_dep/common.py | |
| parent | a1cb2ec2ffcc0146964a376b5645ba0373712143 (diff) | |
| download | miasm-1bb328a8922f8b2220529f0a61c1f50f94bbc367.tar.gz miasm-1bb328a8922f8b2220529f0a61c1f50f94bbc367.zip | |
os_dep: factorize file sandboxing code
Diffstat (limited to 'miasm2/os_dep/common.py')
| -rw-r--r-- | miasm2/os_dep/common.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/miasm2/os_dep/common.py b/miasm2/os_dep/common.py index 41d24405..9f0d2fa2 100644 --- a/miasm2/os_dep/common.py +++ b/miasm2/os_dep/common.py @@ -1,5 +1,10 @@ +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 @@ -31,8 +36,6 @@ def set_str_unic(s): # TODO: real unicode encoding return "\x00".join(list(s)) + '\x00' * 3 - - class heap(object): "Light heap simulation" @@ -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) |