Python27 fix

This commit is contained in:
Zach Riggle 2015-04-09 15:44:42 -04:00
parent bc6daee3f1
commit aa654bf8fa
5 changed files with 97 additions and 0 deletions

View File

@ -3,11 +3,13 @@ import pwndbg.arch
import pwndbg.vmmap
import pwndbg.dt
import pwndbg.memory
import pwndbg.inthook
import pwndbg.elf
import pwndbg.proc
import pwndbg.regs
import pwndbg.stack
import pwndbg.color
import pwndbg.typeinfo
import pwndbg.commands
import pwndbg.commands.hexdump
import pwndbg.commands.context
@ -18,6 +20,8 @@ import pwndbg.commands.search
import pwndbg.commands.auxv
import pwndbg.commands.windbg
import pwndbg.commands.ida
import pwndbg.commands.reload
import pwndbg.commands.rop
prompt = pwndbg.color.red('pwn> ')
prompt = pwndbg.color.bold(prompt)

38
pwndbg/commands/reload.py Normal file
View File

@ -0,0 +1,38 @@
import __builtin__
import imp
import os
import sys
import types
import gdb
import pwndbg.commands
import pwndbg
_reload = __builtin__.reload
def rreload(module, paths=[''], mdict=None):
"""Recursively reload modules."""
name = module.__name__
if mdict is None:
mdict = {}
if module not in mdict:
mdict[module] = []
_reload(module)
for attribute_name in dir(module):
attribute = getattr(module, attribute_name)
if type(attribute) is not types.ModuleType: continue
if not attribute.__name__.startswith(name): continue
if attribute in mdict[module]: continue
mdict[module].append(attribute)
rreload(attribute, paths, mdict)
_reload(module)
@pwndbg.commands.Command
def reload(*a):
rreload(pwndbg)

20
pwndbg/commands/rop.py Normal file
View File

@ -0,0 +1,20 @@
import os
import gdb
import pwndbg.commands
@pwndbg.commands.Command
def rop(start=None, stop=None):
"""
Dump ROP gadgets.
Optionally specify an address to dump all gadgets in that memory
area, or also specify a stop address.
Searches executable mapped pages only.
"""
cmd = ['ROPgadget',
'--rawArch=x86',
'--rawMode=32',
'--binary=dump',
'--offset=0xdeadbeef']
os.system(' '.join(cmd))

26
pwndbg/inthook.py Normal file
View File

@ -0,0 +1,26 @@
# This hook is necessary for compatibility with Python2.7 versions of GDB
# since they cannot directly cast to integer a gdb.Value object that is
# not already an integer type.
import __builtin__
import gdb
import pwndbg.typeinfo
_int = __builtin__.int
# We need this class to get isinstance(7, xint) to return True
class IsAnInt(type):
def __instancecheck__(self, other):
return isinstance(other, _int)
class xint(__builtin__.int):
__metaclass__ = IsAnInt
def __new__(cls, value, *a, **kw):
if isinstance(value, gdb.Value):
if pwndbg.typeinfo.is_pointer(value):
value = value.cast(pwndbg.typeinfo.ulong)
else:
value = value.cast(pwndbg.typeinfo.long)
return _int(value, *a, **kw)
__builtin__.int = xint
globals()['int'] = xint

View File

@ -10,12 +10,21 @@ import pwndbg.memoize
module = sys.modules[__name__]
def is_pointer(value):
type = value
if isinstance(value, gdb.Value):
type = value.type
type = type.strip_typedefs()
return type.code == gdb.TYPE_CODE_PTR
@pwndbg.events.new_objfile
@pwndbg.memoize.reset_on_exit
def update():
module.char = gdb.lookup_type('char')
module.ulong = gdb.lookup_type('unsigned long')
module.long = gdb.lookup_type('long')
module.uchar = gdb.lookup_type('unsigned char')
module.ushort = gdb.lookup_type('unsigned short')
module.uint = gdb.lookup_type('unsigned int')