Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Classes | Functions | Variables
miasm2.jitter.loader.elf Namespace Reference

Classes

class  libimp_elf
 

Functions

def get_import_address_elf
 
def preload_elf
 
def vm_load_elf
 
def guess_arch
 

Variables

tuple log = logging.getLogger('loader_elf')
 
tuple hnd = logging.StreamHandler()
 
dictionary ELF_machine
 

Function Documentation

def miasm2.jitter.loader.elf.get_import_address_elf (   e)

Definition at line 20 of file elf.py.

20 
22  import2addr = defaultdict(set)
23  for sh in e.sh:
24  if not hasattr(sh, 'rel'):
25  continue
26  for k, v in sh.rel.items():
27  import2addr[('xxx', k)].add(v.offset)
28  return import2addr
29 
def get_import_address_elf
Definition: elf.py:20

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.jitter.loader.elf.guess_arch (   elf)
Return the architecture specified by the ELF container @elf.
If unknown, return None

Definition at line 97 of file elf.py.

97 
98 def guess_arch(elf):
99  """Return the architecture specified by the ELF container @elf.
100  If unknown, return None"""
101  return ELF_machine.get((elf.Ehdr.machine, elf.size, elf.sex), None)
def miasm2.jitter.loader.elf.preload_elf (   vm,
  e,
  runtime_lib,
  patch_vm_imp = True 
)

Definition at line 30 of file elf.py.

30 
31 def preload_elf(vm, e, runtime_lib, patch_vm_imp=True):
32  # XXX quick hack
34  dyn_funcs = {}
35  # log.debug('imported funcs: %s' % fa)
36  for (libname, libfunc), ads in fa.items():
37  for ad in ads:
38  ad_base_lib = runtime_lib.lib_get_add_base(libname)
39  ad_libfunc = runtime_lib.lib_get_add_func(ad_base_lib, libfunc, ad)
40 
41  libname_s = canon_libname_libfunc(libname, libfunc)
42  dyn_funcs[libname_s] = ad_libfunc
43  if patch_vm_imp:
44  log.debug('patch 0x%x 0x%x %s', ad, ad_libfunc, libfunc)
45  vm.set_mem(
46  ad, struct.pack(cstruct.size2type[e.size], ad_libfunc))
47  return runtime_lib, dyn_funcs
48 
49 
def get_import_address_elf
Definition: elf.py:20

+ Here is the call graph for this function:

def miasm2.jitter.loader.elf.vm_load_elf (   vm,
  fdata,
  kargs 
)
Very dirty elf loader
TODO XXX: implement real loader

Definition at line 50 of file elf.py.

50 
51 def vm_load_elf(vm, fdata, **kargs):
52  """
53  Very dirty elf loader
54  TODO XXX: implement real loader
55  """
56  #log.setLevel(logging.DEBUG)
57  e = elf_init.ELF(fdata, **kargs)
58  i = interval()
59  all_data = {}
60  for p in e.ph.phlist:
61  if p.ph.type != 1:
62  continue
63  log.debug('0x%x 0x%x 0x%x 0x%x', p.ph.vaddr, p.ph.memsz, p.ph.offset,
64  p.ph.filesz)
65  data_o = e._content[p.ph.offset:p.ph.offset + p.ph.filesz]
66  addr_o = p.ph.vaddr
67  a_addr = addr_o & ~0xFFF
68  b_addr = addr_o + max(p.ph.memsz, p.ph.filesz)
69  b_addr = (b_addr + 0xFFF) & ~0xFFF
70  all_data[addr_o] = data_o
71  # -2: Trick to avoid merging 2 consecutive pages
72  i += [(a_addr, b_addr-2)]
73  for a, b in i.intervals:
74  #print hex(a), hex(b)
75  vm.add_memory_page(a, PAGE_READ | PAGE_WRITE, "\x00"*(b+2-a))
76 
77 
78  for r_vaddr, data in all_data.items():
79  vm.set_mem(r_vaddr, data)
80  return e

Variable Documentation

dictionary miasm2.jitter.loader.elf.ELF_machine
Initial value:
1 = {(elf_csts.EM_ARM, 32, elf_csts.ELFDATA2LSB): "arml",
2  (elf_csts.EM_ARM, 32, elf_csts.ELFDATA2MSB): "armb",
3  (elf_csts.EM_AARCH64, 64, elf_csts.ELFDATA2LSB): "aarch64l",
4  (elf_csts.EM_AARCH64, 64, elf_csts.ELFDATA2MSB): "aarch64b",
5  (elf_csts.EM_MIPS, 32, elf_csts.ELFDATA2MSB): "mips32b",
6  (elf_csts.EM_MIPS, 32, elf_csts.ELFDATA2LSB): "mips32l",
7  (elf_csts.EM_386, 32, elf_csts.ELFDATA2LSB): "x86_32",
8  (elf_csts.EM_X86_64, 64, elf_csts.ELFDATA2LSB): "x86_64",
9  (elf_csts.EM_SH, 32, elf_csts.ELFDATA2LSB): "sh4",
10  }

Definition at line 86 of file elf.py.

tuple miasm2.jitter.loader.elf.hnd = logging.StreamHandler()

Definition at line 15 of file elf.py.

tuple miasm2.jitter.loader.elf.log = logging.getLogger('loader_elf')

Definition at line 14 of file elf.py.