summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2020-02-01 14:37:32 +0200
committerGitHub <noreply@github.com>2020-02-01 14:37:32 +0200
commit0021e056c99c62c13966ee9114e1e31ee2b64302 (patch)
treead6519d9e966def1f7eb139c126afb32f18b7f07
parent961c4233f817617b18950df30c23b54f76060013 (diff)
Add support for known color parsing (#13)
* Added color parsing support * Fixed major flaw in parsing colors. * Removed debugging comments * Additional black run * Extract colors.py and restore Noop parser class * Test for unknown colors as well Co-authored-by: TiberiuD <TiberiuD@users.noreply.github.com>
-rw-r--r--tests/test_parse.py9
-rw-r--r--viewstate/colors.py177
-rw-r--r--viewstate/parse.py18
3 files changed, 198 insertions, 6 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py
index fea1fd4..c1e1abb 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -38,11 +38,16 @@ class TestParse(object):
vs = ViewState(raw=b"\xff\x01\x10\x67\x68\x67")
assert vs.decode() == (True, False, True)
- @pytest.mark.skip(reason="Color parsing is not yet supported")
def test_color(self):
- vs = ViewState(raw=b"\xff\x01\n\x91\x01")
+ vs = ViewState(raw=b"\xff\x01\n\x91")
assert vs.decode() == "Color: Salmon"
+ vs = ViewState(raw=b"\xff\x01\n\x8d\x01")
+ assert vs.decode() == "Color: Red"
+
+ vs = ViewState(raw=b"\xff\x01\n\xff")
+ assert vs.decode() == "Color: Unknown"
+
def test_rgba(self):
vs = ViewState(raw=b"\xff\x01\x09\x10\x20\x30\x40")
assert vs.decode() == "RGBA(16,32,48,64)"
diff --git a/viewstate/colors.py b/viewstate/colors.py
new file mode 100644
index 0000000..114b556
--- /dev/null
+++ b/viewstate/colors.py
@@ -0,0 +1,177 @@
+COLORS = [
+ "None", # https://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/KnownColor.cs,29
+ "ActiveBorder",
+ "ActiveCaption",
+ "ActiveCaptionText",
+ "AppWorkspace",
+ "Control",
+ "ControlDark",
+ "ControlDarkDark",
+ "ControlLight",
+ "ControlLightLight",
+ "ControlText",
+ "Desktop",
+ "GrayText",
+ "Highlight",
+ "HighlightText",
+ "HotTrack",
+ "InactiveBorder",
+ "InactiveCaption",
+ "InactiveCaptionText",
+ "Info",
+ "InfoText",
+ "Menu",
+ "MenuText",
+ "ScrollBar",
+ "Window",
+ "WindowFrame",
+ "WindowText",
+ "Transparent",
+ "AliceBlue",
+ "AntiqueWhite",
+ "Aqua",
+ "Aquamarine",
+ "Azure",
+ "Beige",
+ "Bisque",
+ "Black",
+ "BlanchedAlmond",
+ "Blue",
+ "BlueViolet",
+ "Brown",
+ "BurlyWood",
+ "CadetBlue",
+ "Chartreuse",
+ "Chocolate",
+ "Coral",
+ "CornflowerBlue",
+ "Cornsilk",
+ "Crimson",
+ "Cyan",
+ "DarkBlue",
+ "DarkCyan",
+ "DarkGoldenrod",
+ "DarkGray",
+ "DarkGreen",
+ "DarkKhaki",
+ "DarkMagenta",
+ "DarkOliveGreen",
+ "DarkOrange",
+ "DarkOrchid",
+ "DarkRed",
+ "DarkSalmon",
+ "DarkSeaGreen",
+ "DarkSlateBlue",
+ "DarkSlateGray",
+ "DarkTurquoise",
+ "DarkViolet",
+ "DeepPink",
+ "DeepSkyBlue",
+ "DimGray",
+ "DodgerBlue",
+ "Firebrick",
+ "FloralWhite",
+ "ForestGreen",
+ "Fuchsia",
+ "Gainsboro",
+ "GhostWhite",
+ "Gold",
+ "Goldenrod",
+ "Gray",
+ "Green",
+ "GreenYellow",
+ "Honeydew",
+ "HotPink",
+ "IndianRed",
+ "Indigo",
+ "Ivory",
+ "Khaki",
+ "Lavender",
+ "LavenderBlush",
+ "LawnGreen",
+ "LemonChiffon",
+ "LightBlue",
+ "LightCoral",
+ "LightCyan",
+ "LightGoldenrodYellow",
+ "LightGray",
+ "LightGreen",
+ "LightPink",
+ "LightSalmon",
+ "LightSeaGreen",
+ "LightSkyBlue",
+ "LightSlateGray",
+ "LightSteelBlue",
+ "LightYellow",
+ "Lime",
+ "LimeGreen",
+ "Linen",
+ "Magenta",
+ "Maroon",
+ "MediumAquamarine",
+ "MediumBlue",
+ "MediumOrchid",
+ "MediumPurple",
+ "MediumSeaGreen",
+ "MediumSlateBlue",
+ "MediumSpringGreen",
+ "MediumTurquoise",
+ "MediumVioletRed",
+ "MidnightBlue",
+ "MintCream",
+ "MistyRose",
+ "Moccasin",
+ "NavajoWhite",
+ "Navy",
+ "OldLace",
+ "Olive",
+ "OliveDrab",
+ "Orange",
+ "OrangeRed",
+ "Orchid",
+ "PaleGoldenrod",
+ "PaleGreen",
+ "PaleTurquoise",
+ "PaleVioletRed",
+ "PapayaWhip",
+ "PeachPuff",
+ "Peru",
+ "Pink",
+ "Plum",
+ "PowderBlue",
+ "Purple",
+ "Red",
+ "RosyBrown",
+ "RoyalBlue",
+ "SaddleBrown",
+ "Salmon",
+ "SandyBrown",
+ "SeaGreen",
+ "SeaShell",
+ "Sienna",
+ "Silver",
+ "SkyBlue",
+ "SlateBlue",
+ "SlateGray",
+ "Snow",
+ "SpringGreen",
+ "SteelBlue",
+ "Tan",
+ "Teal",
+ "Thistle",
+ "Tomato",
+ "Turquoise",
+ "Violet",
+ "Wheat",
+ "White",
+ "WhiteSmoke",
+ "Yellow",
+ "YellowGreen",
+ "ButtonFace",
+ "ButtonHighlight",
+ "ButtonShadow",
+ "GradientActiveCaption",
+ "GradientInactiveCaption",
+ "MenuBar",
+ "MenuHighlight",
+]
diff --git a/viewstate/parse.py b/viewstate/parse.py
index 0db6224..b2a85f0 100644
--- a/viewstate/parse.py
+++ b/viewstate/parse.py
@@ -1,5 +1,6 @@
from datetime import datetime
+from .colors import COLORS
from .exceptions import ViewStateException
@@ -42,6 +43,14 @@ class Const(Parser):
return cls.const, remain
+class Noop(Parser):
+ marker = 0x01
+
+ @staticmethod
+ def parse(b):
+ return None, b
+
+
class NoneConst(Const):
marker = 0x64
const = None
@@ -112,10 +121,11 @@ class Color(Parser):
@staticmethod
def parse(b):
- # No specification for color parsing, we're assuming it's just two bytes
- # One example we have is that `\n\x91\x01` is parsed as `Color: Color [Salmon]`
- # Originally reported in https://github.com/yuvadm/viewstate/issues/2
- return "Color: unknown", b[2:]
+ try:
+ color = COLORS[b[0]]
+ except IndexError:
+ color = "Unknown"
+ return "Color: {}".format(color), b[1:]
class Pair(Parser):