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

Skip to content

Commit 57be185

Browse files
committed
Where things could go kaboom (changing terminal coloring)
1 parent a424e4a commit 57be185

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

lib/core/common.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,7 @@ def setColor(message, bold=False):
884884
retVal = colored(message, color=None, on_color=None, attrs=("bold",))
885885
elif level:
886886
level = getattr(logging, level, None) if isinstance(level, basestring) else level
887-
_ = LOGGER_HANDLER.level_map.get(level)
888-
if _:
889-
background, foreground, bold = _
890-
retVal = colored(message, color=foreground, on_color="on_%s" % background if background else None, attrs=("bold",) if bold else None)
891-
887+
retVal = LOGGER_HANDLER.colorize(message, level)
892888
kb.stickyLevel = level if message and message[-1] != "\n" else None
893889

894890
return retVal

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

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

thirdparty/ansistrm/ansistrm.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#
22
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
3+
# (Note: 2018 modifications by @stamparm)
34
#
5+
46
import logging
57
import os
68
import re
@@ -127,9 +129,9 @@ def output_colorized(self, message):
127129

128130
ctypes.windll.kernel32.SetConsoleTextAttribute(h, color)
129131

130-
def colorize(self, message, record):
131-
if record.levelno in self.level_map and self.is_tty:
132-
bg, fg, bold = self.level_map[record.levelno]
132+
def colorize(self, message, levelno):
133+
if levelno in self.level_map and self.is_tty:
134+
bg, fg, bold = self.level_map[levelno]
133135
params = []
134136

135137
if bg in self.color_map:
@@ -148,11 +150,32 @@ def colorize(self, message, record):
148150
else:
149151
prefix = ""
150152

151-
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params),
152-
'm', message, self.reset)))
153+
match = re.search(r"\[([A-Z]+)\]", message)
154+
if match:
155+
level = match.group(1)
156+
if message.startswith("\x1b[1m"):
157+
message = message.replace("\x1b[1m", "")
158+
reset = self.reset + "\x1b[1m"
159+
params.append('1')
160+
else:
161+
reset = self.reset
162+
message = message.replace(level, ''.join((self.csi, ';'.join(params), 'm', level, reset)), 1)
163+
else:
164+
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params), 'm', message, self.reset)))
165+
166+
match = re.search(r"\A\s*\[([\d:]+)\]", message)
167+
if match:
168+
time = match.group(1)
169+
if not message.endswith(self.reset):
170+
reset = self.reset
171+
elif message.startswith("\x1b[1m"): # bold
172+
reset = self.reset + "\x1b[1m"
173+
else:
174+
reset = self.reset
175+
message = message.replace(time, ''.join((self.csi, str(self.color_map["cyan"] + 30), 'm', time, reset)), 1)
153176

154177
return message
155178

156179
def format(self, record):
157180
message = logging.StreamHandler.format(self, record)
158-
return self.colorize(message, record)
181+
return self.colorize(message, record.levelno)

txt/checksum.md5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ c7443613a0a2505b1faec931cee2a6ef lib/controller/handler.py
2828
1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py
2929
0adf547455a76dc71e6a599e52da1ed9 lib/core/agent.py
3030
fd8f239e259afaf5f24bcf34a0ad187f lib/core/bigarray.py
31-
6c3ba41569f9403aef6cd9312fe9b96e lib/core/common.py
31+
ab2f7ecb7d3dff9afd05675031942e8e lib/core/common.py
3232
0d082da16c388b3445e656e0760fb582 lib/core/convert.py
3333
9f87391b6a3395f7f50830b391264f27 lib/core/data.py
3434
72016ea5c994a711a262fd64572a0fcd lib/core/datatype.py
@@ -48,7 +48,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
4848
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
4949
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5050
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
51-
af78e555614c7e1bf89c37271831b486 lib/core/settings.py
51+
9f27c2f2abae2c21eb623f16abfeccf9 lib/core/settings.py
5252
dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py
5353
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5454
95f04c1c1d8c3998d86e1bdf0e12771c lib/core/target.py
@@ -285,7 +285,7 @@ fd1bff6caefe5007444f7a0fabbc8ce9 tamper/space2mysqlblank.py
285285
929a2586dbb7b758a454eb09e13e5a73 tamper/versionedkeywords.py
286286
3aff4d344ebd4f38e033e73b63f84447 tamper/versionedmorekeywords.py
287287
ed1acafbac707bfa71c72f76b81c1bdd tamper/xforwardedfor.py
288-
368165b45dadcdff4422bc010700832a thirdparty/ansistrm/ansistrm.py
288+
b743632abd4eee8654f98dcfdb753246 thirdparty/ansistrm/ansistrm.py
289289
d41d8cd98f00b204e9800998ecf8427e thirdparty/ansistrm/__init__.py
290290
8e775c25bc9e84891ad6fcb4f0005c23 thirdparty/beautifulsoup/beautifulsoup.py
291291
cb2e1fe7c404dff41a2ae9132828f532 thirdparty/beautifulsoup/__init__.py

0 commit comments

Comments
 (0)