Ejemplo 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 xrange(10):
         self.assertEqual(heap.get_size(jit.vm, ptr+i), 10)
Ejemplo n.º 2
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 xrange(10):
         self.assertEqual(heap.get_size(jit.vm, ptr + i), 10)
Ejemplo n.º 3
0
## Memset sets the whole structure
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('\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 omited 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()
assert mstruct.other.deref == other
Ejemplo n.º 4
0
#! /usr/bin/env python2
"""This script is just a short example of common usages for miasm2.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 miasm2.analysis.machine import Machine
from miasm2.core.types import MemStruct, Self, Void, Str, Array, Ptr, \
                              Num, Array, set_allocator
from miasm2.os_dep.common import heap

# Instanciate 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.
        # One way to handle reference to ListNode in ListNode is to use the
        # special marker Self().
        # You could also generate ListNode's fields with ListNode.gen_field
Ejemplo n.º 5
0
 def __init__(self):
     self.alloc_ad = self.base_addr
     self.alloc_align = self.align_addr
     self.heap = heap()
Ejemplo n.º 6
0
'''
passwd_addr = 0x141111
argzero_addr = 0x141166

sb.jitter.vm.add_memory_page(passwd_addr,PAGE_READ | PAGE_WRITE,ascii_letters[:30] + '\x00','required input')
sb.jitter.vm.add_memory_page(argzero_addr,PAGE_READ,'reverseMe\x00','argv[0] -> program path')

sb.jitter.push_uint32_t(passwd_addr) #argv[1]
sb.jitter.push_uint32_t(argzero_addr) #argv[0]
sb.jitter.push_uint32_t(0x2) #argc

'''

#Set default allocator from class heap()
set_allocator(heap().vm_alloc)

#implementing argv[] array busing core types of miasm2
argv_t = Array(Ptr("<I",Str()),3)
argv = argv_t.lval(sb.jitter.vm)

MemStrAnsi = Str().lval

argv[0].val = MemStrAnsi.from_str(sb.jitter.vm, "./reverseMe").get_addr()
argv[1].val = MemStrAnsi.from_str(sb.jitter.vm, ascii_letters[:28]).get_addr()
argv[2].val = 0

sb.jitter.push_uint32_t(argv[2].val) #argv[2]
sb.jitter.push_uint32_t(argv[1].val) #argv[1]
sb.jitter.push_uint32_t(argv[0].val) #argv[0]
sb.jitter.push_uint32_t(0x2) #argc