From 195ae36b8fae391fbe9fcd3058a699f3f439983c Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 25 Jan 2016 13:03:47 +0100 Subject: Move types -> test_types to avoid namespace collision (creds @fmonjalet) --- example/jitter/example_types.py | 258 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 example/jitter/example_types.py (limited to 'example/jitter/example_types.py') diff --git a/example/jitter/example_types.py b/example/jitter/example_types.py new file mode 100644 index 00000000..c37c3b84 --- /dev/null +++ b/example/jitter/example_types.py @@ -0,0 +1,258 @@ +#!/usr/bin/env python +"""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 "