Skip to content

Commit

Permalink
Cleanup unconditional imports (#1753)
Browse files Browse the repository at this point in the history
* Cleanup unconditional imports

This may aid #1725

* Import explicitly

* Add good ol' SIGALRM-based debugs for tests

* Fix py2 GDB tests somehow

XXX: see why this matters

* Update CHANGELOG.md
  • Loading branch information
Arusekk committed Apr 29, 2021
1 parent ad251a8 commit 4b196c7
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -63,12 +63,14 @@ The table below shows which release corresponds to each branch, and what date th
- [#1429][1429] Add a mechanism for ret2csu (originally #1138)
- [#1739][1739] Add/fix shellcraft.linux.kill() / shellcraft.linux.killparent()
- [#1746][1746] Prefer Python3 over Python2 for spawning remote processes over SSH
- [#1753][1753] major change: less unconditional imports in pwnlib
- [#1776][1776] mips: do not use $t0 temporary variable in dupio
- [#1846][1846] support launching GDB in more different terminals

[1429]: https://github.com/Gallopsled/pwntools/pull/1429
[1739]: https://github.com/Gallopsled/pwntools/pull/1739
[1746]: https://github.com/Gallopsled/pwntools/pull/1746
[1753]: https://github.com/Gallopsled/pwntools/pull/1753
[1776]: https://github.com/Gallopsled/pwntools/pull/1776
[1846]: https://github.com/Gallopsled/pwntools/pull/1846

Expand Down
13 changes: 10 additions & 3 deletions docs/source/conf.py
Expand Up @@ -25,7 +25,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../..'))

import pwnlib
import pwnlib.update
pwnlib.update.disabled = True

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -71,8 +71,9 @@ def filter(self, record):
import sys, os
os.environ['PWNLIB_NOTERM'] = '1'
os.environ['PWNLIB_RANDOMIZE'] = '0'
import pwnlib, logging
import pwnlib.update
import pwnlib.util.fiddling
import logging
pwnlib.update.disabled = True
pwnlib.context.context.reset_local()
pwnlib.context.ContextType.defaults['log_level'] = logging.ERROR
Expand Down Expand Up @@ -439,3 +440,9 @@ def setup(app):
import binascii
paramiko.client.hexlify = lambda x: binascii.hexlify(x).decode()
paramiko.util.safe_string = lambda x: '' # function result never *actually used*
class EndlessLoop(Exception): pass
def alrm_handler(sig, frame):
signal.alarm(180) # three minutes
raise EndlessLoop()
signal.signal(signal.SIGALRM, alrm_handler)
signal.alarm(600) # ten minutes
1 change: 0 additions & 1 deletion pwn/__init__.py
Expand Up @@ -7,7 +7,6 @@
pwnlib.log.install_default_handler()
pwnlib.config.initialize()

log = pwnlib.log.getLogger('pwnlib.exploit')
args = pwnlib.args.args

if not platform.architecture()[0].startswith('64'):
Expand Down
1 change: 1 addition & 0 deletions pwn/toplevel.py
Expand Up @@ -78,6 +78,7 @@
from six.moves import cPickle as pickle, cStringIO as StringIO
from six import BytesIO

log = getLogger("pwnlib.exploit")
error = log.error
warning = log.warning
warn = log.warning
Expand Down
10 changes: 4 additions & 6 deletions pwnlib/__init__.py
@@ -1,12 +1,11 @@
from __future__ import absolute_import

import importlib

from pwnlib.version import __version__
from .version import __version__

version = __version__

__all__ = [
'adb',
'args',
'asm',
'atexception',
Expand Down Expand Up @@ -35,9 +34,8 @@
'ui',
'useragents',
'util',
'adb',
'update',
'version',
]

for module in __all__:
importlib.import_module('.%s' % module, 'pwnlib')
from . import args
2 changes: 1 addition & 1 deletion pwnlib/commandline/asm.py
Expand Up @@ -5,7 +5,7 @@
import argparse
import sys

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/constgrep.py
Expand Up @@ -6,7 +6,7 @@
import functools
import re

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/cyclic.py
Expand Up @@ -7,7 +7,7 @@
import string
import sys

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/disasm.py
Expand Up @@ -7,7 +7,7 @@
import string
import sys

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/elfdiff.py
Expand Up @@ -8,7 +8,7 @@
from subprocess import check_output
from tempfile import NamedTemporaryFile

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/elfpatch.py
Expand Up @@ -4,7 +4,7 @@

import sys

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/phd.py
Expand Up @@ -7,7 +7,7 @@
import sys
import io

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/pwnstrip.py
Expand Up @@ -3,7 +3,7 @@

import argparse

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/scramble.py
Expand Up @@ -4,7 +4,7 @@
import argparse
import sys

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/shellcraft.py
Expand Up @@ -8,7 +8,7 @@
import sys
import types

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/update.py
Expand Up @@ -4,7 +4,7 @@

import subprocess

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/commandline/version.py
Expand Up @@ -5,7 +5,7 @@
import os
import subprocess

import pwnlib
import pwnlib.args
pwnlib.args.free_form = False

from pwn import *
Expand Down
5 changes: 2 additions & 3 deletions pwnlib/gdb.py
Expand Up @@ -155,9 +155,6 @@
from threading import Event
import time

from rpyc import BgServingThread
from rpyc.utils.factory import unix_connect

from pwnlib import adb
from pwnlib import atexit
from pwnlib import elf
Expand Down Expand Up @@ -1055,6 +1052,8 @@ def preexec_fn():
return gdb_pid

# connect to the GDB Python API bridge
from rpyc import BgServingThread
from rpyc.utils.factory import unix_connect
if six.PY2:
retriable = socket.error
else:
Expand Down
14 changes: 0 additions & 14 deletions pwnlib/util/__init__.py
@@ -1,19 +1,5 @@
from __future__ import absolute_import

from pwnlib.util import crc
from pwnlib.util import cyclic
from pwnlib.util import fiddling
from pwnlib.util import hashes
from pwnlib.util import iters
from pwnlib.util import lists
from pwnlib.util import misc
from pwnlib.util import net
from pwnlib.util import packing
from pwnlib.util import proc
from pwnlib.util import safeeval
from pwnlib.util import sh_string
from pwnlib.util import web

__all__ = [
'crc', 'cyclic', 'fiddling', 'hashes', 'iters',
'lists', 'misc', 'net', 'packing', 'proc', 'safeeval',
Expand Down

0 comments on commit 4b196c7

Please sign in to comment.