about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/core/locationdb.py16
-rw-r--r--miasm2/jitter/loader/elf.py14
2 files changed, 30 insertions, 0 deletions
diff --git a/miasm2/core/locationdb.py b/miasm2/core/locationdb.py
index 6655f8ac..4c5da29e 100644
--- a/miasm2/core/locationdb.py
+++ b/miasm2/core/locationdb.py
@@ -204,6 +204,22 @@ class LocationDB(object):
         for name, loc_key in self._name_to_loc_key.iteritems():
             assert name in self._loc_key_to_names[loc_key]
 
+    def find_free_name(self, name):
+        """
+        If @name is not known in DB, return it
+        Else append an index to it corresponding to the next unknown name
+
+        @name: string
+        """
+        if self.get_name_location(name) is None:
+            return name
+        i = 0
+        while True:
+            new_name = "%s_%d" % (name, i)
+            if self.get_name_location(new_name) is None:
+                return new_name
+            i += 1
+
     def add_location(self, name=None, offset=None, strict=True):
         """Add a new location in the locationDB. Returns the corresponding LocKey.
         If @name is set, also associate a name to this new location.
diff --git a/miasm2/jitter/loader/elf.py b/miasm2/jitter/loader/elf.py
index b94a9309..17041372 100644
--- a/miasm2/jitter/loader/elf.py
+++ b/miasm2/jitter/loader/elf.py
@@ -65,6 +65,20 @@ def fill_loc_db_with_symbols(elf, loc_db, base_addr=0):
     # Get symbol sections
     symbol_sections = []
     for section_header in elf.sh:
+        if hasattr(section_header, 'symbols'):
+            for name, sym in section_header.symbols.iteritems():
+                if not name or sym.value == 0:
+                    continue
+                name = loc_db.find_free_name(name)
+                loc_db.add_location(name, sym.value, strict=False)
+
+        if hasattr(section_header, 'reltab'):
+            for rel in section_header.reltab:
+                if not rel.sym or rel.offset == 0:
+                    continue
+                name = loc_db.find_free_name(rel.sym)
+                loc_db.add_location(name, rel.offset, strict=False)
+
         if hasattr(section_header, 'symtab'):
             log.debug("Find %d symbols in %r", len(section_header.symtab),
                       section_header)