diff --git a/Makefile b/Makefile index ded52c415..5b9e87792 100644 --- a/Makefile +++ b/Makefile @@ -8,23 +8,35 @@ PYLINT_COMMON_PARAMETERS := --jobs=$(PYLINT_JOBS) --suggestion-mode=$(PYLINT_SUG PYLINT_GEF_PARAMETERS := --disable=$(PYLINT_DISABLE) --enable=$(PYLINT_ENABLE) $(PYLINT_COMMON_PARAMETERS) PYLINT_TEST_PARAMETERS := --disable=$(PYLINT_DISABLE) --enable=$(PYLINT_TEST_ENABLE) $(PYLINT_COMMON_PARAMETERS) TARGET := $(shell lscpu | head -1 | sed -e 's/Architecture:\s*//g') +GEF_PATH ?= $(shell readlink -f gef.py) +TMPDIR ?= /tmp +PYTEST_PARAMETERS := --verbose -n $(NB_CORES) +ifdef DEBUG + PYTEST_PARAMETERS += --pdb +endif -test: testbins - @cp gef.py /tmp/gef.py - python3 -m pytest --verbose --numprocesses=$(NB_CORES) tests/runtests.py - @rm -f /tmp/gef.py - @rm -f /tmp/gef-* - @$(MAKE) -j $(NB_CORES) -C tests/binaries clean +.PHONY: test test_% Test% testbins clean lint -Test%: testbins - @cp gef.py /tmp/gef.py - python3 -m pytest --verbose --numprocesses=$(NB_CORES) tests/runtests.py $@ - @rm -f /tmp/gef.py - @rm -f /tmp/gef-* +test: $(TMPDIR) testbins + TMPDIR=$(TMPDIR) python3 -m pytest $(PYTEST_PARAMETERS) tests/runtests.py -testbins: tests/binaries/*.c - @$(MAKE) -j $(NB_CORES) -C tests/binaries TARGET=$(TARGET) all +Test%: $(TMPDIR) testbins + TMPDIR=$(TMPDIR) python3 -m pytest $(PYTEST_PARAMETERS) tests/runtests.py::$@ + +test_%: $(TMPDIR) testbins + TMPDIR=$(TMPDIR) python3 -m pytest $(PYTEST_PARAMETERS) tests/runtests.py -k $@ + +testbins: $(TMPDIR) $(wildcard tests/binaries/*.c) + @TMPDIR=$(TMPDIR) $(MAKE) -j $(NB_CORES) -C tests/binaries TARGET=$(TARGET) all + +clean: + TMPDIR=$(TMPDIR) $(MAKE) -j $(NB_CORES) -C tests/binaries clean + @rm -rf $(TMPDIR) lint: - python3 -m pylint $(PYLINT_GEF_PARAMETERS) gef.py - python3 -m pylint $(PYLINT_TEST_PARAMETERS) tests/*.py + python3 -m pylint $(PYLINT_GEF_PARAMETERS) $(GEF_PATH) + python3 -m pylint $(PYLINT_TEST_PARAMETERS) $(wildcard tests/*.py) + +$(TMPDIR): + mkdir -p $@ + diff --git a/gef.py b/gef.py index ede091be5..904ddf1b8 100644 --- a/gef.py +++ b/gef.py @@ -7681,7 +7681,8 @@ def get_shellcode(self, sid): return ok("Downloaded, written to disk...") - fd, fname = tempfile.mkstemp(suffix=".txt", prefix="sc-", text=True, dir="/tmp") + tempdir = get_gef_setting("gef.tempdir") + fd, fname = tempfile.mkstemp(suffix=".txt", prefix="sc-", text=True, dir=tempdir) shellcode = res.splitlines()[7:-11] shellcode = b"\n".join(shellcode).replace(b""", b'"') os.write(fd, shellcode) diff --git a/tests/binaries/Makefile b/tests/binaries/Makefile index 8c947ea49..a05d757c6 100644 --- a/tests/binaries/Makefile +++ b/tests/binaries/Makefile @@ -5,7 +5,7 @@ SOURCES = $(wildcard *.c) LINKED = $(SOURCES:.c=.out) LDFLAGS = EXTRA_FLAGS = -BINDIR = /tmp +TMPDIR ?= /tmp ifeq ($(TARGET), i686) CFLAGS += -m32 @@ -25,11 +25,11 @@ all: $(LINKED) %.out : %.c @echo "[+] Building '$@'" - @$(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $(BINDIR)/$@ $? $(LDFLAGS) + @$(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $(TMPDIR)/$@ $? $(LDFLAGS) clean : @echo "[+] Cleaning stuff" - @cd $(BINDIR) && rm -f $(LINKED) + @cd $(TMPDIR) && rm -f $(LINKED) format-string-helper.out: EXTRA_FLAGS := -Wno-format-security diff --git a/tests/helpers.py b/tests/helpers.py index 87b8e3bba..55771e534 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,11 +1,15 @@ -from typing import Iterable, Union, NewType, List +import os +import platform import re import subprocess -import os import sys -import platform +import tempfile +from pathlib import Path +from typing import Iterable, Union, NewType, List -PATH_TO_DEFAULT_BINARY = "/tmp/default.out" +TMPDIR = Path(tempfile.gettempdir()) +DEFAULT_TARGET = TMPDIR / "default.out" +GEF_PATH = Path(os.getenv("GEF_PATH", "gef.py")) STRIP_ANSI_DEFAULT = True DEFAULT_CONTEXT = "-code -stack" ARCH = (os.getenv("GEF_CI_ARCH") or platform.machine()).lower() @@ -30,12 +34,12 @@ def _add_command(commands: CommandType) -> List[str]: def gdb_run_cmd(cmd: CommandType, before: CommandType = (), after: CommandType = (), - target: str = PATH_TO_DEFAULT_BINARY, strip_ansi: bool = STRIP_ANSI_DEFAULT) -> str: + target: Path = DEFAULT_TARGET, strip_ansi: bool = STRIP_ANSI_DEFAULT) -> str: """Execute a command inside GDB. `before` and `after` are lists of commands to be executed before (resp. after) the command to test.""" command = [ "gdb", "-q", "-nx", - "-ex", "source /tmp/gef.py", + "-ex", f"source {GEF_PATH}", "-ex", "gef config gef.debug True" ] @@ -69,7 +73,7 @@ def gdb_run_cmd(cmd: CommandType, before: CommandType = (), after: CommandType = def gdb_run_silent_cmd(cmd: CommandType, before: CommandType = (), after: CommandType = (), - target: str = PATH_TO_DEFAULT_BINARY, + target: Path = DEFAULT_TARGET, strip_ansi: bool = STRIP_ANSI_DEFAULT) -> str: """Disable the output and run entirely the `target` binary.""" before = [*before, "gef config context.clear_screen False", @@ -79,14 +83,14 @@ def gdb_run_silent_cmd(cmd: CommandType, before: CommandType = (), after: Comman def gdb_run_cmd_last_line(cmd: CommandType, before: CommandType = (), after: CommandType = (), - target: str = PATH_TO_DEFAULT_BINARY, + target: Path = DEFAULT_TARGET, strip_ansi: bool = STRIP_ANSI_DEFAULT) -> str: """Execute a command in GDB, and return only the last line of its output.""" return gdb_run_cmd(cmd, before, after, target, strip_ansi).splitlines()[-1] def gdb_start_silent_cmd(cmd: CommandType, before: CommandType = (), after: CommandType = (), - target: str = PATH_TO_DEFAULT_BINARY, + target: Path = DEFAULT_TARGET, strip_ansi: bool = STRIP_ANSI_DEFAULT, context: str = DEFAULT_CONTEXT) -> str: """Execute a command in GDB by starting an execution context. This command @@ -100,14 +104,14 @@ def gdb_start_silent_cmd(cmd: CommandType, before: CommandType = (), after: Comm def gdb_start_silent_cmd_last_line(cmd: CommandType, before: CommandType = (), after: CommandType = (), - target=PATH_TO_DEFAULT_BINARY, + target: Path = DEFAULT_TARGET, strip_ansi=STRIP_ANSI_DEFAULT) -> str: """Execute `gdb_start_silent_cmd()` and return only the last line of its output.""" return gdb_start_silent_cmd(cmd, before, after, target, strip_ansi).splitlines()[-1] def gdb_test_python_method(meth: str, before: str = "", after: str = "", - target: str = PATH_TO_DEFAULT_BINARY, + target: Path = DEFAULT_TARGET, strip_ansi: bool = STRIP_ANSI_DEFAULT) -> str: brk = before + ";" if before else "" cmd = f"pi {brk}print({meth});{after}" @@ -136,3 +140,10 @@ def inner_f(*args, **kwargs): sys.stderr.flush() return inner_f return wrapper + + +def _target(name: str, extension: str = ".out") -> Path: + target = TMPDIR / f"{name}{extension}" + if not target.exists(): + raise FileNotFoundError(f"Could not find file '{target}'") + return target diff --git a/tests/runtests.py b/tests/runtests.py index 35ada1b1f..ce138725e 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -8,8 +8,10 @@ import re -import unittest import subprocess +import tempfile +import unittest +from pathlib import Path from helpers import ( gdb_run_cmd, @@ -19,9 +21,14 @@ gdb_test_python_method, include_for_architectures, ARCH, - is_64b + is_64b, + _target ) +BIN_LS = Path("/bin/ls") +BIN_SH = Path("/bin/sh") +TMPDIR = Path(tempfile.gettempdir()) + class GdbAssertionError(AssertionError): pass @@ -61,7 +68,7 @@ class TestGefCommandsUnit(GefUnitTestGeneric): def test_cmd_canary(self): self.assertFailIfInactiveSession(gdb_run_cmd("canary")) - res = gdb_start_silent_cmd("canary", target="/tmp/canary.out") + res = gdb_start_silent_cmd("canary", target=_target("canary")) self.assertNoException(res) self.assertIn("Found AT_RANDOM at", res) self.assertIn("The canary of process ", res) @@ -102,15 +109,15 @@ def test_cmd_checksec(self): res = gdb_run_cmd(cmd) self.assertNoException(res) - target = "/tmp/checksec-no-canary.out" + target = _target("checksec-no-canary") res = gdb_run_cmd(cmd, target=target) self.assertIn("Canary : ✘", res) - target = "/tmp/checksec-no-nx.out" + target = _target("checksec-no-nx") res = gdb_run_cmd(cmd, target=target) self.assertIn("NX : ✘", res) - target = "/tmp/checksec-no-pie.out" + target = _target("checksec-no-pie") res = gdb_run_cmd(cmd, target=target) self.assertIn("PIE : ✘", res) return @@ -161,7 +168,7 @@ def test_cmd_entry_break(self): def test_cmd_format_string_helper(self): cmd = "format-string-helper" - target = "/tmp/format-string-helper.out" + target = _target("format-string-helper") res = gdb_run_cmd(cmd, after=["set args testtest", "run",], @@ -179,7 +186,7 @@ def test_cmd_functions(self): def test_cmd_got(self): cmd = "got" - target = "/tmp/format-string-helper.out" + target = _target("format-string-helper") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) res = gdb_start_silent_cmd(cmd, target=target) self.assertIn("printf", res) @@ -191,7 +198,7 @@ def test_cmd_got(self): return def test_cmd_gef_remote(self): - def start_gdbserver(exe="/tmp/default.out", port=1234): + def start_gdbserver(exe=_target("default"), port=1234): return subprocess.Popen(["gdbserver", f":{port}", exe], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) @@ -212,7 +219,7 @@ def stop_gdbserver(gdbserver): def test_cmd_heap_arenas(self): cmd = "heap arenas" - target = "/tmp/heap.out" + target = _target("heap") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) res = gdb_start_silent_cmd(cmd, target=target) self.assertNoException(res) @@ -221,16 +228,16 @@ def test_cmd_heap_arenas(self): def test_cmd_heap_set_arena(self): cmd = "heap set-arena main_arena" - target = "/tmp/heap.out" + target = _target("heap") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) - res = gdb_run_silent_cmd(cmd, target=target, after=["heap arenas",]) + res = gdb_run_silent_cmd(cmd, target=target, after=["heap arenas"]) self.assertNoException(res) self.assertIn("Arena(base=", res) return def test_cmd_heap_chunk(self): cmd = "heap chunk p1" - target = "/tmp/heap.out" + target = _target("heap") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) @@ -239,7 +246,7 @@ def test_cmd_heap_chunk(self): def test_cmd_heap_chunks(self): cmd = "heap chunks" - target = "/tmp/heap.out" + target = _target("heap") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) @@ -247,7 +254,7 @@ def test_cmd_heap_chunks(self): self.assertIn("top chunk", res) cmd = "python gdb.execute('heap chunks {}'.format(get_glibc_arena().next))" - target = "/tmp/heap-non-main.out" + target = _target("heap-non-main") res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) self.assertNotIn("using '&main_arena' instead", res) @@ -258,7 +265,7 @@ def test_cmd_heap_chunks(self): def test_cmd_heap_chunks_mult_heaps(self): before = ['run', 'python gdb.execute("heap set-arena {}".format(get_glibc_arena().next))'] cmd = "heap chunks" - target = "/tmp/heap-multiple-heaps.out" + target = _target("heap-multiple-heaps") res = gdb_run_silent_cmd(cmd, before=before, target=target) self.assertNoException(res) self.assertIn("Chunk(addr=", res) @@ -268,7 +275,7 @@ def test_cmd_heap_chunks_mult_heaps(self): def test_cmd_heap_bins_fast(self): cmd = "heap bins fast" before = ["set environment GLIBC_TUNABLES glibc.malloc.tcache_count=0"] - target = "/tmp/heap-fastbins.out" + target = _target("heap-fastbins") self.assertFailIfInactiveSession(gdb_run_cmd(cmd, before=before, target=target)) res = gdb_run_silent_cmd(cmd, before=before, target=target) self.assertNoException(res) @@ -280,7 +287,7 @@ def test_cmd_heap_bins_fast(self): def test_cmd_heap_bins_non_main(self): cmd = "python gdb.execute('heap bins fast {}'.format(get_glibc_arena().next))" before = ["set environment GLIBC_TUNABLES glibc.malloc.tcache_count=0"] - target = "/tmp/heap-non-main.out" + target = _target("heap-non-main") res = gdb_run_silent_cmd(cmd, before=before, target=target) self.assertNoException(res) self.assertIn("size=0x20", res) @@ -288,7 +295,7 @@ def test_cmd_heap_bins_non_main(self): def test_cmd_heap_bins_tcache(self): cmd = "heap bins tcache" - target = "/tmp/heap-non-main.out" + target = _target("heap-non-main") res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) # ensure tcachebins is populated @@ -297,7 +304,7 @@ def test_cmd_heap_bins_tcache(self): def test_cmd_heap_bins_tcache_all(self): cmd = "heap bins tcache all" - target = "/tmp/heap-tcache.out" + target = _target("heap-tcache") res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) # ensure there's 2 tcachebins @@ -307,7 +314,7 @@ def test_cmd_heap_bins_tcache_all(self): def test_cmd_heap_analysis(self): cmd = "heap-analysis-helper" - target = "/tmp/heap-analysis.out" + target = _target("heap-analysis") self.assertFailIfInactiveSession(gdb_run_cmd(cmd)) res = gdb_start_silent_cmd(cmd, after=["continue"], target=target) self.assertNoException(res) @@ -346,19 +353,19 @@ def test_cmd_memory_watch(self): self.assertNoException(res) res = gdb_start_silent_cmd("memory watch $pc") self.assertNoException(res) - target = "/tmp/memwatch.out" + target = _target("memwatch") res = gdb_start_silent_cmd("memory watch &myglobal", - before=["set args 0xdeadbeef",], - after=["continue",], - target=target, - context='memory') + before=["set args 0xdeadbeef"], + after=["continue"], + target=target, + context='memory') self.assertIn("deadbeef", res) self.assertNotIn("cafebabe", res) res = gdb_start_silent_cmd("memory watch &myglobal", - before=["set args 0xcafebabe",], - after=["continue"], - target=target, - context="memory") + before=["set args 0xcafebabe"], + after=["continue"], + target=target, + context="memory") self.assertIn("cafebabe", res) self.assertNotIn("deadbeef", res) @@ -451,7 +458,7 @@ def test_cmd_patch_qword(self): return def test_cmd_patch_qword_symbol(self): - target = "/tmp/bss.out" + target = _target("bss") before = gdb_run_silent_cmd("deref -l 1 $sp", target=target) after = gdb_run_silent_cmd("patch qword $sp &msg", after=["deref -l 1 $sp"], target=target) self.assertNoException(before) @@ -481,7 +488,7 @@ def test_cmd_pattern_create(self): @include_for_architectures(["x86_64", "aarch64"]) def test_cmd_pattern_search(self): - target = "/tmp/pattern.out" + target = _target("pattern") if ARCH == "aarch64": r = "$x30" elif ARCH == "x86_64": @@ -537,18 +544,19 @@ def test_cmd_process_status(self): return def test_cmd_process_search(self): - res = gdb_start_silent_cmd("process-search", target="/tmp/pattern.out", + target = _target("pattern") + res = gdb_start_silent_cmd("process-search", target=target, before=["set args w00tw00t"]) self.assertNoException(res) - self.assertIn("/tmp/pattern.out", res) + self.assertIn(str(target), res) res = gdb_start_silent_cmd("process-search gdb.*fakefake", - target="/tmp/pattern.out", before=["set args w00tw00t"]) + target=target, before=["set args w00tw00t"]) self.assertNoException(res) self.assertIn("gdb", res) res = gdb_start_silent_cmd("process-search --smart-scan gdb.*fakefake", - target="/tmp/pattern.out", before=["set args w00tw00t"]) + target=target, before=["set args w00tw00t"]) self.assertNoException(res) self.assertNotIn("gdb", res) return @@ -591,28 +599,27 @@ def test_cmd_ropper(self): def test_cmd_scan(self): cmd = "scan libc stack" - target = "/tmp/checksec-no-pie.out" + target = _target("checksec-no-pie") self.assertFailIfInactiveSession(gdb_run_cmd(cmd)) res = gdb_start_silent_cmd(cmd, target=target) self.assertNoException(res) - self.assertIn(target, res) + self.assertIn(str(target), res) - target = "/tmp/default.out" - res = gdb_start_silent_cmd("scan binary libc", target=target) + res = gdb_start_silent_cmd("scan binary libc") self.assertNoException(res) self.assertIn("__libc_start_main", res) return def test_cmd_search_pattern(self): - self.assertFailIfInactiveSession(gdb_run_cmd("grep /bin/sh")) - res = gdb_start_silent_cmd("grep /bin/sh") + self.assertFailIfInactiveSession(gdb_run_cmd(f"grep {BIN_SH}")) + res = gdb_start_silent_cmd(f"grep {BIN_SH}") self.assertNoException(res) self.assertIn("0x", res) return def test_cmd_set_permission(self): self.assertFailIfInactiveSession(gdb_run_cmd("set-permission")) - target = "/tmp/set-permission.out" + target = _target("set-permission") # get the initial stack address res = gdb_start_silent_cmd("vmmap", target=target) @@ -622,7 +629,7 @@ def test_cmd_set_permission(self): # compare the new permissions res = gdb_start_silent_cmd(f"set-permission {stack_address:#x}", - after=[f"xinfo {stack_address:#x}",], target=target) + after=[f"xinfo {stack_address:#x}"], target=target) self.assertNoException(res) line = [l.strip() for l in res.splitlines() if l.startswith("Permissions: ")][0] self.assertEqual(line.split()[1], "rwx") @@ -658,10 +665,10 @@ def test_cmd_shellcode(self): return def test_cmd_shellcode_search(self): - cmd = "shellcode search execve /bin/sh" + cmd = f"shellcode search execve {BIN_SH}" res = gdb_start_silent_cmd(cmd) self.assertNoException(res) - self.assertIn("setuid(0) + execve(/bin/sh) 49 bytes", res) + self.assertIn(f"setuid(0) + execve({BIN_SH}) 49 bytes", res) return def test_cmd_shellcode_get(self): @@ -714,8 +721,8 @@ def test_cmd_trace_run(self): self.assertFailIfInactiveSession(res) cmd = "trace-run $pc+1" - res = gdb_start_silent_cmd(cmd, - before=["gef config trace-run.tracefile_prefix /tmp/gef-trace-"]) + res = gdb_start_silent_cmd( + cmd, before=[f"gef config trace-run.tracefile_prefix {TMPDIR / 'gef-trace-'}"]) self.assertNoException(res) self.assertIn("Tracing from", res) return @@ -727,7 +734,7 @@ def test_cmd_unicorn_emulate(self): res = gdb_run_silent_cmd(cmd) self.assertFailIfInactiveSession(res) - target = "/tmp/unicorn.out" + target = _target("unicorn") before = ["break function1"] after = ["si"] start_marker = "= Starting emulation =" @@ -845,23 +852,24 @@ def test_func_which(self): return def test_func_get_filepath(self): - res = gdb_test_python_method("get_filepath()", target="/bin/ls") + res = gdb_test_python_method("get_filepath()", target=BIN_LS) self.assertNoException(res) - subprocess.call(["cp", "/bin/ls", "/tmp/foo bar"]) - res = gdb_test_python_method("get_filepath()", target="/tmp/foo bar") + target = TMPDIR / "foo bar" + subprocess.call(["cp", BIN_LS, target]) + res = gdb_test_python_method("get_filepath()", target=target) self.assertNoException(res) - subprocess.call(["rm", "/tmp/foo bar"]) + subprocess.call(["rm", target]) return def test_func_get_pid(self): - res = gdb_test_python_method("get_pid()", target="/bin/ls") + res = gdb_test_python_method("get_pid()", target=BIN_LS) self.assertNoException(res) self.assertTrue(int(res.splitlines()[-1])) return def test_fun_gef_get_auxiliary_values(self): func = "gef_get_auxiliary_values()" - res = gdb_test_python_method(func, target="/bin/ls") + res = gdb_test_python_method(func, target=BIN_LS) self.assertNoException(res) # we need at least ("AT_PLATFORM", "AT_EXECFN") right now self.assertTrue("'AT_PLATFORM'" in res) @@ -871,7 +879,7 @@ def test_fun_gef_get_auxiliary_values(self): def test_func_gef_convenience(self): func = "gef_convenience('meh')" - res = gdb_test_python_method(func, target="/bin/ls") + res = gdb_test_python_method(func, target=BIN_LS) self.assertNoException(res) return @@ -907,8 +915,9 @@ def test_func_base(self): def test_func_heap(self): cmd = "deref $_heap()" - self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target="/tmp/heap.out")) - res = gdb_run_silent_cmd(cmd, target="/tmp/heap.out") + target = _target("heap") + self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) + res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) if is_64b(): self.assertIn("+0x0048:", res) @@ -916,7 +925,7 @@ def test_func_heap(self): self.assertIn("+0x0024:", res) cmd = "deref $_heap(0x10+0x10)" - res = gdb_run_silent_cmd(cmd, target="/tmp/heap.out") + res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) if is_64b(): self.assertIn("+0x0048:", res) @@ -926,16 +935,18 @@ def test_func_heap(self): def test_func_got(self): cmd = "deref $_got()" - self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target="/tmp/heap.out")) - res = gdb_run_silent_cmd(cmd, target="/tmp/heap.out") + target = _target("heap") + self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) + res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) self.assertIn("malloc", res) return def test_func_bss(self): cmd = "deref $_bss()" - self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target="/tmp/bss.out")) - res = gdb_run_silent_cmd(cmd, target="/tmp/bss.out") + target = _target("bss") + self.assertFailIfInactiveSession(gdb_run_cmd(cmd, target=target)) + res = gdb_run_silent_cmd(cmd, target=target) self.assertNoException(res) self.assertIn("Hello world!", res) return @@ -957,7 +968,7 @@ class TestGefConfigUnit(GefUnitTestGeneric): def test_config_show_opcodes_size(self): """Check opcodes are correctly shown""" - res = gdb_run_cmd("entry-break", before=["gef config context.show_opcodes_size 4",]) + res = gdb_run_cmd("entry-break", before=["gef config context.show_opcodes_size 4"]) self.assertNoException(res) self.assertTrue(len(res.splitlines()) > 1) # output format: 0xaddress opcode mnemo [operands, ...] @@ -990,8 +1001,9 @@ def test_registers_show_registers_in_correct_order(self): @include_for_architectures(["x86_64",]) def test_context_correct_registers_refresh_with_frames(self): """Ensure registers are correctly refreshed when changing frame (PR #668)""" + target = _target("nested") lines = gdb_run_silent_cmd("registers", after=["frame 5", "registers"], - target="/tmp/nested.out").splitlines() + target=target).splitlines() rips = [x for x in lines if x.startswith("$rip")] self.assertEqual(len(rips), 2) # we must have only 2 entries self.assertNotEqual(rips[0], rips[1]) # they must be different