108 if lenSolData != lenData + 6: |
108 if lenSolData != lenData + 6: |
109 raise FlashCookieReaderError( |
109 raise FlashCookieReaderError( |
110 "Flash cookie data lengths don't match\n" |
110 "Flash cookie data lengths don't match\n" |
111 " file length: {0}\n" |
111 " file length: {0}\n" |
112 " data length: {1}" |
112 " data length: {1}" |
113 .format(lenSolData - 6, lenData)) |
113 .format(lenSolData - 6, lenData)) |
114 sDataType = self.__data.read(4).decode("utf-8") # 'TCSO' |
114 sDataType = self.__data.read(4).decode("utf-8") # 'TCSO' |
115 if sDataType != "TCSO": |
115 if sDataType != "TCSO": |
116 raise FlashCookieReaderError( |
116 raise FlashCookieReaderError( |
117 "Flash cookie type is not 'TCSO'; found '{0}'." |
117 "Flash cookie type is not 'TCSO'; found '{0}'." |
118 .format(sDataType)) |
118 .format(sDataType)) |
173 elif b == b"\xFF\xF0\x00\x00\x00\x00\x00\x00": |
173 elif b == b"\xFF\xF0\x00\x00\x00\x00\x00\x00": |
174 value = "-Infinity" |
174 value = "-Infinity" |
175 elif b == b"\x7F\xF8\x00\x00\x00\x00\x00\x00": |
175 elif b == b"\x7F\xF8\x00\x00\x00\x00\x00\x00": |
176 value = "NaN" |
176 value = "NaN" |
177 else: |
177 else: |
178 value, = struct.unpack(">d", b) # double, big-endian |
178 value, = struct.unpack(">d", b) # double, big-endian |
179 value = str(value) |
179 value = str(value) |
180 parent[variableName] = ("number", value) |
180 parent[variableName] = ("number", value) |
181 |
181 |
182 def __parseBoolean(self, variableName, parent): |
182 def __parseBoolean(self, variableName, parent): |
183 """ |
183 """ |
243 @param variableName name of the variable to be parsed |
243 @param variableName name of the variable to be parsed |
244 @type str |
244 @type str |
245 @param parent reference to the dictionary to insert the result into |
245 @param parent reference to the dictionary to insert the result into |
246 @type dict |
246 @type dict |
247 """ |
247 """ |
248 lenCData, = struct.unpack(">L", self.__data.read(4)) |
248 lenCData, = struct.unpack(">L", self.__data.read(4)) |
249 # unsigned long, big-endian |
249 # unsigned long, big-endian |
250 cData = self.__data.read(lenCData) |
250 cData = self.__data.read(lenCData) |
251 value = cData.decode("utf-8") |
251 value = cData.decode("utf-8") |
252 parent[variableName] = ("xml", value) |
252 parent[variableName] = ("xml", value) |
253 |
253 |
290 |
290 |
291 @param variableName name of the variable to be parsed |
291 @param variableName name of the variable to be parsed |
292 @type str |
292 @type str |
293 @param parent reference to the dictionary to insert the result into |
293 @param parent reference to the dictionary to insert the result into |
294 @type dict |
294 @type dict |
|
295 @exception FlashCookieReaderError raised when an issue with the cookie |
|
296 file is found |
295 """ |
297 """ |
296 value = {} |
298 value = {} |
297 parent[variableName] = ("object", value) |
299 parent[variableName] = ("object", value) |
298 |
300 |
299 lenVariableName, = struct.unpack(">H", self.__data.read(2)) |
301 lenVariableName, = struct.unpack(">H", self.__data.read(2)) |
336 |
338 |
337 @param variableName name of the variable to be parsed |
339 @param variableName name of the variable to be parsed |
338 @type str |
340 @type str |
339 @param parent reference to the dictionary to insert the result into |
341 @param parent reference to the dictionary to insert the result into |
340 @type dict |
342 @type dict |
|
343 @exception FlashCookieReaderError raised when an issue with the cookie |
|
344 file is found |
341 """ |
345 """ |
342 arrayLength, = struct.unpack(">L", self.__data.read(4)) |
346 arrayLength, = struct.unpack(">L", self.__data.read(4)) |
343 # unsigned long, big-endian |
347 # unsigned long, big-endian |
344 |
348 |
345 value = {} |
349 value = {} |
385 |
389 |
386 @param variableName name of the variable to be parsed |
390 @param variableName name of the variable to be parsed |
387 @type str |
391 @type str |
388 @param parent reference to the dictionary to insert the result into |
392 @param parent reference to the dictionary to insert the result into |
389 @type dict |
393 @type dict |
|
394 @exception FlashCookieReaderError raised when an issue with the cookie |
|
395 file is found |
390 """ |
396 """ |
391 lenCname = struct.unpack(">H", self.__data.read(2)) |
397 lenCname = struct.unpack(">H", self.__data.read(2)) |
392 # unsigned short, big-endian |
398 # unsigned short, big-endian |
393 cname = self.__data.read(lenCname) |
399 cname = self.__data.read(lenCname) |
394 cname = cname.decode("utf-8") |
400 cname = cname.decode("utf-8") |
454 variableType, value = parent[variableName] |
460 variableType, value = parent[variableName] |
455 if isinstance(value, dict): |
461 if isinstance(value, dict): |
456 resultStr = self.toString(indent + 1, value) |
462 resultStr = self.toString(indent + 1, value) |
457 if resultStr: |
463 if resultStr: |
458 strArr.append("{0}{1}:\n{2}" |
464 strArr.append("{0}{1}:\n{2}" |
459 .format(indentStr, variableName, resultStr)) |
465 .format(indentStr, variableName, resultStr)) |
460 else: |
466 else: |
461 strArr.append("{0}{1}:" |
467 strArr.append("{0}{1}:" |
462 .format(indentStr, variableName)) |
468 .format(indentStr, variableName)) |
463 else: |
469 else: |
464 strArr.append("{0}{1}: {2}" |
470 strArr.append("{0}{1}: {2}" |
465 .format(indentStr, variableName, value)) |
471 .format(indentStr, variableName, value)) |
466 |
472 |
467 return "\n".join(strArr) |
473 return "\n".join(strArr) |