Minor refactoring

This commit is contained in:
Bernardo Damele 2010-05-24 15:46:12 +00:00
parent f718425cf4
commit a43eb64c5d
2 changed files with 15 additions and 6 deletions

View File

@ -1165,7 +1165,6 @@ def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
gobject.timeout_add(1000, win.update, dotOutputFile) gobject.timeout_add(1000, win.update, dotOutputFile)
gtk.main() gtk.main()
def getConsoleWidth(default=80): def getConsoleWidth(default=80):
width = None width = None
@ -1204,22 +1203,25 @@ def initCommonOutputs():
key = None key = None
fileName = os.path.join(paths.SQLMAP_TXT_PATH, 'common-outputs.txt') fileName = os.path.join(paths.SQLMAP_TXT_PATH, 'common-outputs.txt')
file = open(fileName, 'r') cfile = open(fileName, 'r')
for line in file.xreadlines(): for line in cfile.xreadlines():
line = line.strip() line = line.strip()
if len(line) > 1: if len(line) > 1:
if line[0] == '[' and line[-1] == ']': if line[0] == '[' and line[-1] == ']':
key = line[1:-1] key = line[1:-1]
elif key: elif key:
if key not in kb.commonOutputs: if key not in kb.commonOutputs:
kb.commonOutputs[key] = [] kb.commonOutputs[key] = []
kb.commonOutputs[key].append(line.strip()) kb.commonOutputs[key].append(line.strip())
file.close()
cfile.close()
def getGoodSamaritanCharsets(part, prevValue, originalCharset): def getGoodSamaritanCharsets(part, prevValue, originalCharset):
###wild card . (dot) is supported for compatibility with threading ###wild card . (dot) is supported for compatibility with threading
if not kb.commonOutputs: if kb.commonOutputs is None:
initCommonOutputs() initCommonOutputs()
predictionSet = set() predictionSet = set()
@ -1227,8 +1229,10 @@ def getGoodSamaritanCharsets(part, prevValue, originalCharset):
if prevValue[-1] != '.': if prevValue[-1] != '.':
prevValue += '.' prevValue += '.'
charIndex = 0 charIndex = 0
findIndex = prevValue.find('.', charIndex) findIndex = prevValue.find('.', charIndex)
while findIndex != -1: while findIndex != -1:
wildIndexes.append(findIndex) wildIndexes.append(findIndex)
charIndex += 1 charIndex += 1
@ -1239,16 +1243,21 @@ def getGoodSamaritanCharsets(part, prevValue, originalCharset):
if re.search('\A%s' % prevValue, item): if re.search('\A%s' % prevValue, item):
for index in wildIndexes: for index in wildIndexes:
char = item[index] char = item[index]
if char not in predictionSet: if char not in predictionSet:
predictionSet.add(char) predictionSet.add(char)
predictedCharset = [] predictedCharset = []
otherCharset = [] otherCharset = []
for ordChar in originalTable: for ordChar in originalTable:
if chr(ordChar) not in predictionSet: if chr(ordChar) not in predictionSet:
otherCharset.append(ordChar) otherCharset.append(ordChar)
else: else:
predictedCharset.append(ordChar) predictedCharset.append(ordChar)
predictedCharset.sort() predictedCharset.sort()
return predictedCharset, otherCharset return predictedCharset, otherCharset
else: else:
return None, originalTable return None, originalTable

View File

@ -929,8 +929,8 @@ def __setKnowledgeBaseAttributes():
kb.absFilePaths = set() kb.absFilePaths = set()
kb.bannerFp = advancedDict() kb.bannerFp = advancedDict()
kb.data = advancedDict()
kb.commonOutputs = None kb.commonOutputs = None
kb.data = advancedDict()
# Basic back-end DBMS fingerprint # Basic back-end DBMS fingerprint
kb.dbms = None kb.dbms = None