diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-12-16 16:29:13 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2015-12-16 16:29:13 +0100 |
| commit | 797b00e9449368448518ffa5497935569049c3ba (patch) | |
| tree | 9b6540b736f6163197fe8dd4ff066a27a638aff4 | |
| parent | 8ebdbffdc6c86e9b832869046dfc6e11a8fb21be (diff) | |
| download | miasm-797b00e9449368448518ffa5497935569049c3ba.tar.gz miasm-797b00e9449368448518ffa5497935569049c3ba.zip | |
Autopep8
| -rw-r--r-- | example/asm/shellcode.py | 4 | ||||
| -rw-r--r-- | example/jitter/unpack_upx.py | 4 | ||||
| -rw-r--r-- | miasm2/core/bin_stream.py | 3 | ||||
| -rw-r--r-- | miasm2/jitter/loader/elf.py | 16 |
4 files changed, 14 insertions, 13 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py index ce84238a..9dc5c6bc 100644 --- a/example/asm/shellcode.py +++ b/example/asm/shellcode.py @@ -10,8 +10,8 @@ from miasm2.analysis.machine import Machine from miasm2.core.interval import interval parser = ArgumentParser("Multi-arch (32 bits) assembler") -parser.add_argument('architecture', help="architecture: " + \ - ",".join(Machine.available_machine())) +parser.add_argument('architecture', help="architecture: " + + ",".join(Machine.available_machine())) parser.add_argument("source", help="Source file to assemble") parser.add_argument("output", help="Output file") parser.add_argument("--PE", help="Create a PE with a few imports", diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py index c27ecdd8..72a9feb3 100644 --- a/example/jitter/unpack_upx.py +++ b/example/jitter/unpack_upx.py @@ -25,7 +25,8 @@ def kernel32_GetProcAddress(jitter): else jitter.get_str_ansi(args.fname)) logging.info(fname) - # Get the generated address of the library, and store it in memory to dst_ad + # Get the generated address of the library, and store it in memory to + # dst_ad ad = sb.libs.lib_get_add_func(args.libbase, fname, dst_ad) # Add a breakpoint in case of a call on the resolved function # NOTE: never happens in UPX, just for skeleton @@ -34,7 +35,6 @@ def kernel32_GetProcAddress(jitter): jitter.func_ret_stdcall(ret_ad, ad) - parser = Sandbox_Win_x86_32.parser(description="Generic UPX unpacker") parser.add_argument("filename", help="PE Filename") parser.add_argument('-v', "--verbose", diff --git a/miasm2/core/bin_stream.py b/miasm2/core/bin_stream.py index e02523d8..f7b160f9 100644 --- a/miasm2/core/bin_stream.py +++ b/miasm2/core/bin_stream.py @@ -108,7 +108,7 @@ class bin_stream_file(bin_stream): return self.bin.tell() - self.shift def setoffset(self, val): - self.bin.seek(val + self.shift) + self.bin.seek(val + self.shift) offset = property(getoffset, setoffset) def readbs(self, l=1): @@ -123,7 +123,6 @@ class bin_stream_file(bin_stream): return self.l - (self.offset + self.shift) - class bin_stream_container(bin_stream): def __init__(self, virt_view, offset=0L): diff --git a/miasm2/jitter/loader/elf.py b/miasm2/jitter/loader/elf.py index 12670977..08df632a 100644 --- a/miasm2/jitter/loader/elf.py +++ b/miasm2/jitter/loader/elf.py @@ -17,6 +17,7 @@ hnd.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s")) log.addHandler(hnd) log.setLevel(logging.CRITICAL) + def get_import_address_elf(e): import2addr = defaultdict(set) for sh in e.sh: @@ -46,20 +47,20 @@ def preload_elf(vm, e, runtime_lib, patch_vm_imp=True): return runtime_lib, dyn_funcs - def vm_load_elf(vm, fdata, **kargs): """ Very dirty elf loader TODO XXX: implement real loader """ - #log.setLevel(logging.DEBUG) + # log.setLevel(logging.DEBUG) e = elf_init.ELF(fdata, **kargs) i = interval() all_data = {} for p in e.ph.phlist: if p.ph.type != elf_csts.PT_LOAD: continue - log.debug('0x%x 0x%x 0x%x 0x%x 0x%x', p.ph.vaddr, p.ph.memsz, p.ph.offset, + log.debug( + '0x%x 0x%x 0x%x 0x%x 0x%x', p.ph.vaddr, p.ph.memsz, p.ph.offset, p.ph.filesz, p.ph.type) data_o = e._content[p.ph.offset:p.ph.offset + p.ph.filesz] addr_o = p.ph.vaddr @@ -68,16 +69,16 @@ def vm_load_elf(vm, fdata, **kargs): b_addr = (b_addr + 0xFFF) & ~0xFFF all_data[addr_o] = data_o # -2: Trick to avoid merging 2 consecutive pages - i += [(a_addr, b_addr-2)] + i += [(a_addr, b_addr - 2)] for a, b in i.intervals: - #print hex(a), hex(b) - vm.add_memory_page(a, PAGE_READ | PAGE_WRITE, "\x00"*(b+2-a)) - + # print hex(a), hex(b) + vm.add_memory_page(a, PAGE_READ | PAGE_WRITE, "\x00" * (b + 2 - a)) for r_vaddr, data in all_data.items(): vm.set_mem(r_vaddr, data) return e + class libimp_elf(libimp): pass @@ -94,6 +95,7 @@ ELF_machine = {(elf_csts.EM_ARM, 32, elf_csts.ELFDATA2LSB): "arml", (elf_csts.EM_SH, 32, elf_csts.ELFDATA2LSB): "sh4", } + def guess_arch(elf): """Return the architecture specified by the ELF container @elf. If unknown, return None""" |