SIGN IN SIGN UP
sqlmapproject / sqlmap UNCLAIMED

Automatic SQL injection and database takeover tool

0 0 5 Python
2019-03-21 14:00:09 +01:00
#!/usr/bin/env python2
"""
2019-01-05 21:38:52 +01:00
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
2017-10-11 14:50:46 +02:00
See the file 'LICENSE' for copying permission
"""
import functools
2017-12-24 23:54:43 +01:00
import hashlib
2019-01-29 23:44:58 +01:00
import threading
2017-12-24 23:54:43 +01:00
2019-01-29 23:44:58 +01:00
from lib.core.settings import MAX_CACHE_ITEMS
2019-04-30 13:20:31 +02:00
from lib.core.settings import UNICODE_ENCODING
2019-01-29 23:44:58 +01:00
from lib.core.datatype import LRUDict
from lib.core.threads import getCurrentThreadData
2019-01-29 23:44:58 +01:00
_lock = threading.Lock()
def cachedmethod(f, cache=LRUDict(capacity=MAX_CACHE_ITEMS)):
"""
Method with a cached content
Reference: http://code.activestate.com/recipes/325205-cache-decorator-in-python-24/
"""
2013-01-30 10:38:11 +01:00
@functools.wraps(f)
2012-07-30 10:06:14 +02:00
def _(*args, **kwargs):
2019-04-30 13:20:31 +02:00
key = int(hashlib.md5("|".join(str(_) for _ in (f, args, kwargs)).encode(UNICODE_ENCODING)).hexdigest(), 16) & 0x7fffffffffffffff
2016-05-14 14:18:34 +02:00
2019-02-09 23:18:08 +01:00
try:
2019-02-12 10:49:47 +01:00
with _lock:
result = cache[key]
2019-02-09 23:18:08 +01:00
except KeyError:
result = f(*args, **kwargs)
with _lock:
cache[key] = result
return result
2013-01-30 10:38:11 +01:00
2012-07-30 10:06:14 +02:00
return _
def stackedmethod(f):
"""
Method using pushValue/popValue functions (fallback function for stack realignment)
"""
@functools.wraps(f)
def _(*args, **kwargs):
threadData = getCurrentThreadData()
originalLevel = len(threadData.valueStack)
try:
result = f(*args, **kwargs)
finally:
if len(threadData.valueStack) > originalLevel:
threadData.valueStack = threadData.valueStack[:originalLevel]
return result
2018-06-09 23:38:00 +02:00
return _