mirror of https://github.com/pwndbg/pwndbg.git
Fix disable_colors formatting & test ctx disasm showing fds
This commit adds a test for context disasm showing of file descriptors
file paths in syscalls like read() or close().
It also fixes a small issue when Pwndbg is run with PWNDBG_DISABLE_COLORS=1
This issue was that executing:
```
pi '{a:2}'.format(a=pwndbg.color.context.prefix(pwndbg.config.code_prefix))
```
Failed when Pwndbg was run with disabled colors. It failed because our
generate color functions in pwndbg/color/* ended up not processing the
input argument -- which here is a Pwndbg config Paramater object -- so
that we got a very non obvious exception:
```
Exception occurred: context: unsupported format string passed to Parameter.__format__ (<class 'TypeError'>)
```
This issue could hypothetically also exist if our config value would be
empty I think. So with the fix in this commit, where we do str(x) over
the color funciton argument should fix this issue in all cases.
pull/1203/head
parent
21794a6ec4
commit
b209ada229
@ -0,0 +1,17 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
char buf[16] = {0};
|
||||
|
||||
// read 0 bytes so it won't block
|
||||
read(STDOUT_FILENO, buf, 0);
|
||||
|
||||
int fd = open(argv[0], 0);
|
||||
|
||||
read(fd, buf, sizeof(buf));
|
||||
|
||||
close(fd);
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
import re
|
||||
|
||||
import gdb
|
||||
|
||||
import pwndbg.commands
|
||||
import tests
|
||||
|
||||
USE_FDS_BINARY = tests.binaries.get("use-fds.out")
|
||||
|
||||
|
||||
def test_context_disasm_show_fd_filepath(start_binary):
|
||||
"""
|
||||
Tests context disasm command and whether it shows properly opened fd filepath
|
||||
"""
|
||||
start_binary(USE_FDS_BINARY)
|
||||
|
||||
# Run until main
|
||||
gdb.execute("break main")
|
||||
gdb.execute("continue")
|
||||
|
||||
# Stop on read(0, ...) -> should show /dev/pts/X
|
||||
gdb.execute("nextcall")
|
||||
|
||||
out = pwndbg.commands.context.context_disasm()
|
||||
assert "[ DISASM / x86-64 / set emulate on ]" in out[0] # Sanity check
|
||||
|
||||
call_read_line_idx = out.index(next(line for line in out if "<read@plt>" in line))
|
||||
lines_after_call_read = out[call_read_line_idx:]
|
||||
|
||||
line_call_read, line_fd, line_buf, line_nbytes, *_rest = lines_after_call_read
|
||||
|
||||
assert "call read@plt" in line_call_read
|
||||
|
||||
line_fd = line_fd.strip()
|
||||
assert re.match(r"fd:\s+0x1 \(/dev/pts/\d+\)", line_fd)
|
||||
|
||||
line_buf = line_buf.strip()
|
||||
assert re.match(r"buf:\s+0x[0-9a-f]+ ◂— 0x0", line_buf)
|
||||
|
||||
line_nbytes = line_nbytes.strip()
|
||||
assert re.match(r"nbytes:\s+0x0", line_nbytes)
|
||||
|
||||
# Stop on open(...)
|
||||
gdb.execute("nextcall")
|
||||
# Stop on read(...) -> should show use-fds.out
|
||||
gdb.execute("nextcall")
|
||||
|
||||
out = pwndbg.commands.context.context_disasm()
|
||||
assert "[ DISASM / x86-64 / set emulate on ]" in out[0] # Sanity check
|
||||
|
||||
call_read_line_idx = out.index(next(line for line in out if "<read@plt>" in line))
|
||||
lines_after_call_read = out[call_read_line_idx:]
|
||||
|
||||
line_call_read, line_fd, line_buf, line_nbytes, *_rest = lines_after_call_read
|
||||
|
||||
line_fd = line_fd.strip()
|
||||
assert re.match(r"fd:\s+0x3 \([a-z/]*pwndbg/tests/binaries/use-fds.out\)", line_fd)
|
||||
|
||||
line_buf = line_buf.strip()
|
||||
assert re.match(r"buf:\s+0x[0-9a-f]+ ◂— 0x0", line_buf)
|
||||
|
||||
line_nbytes = line_nbytes.strip()
|
||||
assert re.match(r"nbytes:\s+0x10", line_nbytes)
|
||||
Loading…
Reference in new issue