mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-07 13:11:29 +00:00
getting rid of obsolete getCompiledRegex (in newer versions of Python regexes are already cached)
This commit is contained in:
@@ -12,7 +12,6 @@ import re
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
from lib.core.common import Backend
|
||||
from lib.core.common import getCompiledRegex
|
||||
from lib.core.common import isDBMSVersionAtLeast
|
||||
from lib.core.common import isTechniqueAvailable
|
||||
from lib.core.common import randomInt
|
||||
@@ -379,14 +378,14 @@ class Agent:
|
||||
"""
|
||||
|
||||
prefixRegex = "(?:\s+(?:FIRST|SKIP)\s+\d+)*"
|
||||
fieldsSelectTop = getCompiledRegex("\ASELECT\s+TOP\s+[\d]+\s+(.+?)\s+FROM", re.I).search(query)
|
||||
fieldsSelectDistinct = getCompiledRegex("\ASELECT%s\s+DISTINCT\((.+?)\)\s+FROM" % prefixRegex, re.I).search(query)
|
||||
fieldsSelectCase = getCompiledRegex("\ASELECT%s\s+(\(CASE WHEN\s+.+\s+END\))" % prefixRegex, re.I).search(query)
|
||||
fieldsSelectFrom = getCompiledRegex("\ASELECT%s\s+(.+?)\s+FROM\s+" % prefixRegex, re.I).search(query)
|
||||
fieldsExists = getCompiledRegex("EXISTS(.*)", re.I).search(query)
|
||||
fieldsSelect = getCompiledRegex("\ASELECT%s\s+(.*)" % prefixRegex, re.I).search(query)
|
||||
fieldsSubstr = getCompiledRegex("\A(SUBSTR|MID\()", re.I).search(query)
|
||||
fieldsMinMaxstr = getCompiledRegex("(?:MIN|MAX)\(([^\(\)]+)\)", re.I).search(query)
|
||||
fieldsSelectTop = re.search("\ASELECT\s+TOP\s+[\d]+\s+(.+?)\s+FROM", query, re.I)
|
||||
fieldsSelectDistinct = re.search("\ASELECT%s\s+DISTINCT\((.+?)\)\s+FROM" % prefixRegex, query, re.I)
|
||||
fieldsSelectCase = re.search("\ASELECT%s\s+(\(CASE WHEN\s+.+\s+END\))" % prefixRegex, query, re.I)
|
||||
fieldsSelectFrom = re.search("\ASELECT%s\s+(.+?)\s+FROM\s+" % prefixRegex, query, re.I)
|
||||
fieldsExists = re.search("EXISTS(.*)", query, re.I)
|
||||
fieldsSelect = re.search("\ASELECT%s\s+(.*)" % prefixRegex, query, re.I)
|
||||
fieldsSubstr = re.search("\A(SUBSTR|MID\()", query, re.I)
|
||||
fieldsMinMaxstr = re.search("(?:MIN|MAX)\(([^\(\)]+)\)", query, re.I)
|
||||
fieldsNoSelect = query
|
||||
|
||||
if fieldsSubstr:
|
||||
@@ -799,8 +798,7 @@ class Agent:
|
||||
retVal = None
|
||||
|
||||
if inpStr:
|
||||
regObj = getCompiledRegex("%s(?P<result>.*?)%s" % (PAYLOAD_DELIMITER, PAYLOAD_DELIMITER))
|
||||
match = regObj.search(inpStr)
|
||||
match = re.search("%s(?P<result>.*?)%s" % (PAYLOAD_DELIMITER, PAYLOAD_DELIMITER), inpStr)
|
||||
|
||||
if match:
|
||||
retVal = match.group("result")
|
||||
@@ -814,8 +812,7 @@ class Agent:
|
||||
retVal = inpStr
|
||||
|
||||
if inpStr:
|
||||
regObj = getCompiledRegex("(%s.*?%s)" % (PAYLOAD_DELIMITER, PAYLOAD_DELIMITER))
|
||||
retVal = regObj.sub("%s%s%s" % (PAYLOAD_DELIMITER, payload, PAYLOAD_DELIMITER), inpStr)
|
||||
retVal = re.sub("(%s.*?%s)" % (PAYLOAD_DELIMITER, PAYLOAD_DELIMITER), "%s%s%s" % (PAYLOAD_DELIMITER, payload, PAYLOAD_DELIMITER), inpStr)
|
||||
|
||||
return retVal
|
||||
|
||||
|
||||
@@ -1821,22 +1821,6 @@ def goGoodSamaritan(prevValue, originalCharset):
|
||||
else:
|
||||
return None, None, None, originalCharset
|
||||
|
||||
def getCompiledRegex(regex, flags=0):
|
||||
"""
|
||||
Returns compiled regular expression and stores it in cache for further
|
||||
usage (deprecated as newer versions of Python do this automatically)
|
||||
|
||||
>>> getCompiledRegex('test') # doctest: +ELLIPSIS
|
||||
<_sre.SRE_Pattern object at...
|
||||
"""
|
||||
|
||||
if (regex, flags) in kb.cache.regex:
|
||||
retVal = kb.cache.regex[(regex, flags)]
|
||||
else:
|
||||
retVal = re.compile(regex, flags)
|
||||
kb.cache.regex[(regex, flags)] = retVal
|
||||
return retVal
|
||||
|
||||
def getPartRun():
|
||||
"""
|
||||
Goes through call stack and finds constructs matching conf.dbmsHandler.*.
|
||||
@@ -1852,8 +1836,8 @@ def getPartRun():
|
||||
# Goes backwards through the stack to find the conf.dbmsHandler method
|
||||
# calling this function
|
||||
for i in xrange(0, len(stack) - 1):
|
||||
for regex in (getCompiledRegex('self\.(get[^(]+)\(\)'), getCompiledRegex('conf\.dbmsHandler\.([^(]+)\(\)')):
|
||||
match = regex.search(stack[i])
|
||||
for regex in (r"self\.(get[^(]+)\(\)", r"conf\.dbmsHandler\.([^(]+)\(\)"):
|
||||
match = re.search(regex, stack[i])
|
||||
|
||||
if match:
|
||||
# This is the calling conf.dbmsHandler or self method
|
||||
@@ -2158,7 +2142,7 @@ def extractRegexResult(regex, content, flags=0):
|
||||
retVal = None
|
||||
|
||||
if regex and content and '?P<result>' in regex:
|
||||
match = getCompiledRegex(regex, flags).search(content)
|
||||
match = re.search(regex, content, flags)
|
||||
|
||||
if match:
|
||||
retVal = match.group("result")
|
||||
@@ -2257,11 +2241,11 @@ def removeDynamicContent(page):
|
||||
if prefix is None and suffix is None:
|
||||
continue
|
||||
elif prefix is None:
|
||||
page = getCompiledRegex('(?s)^.+%s' % suffix).sub(suffix, page)
|
||||
page = re.sub(r'(?s)^.+%s' % suffix, suffix, page)
|
||||
elif suffix is None:
|
||||
page = getCompiledRegex('(?s)%s.+$' % prefix).sub(prefix, page)
|
||||
page = re.sub(r'(?s)%s.+$' % prefix, prefix, page)
|
||||
else:
|
||||
page = getCompiledRegex('(?s)%s.+%s' % (prefix, suffix)).sub('%s%s' % (prefix, suffix), page)
|
||||
page = re.sub(r'(?s)%s.+%s' % (prefix, suffix), '%s%s' % (prefix, suffix), page)
|
||||
|
||||
return page
|
||||
|
||||
@@ -2327,7 +2311,7 @@ def parseSqliteTableSchema(value):
|
||||
table = {}
|
||||
columns = {}
|
||||
|
||||
for match in re.finditer(getCompiledRegex(r"(\w+)\s+(TEXT|NUMERIC|INTEGER|REAL|NONE)"), value):
|
||||
for match in re.finditer(r"(\w+)\s+(TEXT|NUMERIC|INTEGER|REAL|NONE)", value):
|
||||
columns[match.group(1)] = match.group(2)
|
||||
|
||||
table[conf.tbl] = columns
|
||||
@@ -2473,7 +2457,7 @@ def filterListValue(value, regex):
|
||||
"""
|
||||
|
||||
if isinstance(value, list) and regex:
|
||||
retVal = filter(lambda x: getCompiledRegex(regex, re.I).search(x), value)
|
||||
retVal = filter(lambda _: re.search(regex, _, re.I), value)
|
||||
else:
|
||||
retVal = value
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ from lib.controller.controller import start
|
||||
from lib.core.common import beep
|
||||
from lib.core.common import clearConsoleLine
|
||||
from lib.core.common import dataToStdout
|
||||
from lib.core.common import getCompiledRegex
|
||||
from lib.core.common import readXmlFile
|
||||
from lib.core.data import conf
|
||||
from lib.core.data import logger
|
||||
@@ -231,7 +230,7 @@ def runCase(switches=None, log=None, session=None):
|
||||
def replaceVars(item, vars_):
|
||||
retVal = item
|
||||
if item and vars_:
|
||||
for var in re.findall(getCompiledRegex("\$\{([^}]+)\}"), item):
|
||||
for var in re.findall("\$\{([^}]+)\}", item):
|
||||
if var in vars_:
|
||||
retVal = retVal.replace("${%s}" % var, vars_[var])
|
||||
return retVal
|
||||
|
||||
Reference in New Issue
Block a user