From acb866d6d401e5cfbdb01c4a888fe8017c472281 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Mon, 3 Nov 2014 19:12:35 +0100 Subject: TestDis: update example to use Container --- example/test_dis.py | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'example/test_dis.py') diff --git a/example/test_dis.py b/example/test_dis.py index dc3f7274..ba0d7921 100644 --- a/example/test_dis.py +++ b/example/test_dis.py @@ -2,8 +2,7 @@ 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 @@ -95,36 +94,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) -- cgit 1.4.1 From 1a09c007ae8f6a391a90fa4ef4aa14c71ed672f6 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Mon, 3 Nov 2014 19:15:09 +0100 Subject: TestDis: fix imports --- example/disasm_03.py | 4 +--- example/test_dis.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'example/test_dis.py') diff --git a/example/disasm_03.py b/example/disasm_03.py index 72c08c0d..1141dc55 100644 --- a/example/disasm_03.py +++ b/example/disasm_03.py @@ -1,15 +1,13 @@ 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) cont = Container.from_stream(open(sys.argv[1])) mdis = dis_x86_32(cont.bin_stream) diff --git a/example/test_dis.py b/example/test_dis.py index ba0d7921..722e99c9 100644 --- a/example/test_dis.py +++ b/example/test_dis.py @@ -4,10 +4,8 @@ import time 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 -- cgit 1.4.1