Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add layout mapping API for external plugins #1093

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4550,6 +4550,27 @@ def pane_title():
gef.gdb.add_context_pane(pane_name, display_pane_function, pane_title_function, condition)
return

def register_external_context_layout_mapping(current_pane_name: str, display_pane_function: Callable[[], None], pane_title_function: Callable[[], Optional[str]], condition : Optional[Callable[[], bool]] = None) -> None:
"""
Registering function for new GEF Context View.
current_pane_name: a previously registered (in "layout") pane name.
display_pane_function: a function that uses gef_print() to print strings
pane_title_function: a function that returns a string or None, which will be displayed as the title.
If None, no title line is displayed.
condition: an optional callback: if not None, the callback will be executed first. If it returns true,
then only the pane title and content will displayed. Otherwise, it's simply skipped.

Example usage for a simple text to show when we hit a syscall:
def only_syscall(): return gef_current_instruction(gef.arch.pc).is_syscall()
def display_pane():
gef_print("Wow, I am a context pane!")
def pane_title():
return "example:pane"
register_external_context_pane("example_pane", display_pane, pane_title, only_syscall)
therealdreg marked this conversation as resolved.
Show resolved Hide resolved
"""
gef.gdb.add_context_layout_mapping(current_pane_name, display_pane_function, pane_title_function, condition)
return


#
# Commands
Expand Down Expand Up @@ -9836,6 +9857,14 @@ def invoke(self, args: Any, from_tty: bool) -> None:
gdb.execute("gef help")
return

def add_context_layout_mapping(self, current_pane_name: str, display_pane_function: Callable, pane_title_function: Callable, condition: Optional[Callable]) -> None:
"""Add a new context layout mapping."""
context = self.commands["context"]
assert isinstance(context, ContextCommand)

# overload the printing of pane title
context.layout_mapping[current_pane_name] = (display_pane_function, pane_title_function, condition)

def add_context_pane(self, pane_name: str, display_pane_function: Callable, pane_title_function: Callable, condition: Optional[Callable]) -> None:
"""Add a new context pane to ContextCommand."""
context = self.commands["context"]
Expand All @@ -9845,8 +9874,7 @@ def add_context_pane(self, pane_name: str, display_pane_function: Callable, pane
corrected_settings_name: str = pane_name.replace(" ", "_")
gef.config["context.layout"] += f" {corrected_settings_name}"

# overload the printing of pane title
context.layout_mapping[corrected_settings_name] = (display_pane_function, pane_title_function, condition)
add_context_layout_mapping(corrected_settings_name, display_pane_function, pane_title_function, condition)

def load(self) -> None:
"""Load all the commands and functions defined by GEF into GDB."""
Expand Down
Loading