summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--viewstate/colors.py177
-rw-r--r--viewstate/parse.py211
2 files changed, 189 insertions, 199 deletions
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 95b3c2e..910b21b 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,207 +121,11 @@ class Color(Parser):
@staticmethod
def parse(b):
- # No specification for color parsing
- # The first example we had was that `\n\x91\x01` is parsed as `Color: Color [Salmon]`
- # Originally reported in https://github.com/yuvadm/viewstate/issues/2
-
- # Then, it was found that colors can also be encoded with only one byte
- # For example, `\n\x5b` is parsed as `Color: Color [LightBlue]`
- # Moreover, if we check this page: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor?redirectedfrom=MSDN&view=netframework-4.8
- # we can see that LightBlue corresponds to 91 (0x5b) and Salmon to 145 (0x91)
-
- # I have made the assumption that 0x01 is a null marker and decided to ignore it alltogether.
- # This assumption might be wrong, hence this message.
-
- color_table = [
- "None",
- "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",
- ]
-
- color = "Unknown"
try:
- color = "Color: {}".format(color_table[b[0]])
+ color = "Color: {}".format(COLORS[b[0]])
except IndexError:
- pass
-
- # If color packet ends with `\x01`
- if len(b) > 1 and b[1] == 1:
- return color, b[2:]
- else:
- return color, b[1:]
+ color = "Unknown"
+ return color, b[1:]
class Pair(Parser):