about summary refs log tree commit diff stats
path: root/miasm2/analysis/mem.py
diff options
context:
space:
mode:
authorFlorent Monjalet <florent.monjalet@gmail.com>2015-11-24 17:12:25 +0100
committerFlorent Monjalet <florent.monjalet@gmail.com>2016-01-18 14:02:31 +0100
commitd4b88ab3d84dafeac7b8b1592e4ddaef3df00dbe (patch)
tree6c48a13c7cebda5366da570a731af9c784029b4c /miasm2/analysis/mem.py
parent9f824878c99d9761f25178b00ca009691697bbe9 (diff)
downloadmiasm-d4b88ab3d84dafeac7b8b1592e4ddaef3df00dbe.tar.gz
miasm-d4b88ab3d84dafeac7b8b1592e4ddaef3df00dbe.zip
MemStruct: all MemField __hash__
Diffstat (limited to '')
-rw-r--r--miasm2/analysis/mem.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/miasm2/analysis/mem.py b/miasm2/analysis/mem.py
index ce389f89..da12f5ba 100644
--- a/miasm2/analysis/mem.py
+++ b/miasm2/analysis/mem.py
@@ -259,6 +259,9 @@ class Struct(MemField):
     def __eq__(self, other):
         return self.__class__ == other.__class__ and self._fmt == other._fmt
 
+    def __hash__(self):
+        return hash(hash(self.__class__) + hash(self._fmt))
+
 
 class Num(Struct):
     """Represents a number (integer or float). The number is encoded with
@@ -351,6 +354,10 @@ class Ptr(Num):
                 self._type_args == other._type_args and \
                 self._type_kwargs == other._type_kwargs
 
+    def __hash__(self):
+        return hash(super(Ptr, self).__hash__() + hash(self._dst_type) +
+                hash(self._type_args) + hash(self._type_kwargs))
+
 
 class Inline(MemField):
     """Field used to inline a MemStruct in another MemStruct. Equivalent to
@@ -399,6 +406,10 @@ class Inline(MemField):
                 self._type_args == other._type_args and \
                 self._type_kwargs == other._type_kwargs
 
+    def __hash__(self):
+        return hash(hash(self.__class__) + hash(self._il_type) +
+                hash(self._type_args) + hash(self._type_kwargs))
+
 
 class Array(MemField):
     """A fixed size array (contiguous sequence) of a MemField subclass
@@ -459,6 +470,10 @@ class Array(MemField):
                 self.field_type == other.field_type and \
                 self.array_len == other.array_len
 
+    def __hash__(self):
+        return hash(hash(self.__class__) + hash(self.field_type) +
+                hash(self.array_len))
+
 
 class Union(MemField):
     """Allows to put multiple fields at the same offset in a MemStruct, similar
@@ -505,6 +520,9 @@ class Union(MemField):
         return self.__class__ == other.__class__ and \
                 self.field_list == other.field_list
 
+    def __hash__(self):
+        return hash(hash(self.__class__) + hash(self.field_list))
+
 
 class Bits(MemField):
     """Helper class for BitField, not very useful on its own. Represents some
@@ -565,6 +583,10 @@ class Bits(MemField):
                 self._num == other._num and self._bits == other._bits and \
                 self._bit_offset == other._bit_offset
 
+    def __hash__(self):
+        return hash(hash(self.__class__) + hash(self._num) + hash(self._bits) +
+                hash(self._bit_offset))
+
 
 class BitField(Union):
     """A C-like bitfield.
@@ -617,6 +639,9 @@ class BitField(Union):
         return self.__class__ == other.__class__ and \
                 self._num == other._num and super(BitField, self).__eq__(other)
 
+    def __hash__(self):
+        return hash(super(BitField, self).__hash__() + hash(self._num))
+
 
 # MemStruct classes