From 15c635b873105eda2861430d062ea3f6bdfe9d9b Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 1 Aug 2025 17:02:14 -0400 Subject: Use log_error_for_exception in the Python API to pass tracebacks in the stack trace associated with log messages, instead of creating large mutli-line messages for every exception --- python/plugin.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'python/plugin.py') diff --git a/python/plugin.py b/python/plugin.py index 761591e5..c2d25948 100644 --- a/python/plugin.py +++ b/python/plugin.py @@ -35,7 +35,7 @@ from . import lowlevelil from . import mediumlevelil from .project import Project from .enums import PluginCommandType -from .log import log_error +from .log import log_error_for_exception class PluginCommandContext: @@ -147,7 +147,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) action(view_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._default_action") @staticmethod def _address_action(view, addr, action): @@ -156,7 +156,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) action(view_obj, addr) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._address_action") @staticmethod def _range_action(view, addr, length, action): @@ -165,7 +165,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) action(view_obj, addr, length) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._range_action") @staticmethod def _function_action(view, func, action): @@ -175,7 +175,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) action(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._function_action") @staticmethod def _low_level_il_function_action(view, func, action): @@ -186,7 +186,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) action(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._low_level_il_function_action") @staticmethod def _low_level_il_instruction_action(view, func, instr, action): @@ -197,7 +197,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) action(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._low_level_il_instruction_action") @staticmethod def _medium_level_il_function_action(view, func, action): @@ -210,7 +210,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): ) action(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._medium_level_il_function_action") @staticmethod def _medium_level_il_instruction_action(view, func, instr, action): @@ -223,7 +223,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): ) action(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._medium_level_il_instruction_action") @staticmethod def _high_level_il_function_action(view, func, action): @@ -234,7 +234,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = highlevelil.HighLevelILFunction(owner.arch, core.BNNewHighLevelILFunctionReference(func), owner) action(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._high_level_il_function_action") @staticmethod def _high_level_il_instruction_action(view, func, instr, action): @@ -245,7 +245,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = highlevelil.HighLevelILFunction(owner.arch, core.BNNewHighLevelILFunctionReference(func), owner) action(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._high_level_il_instruction_action") @staticmethod def _project_action(project, action): @@ -253,7 +253,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): project_obj = Project(handle=core.BNNewProjectReference(project)) action(project_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._project_action") @staticmethod def _default_is_valid(view, is_valid): @@ -264,7 +264,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) return is_valid(view_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._default_is_valid") return False @staticmethod @@ -276,7 +276,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) return is_valid(view_obj, addr) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._address_is_valid") return False @staticmethod @@ -288,7 +288,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view)) return is_valid(view_obj, addr, length) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._range_is_valid") return False @staticmethod @@ -301,7 +301,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) return is_valid(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._function_is_valid") return False @staticmethod @@ -315,7 +315,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._low_level_il_function_is_valid") return False @staticmethod @@ -331,7 +331,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._low_level_il_instruction_is_valid") return False @staticmethod @@ -347,7 +347,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): ) return is_valid(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._medium_level_il_function_is_valid") return False @staticmethod @@ -365,7 +365,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): ) return is_valid(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._medium_level_il_instruction_is_valid") return False @staticmethod @@ -379,7 +379,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = highlevelil.HighLevelILFunction(owner.arch, core.BNNewHighLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._high_level_il_function_is_valid") return False @staticmethod @@ -395,7 +395,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = highlevelil.HighLevelILFunction(owner.arch, core.BNNewHighLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj[instr]) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._high_level_il_instruction_is_valid") return False @staticmethod @@ -406,7 +406,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): project_obj = Project(handle=core.BNNewProjectReference(project)) return is_valid(project_obj) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in PluginCommand._project_is_valid") return False @classmethod @@ -1041,7 +1041,7 @@ class MainThreadActionHandler: try: self.add_action(MainThreadAction(action)) except: - log_error(traceback.format_exc()) + log_error_for_exception("Unhandled Python exception in MainThreadActionHandler._add_action") def add_action(self, action): pass -- cgit v1.3.1