diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2014-11-04 10:27:00 +0100 |
|---|---|---|
| committer | serpilliere <serpilliere@users.noreply.github.com> | 2014-11-04 10:27:00 +0100 |
| commit | 1aa333eba9f9bee1c8716fca291e3e080ea66a50 (patch) | |
| tree | 633425e451700154a44767eebeeae0abe49fe4c2 /example | |
| parent | b1225bc72bebdf0ac0b1ac83509e122574b2c7cc (diff) | |
| parent | 1a09c007ae8f6a391a90fa4ef4aa14c71ed672f6 (diff) | |
| download | miasm-1aa333eba9f9bee1c8716fca291e3e080ea66a50.tar.gz miasm-1aa333eba9f9bee1c8716fca291e3e080ea66a50.zip | |
Merge pull request #3 from commial/feature-binary
[Feature] Binary: Container
Diffstat (limited to 'example')
| -rw-r--r-- | example/disasm_03.py | 10 | ||||
| -rw-r--r-- | example/test_dis.py | 42 |
2 files changed, 11 insertions, 41 deletions
diff --git a/example/disasm_03.py b/example/disasm_03.py index 08b209a1..1141dc55 100644 --- a/example/disasm_03.py +++ b/example/disasm_03.py @@ -1,20 +1,16 @@ import sys -from elfesteem import pe_init from miasm2.arch.x86.disasm import dis_x86_32 from miasm2.core.asmbloc import bloc2graph -from miasm2.core.bin_stream import bin_stream_pe +from miasm2.analysis.binary import Container if len(sys.argv) != 3: print 'Example:' print "%s box_upx.exe 0x410f90" % sys.argv[0] sys.exit(0) -fname = sys.argv[1] ad = int(sys.argv[2], 16) -e = pe_init.PE(open(fname).read()) -bs = bin_stream_pe(e.virt) - -mdis = dis_x86_32(bs) +cont = Container.from_stream(open(sys.argv[1])) +mdis = dis_x86_32(cont.bin_stream) # inform the engine not to disasm nul instructions mdis.dont_dis_nulstart_bloc = True blocs = mdis.dis_multibloc(ad) diff --git a/example/test_dis.py b/example/test_dis.py index dc3f7274..722e99c9 100644 --- a/example/test_dis.py +++ b/example/test_dis.py @@ -2,13 +2,10 @@ import sys import os import time -from miasm2.core.bin_stream import bin_stream_elf, bin_stream_pe, bin_stream_str -from elfesteem import * +from miasm2.analysis.binary import Container from miasm2.core.asmbloc import * -from miasm2.expression.simplifications import expr_simp from optparse import OptionParser -from miasm2.core.cpu import dum_arg -from miasm2.expression.expression import * +from miasm2.expression.expression import ExprId from miasm2.core.interval import interval from miasm2.analysis.machine import Machine from pdb import pm @@ -95,36 +92,13 @@ if options.bw != None: if options.funcswd != None: options.funcswd = int(options.funcswd) -log.info('load binary') -b = open(fname).read() - -default_addr = 0 -bs = None -if b.startswith('MZ'): - try: - e = pe_init.PE(b) - if e.isPE() and e.NTsig.signature_value == 0x4550: - bs = bin_stream_pe(e.virt) - default_addr = e.rva2virt(e.Opthdr.AddressOfEntryPoint) - except: - log.error('Cannot read PE!') -elif b.startswith('\x7fELF'): - try: - e = elf_init.ELF(b) - bs = bin_stream_elf(e.virt) - default_addr = e.Ehdr.entry - except: - log.error('Cannot read ELF!') - - -if bs is None or options.shiftoffset is not None: - - if options.shiftoffset is None: - options.shiftoffset = "0" - shift = int(options.shiftoffset, 16) - log.warning('fallback to string input (offset=%s)' % hex(shift)) - bs = bin_stream_str(b, shift=shift) +log.info('Load binary') +with open(fname) as fdesc: + cont = Container.from_stream(fdesc, addr=options.shiftoffset) +default_addr = cont.entry_point +bs = cont.bin_stream +e = cont.executable log.info('ok') mdis = dis_engine(bs) |