mirror of https://github.com/pwndbg/pwndbg.git
Fixing things back up for Python3
parent
29e20acafc
commit
07159546bd
@ -1,31 +1,33 @@
|
|||||||
# This hook is necessary for compatibility with Python2.7 versions of GDB
|
# 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
|
# since they cannot directly cast to integer a gdb.Value object that is
|
||||||
# not already an integer type.
|
# not already an integer type.
|
||||||
import __builtin__
|
|
||||||
import gdb
|
import gdb
|
||||||
|
import sys
|
||||||
import pwndbg.typeinfo
|
import pwndbg.typeinfo
|
||||||
|
|
||||||
_int = __builtin__.int
|
if sys.version_info < (3,0):
|
||||||
|
import __builtin__ as builtins
|
||||||
|
_int = builtins.int
|
||||||
|
|
||||||
# We need this class to get isinstance(7, xint) to return True
|
# We need this class to get isinstance(7, xint) to return True
|
||||||
class IsAnInt(type):
|
class IsAnInt(type):
|
||||||
def __instancecheck__(self, other):
|
def __instancecheck__(self, other):
|
||||||
return isinstance(other, _int)
|
return isinstance(other, _int)
|
||||||
|
|
||||||
class xint(__builtin__.int):
|
class xint(builtins.int):
|
||||||
__metaclass__ = IsAnInt
|
__metaclass__ = IsAnInt
|
||||||
def __new__(cls, value, *a, **kw):
|
def __new__(cls, value, *a, **kw):
|
||||||
if isinstance(value, gdb.Value):
|
if isinstance(value, gdb.Value):
|
||||||
if pwndbg.typeinfo.is_pointer(value):
|
if pwndbg.typeinfo.is_pointer(value):
|
||||||
value = value.cast(pwndbg.typeinfo.ulong)
|
value = value.cast(pwndbg.typeinfo.ulong)
|
||||||
else:
|
else:
|
||||||
value = value.cast(pwndbg.typeinfo.long)
|
value = value.cast(pwndbg.typeinfo.long)
|
||||||
return _int(_int(value, *a, **kw))
|
return _int(_int(value, *a, **kw))
|
||||||
|
|
||||||
__builtin__.int = xint
|
builtins.int = xint
|
||||||
globals()['int'] = xint
|
globals()['int'] = xint
|
||||||
|
|
||||||
# Additionally, we need to compensate for Python2
|
# Additionally, we need to compensate for Python2
|
||||||
if 'long' in globals():
|
if 'long' in globals():
|
||||||
__builtin__.long = xint
|
builtins.long = xint
|
||||||
globals()['long'] = xint
|
globals()['long'] = xint
|
||||||
Loading…
Reference in new issue