forked from pwndbg/pwndbg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be8fdab
commit ca801c0
Showing
30 changed files
with
886 additions
and
93 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ | |
|
||
import gef | ||
|
||
gef.main() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
import struct | ||
import sys | ||
import gdb | ||
import gef.memoize | ||
import gef.events | ||
import gef.types | ||
|
||
current = None | ||
ptrmask = 0xfffffffff | ||
endian = 'little' | ||
ptrsize = gef.types.ptrsize | ||
fmt = '=i' | ||
|
||
@gef.events.stop | ||
def update(): | ||
global current | ||
global ptrmask | ||
current = gdb.selected_frame().architecture().name() | ||
ptrmask = (1 << 8*gef.types.ptrsize)-1 | ||
m = sys.modules[__name__] | ||
|
||
m.current = gdb.selected_frame().architecture().name() | ||
m.ptrsize = gef.types.ptrsize | ||
m.ptrmask = (1 << 8*gef.types.ptrsize)-1 | ||
|
||
if 'little' in gdb.execute('show endian', to_string=True): | ||
m.endian = 'little' | ||
else: | ||
m.endian = 'big' | ||
|
||
m.fmt = { | ||
(4, 'little'): '<I', | ||
(4, 'big'): '>I', | ||
(8, 'little'): '<Q', | ||
(8, 'big'): '>Q', | ||
}.get((m.ptrsize, m.endian)) | ||
|
||
|
||
def pack(integer): | ||
return struct.pack(fmt, integer & ptrmask) | ||
|
||
def unpack(data): | ||
return struct.unpack(fmt, data)[0] |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,67 @@ | ||
import traceback | ||
import gdb | ||
|
||
class Command(gdb.Command): | ||
import gef.regs | ||
import gef.memory | ||
import gef.hexdump | ||
import gef.color | ||
import gef.chain | ||
import gef.enhance | ||
import gef.symbol | ||
import gef.ui | ||
import gef.proc | ||
|
||
debug = True | ||
|
||
class ParsedCommand(gdb.Command): | ||
def __init__(self, function): | ||
super(ParsedCommand, self).__init__(function.__name__, gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION) | ||
self.function = function | ||
|
||
def invoke(self, argument, from_tty): | ||
argv = gdb.string_to_argv(argument) | ||
|
||
for i,arg in enumerate(argv): | ||
try: | ||
argv[i] = gdb.parse_and_eval(arg) | ||
continue | ||
except Exception: | ||
pass | ||
|
||
try: | ||
arg = gef.regs.fix(arg) | ||
argv[i] = gdb.parse_and_eval(arg) | ||
except Exception: | ||
pass | ||
|
||
try: | ||
self.function(*argv) | ||
except TypeError: | ||
if debug: print(traceback.format_exc()) | ||
pass | ||
|
||
def __call__(self, *args): | ||
self.function(*args) | ||
|
||
def OnlyWhenRunning(func): | ||
def wrapper(*a): | ||
func.__doc__ | ||
if not gef.proc.alive: | ||
pass | ||
else: | ||
func(*a) | ||
wrapper.__name__ = func.__name__ | ||
wrapper.__module__ = func.__module__ | ||
return wrapper | ||
|
||
|
||
@ParsedCommand | ||
@OnlyWhenRunning | ||
def searchmem(searchfor): | ||
|
||
if isinstance(searchfor, gdb.Value): | ||
try: | ||
searchfor = gef.memory.read(searchfor.address, searchfor.sizeof) | ||
except: | ||
searchfor = 0 | ||
print(searchfor) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import gdb | ||
import gef.commands | ||
import gef.color | ||
import gef.vmmap | ||
import gef.symbol | ||
import gef.regs | ||
import gef.ui | ||
import gef.disasm | ||
import gef.chain | ||
import gef.commands.telescope | ||
import gef.events | ||
|
||
|
||
@gef.commands.ParsedCommand | ||
@gef.commands.OnlyWhenRunning | ||
@gef.events.stop | ||
def context(*args): | ||
if len(args) == 0: | ||
args = ['reg','code','stack','backtrace'] | ||
|
||
args = [a[0] for a in args] | ||
|
||
print(gef.color.legend()) | ||
if 'r' in args: context_regs() | ||
if 'c' in args: context_code() | ||
if 's' in args: context_stack() | ||
if 'b' in args: context_backtrace() | ||
|
||
def context_regs(): | ||
print(gef.color.blue(gef.ui.banner("registers"))) | ||
for reg in gef.regs.gpr + (gef.regs.frame, gef.regs.stack, '$pc'): | ||
if reg is None: | ||
continue | ||
|
||
value = gef.regs[reg] | ||
|
||
# Make the register stand out | ||
regname = gef.color.bold(reg.ljust(4).upper()) | ||
|
||
print("%s %s" % (regname, gef.chain.format(value))) | ||
|
||
def context_code(): | ||
print(gef.color.blue(gef.ui.banner("code"))) | ||
pc = gef.regs.pc | ||
instructions = gef.disasm.near(gef.regs.pc, 5) | ||
|
||
# In case $pc is in a new map we don't know about, | ||
# this will trigger an exploratory search. | ||
gef.vmmap.find(pc) | ||
|
||
# Ensure screen data is always at the same spot | ||
for i in range(11 - len(instructions)): | ||
print() | ||
|
||
# Find all of the symbols for the addresses | ||
symbols = [] | ||
for i in instructions: | ||
symbol = gef.symbol.get(i.address) | ||
if symbol: | ||
symbol = '<%s> ' % symbol | ||
symbols.append(symbol) | ||
|
||
# Find the longest symbol name so we can adjust | ||
longest_sym = max(map(len, symbols)) | ||
|
||
# Pad them all out | ||
for i,s in enumerate(symbols): | ||
symbols[i] = s.ljust(longest_sym) | ||
|
||
# Print out each instruction | ||
for i,s in zip(instructions, symbols): | ||
asm = gef.disasm.color(i) | ||
prefix = ' =>' if i.address == pc else ' ' | ||
print(prefix, s + hex(i.address), asm) | ||
|
||
def context_stack(): | ||
print(gef.color.blue(gef.ui.banner("stack"))) | ||
gef.commands.telescope.telescope(gef.regs.sp) | ||
|
||
def context_backtrace(): | ||
print(gef.color.blue(gef.ui.banner("backtrace"))) | ||
frame = gdb.selected_frame() | ||
for i in range(0,10): | ||
if frame: | ||
print(gef.ui.addrsz(frame.pc()), frame.name() or '???') | ||
frame = frame.older() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import gdb | ||
import gef.vmmap | ||
import gef.commands | ||
import gef.color | ||
import gef.dt | ||
|
||
@gef.commands.ParsedCommand | ||
@gef.commands.OnlyWhenRunning | ||
def dt(typename, address=None): | ||
print(gef.dt.dt(typename, addr=address)) |
Oops, something went wrong.