-
-
Notifications
You must be signed in to change notification settings - Fork 746
/
gef_remote.py
75 lines (63 loc) · 2.46 KB
/
gef_remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
`gef_remote` command test module
"""
import random
import pytest
from tests.base import RemoteGefUnitTestGeneric
from tests.utils import (
ARCH,
debug_target,
gdbserver_session,
qemuuser_session,
GDBSERVER_DEFAULT_HOST,
)
class GefRemoteCommand(RemoteGefUnitTestGeneric):
"""`gef_remote` command test module"""
def setUp(self) -> None:
self._target = debug_target("default")
return super().setUp()
def test_cmd_gef_remote_gdbserver(self):
gdb = self._gdb
gef = self._gef
root = self._conn.root
gdbserver_mode = "GDBSERVER"
while True:
port = random.randint(1025, 65535)
if port != self._port:
break
with gdbserver_session(port=port):
gdb.execute(f"gef-remote {GDBSERVER_DEFAULT_HOST} {port}")
res: str = root.eval("str(gef.session.remote)")
assert res.startswith(f"RemoteSession(target='{GDBSERVER_DEFAULT_HOST}:{port}', local='/tmp/")
assert res.endswith(f"pid={gef.session.pid}, mode={gdbserver_mode})")
@pytest.mark.slow
@pytest.mark.skipif(ARCH not in ("x86_64",), reason=f"Skipped for {ARCH}")
def test_cmd_gef_remote_qemu_user(self):
gdb = self._gdb
gef = self._gef
root = self._conn.root
qemu_mode = "QEMU"
while True:
port = random.randint(1025, 65535)
if port != self._port:
break
with qemuuser_session(port=port):
cmd = f"gef-remote --qemu-user --qemu-binary {self._target} {GDBSERVER_DEFAULT_HOST} {port}"
gdb.execute(cmd)
res = root.eval("str(gef.session.remote)")
assert res.startswith(f"RemoteSession(target='{GDBSERVER_DEFAULT_HOST}:{port}', local='/tmp/")
assert res.endswith(f"pid={gef.session.pid}, mode={qemu_mode})")
def test_cmd_target_remote(self):
gdb = self._gdb
gef = self._gef
root = self._conn.root
gdbserver_mode = "GDBSERVER"
while True:
port = random.randint(1025, 65535)
if port != self._port:
break
with gdbserver_session(port=port) as _:
gdb.execute(f"target remote {GDBSERVER_DEFAULT_HOST}:{port}")
res: str = root.eval("str(gef.session.remote)")
assert res.startswith("RemoteSession(target=':0', local='/tmp/")
assert res.endswith(f"pid={gef.session.pid}, mode={gdbserver_mode})")