diff options
| author | Florent Monjalet <florent.monjalet@gmail.com> | 2015-12-04 11:05:51 +0100 |
|---|---|---|
| committer | Florent Monjalet <florent.monjalet@gmail.com> | 2016-01-18 14:02:31 +0100 |
| commit | bd85479c0c7aba2d9ec9aeb2e6b2c4bb4b54d3e0 (patch) | |
| tree | c6e369ec923640b48075e9cb26865a66bf3b36e8 /example/jitter | |
| parent | 762362ffbbaa19edf3cd3d7d3db9d18f753a91cd (diff) | |
| download | miasm-bd85479c0c7aba2d9ec9aeb2e6b2c4bb4b54d3e0.tar.gz miasm-bd85479c0c7aba2d9ec9aeb2e6b2c4bb4b54d3e0.zip | |
MemStruct/Types: example on type manipulations
Diffstat (limited to 'example/jitter')
| -rw-r--r-- | example/jitter/types.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/example/jitter/types.py b/example/jitter/types.py index f4a7ddb4..6c0b59af 100644 --- a/example/jitter/types.py +++ b/example/jitter/types.py @@ -229,7 +229,29 @@ print "See that the original array has been modified:" print repr(data) print -# TODO: type manipulation examples +# Some type manipulation examples, for example let's construct an argv for +# a program: +# Let's say that we have two arguments, +1 for the program name and +1 for the +# final null ptr in argv, the array has 4 elements: +argv_t = Array(Ptr("<I", Str()), 4) +print "3 arguments argv type:", argv_t + +# alloc argv somewhere +argv = argv_t.lval(vm) + +# Auto alloc with a buffer type +MemStrAnsi = Str().lval +argv[0].val = MemStrAnsi.from_str(vm, "./my-program").get_addr() +argv[1].val = MemStrAnsi.from_str(vm, "arg1").get_addr() +argv[2].val = MemStrAnsi.from_str(vm, "27").get_addr() +argv[3].val = 0 + +# If you changed your mind on the second arg, you could do: +argv[2].deref.val = "42" + +print "An argv instance:", repr(argv) +print "argv values:", repr([val.deref.val for val in argv[:-1]]) +print print "See test/core/types.py and the miasm2.core.types module doc for " print "more information." |