eric6/WebBrowser/FlashCookieManager/FlashCookieReader.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
permissions
-rw-r--r--

Updated copyright for 2021.

4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class to read flash cookies.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 #
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 # Note: The code is based on s2x.py
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 #
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import struct
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import io
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from PyQt5.QtCore import QDateTime
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class FlashCookieReaderError(Exception):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class containing data of a reader error.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self, msg):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param msg error message
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.msg = msg
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 class FlashCookieReader(object):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Class implementing a reader for flash cookies (*.sol files).
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Number = b'\x00'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 Boolean = b'\x01'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 String = b'\x02'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 ObjObj = b'\x03'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Null = b'\x05'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Undef = b'\x06'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 ObjArr = b'\x08'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 ObjDate = b'\x0B'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 ObjM = b'\x0D'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 ObjXml = b'\x0F'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 ObjCc = b'\x10'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 EpochCorrectionMsecs = 31 * 24 * 60 * 60 * 1000
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 # Flash Epoch starts at 1969-12-01
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def __init__(self):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Constructor
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__result = {}
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 # dictionary with element name as key and tuple of
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 # type and value as value
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__data = None
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.__parsed = False
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def setBytes(self, solData):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Public method to set the contents of a sol file to be parsed.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @param solData contents of the file
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @type bytes
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__data = io.BytesIO(solData)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 def setFileName(self, solFilename):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 Public method to set the name of a sol file to be parsed.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @param solFilename name of the sol file
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__data = open(solFilename, "rb")
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 def setFile(self, solFile):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 Public method to set an open sol file to be parsed.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @param solFile sol file to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @type io.FileIO
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__data = solFile
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 def parse(self):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 Public method to parse the sol file.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @exception FlashCookieReaderError raised when encountering a parse
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 issue
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if self.__data is None:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 return
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__data.seek(0, 2)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 lenSolData = self.__data.tell()
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__data.seek(0)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__data.read(2)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 sLenData = self.__data.read(4)
4934
aeffa295acdb Fixed an issue reading an invalid Flash cookie.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4751
diff changeset
105 if len(sLenData) != 4:
aeffa295acdb Fixed an issue reading an invalid Flash cookie.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4751
diff changeset
106 raise FlashCookieReaderError("Flash cookie is invalid.")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 lenData, = struct.unpack(">L", sLenData) # unsigned long, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if lenSolData != lenData + 6:
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
109 raise FlashCookieReaderError(
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
110 "Flash cookie data lengths don't match\n"
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
111 " file length: {0}\n"
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
112 " data length: {1}"
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
113 .format(lenSolData - 6, lenData))
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 sDataType = self.__data.read(4).decode("utf-8") # 'TCSO'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 if sDataType != "TCSO":
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 raise FlashCookieReaderError(
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 "Flash cookie type is not 'TCSO'; found '{0}'."
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 .format(sDataType))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__data.read(6)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 lenSolName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 solName = self.__data.read(lenSolName)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
123 solName = solName.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__result["SolName"] = ("string", solName)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__data.read(4)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 while self.__data.tell() < lenSolData:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 variableName = self.__data.read(lenVariableName)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
130 variableName = variableName.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 variableType = self.__data.read(1)
4466
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
132 if len(variableType):
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
133 if variableType == self.Number:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
134 self.__parseNumber(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
135 elif variableType == self.Boolean:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
136 self.__parseBoolean(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
137 elif variableType == self.String:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
138 self.__parseString(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
139 elif variableType == self.ObjObj:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
140 self.__parseObject(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
141 elif variableType == self.ObjArr:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
142 self.__parseArray(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
143 elif variableType == self.ObjDate:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
144 self.__parseDate(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
145 elif variableType == self.ObjXml:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
146 self.__parseXml(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
147 elif variableType == self.ObjCc:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
148 self.__parseOcc(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
149 elif variableType == self.ObjM:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
150 self.__parseOjm(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
151 elif variableType == self.Null:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
152 self.__parseNull(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
153 elif variableType == self.Undef:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
154 self.__parseUndefined(variableName, self.__result)
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
155 else:
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
156 raise FlashCookieReaderError(
184660eecb94 Fixed a bug in the Flash cookie reader causing an exception when reading beyond the cookie (wrong cookie length given).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4370
diff changeset
157 "Unexpected Data Type: " + hex(ord(variableType)))
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__data.read(1) # '\x00'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.__data.close()
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__parsed = True
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def __parseNumber(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Private method to parse a number.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 b = self.__data.read(8)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 if b == b"\x7F\xF0\x00\x00\x00\x00\x00\x00":
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 value = "Infinity"
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 elif b == b"\xFF\xF0\x00\x00\x00\x00\x00\x00":
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 value = "-Infinity"
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
176 elif b == b"\x7F\xF8\x00\x00\x00\x00\x00\x00":
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 value = "NaN"
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 else:
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
179 value, = struct.unpack(">d", b) # double, big-endian
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 value = str(value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 parent[variableName] = ("number", value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 def __parseBoolean(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 Private method to parse a boolean.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 b = self.__data.read(1)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 if b == b"\x00":
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 value = "False"
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 elif b == b"\x01":
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 value = "True"
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 else:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 # boolean value error; default to True
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 value = "True"
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 parent[variableName] = ("boolean", value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 def __parseString(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 Private method to parse a string.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 lenStr, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 b = self.__data.read(lenStr)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
214 value = b.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 parent[variableName] = ("string", value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 def __parseDate(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 Private method to parse a date.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 msec, = struct.unpack(">d", self.__data.read(8))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 # double, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 # DateObject: Milliseconds Count From Dec. 1, 1969
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 msec -= self.EpochCorrectionMsecs # correct for Unix epoch
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 minOffset, = struct.unpack(">h", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 # short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 offset = minOffset // 60 # offset in hours
7249
0bf517e60f54 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
233 # Timezone is UTC + Offset
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 value = QDateTime()
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 value.setMSecsSinceEpoch(msec)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 value.setOffsetFromUtc(offset * 3600)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 parent[variableName] = ("date",
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 value.toString("yyyy-MM-dd HH:mm:ss t"))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 def __parseXml(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 Private method to parse XML.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
249 lenCData, = struct.unpack(">L", self.__data.read(4))
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 # unsigned long, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 cData = self.__data.read(lenCData)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
252 value = cData.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 parent[variableName] = ("xml", value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 def __parseOjm(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 Private method to parse an m_object.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 parent[variableName] = ("m_object", "")
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 def __parseNull(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 Private method to parse a null object.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 parent[variableName] = ("null", "")
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 def __parseUndefined(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 Private method to parse an undefined object.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 @type dict
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 parent[variableName] = ("undefined", "")
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 def __parseObject(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 Private method to parse an object.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 @type dict
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
296 @exception FlashCookieReaderError raised when an issue with the cookie
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
297 file is found
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 value = {}
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 parent[variableName] = ("object", value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 while lenVariableName != 0:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 variableName = self.__data.read(lenVariableName)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
306 variableName = variableName.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 variableType = self.__data.read(1)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 if variableType == self.Number:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 self.__parseNumber(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 elif variableType == self.Boolean:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 self.__parseBoolean(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 elif variableType == self.String:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 self.__parseString(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 elif variableType == self.ObjObj:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 self.__parseObject(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 elif variableType == self.ObjArr:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 self.__parseArray(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 elif variableType == self.ObjDate:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 self.__parseDate(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 elif variableType == self.ObjXml:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.__parseXml(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 elif variableType == self.ObjCc:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 self.__parseOcc(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 elif variableType == self.ObjM:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 self.__parseOjm(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 elif variableType == self.Null:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 self.__parseNull(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 elif variableType == self.Undef:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 self.__parseUndefined(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 else:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 raise FlashCookieReaderError(
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 "Unexpected Data Type: " + hex(ord(variableType)))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 self.__data.read(1) # '\x09'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 def __parseArray(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 Private method to parse an array.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 @type dict
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
344 @exception FlashCookieReaderError raised when an issue with the cookie
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
345 file is found
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 arrayLength, = struct.unpack(">L", self.__data.read(4))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 # unsigned long, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 value = {}
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 parent[variableName] = ("array; length={0}".format(arrayLength), value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 while lenVariableName != 0:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 variableName = self.__data.read(lenVariableName)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
357 variableName = variableName.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 variableType = self.__data.read(1)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 if variableType == self.Number:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 self.__parseNumber(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 elif variableType == self.Boolean:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 self.__parseBoolean(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 elif variableType == self.String:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 self.__parseString(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 elif variableType == self.ObjObj:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 self.__parseObject(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 elif variableType == self.ObjArr:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 self.__parseArray(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 elif variableType == self.ObjDate:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 self.__parseDate(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 elif variableType == self.ObjXml:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 self.__parseXml(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 elif variableType == self.ObjCc:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.__parseOcc(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 elif variableType == self.ObjM:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 self.__parseOjm(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 elif variableType == self.Null:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 self.__parseNull(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 elif variableType == self.Undef:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 self.__parseUndefined(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 else:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 raise FlashCookieReaderError(
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 "Unexpected Data Type: " + hex(ord(variableType)))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 self.__data.read(1) # '\x09'
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 def __parseOcc(self, variableName, parent):
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 Private method to parse a c_object.
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 @param variableName name of the variable to be parsed
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 @type str
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 @param parent reference to the dictionary to insert the result into
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 @type dict
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
395 @exception FlashCookieReaderError raised when an issue with the cookie
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
396 file is found
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 """
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 lenCname = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 cname = self.__data.read(lenCname)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
401 cname = cname.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 value = {}
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 parent[variableName] = ("c_object; cname={0}".format(cname), value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 # unsigned short, big-endian
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 while lenVariableName != 0:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 variableName = self.__data.read(lenVariableName)
4614
e8996f522895 Changed the Flash Cookie Reader to ignore UTF-8 decoding issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4466
diff changeset
410 variableName = variableName.decode("utf-8", "replace")
4360
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 variableType = self.__data.read(1)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 if variableType == self.Number:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 self.__parseNumber(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 elif variableType == self.Boolean:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 self.__parseBoolean(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 elif variableType == self.String:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 self.__parseString(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 elif variableType == self.ObjObj:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 self.__parseObject(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 elif variableType == self.ObjArr:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 self.__parseArray(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 elif variableType == self.ObjDate:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 self.__parseDate(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 elif variableType == self.ObjXml:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 self.__parseXml(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 elif variableType == self.ObjCc:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 self.__parseOcc(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 elif variableType == self.ObjM:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 self.__parseOjm(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 elif variableType == self.Null:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 self.__parseNull(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 elif variableType == self.Undef:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 self.__parseUndefined(variableName, value)
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 else:
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 raise FlashCookieReaderError(
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 "Unexpected Data Type: " + hex(ord(variableType)))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 lenVariableName, = struct.unpack(">H", self.__data.read(2))
b8bdb7cd4a92 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 self.__data.read(1) # '\x09'
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
439
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
440 def toString(self, indent=0, parent=None):
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
441 """
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
442 Public method to convert the parsed cookie to a string representation.
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
443
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
444 @param indent indentation level
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
445 @type int
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
446 @param parent reference to the dictionary to be converted
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
447 @type dict
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
448 @return string representation of the cookie
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
449 @rtype str
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
450 """
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
451 indentStr = " " * indent
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
452 strArr = []
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
453
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
454 if parent is None:
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
455 parent = self.__result
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
456
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
457 if not parent:
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
458 return ""
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
459
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
460 for variableName in sorted(parent.keys()):
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
461 variableType, value = parent[variableName]
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
462 if isinstance(value, dict):
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
463 resultStr = self.toString(indent + 1, value)
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
464 if resultStr:
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
465 strArr.append("{0}{1}:\n{2}"
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
466 .format(indentStr, variableName, resultStr))
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
467 else:
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
468 strArr.append("{0}{1}:"
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
469 .format(indentStr, variableName))
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
470 else:
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
471 strArr.append("{0}{1}: {2}"
4370
54dbb658f9e6 Corrected some code style issues and regenerated the source docu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4361
diff changeset
472 .format(indentStr, variableName, value))
4361
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
473
9eec3a532d59 Continued adding code for a Flash cookie manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4360
diff changeset
474 return "\n".join(strArr)

eric ide

mercurial