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

Use target remote for remote connections #1151

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d28c4a3
added ruff linter + fixes
hugsy Sep 22, 2024
cde95b3
checkpoint
hugsy Sep 24, 2024
b83586e
removed `Set` and `Tuple` types (replaced with `tuple` and `set`)
hugsy Nov 1, 2024
32311d7
`Union` type -> `|`
hugsy Nov 1, 2024
741ce7c
removed Tuple in tests
hugsy Nov 1, 2024
854912b
Merge branch 'main' into hugsy/lint-fmt
hugsy Nov 2, 2024
f47f51e
fixed type typo
hugsy Nov 2, 2024
d5d544d
`Optional` is optional
hugsy Nov 2, 2024
60be6a1
fixed ruff toml
hugsy Nov 2, 2024
dc28938
revert changes, only focus on py3.10 improvements
hugsy Nov 2, 2024
417ac63
final fixes
hugsy Nov 2, 2024
9fb1d71
added `untracked` dir to gitignore
hugsy Nov 3, 2024
a277661
checkpoint: added new remote modes, gdbserver & gdbserver-multi work
hugsy Nov 3, 2024
6d166f0
checkpoint: added very basic pytests
hugsy Nov 4, 2024
771a598
removed all obsolete code
hugsy Nov 5, 2024
79447be
fixed `gef-remote` from tests, using only `target remote`
hugsy Nov 5, 2024
ea873bb
use `NotImplementedError`
hugsy Nov 7, 2024
4ae683f
plop
hugsy Nov 7, 2024
8130895
minor lint
hugsy Nov 7, 2024
7973a3f
allow mock mem layout for old qemu versions
hugsy Nov 7, 2024
8cc2231
added repr for Gef class
hugsy Nov 8, 2024
2ba9ac7
[tests] use `gdb-multiarch` by default
hugsy Nov 8, 2024
437cbe2
added regression for issue #1131
hugsy Nov 8, 2024
e5a02b1
constantify all the things
hugsy Nov 8, 2024
68fcc1d
officially deprecating `gef-remote`
hugsy Nov 8, 2024
e8527ad
duplicate test line
hugsy Nov 10, 2024
14c35bd
allow gef to save temporary values
hugsy Nov 10, 2024
03f9cf9
Merge branch 'main' into hugsy/revisit-target-remote
hugsy Nov 10, 2024
2a5c585
test fix
hugsy Nov 10, 2024
36c953c
oops
hugsy Nov 10, 2024
68505a6
bleh
hugsy Nov 10, 2024
02af4d4
revert
hugsy Nov 10, 2024
c89c280
damnit
hugsy Nov 10, 2024
77aa954
restored gdb-multiarch as default for tests
hugsy Nov 11, 2024
1d9f897
minor
hugsy Nov 11, 2024
623ebf1
test
hugsy Nov 11, 2024
532e45d
asd
hugsy Nov 11, 2024
fd0bf0a
Merge branch 'hugsy/revisit-target-remote' of https://github.com/hugs…
hugsy Nov 11, 2024
d262ca5
Merge branch 'main' into hugsy/revisit-target-remote
hugsy Nov 11, 2024
7a9e494
Update generate-coverage-docs.sh
hugsy Nov 11, 2024
b9f564f
Update generate-coverage-docs.sh
hugsy Nov 11, 2024
7ea8588
Update coverage.yml
hugsy Nov 11, 2024
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
Prev Previous commit
Next Next commit
added regression for issue #1131
hugsy committed Nov 8, 2024
commit 437cbe213a61a1f0f098bfb342512d475896f959
2 changes: 0 additions & 2 deletions tests/commands/gef_remote.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@
`gef_remote` command test module
"""

import random

import pytest

from tests.base import RemoteGefUnitTestGeneric
39 changes: 39 additions & 0 deletions tests/regressions/1131_target_remote_registers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pathlib
import pytest
import os
import tempfile

from tests.base import RemoteGefUnitTestGeneric
from tests.utils import get_random_port, qemuuser_session

URL = "https://github.com/user-attachments/files/16913262/repr.zip"

@pytest.mark.slow
class MissingTargetRemoteRegisters(RemoteGefUnitTestGeneric):
"""@ref https://github.com/hugsy/gef/pull/1131"""

def setUp(self) -> None:
repro_script = f"""
wget -O {{0}}/repr.zip {URL}
unzip {{0}}/repr.zip -d {{0}}
"""

self._tempdir = tempfile.TemporaryDirectory(prefix="gef-tests-")
self._tempdir_path = pathlib.Path(self._tempdir.name)
os.system(repro_script.format(self._tempdir_path))
self._current_dir = self._tempdir_path / "repr"
os.chdir(self._current_dir)
self._target = self._current_dir / "chal"
return super().setUp()

def test_target_remote_validate_post_hook_registers_display(self):
_gdb = self._gdb
_gef = self._gef
port = get_random_port()

# cmd: ./qemu-mipsel-static -g 1234 -L ./target ./chal
with qemuuser_session(exe=self._target, port=port, qemu_exe=self._current_dir / "qemu-mipsel-static", args=["-L", str(self._current_dir / "target")]):
_gdb.execute(f"target remote :{port}")

res = str(_gef.session.remote)
assert f"RemoteSession(target='localhost:{port}', local='/', mode=QEMU_USER)" in res
34 changes: 25 additions & 9 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import os
import pathlib
import platform
import shutil
import struct
import subprocess
import tempfile
@@ -19,12 +20,10 @@


def which(program: str) -> pathlib.Path:
for path in os.environ["PATH"].split(os.pathsep):
dirname = pathlib.Path(path)
fpath = dirname / program
if os.access(fpath, os.X_OK):
return fpath
raise FileNotFoundError(f"Missing file `{program}`")
fpath = shutil.which(program)
if not fpath:
raise FileNotFoundError(f"Missing file `{program}`")
return pathlib.Path(fpath)


TMPDIR = pathlib.Path(tempfile.gettempdir())
@@ -162,9 +161,16 @@ def gdbserver_multi_session(
def start_qemuuser(
exe: Union[str, pathlib.Path] = debug_target("default"),
port: int = GDBSERVER_DEFAULT_PORT,
qemu_exe: pathlib.Path = QEMU_USER_X64_BINARY,
args: list[str] | None = None
) -> subprocess.Popen:
cmd = [qemu_exe, "-g", str(port)]
if args:
cmd.extend(args)
cmd.append(exe)
logging.info(f"Starting '{cmd}' in {qemu_exe} on :{port}")
return subprocess.Popen(
[QEMU_USER_X64_BINARY, "-g", str(port), exe],
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
@@ -179,9 +185,19 @@ def stop_qemuuser(process: subprocess.Popen) -> None:
@contextlib.contextmanager
def qemuuser_session(*args, **kwargs):
exe = kwargs.get("exe", "") or debug_target("default")
port = kwargs.get("port", 0) or GDBSERVER_DEFAULT_PORT
sess = start_qemuuser(exe, port)
port = kwargs.get("port", GDBSERVER_DEFAULT_PORT)
qemu_exe = kwargs.get("qemu_exe", None) or QEMU_USER_X64_BINARY
args = kwargs.get("args", None)
if args:
# if specified, expect a list of strings
assert isinstance(args, list)
assert len(args)
for arg in args:
assert isinstance(arg, str)

sess = start_qemuuser(exe, port=port, qemu_exe=qemu_exe, args=args)
try:
time.sleep(GDBSERVER_STARTUP_DELAY_SEC)
yield sess
finally:
stop_qemuuser(sess)