From f6c7616dfb488810bdd96f16c04c67324904108e Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Mon, 8 Jul 2024 18:14:35 +0000 Subject: [PATCH] WIP: add test for user failing to call p.run() --- tests/err_norun.py | 30 ++++++++++++++++++++++++++++++ tests/run_tests.py | 12 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/err_norun.py diff --git a/tests/err_norun.py b/tests/err_norun.py new file mode 100644 index 0000000..7697e61 --- /dev/null +++ b/tests/err_norun.py @@ -0,0 +1,30 @@ +from pyda import * +from pwnlib.elf.elf import ELF +from pwnlib.util.packing import u64 +import string +import sys, time + +p = process() + +e = ELF(p.exe_path) +e.address = p.maps[p.exe_path].base + +plt_map = { e.plt[x]: x for x in e.plt } + +counter = 0 +def lib_hook(p): + global counter + name = plt_map[p.regs.rip] + print(f"[thread {p.tid}] {name}") + + counter += 1 + if counter == 1000: + jsdkfjdsaklfadska + +def thread_entry(p): + print(f"thread_entry for {p.tid}") + +p.set_thread_entry(thread_entry) + +for x in e.plt: + p.hook(e.plt[x], lib_hook) diff --git a/tests/run_tests.py b/tests/run_tests.py index ad9ca4f..1d6e2b8 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -91,6 +91,18 @@ def main(): ) ) + # err_norun.py: user fails to call p.run() + res &= run_test( + "thread_1000.c", "err_norun.py", + ExpectedResult( + retcode=0, + checkers=[ + output_checker, + lambda o, e: e.count(b"[Pyda] ERROR:") == 1, + ] + ) + ) + if not res: exit(1)