Last active
September 30, 2016 15:33
-
-
Save icewall/aadd126fa8081263593be17a20a40523 to your computer and use it in GitHub Desktop.
Very very limited imitation of windbg !heap -p -a addr for gdb based on gdb python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
allocations = {} | |
class FunctionFinishBreakpoint(gdb.FinishBreakpoint): | |
def __init__ (self,allocation): | |
gdb.FinishBreakpoint.__init__(self,gdb.newest_frame(), internal=True) | |
self.silent = True | |
self.allocation = allocation | |
def stop(self): | |
global allocations | |
self.allocation["address"] = int(self.return_value) | |
allocations[ self.allocation["address"] ] = self.allocation | |
return False | |
class MallocBreakpoint(gdb.Breakpoint): | |
def stop(self): | |
global allocations | |
allocation_size = gdb.parse_and_eval("bytes") | |
allocation_size = int(allocation_size) | |
stack = gdb.execute("bt", to_string = True) | |
allocation = {"size": allocation_size, "stack" : stack} | |
FunctionFinishBreakpoint(allocation) | |
return False | |
print ("Installing malloc breakpoint") | |
MallocBreakpoint("__GI___libc_malloc") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage:
b main
start
source alloc_tracer.py
Installing malloc breakpoint
c
(...)
*** SIGSAV SOMEWHERE ***