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

Skip to content

Commit 4d028c7

Browse files
committed
Proper (safe) showing of safe encoded data
1 parent 2b57b4b commit 4d028c7

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/core/convert.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def stdoutencode(data):
103103

104104
if six.PY2:
105105
try:
106-
retVal = getBytes(data or "", sys.stdout.encoding)
106+
retVal = getBytes(data or "", sys.stdout.encoding, unsafe=False)
107107

108108
# Reference: http://bugs.python.org/issue1602
109109
if IS_WIN:
@@ -118,7 +118,7 @@ def stdoutencode(data):
118118
singleTimeWarnMessage(warnMsg)
119119

120120
except:
121-
retVal = getBytes(data or "")
121+
retVal = getBytes(data or "", unsafe=False)
122122

123123
return retVal
124124

@@ -224,7 +224,7 @@ def encodeBase64(value, binary=True):
224224

225225
return retVal
226226

227-
def getBytes(value, encoding=UNICODE_ENCODING, errors="strict"):
227+
def getBytes(value, encoding=UNICODE_ENCODING, errors="strict", unsafe=True):
228228
"""
229229
Returns byte representation of provided Unicode value
230230
@@ -236,14 +236,19 @@ def getBytes(value, encoding=UNICODE_ENCODING, errors="strict"):
236236

237237
if isinstance(value, six.text_type):
238238
if INVALID_UNICODE_PRIVATE_AREA:
239-
for char in xrange(0xF0000, 0xF00FF + 1):
240-
value = value.replace(six.unichr(char), "%s%02x" % (SAFE_HEX_MARKER, char - 0xF0000))
239+
if unsafe:
240+
for char in xrange(0xF0000, 0xF00FF + 1):
241+
value = value.replace(six.unichr(char), "%s%02x" % (SAFE_HEX_MARKER, char - 0xF0000))
241242

242243
retVal = value.encode(encoding, errors)
243-
retVal = re.sub(r"%s([0-9a-f]{2})" % SAFE_HEX_MARKER, lambda _: decodeHex(_.group(1)), retVal)
244+
245+
if unsafe:
246+
retVal = re.sub(r"%s([0-9a-f]{2})" % SAFE_HEX_MARKER, lambda _: decodeHex(_.group(1)), retVal)
244247
else:
245248
retVal = value.encode(encoding, errors)
246-
retVal = re.sub(b"\\\\x([0-9a-f]{2})", lambda _: decodeHex(_.group(1)), retVal)
249+
250+
if unsafe:
251+
retVal = re.sub(b"\\\\x([0-9a-f]{2})", lambda _: decodeHex(_.group(1)), retVal)
247252

248253
return retVal
249254

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty import six
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.40"
21+
VERSION = "1.3.5.41"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

0 commit comments

Comments
 (0)