about summary refs log tree commit diff stats
path: root/miasm2/core/utils.py
diff options
context:
space:
mode:
authorCamille Mougey <commial@gmail.com>2016-02-19 17:11:45 +0100
committerCamille Mougey <commial@gmail.com>2016-02-19 17:11:45 +0100
commit55cc4ec75424a841748b62e230a1abb01b258014 (patch)
tree19e7d45234338c20f5c1f9a753c057a4c32e5749 /miasm2/core/utils.py
parent91e9abd906c0a9f5b43bad5b9789ffa1b054f6fe (diff)
parentf242f79868dbd80ea319e2ae97bb44ba11270400 (diff)
downloadmiasm-55cc4ec75424a841748b62e230a1abb01b258014.tar.gz
miasm-55cc4ec75424a841748b62e230a1abb01b258014.zip
Merge pull request #327 from serpilliere/vm_name_area
Vm name area
Diffstat (limited to 'miasm2/core/utils.py')
-rw-r--r--miasm2/core/utils.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/miasm2/core/utils.py b/miasm2/core/utils.py
index 70520c1b..35ddbb82 100644
--- a/miasm2/core/utils.py
+++ b/miasm2/core/utils.py
@@ -13,10 +13,25 @@ pck32 = lambda x: struct.pack('I', x)
 pck64 = lambda x: struct.pack('Q', x)
 
 
-pck = {8:pck8,
-       16:pck16,
-       32:pck32,
-       64:pck64}
+pck = {8: pck8,
+       16: pck16,
+       32: pck32,
+       64: pck64}
+
+
+def get_caller_name(caller_num=0):
+    """Get the nth caller's name
+    @caller_num: 0 = the caller of get_caller_name, 1 = next parent, ..."""
+    pystk = inspect.stack()
+    if len(pystk) > 1 + caller_num:
+        return pystk[1 + caller_num][3]
+    else:
+        return "Bad caller num"
+
+
+def whoami():
+    """Returns the caller's name"""
+    return get_caller_name(1)
 
 
 class Disasm_Exception(Exception):
@@ -48,11 +63,9 @@ class keydefaultdict(collections.defaultdict):
         value = self[key] = self.default_factory(key)
         return value
 
-def whoami():
-    return inspect.stack()[2][3]
-
 
 class BoundedDict(UserDict.DictMixin):
+
     """Limited in size dictionary.
 
     To reduce combinatory cost, once an upper limit @max_size is reached,
@@ -94,7 +107,7 @@ class BoundedDict(UserDict.DictMixin):
                         self._delete_cb(key)
 
                 # Keep only the most @_min_size used
-                self._data = {key:self._data[key]
+                self._data = {key: self._data[key]
                               for key, _ in most_common[:self._min_size - 1]}
                 self._size = self._min_size