From 2cb81a1d1d4384dcb129ca0c05f15d56cfff3408 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Fri, 16 Aug 2019 20:28:04 -0400 Subject: add hash method for RegisterValue, MediumLevelILOperationAndSize, and MediumLevelILInstruction --- python/function.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'python/function.py') diff --git a/python/function.py b/python/function.py index 2f89c799..0bac5e23 100644 --- a/python/function.py +++ b/python/function.py @@ -112,10 +112,18 @@ class RegisterValue(object): return "" % self._value return "" + def __hash__(self): + if self._type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue, RegisterValueType.ImportedAddressValue, RegisterValueType.ReturnAddressValue]: + return hash(self._value) + elif self.type == RegisterValueType.EntryValue: + return hash(self._reg) + elif self._type == RegisterValueType.StackFrameOffset: + return hash(self._offset) + def __eq__(self, other): - if self._type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue, ImportedAddressValue, ReturnAddressValue] and isinstance(other, numbers.Integral): + if self._type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue, RegisterValueType.ImportedAddressValue, RegisterValueType.ReturnAddressValue] and isinstance(other, numbers.Integral): return self._value == other - elif self._type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue, ImportedAddressValue, ReturnAddressValue] and hasattr(other, 'type') and other.type == self._type: + elif self._type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue, RegisterValueType.ImportedAddressValue, RegisterValueType.ReturnAddressValue] and hasattr(other, 'type') and other.type == self._type: return self._value == other.value elif self._type == RegisterValueType.EntryValue and hasattr(other, "type") and other.type == self._type: return self._reg == other.reg -- cgit v1.3.1