about summary refs log tree commit diff stats
path: root/miasm2/analysis/binary.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/analysis/binary.py')
-rw-r--r--miasm2/analysis/binary.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/miasm2/analysis/binary.py b/miasm2/analysis/binary.py
index 900d76ab..d47ca884 100644
--- a/miasm2/analysis/binary.py
+++ b/miasm2/analysis/binary.py
@@ -2,6 +2,7 @@ import logging
 
 from miasm2.core.bin_stream import bin_stream_str, bin_stream_elf, bin_stream_pe
 from miasm2.jitter.csts import PAGE_READ
+from miasm2.core.asmbloc import asm_symbol_pool
 
 
 log = logging.getLogger("binary")
@@ -93,6 +94,7 @@ class Container(object):
         self._bin_stream = None
         self._entry_point = None
         self._arch = None
+        self._symbol_pool = asm_symbol_pool()
 
         # Launch parsing
         self.parse(*args, **kwargs)
@@ -117,6 +119,11 @@ class Container(object):
         "Return the guessed architecture"
         return self._arch
 
+    @property
+    def symbol_pool(self):
+        "asm_symbol_pool instance preloaded with container symbols (if any)"
+        return self._symbol_pool
+
 
 ## Format dependent classes
 class ContainerPE(Container):
@@ -186,6 +193,22 @@ class ContainerELF(Container):
         except Exception, error:
             raise ContainerParsingException('Cannot read ELF: %s' % error)
 
+        # Add known symbols
+        symtab = self._executable.getsectionbyname(".symtab")
+        if symtab is not None:
+            for name, symb in symtab.symbols.iteritems():
+                offset = symb.value
+                if offset != 0:
+                    try:
+                        self._symbol_pool.add_label(name, offset)
+                    except ValueError:
+                        # Two symbols points on the same offset
+                        log.warning("Same offset (%s) for %s and %s", (hex(offset),
+                                                                       name,
+                                                                       self._symbol_pool.getby_offset(offset)))
+                        continue
+
+
 
 class ContainerUnknown(Container):
     "Container abstraction for unknown format"