diff --git a/lib/core/common.py b/lib/core/common.py index 4cf8056ae..78471cd23 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -151,6 +151,7 @@ from lib.core.threads import getCurrentThreadData from lib.utils.sqlalchemy import _sqlalchemy from thirdparty.clientform.clientform import ParseResponse from thirdparty.clientform.clientform import ParseError +from thirdparty.colorama.initialise import init as coloramainit from thirdparty.magic import magic from thirdparty.odict.odict import OrderedDict from thirdparty.termcolor.termcolor import colored @@ -1068,11 +1069,14 @@ def banner(): This function prints sqlmap banner with its version """ - if not any(_ in sys.argv for _ in ("--version", "--pickled-options")): _ = BANNER - if not getattr(LOGGER_HANDLER, "is_tty", False): + + if not getattr(LOGGER_HANDLER, "is_tty", False) or "--disable-coloring" in sys.argv: _ = re.sub("\033.+?m", "", _) + elif IS_WIN: + coloramainit() + dataToStdout(_, forceOutput=True) def parsePasswordHash(password): diff --git a/lib/core/option.py b/lib/core/option.py index 00317cf48..ccf346b1a 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -151,7 +151,6 @@ from lib.utils.crawler import crawl from lib.utils.deps import checkDependencies from lib.utils.search import search from lib.utils.purge import purge -from thirdparty.colorama.initialise import init as coloramainit from thirdparty.keepalive import keepalive from thirdparty.oset.pyoset import oset from thirdparty.socks import socks @@ -2532,9 +2531,6 @@ def _resolveCrossReferences(): lib.controller.checks.setVerbosity = setVerbosity def initOptions(inputOptions=AttribDict(), overrideOptions=False): - if IS_WIN: - coloramainit() - _setConfAttributes() _setKnowledgeBaseAttributes() _mergeOptions(inputOptions, overrideOptions) diff --git a/lib/core/settings.py b/lib/core/settings.py index 406179eed..9b3d5aa87 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from lib.core.revision import getRevisionNumber # sqlmap version (...) -VERSION = "1.0.4.22" +VERSION = "1.0.4.23" REVISION = getRevisionNumber() STABLE = VERSION.count('.') <= 2 VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev") diff --git a/thirdparty/colorama/initialise.py b/thirdparty/colorama/initialise.py index 834962a35..a996d0788 100644 --- a/thirdparty/colorama/initialise.py +++ b/thirdparty/colorama/initialise.py @@ -21,13 +21,15 @@ def reset_all(): def init(autoreset=False, convert=None, strip=None, wrap=True): + global wrapped_stdout, wrapped_stderr + global orig_stdout, orig_stderr + + if orig_stdout is not None: + return if not wrap and any([autoreset, convert, strip]): raise ValueError('wrap=False conflicts with any other arg=True') - global wrapped_stdout, wrapped_stderr - global orig_stdout, orig_stderr - orig_stdout = sys.stdout orig_stderr = sys.stderr @@ -49,10 +51,15 @@ def init(autoreset=False, convert=None, strip=None, wrap=True): def deinit(): + global orig_stdout + global orig_stderr + if orig_stdout is not None: sys.stdout = orig_stdout + orig_stdout = None if orig_stderr is not None: sys.stderr = orig_stderr + orig_stderr = None @contextlib.contextmanager