diff options
| author | Yuval Adam <_@yuv.al> | 2020-02-01 13:53:42 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2020-02-01 13:53:42 +0200 |
| commit | 2ad4772b76dacb386c1b774eac8e4c9c8f2d26c0 (patch) | |
| tree | be41937d3f269ca53a134c28a2208e9c751200d1 | |
| parent | 1b5fadb7e676bf5036f73319359cd0e1c1ac3b95 (diff) | |
| parent | 7100e9aee3088c6cfc91bacc1580a9a371140407 (diff) | |
Merge branch 'master' of https://github.com/TiberiuD/viewstate into colors
| -rw-r--r-- | tests/test_parse.py | 6 | ||||
| -rw-r--r-- | viewstate/parse.py | 203 |
2 files changed, 204 insertions, 5 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py index fea1fd4..f5a0828 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -38,11 +38,13 @@ 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" + 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/parse.py b/viewstate/parse.py index 0db6224..b136681 100644 --- a/viewstate/parse.py +++ b/viewstate/parse.py @@ -112,10 +112,207 @@ 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]` + # 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 - return "Color: unknown", b[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]]) + 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:] class Pair(Parser): |
