diff options
| author | Florent Monjalet <florent.monjalet@gmail.com> | 2015-11-24 19:14:23 +0100 |
|---|---|---|
| committer | Florent Monjalet <florent.monjalet@gmail.com> | 2016-01-18 14:02:31 +0100 |
| commit | 82fa0e423f7f3f0d33c7ca9b32029d0022c31dec (patch) | |
| tree | 44c9ff025aa6737ee17296a65d967aa6a061a2e7 | |
| parent | 7192718eeba19d4b96f8cd59d31d8b0c865cc67c (diff) | |
| download | miasm-82fa0e423f7f3f0d33c7ca9b32029d0022c31dec.tar.gz miasm-82fa0e423f7f3f0d33c7ca9b32029d0022c31dec.zip | |
MemStruct: Fix MemStruct __eq__
| -rw-r--r-- | example/jitter/memstruct.py | 2 | ||||
| -rw-r--r-- | miasm2/analysis/mem.py | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/example/jitter/memstruct.py b/example/jitter/memstruct.py index f2e9f8dc..775b3643 100644 --- a/example/jitter/memstruct.py +++ b/example/jitter/memstruct.py @@ -184,7 +184,7 @@ assert link.size == 2 # Make the Array Ptr point to the data's array field data.arrayptr = data.get_addr("array") # Now the pointer dereference is equal to the array field's value -assert data.deref_arrayptr == data.array +assert data.deref_arrayptr.value == data.array # Let's say that it is a DataStr: datastr = data.cast(DataStr) diff --git a/miasm2/analysis/mem.py b/miasm2/analysis/mem.py index 2e52ec1a..86db0fc5 100644 --- a/miasm2/analysis/mem.py +++ b/miasm2/analysis/mem.py @@ -875,11 +875,7 @@ class MemStruct(object): return '%r:\n' % self.__class__ + indent('\n'.join(out), 2) def __eq__(self, other): - # Do not test class equality, because of dynamically generated fields - # self.__class__ == other.__class__ and - # Could test attrs? - # TODO: self._attrs == other._attrs and - return str(self) == str(other) + return self.__class__ == other.__class__ and str(self) == str(other) def __ne__(self, other): return not self == other @@ -1216,6 +1212,13 @@ class MemSizedArray(MemArray): items = ', '.join(item_reprs) return "[%s] [%r; %s]" % (items, self._field_type, self._array_len) + def __eq__(self, other): + # Special implementation to handle dynamic subclasses + return isinstance(other, MemSizedArray) and \ + self._field_type == other._field_type and \ + self._array_len == other._array_len and \ + str(self) == str(other) + def mem_array_type(field_type): """Generate a MemArray subclass that has a fixed @field_type. It allows to |