From f8eed1f3658411d275bf70fac09a241e8059a633 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 28 Mar 2019 22:45:44 +0100 Subject: [PATCH] Minor update --- lib/core/convert.py | 39 +++++++++++++++++++++++++-------------- lib/core/settings.py | 2 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index 16c6d6b55..fe8148d16 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -27,7 +27,7 @@ def base64decode(value): 'foobar' """ - return base64.b64decode(value) + return base64.b64decode(unicodeencode(value)) def base64encode(value): """ @@ -37,7 +37,7 @@ def base64encode(value): 'Zm9vYmFy' """ - return base64.b64encode(value) + return base64.b64encode(unicodeencode(value)) def base64pickle(value): """ @@ -89,7 +89,14 @@ def hexdecode(value): """ value = value.lower() - return (value[2:] if value.startswith("0x") else value).decode("hex") + value = value[2:] if value.startswith("0x") else value + + if six.PY2: + retVal = value.decode("hex") + else: + retVal = bytes.fromhex(value) + + return retVal def hexencode(value, encoding=None): """ @@ -99,7 +106,14 @@ def hexencode(value, encoding=None): '666f6f626172' """ - return unicodeencode(value, encoding).encode("hex") + retVal = unicodeencode(value, encoding) + + if six.PY2: + retVal = retVal.encode("hex") + else: + retVal = retVal.hex() + + return retVal def unicodeencode(value, encoding=None): """ @@ -110,11 +124,13 @@ def unicodeencode(value, encoding=None): """ retVal = value - if isinstance(value, unicode): + + if isinstance(value, six.text_type): try: retVal = value.encode(encoding or UNICODE_ENCODING) except UnicodeEncodeError: - retVal = value.encode(UNICODE_ENCODING, "replace") + retVal = value.encode(encoding or UNICODE_ENCODING, "replace") + return retVal def utf8encode(value): @@ -164,13 +180,11 @@ def stdoutencode(data): retVal = None try: - data = data or "" + retVal = unicodeencode(data or "", sys.stdout.encoding) # Reference: http://bugs.python.org/issue1602 if IS_WIN: - output = data.encode(sys.stdout.encoding, "replace") - - if '?' in output and '?' not in data: + if '?' in retVal and '?' not in retVal: warnMsg = "cannot properly display Unicode characters " warnMsg += "inside Windows OS command prompt " warnMsg += "(http://bugs.python.org/issue1602). All " @@ -180,11 +194,8 @@ def stdoutencode(data): warnMsg += "corresponding output files. " singleTimeWarnMessage(warnMsg) - retVal = output - else: - retVal = data.encode(sys.stdout.encoding) except: - retVal = data.encode(UNICODE_ENCODING) if isinstance(data, unicode) else data + retVal = unicodeencode(data or "") return retVal diff --git a/lib/core/settings.py b/lib/core/settings.py index 0dc3bc4c6..a826a7050 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -17,7 +17,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.3.3.74" +VERSION = "1.3.3.75" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)