Skip to content

Commit

Permalink
Feature: detect the launching of a decompiler (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz authored Nov 4, 2024
1 parent 53fa676 commit 0e0f35b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/change_watcher_plugin/bs_change_watcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def create_plugin(*args, **kwargs):
FunctionHeader, StackVariable, Enum, Struct, GlobalVariable, Comment, Context
)

decompiler_started_event_callbacks = [lambda *x, **y: print(f"[BSChangeWatcher] Started with plugin version {__version__}")]
deci = DecompilerInterface.discover(
plugin_name="ArtifactChangeWatcher",
init_plugin=True,
decompiler_started_callbacks=decompiler_started_event_callbacks,
gui_init_args=args,
gui_init_kwargs=kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion libbs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.1"
__version__ = "2.3.0"


import logging
Expand Down
9 changes: 9 additions & 0 deletions libbs/api/decompiler_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(
# [artifact_class] = list(callback_func)
artifact_change_callbacks: Optional[Dict[Type[Artifact], List[Callable]]] = None,
undo_event_callbacks: Optional[List[Callable]] = None,
decompiler_started_callbacks: Optional[List[Callable]] = None,
thread_artifact_callbacks: bool = True,
):
self.name = name
Expand Down Expand Up @@ -89,6 +90,7 @@ def __init__(
# callback functions, keyed by Artifact class
self.artifact_change_callbacks = artifact_change_callbacks or defaultdict(list)
self.undo_event_callbacks = undo_event_callbacks or []
self.decompiler_started_callbacks = decompiler_started_callbacks or []
self._thread_artifact_callbacks = thread_artifact_callbacks

# artifact dict aliases:
Expand Down Expand Up @@ -633,6 +635,13 @@ def _set_function_header(self, fheader: FunctionHeader, **kwargs) -> bool:
# lift it ONCE inside this function. Each one will return the lifted form, for easier overriding.
#

def decompiler_started_event(self, **kwargs):
for callback_func in self.decompiler_started_callbacks:
if self._thread_artifact_callbacks:
threading.Thread(target=callback_func, kwargs=kwargs, daemon=True).start()
else:
callback_func(**kwargs)

def gui_undo_event(self, **kwargs):
for callback_func in self.undo_event_callbacks:
if self._thread_artifact_callbacks:
Expand Down
1 change: 1 addition & 0 deletions libbs/decompilers/ida/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _init_gui_hooks(self):
hook.hook()

def _init_gui_plugin(self, *args, **kwargs):
self.decompiler_started_event()
plugin_cls_name = self._plugin_name + "_cls"
IDAPluginCls = compat.generate_generic_ida_plugic_cls(cls_name=plugin_cls_name)
return IDAPluginCls(*args, name=self._plugin_name, interface=self, **kwargs)
Expand Down

0 comments on commit 0e0f35b

Please sign in to comment.