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

Skip to content

Commit 22907d5

Browse files
committed
Some more trivial refactoring
1 parent b1a8986 commit 22907d5

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/core/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from lib.core.settings import DEFAULT_COOKIE_DELIMITER
4040
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
4141
from lib.core.settings import GENERIC_SQL_COMMENT
42+
from lib.core.settings import INFERENCE_MARKER
4243
from lib.core.settings import NULL
4344
from lib.core.settings import PAYLOAD_DELIMITER
4445
from lib.core.settings import REPLACEMENT_MARKER
@@ -319,7 +320,7 @@ def cleanupPayload(self, payload, origValue=None):
319320
origValue = getUnicode(origValue)
320321
payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if origValue.isdigit() else unescaper.escape("'%s'" % origValue))
321322

322-
if "[INFERENCE]" in payload:
323+
if INFERENCE_MARKER in payload:
323324
if Backend.getIdentifiedDbms() is not None:
324325
inference = queries[Backend.getIdentifiedDbms()].inference
325326

@@ -331,7 +332,7 @@ def cleanupPayload(self, payload, origValue=None):
331332
else:
332333
inferenceQuery = inference.query
333334

334-
payload = payload.replace("[INFERENCE]", inferenceQuery)
335+
payload = payload.replace(INFERENCE_MARKER, inferenceQuery)
335336
elif not kb.testMode:
336337
errMsg = "invalid usage of inference payload without "
337338
errMsg += "knowledge of underlying DBMS"

lib/core/bigarray.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ def _size_of(object_):
2727
"""
2828

2929
retval = sys.getsizeof(object_, DEFAULT_SIZE_OF)
30+
3031
if isinstance(object_, dict):
3132
retval += sum(_size_of(_) for _ in itertools.chain.from_iterable(object_.items()))
3233
elif hasattr(object_, "__iter__"):
3334
retval += sum(_size_of(_) for _ in object_)
35+
3436
return retval
3537

3638
class Cache(object):
@@ -58,11 +60,13 @@ def __init__(self):
5860

5961
def append(self, value):
6062
self.chunks[-1].append(value)
63+
6164
if self.chunk_length == sys.maxint:
6265
self._size_counter += _size_of(value)
6366
if self._size_counter >= BIGARRAY_CHUNK_SIZE:
6467
self.chunk_length = len(self.chunks[-1])
6568
self._size_counter = None
69+
6670
if len(self.chunks[-1]) >= self.chunk_length:
6771
filename = self._dump(self.chunks[-1])
6872
self.chunks[-1] = filename
@@ -82,12 +86,14 @@ def pop(self):
8286
errMsg = "exception occurred while retrieving data "
8387
errMsg += "from a temporary file ('%s')" % ex.message
8488
raise SqlmapSystemException, errMsg
89+
8590
return self.chunks[-1].pop()
8691

8792
def index(self, value):
8893
for index in xrange(len(self)):
8994
if self[index] == value:
9095
return index
96+
9197
return ValueError, "%s is not in list" % value
9298

9399
def _dump(self, chunk):
@@ -110,6 +116,7 @@ def _checkcache(self, index):
110116
if (self.cache and self.cache.index != index and self.cache.dirty):
111117
filename = self._dump(self.cache.data)
112118
self.chunks[self.cache.index] = filename
119+
113120
if not (self.cache and self.cache.index == index):
114121
try:
115122
with open(self.chunks[index], "rb") as fp:
@@ -128,18 +135,23 @@ def __setstate__(self, state):
128135

129136
def __getslice__(self, i, j):
130137
retval = BigArray()
138+
131139
i = max(0, len(self) + i if i < 0 else i)
132140
j = min(len(self), len(self) + j if j < 0 else j)
141+
133142
for _ in xrange(i, j):
134143
retval.append(self[_])
144+
135145
return retval
136146

137147
def __getitem__(self, y):
138148
if y < 0:
139149
y += len(self)
150+
140151
index = y / self.chunk_length
141152
offset = y % self.chunk_length
142153
chunk = self.chunks[index]
154+
143155
if isinstance(chunk, list):
144156
return chunk[offset]
145157
else:
@@ -150,6 +162,7 @@ def __setitem__(self, y, value):
150162
index = y / self.chunk_length
151163
offset = y % self.chunk_length
152164
chunk = self.chunks[index]
165+
153166
if isinstance(chunk, list):
154167
chunk[offset] = value
155168
else:

lib/core/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def htmlunescape(value):
166166

167167
retVal = value
168168
if value and isinstance(value, basestring):
169-
codes = (('&lt;', '<'), ('&gt;', '>'), ('&quot;', '"'), ('&nbsp;', ' '), ('&amp;', '&'))
169+
codes = (("&lt;", '<'), ("&gt;", '>'), ("&quot;", '"'), ("&nbsp;", ' '), ("&amp;", '&'), ("&apos;", "'"))
170170
retVal = reduce(lambda x, y: x.replace(y[0], y[1]), codes, retVal)
171171
try:
172172
retVal = re.sub(r"&#x([^ ;]+);", lambda match: unichr(int(match.group(1), 16)), retVal)

lib/request/inject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from lib.core.exception import SqlmapNotVulnerableException
4444
from lib.core.exception import SqlmapUserQuitException
4545
from lib.core.settings import GET_VALUE_UPPERCASE_KEYWORDS
46+
from lib.core.settings import INFERENCE_MARKER
4647
from lib.core.settings import MAX_TECHNIQUES_PER_VALUE
4748
from lib.core.settings import SQL_SCALAR_REGEX
4849
from lib.core.threads import getCurrentThreadData
@@ -304,7 +305,7 @@ def _goBooleanProxy(expression):
304305
return output
305306

306307
vector = kb.injection.data[kb.technique].vector
307-
vector = vector.replace("[INFERENCE]", expression)
308+
vector = vector.replace(INFERENCE_MARKER, expression)
308309
query = agent.prefixQuery(vector)
309310
query = agent.suffixQuery(query)
310311
payload = agent.payload(newValue=query)

0 commit comments

Comments
 (0)