Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8f57e1

Browse files
committed
Minor patches
1 parent a793175 commit f8f57e1

7 files changed

Lines changed: 63 additions & 11 deletions

File tree

lib/core/common.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,19 +4646,20 @@ def resetCookieJar(cookieJar):
46464646
def decloakToTemp(filename):
46474647
"""
46484648
Decloaks content of a given file to a temporary file with similar name and extension
4649+
4650+
>>> _ = decloakToTemp(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.asp_"))
4651+
>>> openFile(_, "rb", encoding=None).read().startswith(b'<%')
4652+
True
46494653
"""
46504654

46514655
content = decloak(filename)
46524656

4653-
_ = getBytes(os.path.split(filename[:-1])[-1])
4654-
4655-
prefix, suffix = os.path.splitext(_)
4656-
prefix = prefix.split(os.extsep)[0]
4657-
4657+
parts = getBytes(os.path.split(filename[:-1])[-1]).split(b'.')
4658+
prefix, suffix = parts[0], b".%s" % parts[-1]
46584659
handle, filename = tempfile.mkstemp(prefix=prefix, suffix=suffix)
46594660
os.close(handle)
46604661

4661-
with open(filename, "w+b") as f:
4662+
with openFile(filename, "w+b", encoding=None) as f:
46624663
f.write(content)
46634664

46644665
return filename

lib/core/datatype.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
class AttribDict(dict):
1515
"""
16-
This class defines the sqlmap object, inheriting from Python data
17-
type dictionary.
16+
This class defines the dictionary with added capability to access members as attributes
1817
1918
>>> foo = AttribDict()
2019
>>> foo.bar = 1
@@ -110,6 +109,19 @@ def __init__(self):
110109

111110
# Reference: https://www.kunxi.org/2014/05/lru-cache-in-python
112111
class LRUDict(object):
112+
"""
113+
This class defines the LRU dictionary
114+
115+
>>> foo = LRUDict(capacity=2)
116+
>>> foo["first"] = 1
117+
>>> foo["second"] = 2
118+
>>> foo["third"] = 3
119+
>>> "first" in foo
120+
False
121+
>>> "third" in foo
122+
True
123+
"""
124+
113125
def __init__(self, capacity):
114126
self.capacity = capacity
115127
self.cache = OrderedDict()
@@ -144,6 +156,21 @@ def keys(self):
144156

145157
# Reference: https://code.activestate.com/recipes/576694/
146158
class OrderedSet(collections.MutableSet):
159+
"""
160+
This class defines the set with ordered (as added) items
161+
162+
>>> foo = OrderedSet()
163+
>>> foo.add(1)
164+
>>> foo.add(2)
165+
>>> foo.add(3)
166+
>>> foo.pop()
167+
3
168+
>>> foo.pop()
169+
2
170+
>>> foo.pop()
171+
1
172+
"""
173+
147174
def __init__(self, iterable=None):
148175
self.end = end = []
149176
end += [None, end, end] # sentinel node for doubly linked list

lib/core/decorators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def cachedmethod(f, cache=LRUDict(capacity=MAX_CACHE_ITEMS)):
2020
"""
2121
Method with a cached content
2222
23+
>>> __ = cachedmethod(lambda _: _)
24+
>>> __(1)
25+
1
26+
>>> __ = cachedmethod(lambda *args, **kwargs: args[0])
27+
>>> __(2)
28+
2
29+
>>> __ = cachedmethod(lambda *args, **kwargs: list(kwargs.values())[0])
30+
>>> __(foobar=3)
31+
3
32+
2333
Reference: http://code.activestate.com/recipes/325205-cache-decorator-in-python-24/
2434
"""
2535

@@ -43,6 +53,13 @@ def _(*args, **kwargs):
4353
def stackedmethod(f):
4454
"""
4555
Method using pushValue/popValue functions (fallback function for stack realignment)
56+
57+
>>> threadData = getCurrentThreadData()
58+
>>> original = len(threadData.valueStack)
59+
>>> __ = stackedmethod(lambda _: threadData.valueStack.append(_))
60+
>>> __(1)
61+
>>> len(threadData.valueStack) == original
62+
True
4663
"""
4764

4865
@functools.wraps(f)

lib/core/readlineng.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# Thanks to Boyd Waters for this patch.
3636
uses_libedit = False
3737

38-
if PLATFORM == 'mac' and _readline:
38+
if PLATFORM == "mac" and _readline:
3939
import commands
4040

4141
(status, result) = commands.getstatusoutput("otool -L %s | grep libedit" % _readline.__file__)

lib/core/revision.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
def getRevisionNumber():
1313
"""
1414
Returns abbreviated commit hash number as retrieved with "git rev-parse --short HEAD"
15+
16+
>>> len(getRevisionNumber() or (' ' * 7)) == 7
17+
True
1518
"""
1619

1720
retVal = None

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty import six
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.28"
21+
VERSION = "1.3.5.29"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/wordlist.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
class Wordlist(six.Iterator):
1717
"""
1818
Iterator for looping over a large dictionaries
19+
20+
>>> from lib.core.option import paths
21+
>>> isinstance(next(Wordlist(paths.SMALL_DICT)), six.string_types)
22+
True
1923
"""
2024

2125
def __init__(self, filenames, proc_id=None, proc_count=None, custom=None):
22-
self.filenames = filenames
26+
self.filenames = [filenames] if isinstance(filenames, six.string_types) else filenames
2327
self.fp = None
2428
self.index = 0
2529
self.counter = -1

0 commit comments

Comments
 (0)