public virtual ResXMLTree_startelement ReadResXMLTree_startelement(ResXMLTree_node node, ResXMLTree_attrExt attrExt) { var element = new ResXMLTree_startelement { Node = node, AttrExt = attrExt, Attributes = new List<ResXMLTree_attribute>() }; uint bytesLeft = node.Header.Size - 0x24u; for (int i = 0; i < attrExt.AttributeCount; i++) { element.Attributes.Add(ReadResXMLTree_attribute()); bytesLeft -= 0x14u; } if (bytesLeft < 0) { throw new InvalidDataException("The length of the content exceeds the ResStringPool block boundary."); } if (bytesLeft > 0) { Debug.WriteLine("Warning: Garbage at the end of the StringPool block. Padding?"); ReadBytes((int) bytesLeft); } return element; }
private IEnumerable<XmlParserEventCode> ParserIterator() { while (true) { ClearState(); ResChunk_header header; try { header = _reader.ReadResChunk_header(); } catch (EndOfStreamException) { break; } var subStream = new BoundedStream(_reader.BaseStream, header.Size - 8); var subReader = new ResReader(subStream); switch (header.Type) { case ResourceType.RES_XML_TYPE: yield return XmlParserEventCode.START_DOCUMENT; _reader = subReader; // Bound whole file continue; // Don't skip content case ResourceType.RES_STRING_POOL_TYPE: ResStringPool_header stringPoolHeader = subReader.ReadResStringPool_header(header); _strings = subReader.ReadResStringPool(stringPoolHeader); break; case ResourceType.RES_XML_RESOURCE_MAP_TYPE: ResResourceMap resourceMap = subReader.ReadResResourceMap(header); _resourceMap = resourceMap; break; case ResourceType.RES_XML_START_NAMESPACE_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_namespaceExt(); yield return XmlParserEventCode.START_NAMESPACE; break; case ResourceType.RES_XML_END_NAMESPACE_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_namespaceExt(); yield return XmlParserEventCode.END_NAMESPACE; break; case ResourceType.RES_XML_START_ELEMENT_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); ResXMLTree_attrExt attrExt = subReader.ReadResXMLTree_attrExt(); _currentExtension = attrExt; _attributes = new List<ResXMLTree_attribute>(); for (int i = 0; i < attrExt.AttributeCount; i++) { _attributes.Add(subReader.ReadResXMLTree_attribute()); } yield return XmlParserEventCode.START_TAG; break; case ResourceType.RES_XML_END_ELEMENT_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_endElementExt(); yield return XmlParserEventCode.END_TAG; break; case ResourceType.RES_XML_CDATA_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_cdataExt(); yield return XmlParserEventCode.TEXT; break; default: Console.WriteLine("Warning: Skipping chunk of type {0} (0x{1:x4})", header.Type, (int) header.Type); break; } byte[] junk = subStream.ReadFully(); if (junk.Length > 0) { Console.WriteLine("Warning: Skipping {0} bytes at the end of a {1} (0x{2:x4}) chunk.", junk.Length, header.Type, (int) header.Type); } } }
private void ClearState() { _currentNode = null; _currentExtension = null; _attributes = null; }
private IEnumerable <XmlParserEventCode> ParserIterator() { while (true) { ClearState(); if (_reader.BaseStream.Position >= _reader.BaseStream.Length) { // If we're at the end of the file, stop reading chunks. // Don't try to catch an EndOfStreamException - this way, // we avoid an exception being created. break; } ResChunk_header header; try { header = _reader.ReadResChunk_header(); } catch (EndOfStreamException) { // Keep this just in case. break; } var subStream = new BoundedStream(_reader.BaseStream, header.Size - 8); var subReader = new ResReader(subStream); switch (header.Type) { case ResourceType.RES_XML_TYPE: yield return(XmlParserEventCode.START_DOCUMENT); _reader = subReader; // Bound whole file continue; // Don't skip content case ResourceType.RES_STRING_POOL_TYPE: ResStringPool_header stringPoolHeader = subReader.ReadResStringPool_header(header); _strings = subReader.ReadResStringPool(stringPoolHeader); break; case ResourceType.RES_XML_RESOURCE_MAP_TYPE: ResResourceMap resourceMap = subReader.ReadResResourceMap(header); _resourceMap = resourceMap; break; case ResourceType.RES_XML_START_NAMESPACE_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_namespaceExt(); yield return(XmlParserEventCode.START_NAMESPACE); break; case ResourceType.RES_XML_END_NAMESPACE_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_namespaceExt(); yield return(XmlParserEventCode.END_NAMESPACE); break; case ResourceType.RES_XML_START_ELEMENT_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); ResXMLTree_attrExt attrExt = subReader.ReadResXMLTree_attrExt(); _currentExtension = attrExt; _attributes = new List <ResXMLTree_attribute>(); for (int i = 0; i < attrExt.AttributeCount; i++) { _attributes.Add(subReader.ReadResXMLTree_attribute()); } yield return(XmlParserEventCode.START_TAG); break; case ResourceType.RES_XML_END_ELEMENT_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_endElementExt(); yield return(XmlParserEventCode.END_TAG); break; case ResourceType.RES_XML_CDATA_TYPE: _currentNode = subReader.ReadResXMLTree_node(header); _currentExtension = subReader.ReadResXMLTree_cdataExt(); yield return(XmlParserEventCode.TEXT); break; default: #if !CORECLR Console.WriteLine("Warning: Skipping chunk of type {0} (0x{1:x4})", header.Type, (int)header.Type); #endif break; } byte[] junk = subStream.ReadFully(); if (junk.Length > 0) { #if !CORECLR Console.WriteLine("Warning: Skipping {0} bytes at the end of a {1} (0x{2:x4}) chunk.", junk.Length, header.Type, (int)header.Type); #endif } } }
public virtual void Write(ResXMLTree_node data) { Write(data.Header); _writer.Write(data.LineNumber); Write(data.Comment); }