Fix base address of DSOs

pull/10/head
Zach Riggle 11 years ago
parent 1af8b74553
commit bdfad5dff9

@ -7,6 +7,7 @@ by using a decorator.
""" """
import traceback import traceback
import gdb import gdb
import sys
debug = False debug = False
pause = 0 pause = 0
@ -29,7 +30,7 @@ class Pause(object):
def connect(func, event_handler, name=''): def connect(func, event_handler, name=''):
def caller(*a): def caller(*a):
func.__doc__ 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 if pause: return
try: try:
func() func()

@ -63,14 +63,18 @@ def available():
return True return True
def l2r(addr): 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): 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 @pwndbg.memoize.reset_on_objfile
def base(): def base():
return _ida.NextSeg(0) & ~(0xfff) result = _ida.NextSeg(0) & ~(0xfff)
if result < 0x100000:
return 0
@withIDA @withIDA
@takes_address @takes_address

@ -76,6 +76,9 @@ def find_upper_boundary(addr):
addr = pwndbg.memory.page_align(int(addr)) addr = pwndbg.memory.page_align(int(addr))
try: try:
while True: while True:
import sys
sys.stdout.write(hex(addr) + '\n')
sys.stdout.flush()
pwndbg.memory.read(addr, 1) pwndbg.memory.read(addr, 1)
addr += pwndbg.memory.PAGE_SIZE addr += pwndbg.memory.PAGE_SIZE
except gdb.MemoryError: except gdb.MemoryError:
@ -86,6 +89,8 @@ def find_lower_boundary(addr):
addr = pwndbg.memory.page_align(int(addr)) addr = pwndbg.memory.page_align(int(addr))
try: try:
while True: while True:
sys.stdout.write(hex(addr) + '\n')
sys.stdout.flush()
pwndbg.memory.read(addr, 1) pwndbg.memory.read(addr, 1)
addr -= pwndbg.memory.PAGE_SIZE addr -= pwndbg.memory.PAGE_SIZE
except gdb.MemoryError: except gdb.MemoryError:

@ -37,6 +37,9 @@ def update():
For each running thread, updates the known address range For each running thread, updates the known address range
for its stack. for its stack.
""" """
# import pdb
# pdb.set_trace()
curr_thread = gdb.selected_thread() curr_thread = gdb.selected_thread()
try: try:
@ -48,7 +51,7 @@ def update():
# a new Page mapping for it. # a new Page mapping for it.
page = stacks.get(thread.ptid, None) page = stacks.get(thread.ptid, None)
if page is 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) stop = pwndbg.memory.find_upper_boundary(sp)
page = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]') page = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
stacks[thread.ptid] = page stacks[thread.ptid] = page

Loading…
Cancel
Save