diff options
| author | Florent Monjalet <florent.monjalet@gmail.com> | 2015-11-08 02:06:32 +0100 |
|---|---|---|
| committer | Florent Monjalet <florent.monjalet@gmail.com> | 2016-01-18 14:02:31 +0100 |
| commit | a03c4cb22a2bdaefe19ab2908dc55894211e5070 (patch) | |
| tree | 60320ca2802dad8b51b99a85cbd2d1dfed041cf3 /miasm2/os_dep/common.py | |
| parent | 6e635113b53f932573687f9a6e3fc227cde6c0d9 (diff) | |
| download | miasm-a03c4cb22a2bdaefe19ab2908dc55894211e5070.tar.gz miasm-a03c4cb22a2bdaefe19ab2908dc55894211e5070.zip | |
MemStruct: auto-allocation feature
MemStruct can be automatically allocated if a None addr is passed to the constructor and mem.allocator has been set to an allocation function. miasm2.os_dep.common.heap API has been extended to directly support a VmMngr as an argument. NOTE: heap.alloc and heap.vm_alloc could be merged, but allowing the first argument to be either a jitter or a vm is misleading, and changing the old API would have broken some code.
Diffstat (limited to 'miasm2/os_dep/common.py')
| -rw-r--r-- | miasm2/os_dep/common.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/miasm2/os_dep/common.py b/miasm2/os_dep/common.py index 7f8caed1..b7eb656a 100644 --- a/miasm2/os_dep/common.py +++ b/miasm2/os_dep/common.py @@ -60,9 +60,15 @@ class heap(object): @jitter: a jitter instance @size: the size to allocate """ + return self.vm_alloc(jitter.vm, size) + def vm_alloc(self, vm, size): + """ + @vm: a VmMngr instance + @size: the size to allocate + """ addr = self.next_addr(size) - jitter.vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * size) + vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * size) return addr |