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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -4550,6 +4550,10 @@ 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:
gef.gdb.add_context_layout_mapping(current_pane_name, display_pane_function, pane_title_function, condition)
return


#
# Commands
Expand Down Expand Up @@ -9836,6 +9840,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 +9857,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
4 changes: 3 additions & 1 deletion scripts/gef-extras.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down