add layout mapping API for external plugins (#1093)

## Description

This fixes all the issues with the context panes and it now works as it
did before the plugins were created.

In the GEF part, it was just a minor refactor and a new external API. 

In the gef-extras part, it was only necessary to call this new function!

I think the proposed solution is simple and it works.

Related to hugsy/gef-extras#111
This commit is contained in:
Dreg
2024-04-26 08:35:03 -07:00
committed by GitHub
parent 92f45ba14e
commit 29fb74efa2
3 changed files with 41 additions and 3 deletions
+25
View File
@@ -121,6 +121,31 @@ def register_external_context_pane(
* `condition_callback` (optional): a function that returns a boolean deciding whether this context
pane should be shown
### Context Layout Mapping API
This API is designed for registering a new layout mapping for a GEF Context View. It specifies
the interface for the function register_external_context_layout_mapping which operates similarly
to the previously discussed register_external_context_pane. Pane must have been previously
established in the layout configuration.
```python
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:
```
Registers a new mapping for an existing pane within the GEF Context View.
* `current_pane_name`: the name of an already registered pane in the layout
* `display_pane_function`: a function that prints content in the pane using `gef_print()`
* `pane_title_function`: a function that returns a string to be used as the pane title or
None if no title should be displayed
* `condition`: (optional) a predicate function that must return True for the pane content
and title to be displayed; if it returns False, the pane is skipped
## API
Some of the most important parts of the API for creating new commands are mentioned (but not limited
+13 -2
View File
@@ -4550,6 +4550,10 @@ def register_external_context_pane(pane_name: str, display_pane_function: Callab
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:
gef.gdb.add_context_layout_mapping(current_pane_name, display_pane_function, pane_title_function, condition)
return
#
# Commands
@@ -9836,6 +9840,14 @@ class GefCommand(gdb.Command):
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"]
@@ -9845,8 +9857,7 @@ class GefCommand(gdb.Command):
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."""
+3 -1
View File
@@ -38,7 +38,9 @@ fi
git clone --branch ${branch} https://github.com/hugsy/gef-extras.git "${DIR}"
ver=$(gdb -q -nx -ex 'pi print(f"{sys.version_info.major}.{sys.version_info.minor}", end="")' -ex quit)
python${ver} -m pip install --requirement "${DIR}"/requirements.txt --upgrade
gdb -q -ex "gef config gef.extra_plugins_dir '${DIR}/scripts'" \
gdb -q -ex "pi gef.config['context.layout'] += ' syscall_args'" \
-ex "pi gef.config['context.layout'] += ' libc_function_args'" \
-ex "gef config gef.extra_plugins_dir '${DIR}/scripts'" \
-ex "gef config pcustom.struct_path '${DIR}/structs'" \
-ex "gef config syscall-args.path '${DIR}/syscall-tables'" \
-ex "gef config context.libc_args True" \