class ContainerPE(Container): "Container abstraction for PE" def parse(self, data, vm=None): from miasm2.jitter.loader.pe import vm_load_pe, guess_arch from elfesteem import pe_init # Parse signature if not data.startswith('MZ'): raise ContainerSignatureException() # Build executable instance try: if vm is not None: self._executable = vm_load_pe(vm, data) else: self._executable = pe_init.PE(data) except Exception, error: raise ContainerParsingException('Cannot read PE: %s' % error) # Check instance validity if not self._executable.isPE() or \ self._executable.NTsig.signature_value != 0x4550: raise ContainerSignatureException() # Guess the architecture self._arch = guess_arch(self._executable) # Build the bin_stream instance and set the entry point try: self._bin_stream = bin_stream_pe(self._executable.virt) ep_detected = self._executable.Opthdr.AddressOfEntryPoint self._entry_point = self._executable.rva2virt(ep_detected) except Exception, error: raise ContainerParsingException('Cannot read PE: %s' % error)
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 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) # inform the engine not to disasm nul instructions mdis.dont_dis_nulstart_bloc = True blocs = mdis.dis_multibloc(ad) g = bloc2graph(blocs) open("graph.txt", "w").write(g)
if options.bw != None: options.bw = int(options.bw) 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: