-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement BugHouse components plugin. (#179)
Also with the following improvements: - Plugins now support headless mode. - URL scheme handling now only requires implementing a single handler (instead of three).
- Loading branch information
Showing
23 changed files
with
659 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ class GlobalInfo: | |
main_window = None | ||
daemon_inst = None | ||
daemon_conn = None | ||
headless_plugin_manager = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .components import ComponentsPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from typing import Optional | ||
|
||
from angrmanagement.logic.threads import is_gui_thread, gui_thread_schedule_async | ||
from angrmanagement.plugins.base_plugin import BasePlugin | ||
|
||
from .ui import LoadComponentsDialog, ComponentsView | ||
|
||
|
||
class ComponentsPlugin(BasePlugin): | ||
REQUIRE_WORKSPACE = False | ||
|
||
""" | ||
Implement a component viewer that takes JSON messages on function clustering from the server side and visualizes | ||
the clusters in a treeview. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
if self.workspace is not None: | ||
self.view: ComponentsView = ComponentsView(self.workspace, "left") | ||
|
||
# register a new view | ||
self.workspace.view_manager.add_view(self.view, self.view.caption, self.view.category) | ||
|
||
def teardown(self): | ||
pass | ||
|
||
# | ||
# Menus | ||
# | ||
|
||
MENU_BUTTONS = [ | ||
'Load components...', | ||
'Reset components', | ||
] | ||
LOAD_COMPONENTS = 0 | ||
RESET_COMPONENTS = 1 | ||
|
||
def handle_click_menu(self, idx): | ||
|
||
if idx < 0 or idx >= len(self.MENU_BUTTONS): | ||
return | ||
|
||
if self.workspace.instance.project is None: | ||
return | ||
|
||
mapping = { | ||
self.LOAD_COMPONENTS: self.load_components, | ||
self.RESET_COMPONENTS: self.reset_components, | ||
} | ||
mapping.get(idx)() | ||
|
||
def load_components(self, url: Optional[str]=None): | ||
""" | ||
Open a new dialog and take a JSON URL or a file path. Then load components from that URL. | ||
""" | ||
dialog = LoadComponentsDialog(workspace=self.workspace, url=url) | ||
dialog.exec_() | ||
if dialog.tree is not None: | ||
self.view.load(dialog.tree) | ||
|
||
def reset_components(self): | ||
""" | ||
Clear existing components information. | ||
""" | ||
self.view.reset() | ||
|
||
# | ||
# URLs | ||
# | ||
|
||
# register actions | ||
URL_ACTIONS = [ | ||
'bughouse_component', | ||
] | ||
|
||
def handle_url_action(self, action, kwargs): | ||
mapping = { | ||
'bughouse_component': self.handle_url_action_bughouse_component, | ||
} | ||
|
||
func = mapping.get(action) | ||
if is_gui_thread(): | ||
func(**kwargs) | ||
else: | ||
gui_thread_schedule_async(func, kwargs=kwargs) | ||
|
||
def handle_url_action_bughouse_component(self, url=None): | ||
self.load_components(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .component_tree import ComponentTreeNode, ComponentTree, ComponentFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import List, Optional | ||
|
||
|
||
class ComponentFunction: | ||
|
||
__slots__ = ('mapped_base', 'virtual_addr', 'symbol_name', ) | ||
|
||
def __init__(self, mapped_base: int, virtual_addr: int, symbol_name: Optional[str]=None): | ||
self.mapped_base = mapped_base | ||
self.virtual_addr = virtual_addr | ||
self.symbol_name = symbol_name | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, ComponentFunction) and \ | ||
self.mapped_base == other.mapped_base and \ | ||
self.virtual_addr == other.virtual_addr | ||
|
||
def __hash__(self): | ||
return hash((ComponentFunction, self.mapped_base, self.virtual_addr)) | ||
|
||
|
||
class ComponentTreeNode: | ||
def __init__(self, name=None): | ||
self.name = name | ||
self.components: List['ComponentTreeNode'] = [ ] | ||
self.functions: List[ComponentFunction] = [ ] | ||
|
||
def __eq__(self, other): | ||
return isinstance(other, ComponentTreeNode) \ | ||
and self.components == other.components \ | ||
and set(self.functions) == set(other.functions) | ||
|
||
def __hash__(self): | ||
return hash((ComponentTreeNode, | ||
hash(tuple(self.components)), | ||
hash(tuple(sorted((f.mapped_base + f.virtual_addr) for f in self.functions))), | ||
) | ||
) | ||
|
||
|
||
class ComponentTree: | ||
def __init__(self, root: Optional[ComponentTreeNode]=None): | ||
self.root = root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .load_components_dialog import LoadComponentsDialog | ||
from .components_treeview import ComponentsView |
Oops, something went wrong.