示例#1
0
 public virtual ResResourceMap ReadResResourceMap(ResChunk_header header)
 {
     var result = new ResResourceMap
     {
         Header = header,
         ResouceIds = new List<uint>()
     };
     for (int pos = 8; pos < header.Size; pos += 4)
     {
         result.ResouceIds.Add(ReadUInt32());
     }
     return result;
 }
示例#2
0
        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);
                }
            }
        }