from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys

import gdb

import pwndbg.typeinfo

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
    class IsAnInt(type):
        def __instancecheck__(self, other):
            return isinstance(other, _int)

    class xint(builtins.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(_int(value, *a, **kw))

    builtins.int = xint
    globals()['int'] = xint

    # Additionally, we need to compensate for Python2
else:
    import builtins
    builtins.long = int
    globals()['long'] = int

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys

import gdb

import pwndbg.typeinfo

if sys.version_info < (3,0):
    import __builtin__ as builtins
else:
    import builtins

_int = builtins.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(builtins.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(_int(value, *a, **kw))

builtins.int = xint
globals()['int'] = xint

if sys.version_info >= (3,0):
    builtins.long = xint
    globals()['long'] = xint


Add int hook to Python3
Add int hook to Python3

Fixes #120

  from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  
  import sys
  
  import gdb
  
  import pwndbg.typeinfo
  
  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
-     class IsAnInt(type):
-         def __instancecheck__(self, other):
-             return isinstance(other, _int)
- 
-     class xint(builtins.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(_int(value, *a, **kw))
- 
-     builtins.int = xint
-     globals()['int'] = xint
- 
-     # Additionally, we need to compensate for Python2
  else:
      import builtins
-     builtins.long = int
-     globals()['long'] = int
  
+ _int = builtins.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(builtins.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(_int(value, *a, **kw))
+ 
+ builtins.int = xint
+ globals()['int'] = xint
+ 
+ if sys.version_info >= (3,0):
+     builtins.long = xint
+     globals()['long'] = xint
+ 
+ 
Add int hook to Python3
## Code Before:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys

import gdb

import pwndbg.typeinfo

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
    class IsAnInt(type):
        def __instancecheck__(self, other):
            return isinstance(other, _int)

    class xint(builtins.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(_int(value, *a, **kw))

    builtins.int = xint
    globals()['int'] = xint

    # Additionally, we need to compensate for Python2
else:
    import builtins
    builtins.long = int
    globals()['long'] = int

## Instruction:
Add int hook to Python3
## Code After:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys

import gdb

import pwndbg.typeinfo

if sys.version_info < (3,0):
    import __builtin__ as builtins
else:
    import builtins

_int = builtins.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(builtins.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(_int(value, *a, **kw))

builtins.int = xint
globals()['int'] = xint

if sys.version_info >= (3,0):
    builtins.long = xint
    globals()['long'] = xint

