diff options
| author | Brandon Miller <brandon@vector35.com> | 2025-04-07 11:00:27 -0400 |
|---|---|---|
| committer | Brandon Miller <brandon@vector35.com> | 2025-04-07 15:52:27 -0400 |
| commit | bb2b80d9b09f67859081ff3cd30d118c9d0372f5 (patch) | |
| tree | a30c4780d9c6b0f2f28a75051f2142650a8a2f50 /python | |
| parent | 34e464b40adee31b9247d40435340767b360319c (diff) | |
Return None instead of raising in func IL getters
Return None instead of raising an ILException in Python Function.llil,
mlil, etc to allow these properties to play nice with map and filter
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 12 | ||||
| -rw-r--r-- | python/function.py | 43 |
2 files changed, 20 insertions, 35 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 250d69ab..b0ca13ef 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -47,7 +47,7 @@ from .enums import ( TypeClass, BinaryViewEventType, FunctionGraphType, TagReferenceType, TagTypeType, RegisterValueType, DisassemblyOption, RelocationType ) -from .exceptions import RelocationWriteException, ILException, ExternalLinkException +from .exceptions import RelocationWriteException, ExternalLinkException from . import associateddatastore # required for _BinaryViewAssociatedDataStore from .log import log_warn, log_error, Logger @@ -3181,10 +3181,7 @@ class BinaryView: for func in AdvancedILFunctionList( self, self.preload_limit if preload_limit is None else preload_limit, function_generator ): - try: - yield func.mlil - except ILException: - pass + yield func.mlil def hlil_functions( self, preload_limit: Optional[int] = None, @@ -3197,10 +3194,7 @@ class BinaryView: for func in AdvancedILFunctionList( self, self.preload_limit if preload_limit is None else preload_limit, function_generator ): - try: - yield func.hlil - except ILException: - pass + yield func.hlil @property def has_functions(self) -> bool: diff --git a/python/function.py b/python/function.py index 79bbb753..6d20359a 100644 --- a/python/function.py +++ b/python/function.py @@ -31,7 +31,6 @@ from .enums import ( HighlightColorStyle, DisassemblyOption, IntegerDisplayType, FunctionAnalysisSkipOverride, FunctionUpdateType, BuiltinType ) -from .exceptions import ILException from . import associateddatastore # Required in the main scope due to being an argument for _FunctionAssociatedDataStore from . import types @@ -981,7 +980,6 @@ class Function: """ returns LowLevelILFunction used to represent Function low level IL (read-only) - :raises ILException: if the low level IL could not be loaded :rtype: lowlevelil.LowLevelILFunction """ return self.llil @@ -989,14 +987,14 @@ class Function: @property def llil(self) -> 'lowlevelil.LowLevelILFunction': """ - returns LowLevelILFunction used to represent Function low level IL (read-only) + returns LowLevelILFunction used to represent Function low level IL, or None if an error occurs while loading + the IL (read-only) - :raises ILException: if the low level IL could not be loaded :rtype: lowlevelil.LowLevelILFunction """ result = core.BNGetFunctionLowLevelIL(self.handle) if not result: - raise ILException(f"Low level IL was not loaded for {self!r}") + return None return lowlevelil.LowLevelILFunction(self.arch, result, self) @property @@ -1010,14 +1008,14 @@ class Function: @property def lifted_il(self) -> 'lowlevelil.LowLevelILFunction': """ - returns LowLevelILFunction used to represent Function lifted IL (read-only) + returns LowLevelILFunction used to represent Function lifted IL, or None if an error occurs while loading the IL + (read-only) - :raises ILException: if the lifted IL could not be loaded :rtype: lowlevelil.LowLevelILFunction """ result = core.BNGetFunctionLiftedIL(self.handle) if not result: - raise ILException(f"Lifted IL was not loaded for {self!r}") + return None return lowlevelil.LowLevelILFunction(self.arch, result, self) @property @@ -1033,7 +1031,6 @@ class Function: """ returns MediumLevelILFunction used to represent Function medium level IL (read-only) - :raises ILException: if the medium level IL could not be loaded :rtype: mediumlevelil.MediumLevelILFunction """ return self.mlil @@ -1041,14 +1038,14 @@ class Function: @property def mlil(self) -> 'mediumlevelil.MediumLevelILFunction': """ - returns MediumLevelILFunction used to represent Function medium level IL (read-only) + returns MediumLevelILFunction used to represent Function medium level IL, or None if an error occurs while + loading the IL (read-only) - :raises ILException: if the medium level IL could not be loaded :rtype: mediumlevelil.MediumLevelILFunction """ result = core.BNGetFunctionMediumLevelIL(self.handle) if not result: - raise ILException(f"Medium level IL was not loaded for {self!r}") + return None return mediumlevelil.MediumLevelILFunction(self.arch, result, self) @property @@ -1062,14 +1059,14 @@ class Function: @property def mmlil(self) -> 'mediumlevelil.MediumLevelILFunction': """ - returns MediumLevelILFunction used to represent Function mapped medium level IL (read-only) + returns MediumLevelILFunction used to represent Function mapped medium level IL, or None if an error occurs + while loading the IL (read-only) - :raises ILException: if the mapped medium level IL could not be loaded :rtype: mediumlevelil.MediumLevelILFunction """ result = core.BNGetFunctionMappedMediumLevelIL(self.handle) if not result: - raise ILException(f"Mapped medium level IL was not loaded for {self!r}") + return None return mediumlevelil.MediumLevelILFunction(self.arch, result, self) @property @@ -1077,7 +1074,6 @@ class Function: """ returns MediumLevelILFunction used to represent Function mapped medium level IL (read-only) - :raises ILException: if the mapped medium level IL could not be loaded :rtype: mediumlevelil.MediumLevelILFunction """ return self.mmlil @@ -1095,7 +1091,6 @@ class Function: """ returns HighLevelILFunction used to represent Function high level IL (read-only) - :raises ILException: if the high level IL could not be loaded :rtype: highlevelil.HighLevelILFunction """ return self.hlil @@ -1103,14 +1098,14 @@ class Function: @property def hlil(self) -> 'highlevelil.HighLevelILFunction': """ - returns HighLevelILFunction used to represent Function high level IL (read-only) + returns HighLevelILFunction used to represent Function high level IL, or None if an error occurs while loading + the IL (read-only) - :raises ILException: if the high level IL could not be loaded :rtype: highlevelil.HighLevelILFunction """ result = core.BNGetFunctionHighLevelIL(self.handle) if not result: - raise ILException(f"High level IL was not loaded for {self!r}") + return None return highlevelil.HighLevelILFunction(self.arch, result, self) @property @@ -1800,12 +1795,8 @@ class Function: idx = core.BNGetLowLevelILForInstruction(self.handle, arch.handle, addr) - try: - llil = self.llil - except ILException: - return None - - if idx == len(llil): + llil = self.llil + if llil is None or idx == len(llil): return None return llil[idx] |
