From bdfad5dff925b3e8ff0d7b95024f12a684fffc68 Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Sat, 18 Apr 2015 09:53:46 -0700 Subject: [PATCH] Fix base address of DSOs --- pwndbg/events.py | 3 ++- pwndbg/ida.py | 10 +++++++--- pwndbg/memory.py | 5 +++++ pwndbg/stack.py | 5 ++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pwndbg/events.py b/pwndbg/events.py index b23c1a044..f1d587888 100644 --- a/pwndbg/events.py +++ b/pwndbg/events.py @@ -7,6 +7,7 @@ by using a decorator. """ import traceback import gdb +import sys debug = False pause = 0 @@ -29,7 +30,7 @@ class Pause(object): def connect(func, event_handler, name=''): def caller(*a): func.__doc__ - if debug: print('%r %s.%s' % (name, func.__module__, func.__name__), a) + if debug: sys.stdout.write('%r %s.%s %r\n' % (name, func.__module__, func.__name__, a)) if pause: return try: func() diff --git a/pwndbg/ida.py b/pwndbg/ida.py index 7e5850f06..f07fae234 100644 --- a/pwndbg/ida.py +++ b/pwndbg/ida.py @@ -63,14 +63,18 @@ def available(): return True def l2r(addr): - return (addr - int(pwndbg.elf.exe().address) + base()) & pwndbg.arch.ptrmask + result = (addr - int(pwndbg.elf.exe().address) + base()) & pwndbg.arch.ptrmask + return result def r2l(addr): - return (addr - base() + int(pwndbg.elf.exe().address)) & pwndbg.arch.ptrmask + result = (addr - base() + int(pwndbg.elf.exe().address)) & pwndbg.arch.ptrmask + return result @pwndbg.memoize.reset_on_objfile def base(): - return _ida.NextSeg(0) & ~(0xfff) + result = _ida.NextSeg(0) & ~(0xfff) + if result < 0x100000: + return 0 @withIDA @takes_address diff --git a/pwndbg/memory.py b/pwndbg/memory.py index 212808ea6..4e6699648 100644 --- a/pwndbg/memory.py +++ b/pwndbg/memory.py @@ -76,6 +76,9 @@ def find_upper_boundary(addr): addr = pwndbg.memory.page_align(int(addr)) try: while True: + import sys + sys.stdout.write(hex(addr) + '\n') + sys.stdout.flush() pwndbg.memory.read(addr, 1) addr += pwndbg.memory.PAGE_SIZE except gdb.MemoryError: @@ -86,6 +89,8 @@ def find_lower_boundary(addr): addr = pwndbg.memory.page_align(int(addr)) try: while True: + sys.stdout.write(hex(addr) + '\n') + sys.stdout.flush() pwndbg.memory.read(addr, 1) addr -= pwndbg.memory.PAGE_SIZE except gdb.MemoryError: diff --git a/pwndbg/stack.py b/pwndbg/stack.py index a0db0d6cc..f3e63c25f 100644 --- a/pwndbg/stack.py +++ b/pwndbg/stack.py @@ -37,6 +37,9 @@ def update(): For each running thread, updates the known address range for its stack. """ + # import pdb + # pdb.set_trace() + curr_thread = gdb.selected_thread() try: @@ -48,7 +51,7 @@ def update(): # a new Page mapping for it. page = stacks.get(thread.ptid, None) if page is None: - start = pwndbg.memory.find_lower_boundary(sp) + start = sp + 0x1000 & ~(0xfff) #pwndbg.memory.find_lower_boundary(sp) stop = pwndbg.memory.find_upper_boundary(sp) page = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]') stacks[thread.ptid] = page