summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2018-03-12 22:43:12 +0200
committerYuval Adam <_@yuv.al>2018-03-12 22:43:12 +0200
commit2f3a1e2fa48c39a190997fd60fce99ed1f9b7bca (patch)
tree0f66020e78ee824d1836cb60a2927968ec4bb703
parent4ccc60ad95b6089934a55b0cbb46d63097db90cc (diff)
Add support for formatted strings
-rw-r--r--tests/test_parse.py7
-rw-r--r--viewstate/parse.py11
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py
index aec69fe..cb0a354 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -40,6 +40,13 @@ class TestParse(object):
vs = ViewState(raw=b'\xff\x01\n\x01\x02')
assert vs.decode() == 'Color: unknown' # all colors are unknown for now
+ def test_formatted_string(self):
+ vs = ViewState()
+ s1 = 'System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
+ s2 = '6111733106'
+ vs.raw = b'\xff\x01()' + bytes([len(s1)]) + s1.encode() + bytes([len(s2)]) + s2.encode()
+ assert vs.decode() == 'Formatted string: {} {}'.format(s2, s1)
+
def test_complex_pair(self):
vs = ViewState()
vs.raw = b'\xff\x01\x0f\x67\x0f\x68\x66'
diff --git a/viewstate/parse.py b/viewstate/parse.py
index e141a7e..03749f7 100644
--- a/viewstate/parse.py
+++ b/viewstate/parse.py
@@ -79,6 +79,15 @@ def parse_stringref(b):
val, remain = parse_int(b)
return 'Stringref #{}'.format(val), remain
+def parse_formatted_string(b):
+ if b[0] == 0x29:
+ s1, remain = parse_string(b[1:])
+ s2, remain = parse_string(remain)
+ return 'Formatted string: {} {}'.format(s2, s1), remain
+ else:
+ raise ViewStateException('Unknown formatted string type marker {}'.format(b[:20]))
+
+
def parse_sparse_array(b):
type, remain = parse_type(b)
length, remain = parse_int(remain)
@@ -147,6 +156,8 @@ def parse(b):
return parse_dict(b[1:])
elif b[0] == 0x1f:
return parse_stringref(b[1:])
+ elif b[0] == 0x28:
+ return parse_formatted_string(b[1:])
elif b[0] == 0x3c:
return parse_sparse_array(b[1:])
else: