about summary refs log tree commit diff stats
path: root/miasm2/core
diff options
context:
space:
mode:
authorCamille Mougey <commial@gmail.com>2019-02-11 11:19:35 +0100
committerGitHub <noreply@github.com>2019-02-11 11:19:35 +0100
commitd73460dd09302b1a272ad7e3e2cfd1c7cf0bf86c (patch)
tree4c39812adebc319b1e1841b0eaa2dbfc45719a9e /miasm2/core
parent1d42f745d930d21fdc64d1a7689fae2d5e926909 (diff)
parentc22769c31f7fb7ecfdfd952757eb37d4d7e5dfbd (diff)
downloadmiasm-d73460dd09302b1a272ad7e3e2cfd1c7cf0bf86c.tar.gz
miasm-d73460dd09302b1a272ad7e3e2cfd1c7cf0bf86c.zip
Merge pull request #953 from serpilliere/elf_add_sym
Elf add sym
Diffstat (limited to 'miasm2/core')
-rw-r--r--miasm2/core/locationdb.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/miasm2/core/locationdb.py b/miasm2/core/locationdb.py
index b6e60794..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.
@@ -252,7 +268,10 @@ class LocationDB(object):
             # Non-strict mode
             if name_loc_key is not None:
                 known_offset = self.get_offset_location(name_loc_key)
-                if known_offset != offset:
+                if known_offset is None:
+                    if offset is not None:
+                        self.set_location_offset(name_loc_key, offset)
+                elif known_offset != offset:
                     raise ValueError(
                         "Location with name '%s' already have an offset: 0x%x "
                         "(!= 0x%x)" % (name, offset, known_offset)