mirror of https://github.com/pwndbg/pwndbg.git
Merge branch 'heap'
commit
66e9f40520
@ -0,0 +1,41 @@
|
||||
import pwndbg.arch
|
||||
import pwndbg.events
|
||||
import pwndbg.memory
|
||||
import pwndbg.regs
|
||||
|
||||
argc = None
|
||||
argv = None
|
||||
envp = None
|
||||
envc = None
|
||||
|
||||
@pwndbg.events.start
|
||||
def update():
|
||||
global argc
|
||||
global argv
|
||||
global envp
|
||||
global envc
|
||||
|
||||
pwndbg.arch.update() # :-(
|
||||
|
||||
sp = pwndbg.regs.sp
|
||||
ptrsize = pwndbg.arch.ptrsize
|
||||
ptrbits = 8 * ptrsize
|
||||
|
||||
argc = pwndbg.memory.u(sp, ptrbits)
|
||||
sp += ptrsize
|
||||
|
||||
argv = sp
|
||||
|
||||
while pwndbg.memory.u(sp, ptrbits):
|
||||
sp += ptrsize
|
||||
|
||||
sp += ptrsize
|
||||
|
||||
envp = sp
|
||||
|
||||
envc = 0
|
||||
while pwndbg.memory.u(sp, ptrbits):
|
||||
sp += ptrsize
|
||||
envc += 1
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
import gdb
|
||||
import pwndbg.argv
|
||||
import pwndbg.commands
|
||||
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.Command
|
||||
def argc():
|
||||
"""
|
||||
Prints out the number of arguments.
|
||||
"""
|
||||
print pwndbg.argv.argc
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.Command
|
||||
def argv():
|
||||
"""
|
||||
Prints out the contents of argv.
|
||||
"""
|
||||
pwndbg.commands.telescope.telescope(pwndbg.argv.argv, pwndbg.argv.argc+1)
|
||||
|
||||
@pwndbg.commands.Command
|
||||
def args():
|
||||
"""
|
||||
Prints out the contents of argv.
|
||||
"""
|
||||
argv()
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.Command
|
||||
def envp():
|
||||
"""
|
||||
Prints out the contents of the environment.
|
||||
"""
|
||||
envp = pwndbg.argv.envp
|
||||
pwndbg.commands.telescope.telescope(pwndbg.argv.envp, pwndbg.argv.envc+1)
|
||||
|
||||
@pwndbg.commands.Command
|
||||
def env():
|
||||
"""
|
||||
Prints out the contents of the environment.
|
||||
"""
|
||||
envp()
|
||||
|
||||
@pwndbg.commands.Command
|
||||
def environ():
|
||||
"""
|
||||
Prints out the contents of the environment.
|
||||
"""
|
||||
envp()
|
||||
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Heap commands.
|
||||
"""
|
||||
import argparse
|
||||
import gdb
|
||||
import pwndbg.commands
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.ParsedCommand
|
||||
def brk(n=0):
|
||||
gdb.execute('call brk(%i)' % n)
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.ParsedCommand
|
||||
def sbrk(n=0):
|
||||
gdb.execute('call sbrk(%i)' % n)
|
||||
|
||||
|
||||
|
||||
|
||||
p = argparse.ArgumentParser(prog='hheap')
|
||||
|
||||
p.add_argument('--size',
|
||||
help='Heap size. May be expressed as an integer or range (e.g. 32-64).')
|
||||
p.add_argument('--verbose', action='store_true',
|
||||
help='Print more information')
|
||||
p.add_argument('--free', action='store_true',
|
||||
help='Only show free slots')
|
||||
p.add_argument('address', type=int, default=0,
|
||||
help='Heap allocation to display')
|
||||
|
||||
@pwndbg.commands.OnlyWhenRunning
|
||||
@pwndbg.commands.Command
|
||||
def hheap(*a):
|
||||
"""Prints out heap information.
|
||||
""" + p.format_help()
|
||||
try:
|
||||
args = p.parse_args(a)
|
||||
except SystemExit:
|
||||
return
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
|
||||
import pwndbg.heap.heap
|
||||
import pwndbg.heap.dlmalloc
|
||||
import pwndbg.heap.ptmalloc
|
||||
|
||||
current = pwndbg.heap.heap.Heap()
|
||||
|
||||
@pwndbg.events.new_objfile
|
||||
def update():
|
||||
global current
|
||||
|
||||
|
||||
if pwndbg.symbol.get('ptmalloc_init'):
|
||||
current = pwndbg.heap.ptmalloc.Heap()
|
||||
|
||||
elif pwndbg.symbol.get('malloc_stats'):
|
||||
current = pwndbg.heap.dlmalloc.Heap()
|
||||
@ -0,0 +1,13 @@
|
||||
import gdb
|
||||
import pwndbg.events
|
||||
import pwndbg.typeinfo
|
||||
|
||||
malloc_chunk = None
|
||||
malloc_state = None
|
||||
mallinfo = None
|
||||
|
||||
@pwndbg.events.new_objfile
|
||||
def update():
|
||||
malloc_chunk = gdb.lookup_type('struct malloc_chunk')
|
||||
malloc_state = gdb.lookup_type('struct malloc_state')
|
||||
mallinfo = gdb.lookup_type('struct mallinfo')
|
||||
@ -0,0 +1,38 @@
|
||||
import pwndbg.events
|
||||
import pwndbg.symbol
|
||||
|
||||
class Heap(object):
|
||||
"""Heap abstraction layer."""
|
||||
|
||||
def breakpoint(event):
|
||||
"""Enables breakpoints on the specific event.
|
||||
|
||||
Arguments:
|
||||
event(str): One of 'alloc','realloc','free'
|
||||
|
||||
Returns:
|
||||
A gdb.Breakpoint object.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def summarize(address, **kwargs):
|
||||
"""Returns a textual summary of the specified address.
|
||||
|
||||
Arguments:
|
||||
address(int): Address of the heap block to summarize.
|
||||
|
||||
Returns:
|
||||
A string.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def containing(address):
|
||||
"""Returns the address of the allocation which contains 'address'.
|
||||
|
||||
Arguments:
|
||||
address(int): Address to look up.
|
||||
|
||||
Returns:
|
||||
An integer.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
||||
import gdb
|
||||
import pwndbg.events
|
||||
import pwndbg.typeinfo
|
||||
|
||||
malloc_chunk = None
|
||||
malloc_state = None
|
||||
mallinfo = None
|
||||
|
||||
@pwndbg.events.new_objfile
|
||||
def update():
|
||||
malloc_chunk = gdb.lookup_type('struct malloc_chunk')
|
||||
malloc_state = gdb.lookup_type('struct malloc_state')
|
||||
mallinfo = gdb.lookup_type('struct mallinfo')
|
||||
Loading…
Reference in new issue