Esempio n. 1
0
 def test_get_size(self):
     heap = commonapi.heap()
     with self.assertRaises(AssertionError):
         heap.get_size(jit.vm, 0)
     heap.alloc(jit, 20)
     heap.alloc(jit, 40)
     heap.alloc(jit, 50)
     heap.alloc(jit, 60)
     ptr = heap.alloc(jit, 10)
     heap.alloc(jit, 80)
     for i in range(10):
         self.assertEqual(heap.get_size(jit.vm, ptr + i), 10)
Esempio n. 2
0
mstruct.memset()
assert mstruct.num == 0
assert mstruct.flags == 0
assert mstruct.other.val == 0
assert mstruct.s.val == 0
assert mstruct.i.val == 0
mstruct.memset(b'\x11')
assert mstruct.num == 0x11111111
assert mstruct.flags == 0x11
assert mstruct.other.val == 0x11111111
assert mstruct.s.val == 0x11111111
assert mstruct.i.val == 0x11111111


# From now, just use heap.vm_alloc
my_heap = heap()
set_allocator(my_heap.vm_alloc)


# Ptr tests
## Setup for Ptr tests
# the addr field can now be omitted since allocator is set
other = OtherStruct(jitter.vm)
other.foo = 0x1234
assert other.foo == 0x1234

## Basic usage
mstruct.other.val = other.get_addr()
# This also works for now:
# mstruct.other = other.get_addr()
assert mstruct.other.val == other.get_addr()
Esempio n. 3
0
 def __init__(self):
     self.alloc_ad = self.base_addr
     self.alloc_align = self.align_addr
     self.heap = heap()
Esempio n. 4
0
#! /usr/bin/env python2
"""This script is just a short example of common usages for miasm.core.types.
For a more complete view of what is possible, tests/core/types.py covers
most of the module possibilities, and the module doc gives useful information
as well.
"""
from __future__ import print_function

from miasm.core.utils import iterbytes
from miasm.analysis.machine import Machine
from miasm.core.types import MemStruct, Self, Void, Str, Array, Ptr, \
                              Num, Array, set_allocator
from miasm.os_dep.common import heap

# Instantiate a heap
my_heap = heap()
# And set it as the default memory allocator, to avoid manual allocation and
# explicit address passing to the MemType subclasses (like MemStruct)
# constructor
set_allocator(my_heap.vm_alloc)

# Let's reimplement a simple C generic linked list mapped on a VmMngr.

# All the structures and methods will use the python objects but all the data
# is in fact stored in the VmMngr


class ListNode(MemStruct):
    fields = [
        # The "<I" is the struct-like format of the pointer in memory, in this
        # case a Little Endian 32 bits unsigned int.
Esempio n. 5
0
 def __init__(self):
     self.alloc_ad = self.base_addr
     self.alloc_align = self.align_addr
     self.heap = heap()