示例#1
0
        internal static ManifestHeader Parse(BinaryReader reader)
        {
            var result = new ManifestHeader();

            var testValue = reader.ReadUInt32();

            if (testValue == 0)
            {
                result.Version = reader.ReadUInt16();

                if (result.Version != 7)
                {
                    throw new InvalidDataException();
                }

                result.IsBigEndian = reader.ReadBooleanChecked();
                result.IsLinked    = reader.ReadBooleanChecked();
            }
            else
            {
                reader.BaseStream.Seek(-4, SeekOrigin.Current);

                result.IsBigEndian = reader.ReadBooleanChecked();
                result.IsLinked    = reader.ReadBooleanChecked();
                result.Version     = reader.ReadUInt16();

                if (result.Version != 5 && result.Version != 6)
                {
                    throw new InvalidDataException();
                }
            }

            result.StreamChecksum                   = reader.ReadUInt32();
            result.AllTypesHash                     = reader.ReadUInt32();
            result.AssetCount                       = reader.ReadUInt32();
            result.TotalInstanceDataSize            = reader.ReadUInt32();
            result.MaxInstanceChunkSize             = reader.ReadUInt32();
            result.MaxRelocationChunkSize           = reader.ReadUInt32();
            result.MaxImportsChunkSize              = reader.ReadUInt32();
            result.AssetReferenceBufferSize         = reader.ReadUInt32();
            result.ReferencedManifestNameBufferSize = reader.ReadUInt32();
            result.AssetNameBufferSize              = reader.ReadUInt32();
            result.SourceFileNameBufferSize         = reader.ReadUInt32();

            return(result);
        }
示例#2
0
        internal static ManifestHeader Parse(BinaryReader reader)
        {
            var result = new ManifestHeader();

            result.IsBigEndian = reader.ReadBooleanChecked();
            result.IsLinked    = reader.ReadBooleanChecked();
            result.Version     = reader.ReadUInt16();

            result.StreamChecksum                   = reader.ReadUInt32();
            result.AllTypesHash                     = reader.ReadUInt32();
            result.AssetCount                       = reader.ReadUInt32();
            result.TotalInstanceDataSize            = reader.ReadUInt32();
            result.MaxInstanceChunkSize             = reader.ReadUInt32();
            result.MaxRelocationChunkSize           = reader.ReadUInt32();
            result.MaxImportsChunkSize              = reader.ReadUInt32();
            result.AssetReferenceBufferSize         = reader.ReadUInt32();
            result.ReferencedManifestNameBufferSize = reader.ReadUInt32();
            result.AssetNameBufferSize              = reader.ReadUInt32();
            result.SourceFileNameBufferSize         = reader.ReadUInt32();

            return(result);
        }
示例#3
0
        public static ManifestFile FromFileSystemEntry(FileSystemEntry entry)
        {
            using (var stream = entry.Open())
                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var result = new ManifestFile
                    {
                        Header = ManifestHeader.Parse(reader)
                    };

                    switch (result.Header.Version)
                    {
                    case 5:
                    case 6:
                    case 7:
                        break;

                    default:
                        throw new InvalidDataException();
                    }

                    result.Assets = new Asset[result.Header.AssetCount];
                    for (var i = 0; i < result.Assets.Length; i++)
                    {
                        result.Assets[i] = new Asset
                        {
                            Header = AssetEntry.Parse(reader, result.Header.Version)
                        };
                    }

                    result.AssetReferences = new AssetReference[result.Header.AssetReferenceBufferSize / AssetReference.SizeInBytes];
                    for (var i = 0; i < result.AssetReferences.Length; i++)
                    {
                        result.AssetReferences[i] = AssetReference.Parse(reader);
                    }

                    foreach (var asset in result.Assets)
                    {
                        asset.AssetReferences = result.AssetReferences.AsSpan().Slice(
                            (int)asset.Header.AssetReferenceOffset / AssetReference.SizeInBytes,
                            (int)asset.Header.AssetReferenceCount);
                    }

                    {
                        var endPosition        = stream.Position + result.Header.ReferencedManifestNameBufferSize;
                        var manifestReferences = new List <ManifestReference>();

                        while (stream.Position < endPosition)
                        {
                            manifestReferences.Add(ManifestReference.Parse(reader));
                        }
                        result.ManifestReferences = manifestReferences;
                    }

                    {
                        var endPosition = stream.Position + result.Header.AssetNameBufferSize;
                        var assetNames  = ReadNameBuffer(reader, endPosition);

                        foreach (var asset in result.Assets)
                        {
                            asset.Name = assetNames[asset.Header.NameOffset];
                        }
                    }

                    {
                        var endPosition     = stream.Position + result.Header.SourceFileNameBufferSize;
                        var sourceFileNames = ReadNameBuffer(reader, endPosition);

                        foreach (var asset in result.Assets)
                        {
                            asset.SourceFileName = sourceFileNames[asset.Header.SourceFileNameOffset];
                        }
                    }

                    return(result);
                }
        }
示例#4
0
        public static ManifestFile FromFileSystemEntry(FileSystemEntry entry)
        {
            using (var stream = entry.Open())
                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var result = new ManifestFile
                    {
                        Header = ManifestHeader.Parse(reader)
                    };

                    if (result.Header.Version != 5)
                    {
                        throw new System.NotImplementedException();
                    }

                    result.Assets = new Asset[result.Header.AssetCount];
                    for (var i = 0; i < result.Assets.Length; i++)
                    {
                        result.Assets[i] = new Asset
                        {
                            Header = AssetEntry.Parse(reader)
                        };
                    }

                    result.AssetReferences = new AssetReference[result.Header.AssetReferenceBufferSize / AssetReference.SizeInBytes];
                    for (var i = 0; i < result.AssetReferences.Length; i++)
                    {
                        result.AssetReferences[i] = AssetReference.Parse(reader);
                    }

                    {
                        var endPosition        = stream.Position + result.Header.ReferencedManifestNameBufferSize;
                        var manifestReferences = new List <ManifestReference>();

                        while (stream.Position < endPosition)
                        {
                            manifestReferences.Add(ManifestReference.Parse(reader));
                        }
                        result.ManifestReferences = manifestReferences;
                    }

                    {
                        var endPosition = stream.Position + result.Header.AssetNameBufferSize;
                        var assetNames  = ReadNameBuffer(reader, endPosition);

                        foreach (var asset in result.Assets)
                        {
                            asset.Name = assetNames[asset.Header.NameOffset];
                        }
                    }

                    {
                        var endPosition     = stream.Position + result.Header.SourceFileNameBufferSize;
                        var sourceFileNames = ReadNameBuffer(reader, endPosition);

                        foreach (var asset in result.Assets)
                        {
                            asset.SourceFileName = sourceFileNames[asset.Header.SourceFileNameOffset];
                        }
                    }

                    var instanceDataOffset   = 4u;
                    var relocationDataOffset = 4u;
                    var importsDataOffset    = 4u;
                    foreach (var asset in result.Assets)
                    {
                        asset.InstanceDataOffset   = instanceDataOffset;
                        asset.RelocationDataOffset = relocationDataOffset;
                        asset.ImportsDataOffset    = importsDataOffset;

                        instanceDataOffset   += asset.Header.InstanceDataSize;
                        relocationDataOffset += asset.Header.RelocationDataSize;
                        importsDataOffset    += asset.Header.ImportsDataSize;
                    }

                    return(result);
                }
        }