-
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command in gef: `arch` with available subcommands: - `get` -> prints the current arch and the reason - `set` -> manually set the current arch (or auto-detect if no arg is provided) - `list` -> list available architectures Implements this: #1002 --------- Co-authored-by: crazy hugsy <[email protected]>
- Loading branch information
Showing
3 changed files
with
138 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Command `arch` | ||
|
||
`arch` manages the loaded architecture. | ||
|
||
There are 3 available sub-commands: | ||
|
||
- `list`: List the installed architectures. | ||
- `get`: Print the currently loaded architecture, and why it is selected. | ||
- `set`: Manually set the loaded architecture by providing its name as an argument, or let | ||
gef do magic to detect the architecture by not providing arguments. | ||
|
||
> [!WARNING] | ||
> Setting manually should be done as a last resort as GEF expects to find the architecture | ||
> automatically. Force-setting the architecture can lead to unexpected behavior if not done correctly. | ||
|
||
![arch](https://github.com/hugsy/gef/assets/590234/c4481a78-9311-43ba-929f-2817c5c9290e) |
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,45 @@ | ||
""" | ||
Arch commands test module | ||
""" | ||
|
||
import pytest | ||
|
||
from tests.base import RemoteGefUnitTestGeneric | ||
from tests.utils import ARCH | ||
|
||
|
||
class ArchCommand(RemoteGefUnitTestGeneric): | ||
"""Class for `arch` command testing.""" | ||
|
||
@pytest.mark.skipif(ARCH != "x86_64", reason=f"Skipped for {ARCH}") | ||
def test_cmd_arch_get(self): | ||
gdb = self._gdb | ||
|
||
res = gdb.execute("arch get", to_string=True) | ||
assert " Architecture(X86, 64, LITTLE_ENDIAN)" in res | ||
assert " The architecture has been detected via the ELF headers" in res | ||
|
||
def test_cmd_arch_set(self): | ||
gdb = self._gdb | ||
|
||
gdb.execute("arch set X86") | ||
|
||
res = gdb.execute("arch get", to_string=True) | ||
assert " Architecture(X86, 32, LITTLE_ENDIAN)" in res | ||
assert " The architecture has been set manually" in res | ||
|
||
|
||
gdb.execute("arch set ppc") | ||
|
||
res = gdb.execute("arch get", to_string=True) | ||
assert " Architecture(PPC, PPC32, LITTLE_ENDIAN)" in res | ||
assert " The architecture has been set manually" in res | ||
|
||
def test_cmd_arch_list(self): | ||
gdb = self._gdb | ||
|
||
res = gdb.execute("arch list", to_string=True) | ||
assert "- GenericArchitecture" not in res | ||
assert " Architecture(X86, 64, LITTLE_ENDIAN)" in res | ||
assert " X86" in res | ||
assert " X86_64" in res |