From a03c4cb22a2bdaefe19ab2908dc55894211e5070 Mon Sep 17 00:00:00 2001 From: Florent Monjalet Date: Sun, 8 Nov 2015 02:06:32 +0100 Subject: 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. --- miasm2/os_dep/common.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'miasm2/os_dep/common.py') 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 -- cgit 1.4.1 From 81076e0cfbe80e1e9aa090dd509f272b1e3cdfd0 Mon Sep 17 00:00:00 2001 From: Florent Monjalet Date: Thu, 26 Nov 2015 14:10:27 +0100 Subject: Heap: adding page permissions option --- miasm2/os_dep/common.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'miasm2/os_dep/common.py') diff --git a/miasm2/os_dep/common.py b/miasm2/os_dep/common.py index b7eb656a..d70cdccf 100644 --- a/miasm2/os_dep/common.py +++ b/miasm2/os_dep/common.py @@ -55,20 +55,23 @@ class heap(object): self.addr &= self.mask ^ (self.align - 1) return ret - def alloc(self, jitter, size): + def alloc(self, jitter, size, perm=PAGE_READ|PAGE_WRITE): """ @jitter: a jitter instance @size: the size to allocate + @perm: permission flags (see vm_alloc doc) """ - return self.vm_alloc(jitter.vm, size) + return self.vm_alloc(jitter.vm, size, perm) - def vm_alloc(self, vm, size): + def vm_alloc(self, vm, size, perm=PAGE_READ|PAGE_WRITE): """ @vm: a VmMngr instance @size: the size to allocate + @perm: permission flags (PAGE_READ, PAGE_WRITE, PAGE_EXEC or any `|` + combination of them); default is PAGE_READ|PAGE_WRITE """ addr = self.next_addr(size) - vm.add_memory_page(addr, PAGE_READ | PAGE_WRITE, "\x00" * size) + vm.add_memory_page(addr, perm, "\x00" * size) return addr -- cgit 1.4.1