From 79ca9d5fa116baf13908d49ee38f2169d45581bc Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Mon, 11 May 2015 17:36:58 -0700 Subject: [PATCH] Python3 fixes --- pwndbg/commands/context.py | 2 +- pwndbg/commands/vmmap.py | 3 ++- pwndbg/compat.py | 4 +++- pwndbg/funcparser.py | 8 ++++---- pwndbg/regs.py | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py index 6bf766d38..343440248 100644 --- a/pwndbg/commands/context.py +++ b/pwndbg/commands/context.py @@ -38,7 +38,7 @@ def context(*args): result.extend(context_signal()) for line in result: - print(line.encode('utf-8')) + print(line) def context_regs(): result = [] diff --git a/pwndbg/commands/vmmap.py b/pwndbg/commands/vmmap.py index 6c5c80bbc..87230b6a2 100644 --- a/pwndbg/commands/vmmap.py +++ b/pwndbg/commands/vmmap.py @@ -6,6 +6,7 @@ Command to print the vitual memory map a la /proc/self/maps. import gdb import pwndbg.color import pwndbg.commands +import pwndbg.compat import pwndbg.vmmap @@ -17,7 +18,7 @@ def vmmap(map=None): """ int_map = None str_map = None - if isinstance(map, str): + if isinstance(map, pwndbg.compat.basestring): str_map = map elif isinstance(map, (long, int, gdb.Value)): int_map = int(map) diff --git a/pwndbg/compat.py b/pwndbg/compat.py index f974c37b7..804179a85 100644 --- a/pwndbg/compat.py +++ b/pwndbg/compat.py @@ -12,4 +12,6 @@ python2 = sys.version_info.major == 2 python3 = sys.version_info.major == 3 if python3: - globals()['basestring'] = str \ No newline at end of file + basestring = str +else: + basestring = basestring diff --git a/pwndbg/funcparser.py b/pwndbg/funcparser.py index b5e44b281..e38eabe7e 100644 --- a/pwndbg/funcparser.py +++ b/pwndbg/funcparser.py @@ -40,8 +40,8 @@ def ExtractFuncDecl(node, verbose=False): ftype, fderef, fname = extractTypeAndName(node) if not fname: - print "Skipping function without a name!" - print node.show() + print("Skipping function without a name!") + print(node.show()) return fargs = [] @@ -55,7 +55,7 @@ def ExtractFuncDecl(node, verbose=False): Func = Function(ftype, fderef, fname, fargs) if verbose: - print Stringify(Func) + '(' + ','.join(Stringify(a) for a in Func.args) + ');' + print(Stringify(Func) + '(' + ','.join(Stringify(a) for a in Func.args) + ');') return Func @@ -81,4 +81,4 @@ def ExtractFuncDeclFromSource(source): except Exception as e: import traceback traceback.print_exc() - # eat it \ No newline at end of file + # eat it diff --git a/pwndbg/regs.py b/pwndbg/regs.py index 6a0321407..d44d7cc38 100644 --- a/pwndbg/regs.py +++ b/pwndbg/regs.py @@ -10,6 +10,7 @@ from types import ModuleType import gdb import pwndbg.arch +import pwndbg.compat import pwndbg.events import pwndbg.memoize @@ -204,8 +205,8 @@ class module(ModuleType): if isinstance(item, int): return arch_to_regs[pwndbg.arch.current][item] - if not isinstance(item, basestring): - print "Unknown register type: %r" % (item) + if not isinstance(item, pwndbg.compat.basestring): + print("Unknown register type: %r" % (item)) import pdb, traceback traceback.print_stack() pdb.set_trace()