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

Skip to content

Commit 9697e80

Browse files
committed
some more optimizations
1 parent 267d67b commit 9697e80

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

_sqlmap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def main():
129129
kb.threadContinue = False
130130
kb.threadException = True
131131

132+
if conf.hashDB:
133+
conf.hashDB.flush(True)
134+
132135
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
133136
if hasattr(conf, "threads") and conf.threads > 1:
134137
os._exit(0)

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,7 @@
414414
DEFAULT_GET_POST_DELIMITER = '&'
415415

416416
# Default delimiter in cookie values
417-
DEFAULT_COOKIE_DELIMITER = ';'
417+
DEFAULT_COOKIE_DELIMITER = ';'
418+
419+
# Skip unforced HashDB flush requests below the threshold number of cached items
420+
HASHDB_FLUSH_THRESHOLD = 10

lib/core/threads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
181181
kb.threadContinue = True
182182
kb.threadException = False
183183

184-
conf.hashDB.flush()
184+
conf.hashDB.flush(True)
185185

186186
if cleanupFunction:
187187
cleanupFunction()

lib/utils/hashdb.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import threading
1313

1414
from lib.core.data import conf
15+
from lib.core.settings import HASHDB_FLUSH_THRESHOLD
1516
from lib.core.settings import UNICODE_ENCODING
1617
from lib.core.threads import getCurrentThreadData
1718
from lib.core.threads import getCurrentThreadName
@@ -54,15 +55,17 @@ def retrieve(self, key):
5455
retVal = None
5556
if key:
5657
hash_ = HashDB.hashKey(key)
57-
while True:
58-
try:
59-
for row in self.cursor.execute("SELECT value FROM storage WHERE id=?", (hash_,)):
60-
retVal = row[0]
61-
except sqlite3.OperationalError, ex:
62-
if not 'locked' in ex.message:
63-
raise
64-
else:
65-
break
58+
retVal = self._write_cache.get(hash_, None)
59+
if not retVal:
60+
while True:
61+
try:
62+
for row in self.cursor.execute("SELECT value FROM storage WHERE id=?", (hash_,)):
63+
retVal = row[0]
64+
except sqlite3.OperationalError, ex:
65+
if not 'locked' in ex.message:
66+
raise
67+
else:
68+
break
6669
return retVal
6770

6871
def write(self, key, value):
@@ -75,10 +78,13 @@ def write(self, key, value):
7578
if getCurrentThreadName() in ('0', 'MainThread'):
7679
self.flush()
7780

78-
def flush(self):
81+
def flush(self, forced=False):
7982
if not self._write_cache:
8083
return
8184

85+
if not forced and len(self._write_cache) < HASHDB_FLUSH_THRESHOLD:
86+
return
87+
8288
self._cache_lock.acquire()
8389
items = self._write_cache.items()
8490
self._write_cache.clear()

plugins/generic/enumeration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,6 @@ def dumpTable(self, foundData=None):
15641564

15651565
try:
15661566
kb.dumpMode = True
1567-
#conf.hashDB.beginTransaction()
15681567

15691568
if not safeSQLIdentificatorNaming(conf.db) in kb.data.cachedColumns \
15701569
or safeSQLIdentificatorNaming(tbl, True) not in \
@@ -1789,7 +1788,6 @@ def dumpTable(self, foundData=None):
17891788

17901789
finally:
17911790
kb.dumpMode = False
1792-
#conf.hashDB.endTransaction()
17931791

17941792
def dumpAll(self):
17951793
if conf.db is not None and conf.tbl is None:

0 commit comments

Comments
 (0)