(self, byteWBXML)
| 826 | return self.xmlDoc.toxml() |
| 827 | |
| 828 | def loadBytes(self, byteWBXML): |
| 829 | |
| 830 | currentNode = self.xmlDoc |
| 831 | |
| 832 | wbXMLBytes = ASWBXMLByteQueue(byteWBXML) |
| 833 | # Version is ignored |
| 834 | version = wbXMLBytes.dequeueAndLog() |
| 835 | |
| 836 | # Public Identifier is ignored |
| 837 | publicId = wbXMLBytes.dequeueMultibyteInt() |
| 838 | |
| 839 | logging.debug("Version: %d, Public Identifier: %d" % (version, publicId)) |
| 840 | |
| 841 | # Character set |
| 842 | # Currently only UTF-8 is supported, throw if something else |
| 843 | charset = wbXMLBytes.dequeueMultibyteInt() |
| 844 | if (charset != 0x6A): |
| 845 | raise InvalidDataException("ASWBXML only supports UTF-8 encoded XML.") |
| 846 | |
| 847 | # String table length |
| 848 | # This should be 0, MS-ASWBXML does not use string tables |
| 849 | stringTableLength = wbXMLBytes.dequeueMultibyteInt() |
| 850 | if (stringTableLength != 0): |
| 851 | raise InvalidDataException("WBXML data contains a string table.") |
| 852 | |
| 853 | # Now we should be at the body of the data. |
| 854 | # Add the declaration |
| 855 | unusedArray = [GlobalTokens.ENTITY, GlobalTokens.EXT_0, GlobalTokens.EXT_1, GlobalTokens.EXT_2, GlobalTokens.EXT_I_0, GlobalTokens.EXT_I_1, GlobalTokens.EXT_I_2, GlobalTokens.EXT_T_0, GlobalTokens.EXT_T_1, GlobalTokens.EXT_T_2, GlobalTokens.LITERAL, GlobalTokens.LITERAL_A, GlobalTokens.LITERAL_AC, GlobalTokens.LITERAL_C, GlobalTokens.PI, GlobalTokens.STR_T] |
| 856 | |
| 857 | while ( wbXMLBytes.qsize() > 0): |
| 858 | currentByte = wbXMLBytes.dequeueAndLog() |
| 859 | if ( currentByte == GlobalTokens.SWITCH_PAGE ): |
| 860 | newCodePage = wbXMLBytes.dequeueAndLog() |
| 861 | if (newCodePage >= 0 and newCodePage < 25): |
| 862 | self.currentCodePage = newCodePage |
| 863 | else: |
| 864 | raise InvalidDataException("Unknown code page ID 0x{0:X} encountered in WBXML".format(currentByte)) |
| 865 | elif ( currentByte == GlobalTokens.END ): |
| 866 | if (currentNode != None and currentNode.parentNode != None): |
| 867 | currentNode = currentNode.parentNode |
| 868 | else: |
| 869 | raise InvalidDataException("END global token encountered out of sequence") |
| 870 | break |
| 871 | elif ( currentByte == GlobalTokens.OPAQUE ): |
| 872 | CDATALength = wbXMLBytes.dequeueMultibyteInt() |
| 873 | newOpaqueNode = self.xmlDoc.createCDATASection(wbXMLBytes.dequeueString(CDATALength)) |
| 874 | currentNode.appendChild(newOpaqueNode) |
| 875 | |
| 876 | elif ( currentByte == GlobalTokens.STR_I ): |
| 877 | newTextNode = self.xmlDoc.createTextNode(wbXMLBytes.dequeueString()) |
| 878 | currentNode.appendChild(newTextNode) |
| 879 | |
| 880 | elif ( currentByte in unusedArray): |
| 881 | raise InvalidDataException("Encountered unknown global token 0x{0:X}.".format(currentByte)) |
| 882 | else: |
| 883 | hasAttributes = (currentByte & 0x80) > 0 |
| 884 | hasContent = (currentByte & 0x40) > 0 |
| 885 |
no test coverage detected