Skip to content

Commit

Permalink
Defer import of requests and urllib
Browse files Browse the repository at this point in the history
This saves 100ms-150ms of startup time on "from pwn import *"
  • Loading branch information
heapcrash committed May 31, 2021
1 parent ef37e99 commit fd4f940
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion pwn/toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import platform
import re
import requests
import socks
import signal
import string
Expand Down
10 changes: 7 additions & 3 deletions pwnlib/libcdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import codecs
import json
import os
import requests
import tempfile

from six.moves import urllib

from pwnlib.context import context
from pwnlib.elf import ELF
from pwnlib.log import getLogger
Expand All @@ -29,6 +26,10 @@
# https://gitlab.com/libcdb/libcdb wasn't updated after 2019,
# but still is a massive database of older libc binaries.
def provider_libcdb(hex_encoded_id, hash_type):
# Deferred import because it's slow
import requests
from six.moves import urllib

# Build the URL using the requested hash type
url_base = "https://gitlab.com/libcdb/libcdb/raw/master/hashes/%s/" % hash_type
url = urllib.parse.urljoin(url_base, hex_encoded_id)
Expand All @@ -53,6 +54,9 @@ def provider_libcdb(hex_encoded_id, hash_type):

# https://libc.rip/
def provider_libc_rip(hex_encoded_id, hash_type):
# Deferred import because it's slow
import requests

# Build the request for the hash type
# https://github.com/niklasb/libc-database/blob/master/searchengine/api.yml
if hash_type == 'build_id':
Expand Down

0 comments on commit fd4f940

Please sign in to comment.