Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
miasm2.analysis.binary.ContainerELF Class Reference
+ Inheritance diagram for miasm2.analysis.binary.ContainerELF:
+ Collaboration diagram for miasm2.analysis.binary.ContainerELF:

Public Member Functions

def parse
 
def from_string
 
def register_container
 
def register_fallback
 
def from_stream
 
def parse
 
def bin_stream
 
def executable
 
def entry_point
 
def arch
 

Static Public Attributes

list available_container = []
 
 fallback_container = None
 

Private Attributes

 _executable
 
 _arch
 
 _bin_stream
 
 _entry_point
 

Detailed Description

Definition at line 159 of file binary.py.

Member Function Documentation

def miasm2.analysis.binary.Container.arch (   self)
inherited

Definition at line 116 of file binary.py.

117  def arch(self):
118  "Return the guessed architecture"
119  return self._arch
120 
def miasm2.analysis.binary.Container.bin_stream (   self)
inherited

Definition at line 101 of file binary.py.

102  def bin_stream(self):
103  "Return the BinStream instance corresponding to container content"
104  return self._bin_stream
def miasm2.analysis.binary.Container.entry_point (   self)
inherited

Definition at line 111 of file binary.py.

112  def entry_point(self):
113  "Return the detected entry_point"
114  return self._entry_point
def miasm2.analysis.binary.Container.executable (   self)
inherited

Definition at line 106 of file binary.py.

107  def executable(self):
108  "Return the abstract instance standing for parsed executable"
109  return self._executable
def miasm2.analysis.binary.Container.from_stream (   cls,
  stream,
  args,
  kwargs 
)
inherited
Instanciate a container and parse the binary
@stream: stream to use as binary
@vm: (optional) VmMngr instance to link with the executable
@addr: (optional) Shift to apply before parsing the binary. If set,
       force the unknown format

Definition at line 76 of file binary.py.

76 
77  def from_stream(cls, stream, *args, **kwargs):
78  """Instanciate a container and parse the binary
79  @stream: stream to use as binary
80  @vm: (optional) VmMngr instance to link with the executable
81  @addr: (optional) Shift to apply before parsing the binary. If set,
82  force the unknown format
83  """
84  return Container.from_string(stream.read(), *args, **kwargs)
def miasm2.analysis.binary.Container.from_string (   cls,
  data,
  vm = None,
  addr = None 
)
inherited
Instanciate a container and parse the binary
@data: str containing the binary
@vm: (optional) VmMngr instance to link with the executable
@addr: (optional) Base address for the binary. If set,
       force the unknown format

Definition at line 36 of file binary.py.

36 
37  def from_string(cls, data, vm=None, addr=None):
38  """Instanciate a container and parse the binary
39  @data: str containing the binary
40  @vm: (optional) VmMngr instance to link with the executable
41  @addr: (optional) Base address for the binary. If set,
42  force the unknown format
43  """
44  log.info('Load binary')
45 
46  if not addr:
47  addr = 0
48  else:
49  # Force fallback mode
50  log.warning('Fallback to string input (offset=%s)', hex(addr))
51  return cls.fallback_container(data, vm, addr)
52 
53  # Try each available format
54  for container_type in cls.available_container:
55  try:
56  return container_type(data, vm)
57  except ContainerSignatureException:
58  continue
59  except ContainerParsingException, error:
60  log.error(error)
61 
62  # Fallback mode
63  log.warning('Fallback to string input (offset=%s)', hex(addr))
64  return cls.fallback_container(data, vm, addr)
def miasm2.analysis.binary.Container.parse (   self,
  data,
  args,
  kwargs 
)
inherited

Definition at line 85 of file binary.py.

85 
86  def parse(self, data, *args, **kwargs):
87  "Launch parsing of @data"
88  raise NotImplementedError("Abstract method")
def miasm2.analysis.binary.ContainerELF.parse (   self,
  data,
  vm = None 
)

Definition at line 162 of file binary.py.

163  def parse(self, data, vm=None):
164  from miasm2.jitter.loader.elf import \
165  vm_load_elf, preload_elf, guess_arch
166  from elfesteem import elf_init
167 
168  # Parse signature
169  if not data.startswith('\x7fELF'):
171 
172  # Build executable instance
173  try:
174  if vm is not None:
175  self._executable = vm_load_elf(vm, data)
176  else:
177  self._executable = elf_init.ELF(data)
178  except Exception, error:
179  raise ContainerParsingException('Cannot read ELF: %s' % error)
180 
181  # Guess the architecture
182  self._arch = guess_arch(self._executable)
183 
184  # Build the bin_stream instance and set the entry point
185  try:
186  self._bin_stream = bin_stream_elf(self._executable.virt)
187  self._entry_point = self._executable.Ehdr.entry
188  except Exception, error:
189  raise ContainerParsingException('Cannot read ELF: %s' % error)
190 
def miasm2.analysis.binary.Container.register_container (   cls,
  container 
)
inherited

Definition at line 66 of file binary.py.

66 
67  def register_container(cls, container):
68  "Add a Container format"
69  cls.available_container.append(container)
def miasm2.analysis.binary.Container.register_fallback (   cls,
  container 
)
inherited

Definition at line 71 of file binary.py.

71 
72  def register_fallback(cls, container):
73  "Set the Container fallback format"
74  cls.fallback_container = container

Member Data Documentation

miasm2.analysis.binary.ContainerELF._arch
private

Definition at line 181 of file binary.py.

miasm2.analysis.binary.ContainerELF._bin_stream
private

Definition at line 185 of file binary.py.

miasm2.analysis.binary.ContainerELF._entry_point
private

Definition at line 186 of file binary.py.

miasm2.analysis.binary.ContainerELF._executable
private

Definition at line 174 of file binary.py.

list miasm2.analysis.binary.Container.available_container = []
staticinherited

Definition at line 32 of file binary.py.

miasm2.analysis.binary.Container.fallback_container = None
staticinherited

Definition at line 33 of file binary.py.


The documentation for this class was generated from the following file: