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

Skip to content

Commit 5770c08

Browse files
committed
minor optimization and refactoring
1 parent 0a7a648 commit 5770c08

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

lib/core/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
ROTATING_CHARS = ('\\', '|', '|', '/', '-')
385385

386386
# Chunk length (in items) used by BigArray objects (only last chunk and cached one are held in memory)
387-
BIGARRAY_CHUNK_LENGTH = 5000
387+
BIGARRAY_CHUNK_LENGTH = 4096
388388

389389
# Only console display last n table rows
390-
TRIM_STDOUT_DUMP_SIZE = 256
390+
TRIM_STDOUT_DUMP_SIZE = 1024

lib/techniques/error/use.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def errorUse(expression, expected=None, resumeValue=True, dump=False):
320320
stopLimit = 1
321321

322322
threadData = getCurrentThreadData()
323-
threadData.shared.limits = range(startLimit, stopLimit)
324-
numThreads = min(conf.threads, len(threadData.shared.limits))
323+
threadData.shared.limits = iter(xrange(startLimit, stopLimit))
324+
numThreads = min(conf.threads, (stopLimit - startLimit))
325325
threadData.shared.outputs = BigArray()
326326

327327
if stopLimit > TURN_OFF_RESUME_INFO_LIMIT:
@@ -340,13 +340,12 @@ def errorThread():
340340

341341
while kb.threadContinue:
342342
kb.locks.limits.acquire()
343-
if threadData.shared.limits:
344-
num = threadData.shared.limits[-1]
345-
del threadData.shared.limits[-1]
346-
kb.locks.limits.release()
347-
else:
348-
kb.locks.limits.release()
343+
try:
344+
num = threadData.shared.limits.next()
345+
except StopIteration:
349346
break
347+
finally:
348+
kb.locks.limits.release()
350349

351350
output = __errorFields(expression, expressionFields, expressionFieldsList, expected, num, resumeValue)
352351

lib/techniques/union/use.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ def unionUse(expression, unpack=True, dump=False):
261261
stopLimit = 1
262262

263263
threadData = getCurrentThreadData()
264-
threadData.shared.limits = range(startLimit, stopLimit)
265-
numThreads = min(conf.threads, len(threadData.shared.limits))
264+
threadData.shared.limits = iter(xrange(startLimit, stopLimit))
265+
numThreads = min(conf.threads, (stopLimit - startLimit))
266266
threadData.shared.value = BigArray()
267267

268268
if stopLimit > TURN_OFF_RESUME_INFO_LIMIT:
@@ -281,13 +281,12 @@ def unionThread():
281281

282282
while kb.threadContinue:
283283
kb.locks.limits.acquire()
284-
if threadData.shared.limits:
285-
num = threadData.shared.limits[-1]
286-
del threadData.shared.limits[-1]
287-
kb.locks.limits.release()
288-
else:
289-
kb.locks.limits.release()
284+
try:
285+
num = threadData.shared.limits.next()
286+
except StopIteration:
290287
break
288+
finally:
289+
kb.locks.limits.release()
291290

292291
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
293292
field = expressionFieldsList[0]

lib/utils/hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def attackDumpedTable():
266266
colUser = column
267267
break
268268

269-
for i in range(count):
269+
for i in xrange(count):
270270
for column in columns:
271271
if column == colUser or column == '__infos__':
272272
continue

sqlmap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def main():
130130
kb.threadException = True
131131

132132
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
133-
os._exit(0)
133+
if conf.threads > 1:
134+
os._exit(0)
134135

135136
if __name__ == "__main__":
136137
main()

0 commit comments

Comments
 (0)