From a75ab8b1280a18fa6755d5e5ae827fc5b05bdf88 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 29 Oct 2019 15:00:53 +0100 Subject: [PATCH] Minor improvement of table dump formatting --- lib/core/convert.py | 19 ++++++++++++++++++- lib/core/dump.py | 5 +++-- lib/core/settings.py | 2 +- plugins/generic/entries.py | 3 ++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index d7f911019..51e7d7b85 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -263,7 +263,7 @@ def getOrds(value): def getUnicode(value, encoding=None, noneToNull=False): """ - Return the unicode representation of the supplied value: + Returns the unicode representation of the supplied value >>> getUnicode('test') == u'test' True @@ -375,3 +375,20 @@ def stdoutEncode(value): retVal = value return retVal + +def getConsoleLength(value): + """ + Returns console width of unicode values + + >>> getConsoleLength("abc") + 3 + >>> getConsoleLength(u"\\u957f\\u6c5f") + 4 + """ + + if isinstance(value, six.text_type): + retVal = sum((2 if ord(_) >= 0x3000 else 1) for _ in value) + else: + retVal = len(value) + + return retVal \ No newline at end of file diff --git a/lib/core/dump.py b/lib/core/dump.py index 3f7843a60..f7ecac695 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -28,6 +28,7 @@ from lib.core.common import safeCSValue from lib.core.common import unsafeSQLIdentificatorNaming from lib.core.compat import xrange from lib.core.convert import getBytes +from lib.core.convert import getConsoleLength from lib.core.convert import getText from lib.core.convert import getUnicode from lib.core.data import conf @@ -547,7 +548,7 @@ class Dump(object): column = unsafeSQLIdentificatorNaming(column) maxlength = int(info["length"]) - blank = " " * (maxlength - len(column)) + blank = " " * (maxlength - getConsoleLength(column)) self._write("| %s%s" % (column, blank), newline=False) @@ -602,7 +603,7 @@ class Dump(object): values.append(value) maxlength = int(info["length"]) - blank = " " * (maxlength - len(value)) + blank = " " * (maxlength - getConsoleLength(value)) self._write("| %s%s" % (value, blank), newline=False, console=console) if len(value) > MIN_BINARY_DISK_DUMP_SIZE and r'\x' in value: diff --git a/lib/core/settings.py b/lib/core/settings.py index acaa50292..c4425ab7c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.3.10.28" +VERSION = "1.3.10.29" 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) diff --git a/plugins/generic/entries.py b/plugins/generic/entries.py index 140e820fd..df0a747eb 100644 --- a/plugins/generic/entries.py +++ b/plugins/generic/entries.py @@ -25,6 +25,7 @@ from lib.core.common import singleTimeLogMessage from lib.core.common import singleTimeWarnMessage from lib.core.common import unArrayizeValue from lib.core.common import unsafeSQLIdentificatorNaming +from lib.core.convert import getConsoleLength from lib.core.convert import getUnicode from lib.core.data import conf from lib.core.data import kb @@ -269,7 +270,7 @@ class Entries(object): else: colEntry = unArrayizeValue(entry[index]) if index < len(entry) else u'' - maxLen = max(len(column), len(DUMP_REPLACEMENTS.get(getUnicode(colEntry), getUnicode(colEntry)))) + maxLen = max(getConsoleLength(column), getConsoleLength(DUMP_REPLACEMENTS.get(getUnicode(colEntry), getUnicode(colEntry)))) if maxLen > kb.data.dumpedTable[column]["length"]: kb.data.dumpedTable[column]["length"] = maxLen