77See the file 'doc/COPYING' for copying permission
88"""
99
10+ from lib .core .data import kb
11+ from lib .core .common import isDBMSVersionAtLeast
1012from lib .core .exception import sqlmapSyntaxException
1113
1214from plugins .generic .syntax import Syntax as GenericSyntax
@@ -21,57 +23,58 @@ def __init__(self):
2123
2224 @staticmethod
2325 def unescape (expression , quote = True ):
24- #if quote:
25- #while True:
26- #index = expression.find("'")
27- #if index == -1:
28- #break
26+ if isDBMSVersionAtLeast ('2.1' ):
27+ if quote :
28+ while True :
29+ index = expression .find ("'" )
30+ if index == - 1 :
31+ break
2932
30- # firstIndex = index + 1
31- # index = expression[firstIndex:].find("'")
33+ firstIndex = index + 1
34+ index = expression [firstIndex :].find ("'" )
3235
33- # if index == -1:
34- # raise sqlmapSyntaxException, "Unenclosed ' in '%s'" % expression
36+ if index == - 1 :
37+ raise sqlmapSyntaxException , "Unenclosed ' in '%s'" % expression
3538
36- # lastIndex = firstIndex + index
37- # old = "'%s'" % expression[firstIndex:lastIndex]
38- # unescaped = ""
39+ lastIndex = firstIndex + index
40+ old = "'%s'" % expression [firstIndex :lastIndex ]
41+ unescaped = ""
3942
40- # for i in range(firstIndex, lastIndex):
41- # unescaped += "ASCII_CHAR(%d)" % (ord(expression[i]))
42- # if i < lastIndex - 1:
43- # unescaped += "||"
43+ for i in range (firstIndex , lastIndex ):
44+ unescaped += "ASCII_CHAR(%d)" % (ord (expression [i ]))
45+ if i < lastIndex - 1 :
46+ unescaped += "||"
4447
45- # expression = expression.replace(old, unescaped)
46- # else:
47- # unescaped = "".join("ASCII_CHAR(%d)||" % ord(c) for c in expression)
48- # if unescaped[-1] == "||":
49- # unescaped = unescaped[:-1]
48+ expression = expression .replace (old , unescaped )
49+ else :
50+ unescaped = "" .join ("ASCII_CHAR(%d)||" % ord (c ) for c in expression )
51+ if unescaped [- 1 ] == "||" :
52+ unescaped = unescaped [:- 1 ]
5053
51- # expression = unescaped
54+ expression = unescaped
5255
5356 return expression
5457
5558 @staticmethod
5659 def escape (expression ):
57- # while True:
58- # index = expression.find("ASCII_CHAR(")
59- # if index == -1:
60- # break
60+ while True :
61+ index = expression .find ("ASCII_CHAR(" )
62+ if index == - 1 :
63+ break
6164
62- # firstIndex = index
63- # index = expression[firstIndex:].find(")")
65+ firstIndex = index
66+ index = expression [firstIndex :].find (")" )
6467
65- # if index == -1:
66- # raise sqlmapSyntaxException, "Unenclosed ) in '%s'" % expression
68+ if index == - 1 :
69+ raise sqlmapSyntaxException , "Unenclosed ) in '%s'" % expression
6770
68- # lastIndex = firstIndex + index + 1
69- # old = expression[firstIndex:lastIndex]
70- # oldUpper = old.upper()
71- # oldUpper = oldUpper.lstrip("ASCII_CHAR(").rstrip(")")
72- # oldUpper = oldUpper.split("||")
71+ lastIndex = firstIndex + index + 1
72+ old = expression [firstIndex :lastIndex ]
73+ oldUpper = old .upper ()
74+ oldUpper = oldUpper .lstrip ("ASCII_CHAR(" ).rstrip (")" )
75+ oldUpper = oldUpper .split ("||" )
7376
74- # escaped = "'%s'" % "".join([chr(int(char)) for char in oldUpper])
75- # expression = expression.replace(old, escaped).replace("'||'", "")
77+ escaped = "'%s'" % "" .join ([chr (int (char )) for char in oldUpper ])
78+ expression = expression .replace (old , escaped ).replace ("'||'" , "" )
7679
7780 return expression
0 commit comments