diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2014-10-11 20:37:52 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2014-10-11 20:37:52 +0200 |
| commit | 4717e8f6295c46fbfc7e27cc750df7ccf7a599be (patch) | |
| tree | 1460142711f3210893578b477a8ebcd826815bad /miasm2/os_dep/common.py | |
| parent | fa5b335bcc2ac2bc4b2abe63c53b427e9deb99d7 (diff) | |
| download | miasm-4717e8f6295c46fbfc7e27cc750df7ccf7a599be.tar.gz miasm-4717e8f6295c46fbfc7e27cc750df7ccf7a599be.zip | |
os_dep: missing file
Diffstat (limited to 'miasm2/os_dep/common.py')
| -rw-r--r-- | miasm2/os_dep/common.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/miasm2/os_dep/common.py b/miasm2/os_dep/common.py new file mode 100644 index 00000000..83b00ae6 --- /dev/null +++ b/miasm2/os_dep/common.py @@ -0,0 +1,64 @@ +from miasm2.jitter.csts import * + +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"): + tmp += 1 + l += 1 + return jitter.vm.get_mem(ad_str, l) + + +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"): + tmp += 2 + l += 2 + s = jitter.vm.get_mem(ad_str, l) + # TODO: real unicode decoding + s = s[::2] + return s + + +def set_str_ansi(s): + return s + "\x00" + + +def set_str_unic(s): + # TODO: real unicode encoding + return "\x00".join(list(s)) + '\x00' * 3 + + + +class heap(object): + "Light heap simulation" + + addr = 0x20000000 + align = 0x1000 + size = 32 + mask = (1<< size) - 1 + + def next_addr(self, size): + """ + @size: the size to allocate + return the future checnk address + """ + ret = self.addr + self.addr = (self.addr + size + self.align - 1) + self.addr &= self.mask ^ (self.align - 1) + return ret + + + def alloc(self, jitter, size): + """ + @jitter: a jitter instance + @size: the size to allocate + """ + + addr = self.next_addr(size) + jitter.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * size) + return addr + |