From 94bc5910d9860ac0fec061bd0bd201cae6c28ef3 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Fri, 18 Nov 2016 18:43:33 +0100 Subject: [PATCH] Add check for UTF-8 encoding (#131) (#135) Also moved workaround from #117 to common place - gdbinit.py --- gdbinit.py | 20 ++++++++++++++++++++ pwndbg/__init__.py | 9 --------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gdbinit.py b/gdbinit.py index 98e46aa42..d02dc6e7b 100644 --- a/gdbinit.py +++ b/gdbinit.py @@ -4,6 +4,8 @@ from __future__ import print_function from __future__ import unicode_literals import sys +import six +import locale from os import path directory, file = path.split(__file__) @@ -12,4 +14,22 @@ directory = path.abspath(directory) sys.path.append(directory) +# this is an unconventional workaround to +# support unicode printing for python2 +# https://github.com/pwndbg/pwndbg/issues/117 +# on python3 it warns if the user has different +# encoding than utf-8 +encoding = locale.getpreferredencoding() +if six.PY2: + reload(sys) + sys.setdefaultencoding('utf-8') + +elif encoding != 'UTF-8': + print('******') + print('Your encoding ({}) is different than UTF-8. pwndbg might not work properly.'.format(encoding)) + print('You might try launching gdb with:') + print(' LC_ALL=en_US.UTF-8 PYTHONIOENCODING=UTF-8 gdb') + print('Make sure that en_US.UTF-8 is activated in /etc/locale.gen and you called locale-gen') + print('******') + import pwndbg # isort:skip diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 3a768adf6..9c5e82c86 100755 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -8,7 +8,6 @@ from __future__ import unicode_literals import sys import gdb -import six import pwndbg.android import pwndbg.arch @@ -73,14 +72,6 @@ try: except: pass -# this is an unconventional workaround to -# support unicode printing for python2 -# https://github.com/pwndbg/pwndbg/issues/117 -if six.PY2: - reload(sys) - sys.setdefaultencoding('utf-8') - - __all__ = [ 'arch', 'auxv',