2016-09-13 10:35:46 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-07-16 23:40:44 +08:00
|
|
|
import glob
|
2016-11-19 01:43:33 +08:00
|
|
|
import locale
|
2017-02-11 03:00:07 +08:00
|
|
|
import sys
|
2022-07-16 23:40:44 +08:00
|
|
|
from os import path, environ
|
|
|
|
|
|
|
|
virtual_env = environ.get('VIRTUAL_ENV')
|
|
|
|
|
|
|
|
|
|
|
|
if virtual_env:
|
|
|
|
print("Found that you're using VIRTUAL_ENV '%s'" % virtual_env)
|
|
|
|
possible_site_packages = glob.glob(path.join(virtual_env, 'lib', 'python*', 'site-packages'))
|
|
|
|
if len(possible_site_packages) > 1:
|
|
|
|
print("Found multiple site packages in virtualenv, using the last choice.")
|
|
|
|
virtualenv_site_packages = []
|
|
|
|
for site_packages in possible_site_packages:
|
|
|
|
virtualenv_site_packages = site_packages
|
|
|
|
if not virtualenv_site_packages:
|
|
|
|
print("Not found site-packages in virtualenv, guessing")
|
|
|
|
guessed_python_directory = 'python%s.%s' % (sys.version_info.major, sys.version_info.minor)
|
|
|
|
virtualenv_site_packages = path.join(virtual_env, 'lib', guessed_python_directory, 'site-packages')
|
|
|
|
print("Using virtualenv's python site packages: %s " % virtualenv_site_packages)
|
|
|
|
sys.path.append(virtualenv_site_packages)
|
2015-02-14 00:08:56 +08:00
|
|
|
|
|
|
|
directory, file = path.split(__file__)
|
|
|
|
directory = path.expanduser(directory)
|
|
|
|
directory = path.abspath(directory)
|
|
|
|
|
|
|
|
sys.path.append(directory)
|
|
|
|
|
2020-08-16 03:27:47 +08:00
|
|
|
# warn if the user has different encoding than utf-8
|
2016-11-19 01:43:33 +08:00
|
|
|
encoding = locale.getpreferredencoding()
|
|
|
|
|
2020-08-16 03:27:47 +08:00
|
|
|
if encoding != 'UTF-8':
|
2016-11-19 01:43:33 +08:00
|
|
|
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('******')
|
|
|
|
|
2016-06-15 03:16:40 +08:00
|
|
|
import pwndbg # isort:skip
|