internal void SetNameValues(BinaryDataTreeDecompiler decompiler, BinaryDataTreePackedNode packedNode, int numNameValues)
        {
            NameValues = new List <BinaryDataTreeBuildNameValue>(numNameValues);
            for (int y = 0; y < numNameValues; y++)
            {
                NameValues.Add(new BinaryDataTreeBuildNameValue());
            }

            for (int x = 0; x < NameValues.Count; x++)
            {
                int packed_name_value_index = packedNode.NameValueOffset + x;
                var packed_name_value       = decompiler.NameValues[packed_name_value_index];
                var build_name_value        = NameValues[x];

                if (x == (NameValues.Count - 1))
                {
                    if (!packed_name_value.IsLastNameValue)
                    {
                        throw new InvalidDataException("Expected IsLastNameValue");
                    }
                }

                build_name_value.Name = decompiler.ReadName(packed_name_value.NameOffset);
                build_name_value.Variant.Read(decompiler.ValueDataPool, packed_name_value);

                if (packed_name_value.HasUnicodeData)
                {
                    decompiler.HasUnicodeStrings = true;
                }
            }
        }
 internal void SetChildren(BinaryDataTreeDecompiler decompiler, BinaryDataTreePackedNode packedNode, int numChildNodes)
 {
     Children = new List <BinaryDataTreeBuildNode>(numChildNodes);
     for (int x = 0; x < numChildNodes; x++)
     {
         Children.Add(decompiler.Nodes[packedNode.ChildNodeIndex + x]);
     }
 }
 internal void SetParent(BinaryDataTreeDecompiler decompiler, BinaryDataTreePackedNode packedNode)
 {
     if (packedNode.IsRootNode)
     {
         decompiler.RootNode = this;
         Parent = null;
     }
     else
     {
         Parent = decompiler.Nodes[packedNode.ParentIndex];
     }
 }
Ejemplo n.º 4
0
        private void ReadInternal(IO.EndianStream s)
        {
            long stream_length = s.BaseStream.Length - s.BaseStream.Position;

            #region Header
            if (ValidateData)
            {
                if (stream_length < BinaryDataTreeHeader.kSizeOf)
                {
                    throw new InvalidDataException("Expected more bytes for header data");
                }
            }

            mHeader.Serialize(s);

            if (ValidateData)
            {
                mHeader.Validate();

                long min_expected_bytes_remaining =
                    BinaryDataTreeHeader.kSizeOf +
                    (BinaryDataTreeSectionHeader.kSizeOf * mHeader.UserSectionCount);
                if (stream_length < min_expected_bytes_remaining)
                {
                    throw new InvalidDataException("Expected more bytes for header and user sections data");
                }
            }
            #endregion

            #region Data
            long data_position = s.BaseStream.Position;
            if (ValidateData)
            {
                long total_size = BinaryDataTreeHeader.kSizeOf + mHeader.DataSize;
                if (stream_length < total_size)
                {
                    throw new InvalidDataException("Expected more bytes for header and payload data");
                }

                uint actual_data_crc = GetDataCrc32(s.BaseStream);
                if (mHeader.DataCrc32 != actual_data_crc)
                {
                    throw new InvalidDataException(string.Format("Invalid Data CRC 0x{0}, expected 0x{1}",
                                                                 actual_data_crc.ToString("X8"), mHeader.DataCrc32.ToString("X8")));
                }
            }
            #endregion

            #region Sections
            var section_headers = new BinaryDataTreeSectionHeader[mHeader.UserSectionCount];
            s.StreamArray(section_headers);

            if (ValidateData)
            {
                foreach (var header in section_headers)
                {
                    if (stream_length < (header.Offset + header.Size))
                    {
                        throw new InvalidDataException("Expected more bytes for section data");
                    }
                }
            }

            long offset_cursor = data_position;

            uint nodes_size   = mHeader[BinaryDataTreeSectionID.NodeSectionIndex];
            long nodes_offset = nodes_size > 0
                                ? offset_cursor
                                : 0;
            offset_cursor += nodes_size;

            uint name_values_size   = mHeader[BinaryDataTreeSectionID.NameValueSectionIndex];
            long name_values_offset = name_values_size > 0
                                ? offset_cursor
                                : 0;
            offset_cursor += name_values_size;

            uint name_data_size   = mHeader[BinaryDataTreeSectionID.NameDataSectionIndex];
            long name_data_offset = name_data_size > 0
                                ? offset_cursor
                                : 0;
            offset_cursor += name_data_size;

            if (mHeader[BinaryDataTreeSectionID.ValueDataSectionIndex] > 0)
            {
                offset_cursor = IntegerMath.Align(IntegerMath.k16ByteAlignmentBit, offset_cursor);
            }
            uint value_data_size   = mHeader[BinaryDataTreeSectionID.ValueDataSectionIndex];
            long value_data_offset = value_data_size > 0
                                ? offset_cursor
                                : 0;
            offset_cursor += value_data_size;

            if (ValidateData)
            {
                if (stream_length < offset_cursor)
                {
                    throw new InvalidDataException("Expected more bytes for section data");
                }
            }
            #endregion

            #region Decompiler
            Decompiler = new BinaryDataTreeDecompiler();

            s.Seek(name_data_offset);
            Decompiler.NameData = new byte[name_data_size];
            s.Stream(Decompiler.NameData);

            s.Seek(value_data_offset);
            Decompiler.ValueData = new byte[value_data_size];
            s.Stream(Decompiler.ValueData);

            s.Seek(nodes_offset);
            Decompiler.PackedNodes = new BinaryDataTreePackedNode[nodes_size / BinaryDataTreePackedNode.kSizeOf];
            s.StreamArray(Decompiler.PackedNodes);

            s.Seek(name_values_offset);
            Decompiler.NameValues = new BinaryDataTreeNameValue[name_values_size / BinaryDataTreeNameValue.kSizeOf];
            s.StreamArray(Decompiler.NameValues);

            Decompiler.Decompile();
            #endregion
        }