From 955595f40dfa7a8bb246050dd3bbb5a4ecb67f0e Mon Sep 17 00:00:00 2001 From: Florent Monjalet Date: Thu, 26 Nov 2015 14:19:34 +0100 Subject: MemStruct: MemSelf usage fix --- miasm2/analysis/mem.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'miasm2') diff --git a/miasm2/analysis/mem.py b/miasm2/analysis/mem.py index 006fecd0..dbfd335a 100644 --- a/miasm2/analysis/mem.py +++ b/miasm2/analysis/mem.py @@ -314,7 +314,13 @@ class Ptr(Num): if isinstance(dst_type, MemField): # Patch the field to propagate the MemSelf replacement dst_type._get_self_type = lambda: self._get_self_type() - dst_type = mem(dst_type) + # dst_type cannot be patched here, since _get_self_type of the outer + # class has not yet been set. Patching dst_type involves calling + # mem(dst_type), which will only return a type that does not point + # on MemSelf but on the right class only when _get_self_type of the + # outer class has been replaced by _MetaMemStruct. + # In short, dst_type = mem(dst_type) is not valid here, it is done + # lazily in _fix_dst_type self._dst_type = dst_type self._type_args = type_args self._type_kwargs = type_kwargs @@ -325,6 +331,8 @@ class Ptr(Num): self._dst_type = self._get_self_type() else: raise ValueError("Unsupported usecase for MemSelf, sorry") + if isinstance(self._dst_type, MemField): + self._dst_type = mem(self._dst_type) @property def dst_type(self): -- cgit 1.4.1