some speedup (usage of xrange (virtual range) instead of range)

This commit is contained in:
Miroslav Stampar 2010-05-23 22:14:57 +00:00
parent 2c2d6d3623
commit 887352746b

View File

@ -141,23 +141,26 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
return None return None
def getChar(idx, asciiTbl=asciiTbl): def getChar(idx, charTbl=asciiTbl):
result = tryHint(idx) result = tryHint(idx)
if result: if result:
return result return result
maxChar = maxValue = asciiTbl[-1] maxChar = maxValue = charTbl[-1]
minValue = asciiTbl[0] minValue = charTbl[0]
while len(asciiTbl) != 1: while len(charTbl) != 1:
queriesCount[0] += 1 queriesCount[0] += 1
position = (len(asciiTbl) / 2) position = (len(charTbl) >> 1)
posValue = asciiTbl[position] posValue = charTbl[position]
if kb.dbms == "SQLite": if kb.dbms == "SQLite":
posValueOld = posValue posValueOld = posValue
posValue = chr(posValue) if posValue < 256:
posValue = chr(posValue)
else:
posValue = unichr(posValue)
if not conf.useBetween or kb.dbms == "SQLite": if not conf.useBetween or kb.dbms == "SQLite":
forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx, posValue)) forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx, posValue))
@ -171,18 +174,24 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
if result: if result:
minValue = posValue minValue = posValue
asciiTbl = asciiTbl[position:] if type(charTbl) != xrange:
charTbl = charTbl[position:]
else:
charTbl = xrange(charTbl[position], charTbl[-1] + 1)
else: else:
maxValue = posValue maxValue = posValue
asciiTbl = asciiTbl[:position] if type(charTbl) != xrange:
charTbl = charTbl[:position]
else:
charTbl = xrange(charTbl[0], charTbl[position] + 1)
if len(asciiTbl) == 1: if len(charTbl) == 1:
if maxValue == 1: if maxValue == 1:
return None return None
elif minValue == maxChar: elif minValue == maxChar:
asciiTbl = range( maxChar + 1, (maxChar + 1) << 8 ) charTbl = xrange( maxChar + 1, (maxChar + 1) << 8 )
maxChar = maxValue = asciiTbl[-1] maxChar = maxValue = charTbl[-1]
minValue = asciiTbl[0] minValue = charTbl[0]
else: else:
retVal = minValue + 1 retVal = minValue + 1
if retVal < 256: if retVal < 256: