Ejemplo n.º 1
0
        private void ProcessNextXmlToken(BinaryXmlElement element, ref int offset)
        {
            if (offset >= element.Offset + element.Length)
            {
                return;
            }

            byte nextToken = this.buffer[offset];

            switch (nextToken)
            {
            case 0x00:
                ////EOF for the xml
                offset++;
                return;

            case 0x01:
            case 0x41:
                ////starting a new element.
                return;

            case 0x02:
            case 0x03:
                ////closing a start element or empty element
                offset++;
                this.ProcessNextXmlToken(element, ref offset);

                break;

            case 0x04:
                ////End tag of an element
                offset++;
                this.ProcessNextXmlToken(element, ref offset);

                break;

            case 0x05:
                ////value
                this.ReadAttribute(element, ref offset);
                this.ProcessNextXmlToken(element, ref offset);

                break;

            case 0x0D:
            case 0x0E:
                ////I'm not 100% about the 0x0D
                offset++;
                element.ValueIndex = BitConverter.ToInt16(this.buffer, offset);

                offset           += 2;
                element.ValueType = (BinaryValueType)this.buffer[offset];

                offset++;

                this.ProcessNextXmlToken(element, ref offset);

                break;
            }
        }
Ejemplo n.º 2
0
        private BinaryXmlElement ReadBinaryXmlElement(ref int offset)
        {
            bool             hasAttributes = this.buffer[offset] == 0x41;
            BinaryXmlElement element       = new BinaryXmlElement();

            element.Offset = offset;

            ////I don't know what the next two bytes mean
            offset        += 3;
            element.Length = BitConverter.ToInt32(this.buffer, offset) + 7;

            offset += 4;
            int nameOffset = BitConverter.ToInt32(this.buffer, offset);

            element.Name = this.ReadName(ref nameOffset);
            if (nameOffset < element.Offset)
            {
                ////The name was stored with a previous element.  Restore the offset plus the length of pointer for the name
                offset    += 4;
                nameOffset = offset;
            }

            if (hasAttributes)
            {
                int attributesOffset = nameOffset;
                int attributesSize   = BitConverter.ToInt32(this.buffer, attributesOffset);

                attributesOffset += 4;
                offset            = attributesOffset;
                while (hasAttributes)
                {
                    hasAttributes = this.buffer[attributesOffset] == 0x46;
                    attributesOffset++;
                    offset = attributesOffset;

                    ////seems silly because this is getting an offset immeadiately after the offset
                    attributesOffset = BitConverter.ToInt32(this.buffer, attributesOffset);

                    BinaryXmlAttribute attribute = new BinaryXmlAttribute();
                    attribute.Name = this.ReadName(ref attributesOffset);
                    if (attributesOffset < element.Offset)
                    {
                        ////The name was stored with a previous element.  Restore the offset plus the length of pointer for the name
                        attributesOffset = offset + 4;
                    }

                    this.ReadAttribute(attribute, ref attributesOffset);
                    element.Attributes.Add(attribute);
                }

                offset = attributesOffset;
            }
            else
            {
                offset = nameOffset;
            }

            this.ProcessNextXmlToken(element, ref offset);

            while (offset < element.Offset + element.Length &&
                   (this.buffer[offset] == 0x41 || this.buffer[offset] == 0x01))
            {
                element.Children.Add(this.ReadBinaryXmlElement(ref offset));
            }

            this.ProcessNextXmlToken(element, ref offset);
            if (this.buffer[offset] == 0x00)
            {
                ////null terminator for the template
                offset++;
            }

            return(element);
        }