mirror of https://github.com/pwndbg/pwndbg.git
This commit adds a fix and tests for #1600 and #752. * https://github.com/pwndbg/pwndbg/issues/1600 * https://github.com/pwndbg/pwndbg/issues/752 Generally, for an example like this: ```cpp struct A { void foo(int, int) { }; }; int main() { A a; a.foo(1, 1); } ``` The output for `info symbol <address of A::foo>` returns: ``` 'A::foo(int, int) [clone.isra.0] + 3 in section .text of /root/pwndbg/tests/gdb-tests/tests/binaries/a.out\n' ``` We then used this code to parse this: ```py # Expected format looks like this: # main in section .text of /bin/bash # main + 3 in section .text of /bin/bash # system + 1 in section .text of /lib/x86_64-linux-gnu/libc.so.6 # No symbol matches system-1. a, b, c, _ = result.split(maxsplit=3) if b == "+": return "%s+%s" % (a, c) if b == "in": return a return "" ``` The `result.split(maxsplit=3)` here splitted the string to: ```py ['A::foo(int,', 'int)', '[clone.isra.0] + 3 in section .text of /root/pwndbg/tests/gdb-tests/tests/binaries/a.out\n'] ``` And since `b` was not `"+"` or `"in"` we eventually returned an empty string instead of the `A::foo(int, int)` which would be expected here.pull/1609/head
parent
5ecd5d000f
commit
6d7d06710e
@ -0,0 +1,23 @@
|
||||
void break_here(void* p) { }
|
||||
|
||||
struct A {
|
||||
__attribute__((noinline))
|
||||
void foo(int, int) { break_here(0); }
|
||||
|
||||
void call_foo() { foo(1, 2); }
|
||||
};
|
||||
|
||||
int main() {
|
||||
break_here((void*)main);
|
||||
break_here((void*)break_here);
|
||||
|
||||
// code for issue 1600
|
||||
break_here((void*)&A::foo);
|
||||
|
||||
// just another check for mangled symbols
|
||||
break_here((void*)&A::call_foo);
|
||||
|
||||
// code for issue 752
|
||||
A a;
|
||||
a.call_foo();
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
import gdb
|
||||
|
||||
import pwndbg
|
||||
import tests
|
||||
|
||||
MANGLING_BINARY = tests.binaries.get("symbol_1600_and_752.out")
|
||||
|
||||
|
||||
def test_symbol_get(start_binary):
|
||||
start_binary(MANGLING_BINARY)
|
||||
gdb.execute("break break_here")
|
||||
|
||||
def get_next_ptr():
|
||||
gdb.execute("continue")
|
||||
|
||||
# To fetch the value of 'p' it must be set first
|
||||
# and it will be set by the program copying from register to the stack
|
||||
# (we pass `to_string=True` to suppress the context output)
|
||||
gdb.execute("nextret", to_string=True)
|
||||
p = int(gdb.parse_and_eval("p"))
|
||||
return pwndbg.gdblib.symbol.get(p)
|
||||
|
||||
assert get_next_ptr() == "main"
|
||||
|
||||
assert get_next_ptr() == "break_here(void*)"
|
||||
|
||||
# Test for the bug https://github.com/pwndbg/pwndbg/issues/1600
|
||||
assert get_next_ptr() == "A::foo(int, int)"
|
||||
|
||||
assert get_next_ptr() == "A::call_foo()"
|
||||
Loading…
Reference in new issue