Ejemplo n.º 1
0
            public static EncryptedChunkEntry Read(Stream input, Endian endian)
            {
                EncryptedChunkEntry instance;

                instance.Entry      = NormalEntry.Read(input, endian);
                instance.CryptoInfo = CryptoInfo.Read(input, endian);
                return(instance);
            }
Ejemplo n.º 2
0
            public static NormalEntry Read(Stream input, Endian endian)
            {
                var instance = new NormalEntry();

                instance.Id          = new SHA1Hash(input.ReadBytes(20));
                instance.Offset      = input.ReadValueU32(endian);
                instance.Size        = input.ReadValueU32(endian);
                instance.TailSize    = input.ReadValueU32(endian);
                instance.DataIndex   = input.ReadValueU8();
                instance.IsEncrypted = input.ReadValueB8();
                var padding = input.ReadBytes(2);

                if (padding.Any(b => b != 0) == true)
                {
                    throw new FormatException();
                }
                return(instance);
            }
Ejemplo n.º 3
0
        public static CatalogFile Read(Stream input)
        {
            const Endian endian = Endian.Little;

            var magic1 = input.ReadValueU64(endian);
            var magic2 = input.ReadValueU64(endian);

            if (magic1 != Signature || magic2 != Signature)
            {
                throw new FormatException();
            }

            var instance = new CatalogFile();

            var normalCount    = input.ReadValueU32(endian);
            var patchCount     = input.ReadValueU32(endian);
            var encryptedCount = input.ReadValueU32(endian);
            var unknown1C      = input.ReadValueS32(endian); // patch version related?
            var unknown20      = input.ReadValueS32(endian); // patch version related?
            var unknown24      = input.ReadValueS32(endian); // patch version related?

            instance.NormalEntries.Clear();
            for (int i = 0; i < normalCount; i++)
            {
                var entry = NormalEntry.Read(input, endian);
                if (entry.IsEncrypted == true)
                {
                    throw new FormatException();
                }
                instance.NormalEntries.Add(entry);
            }

            instance.EncryptedEntries.Clear();
            for (int i = 0; i < encryptedCount; i++)
            {
                var encryptedEntry = EncryptedChunkEntry.Read(input, endian);
                if (encryptedEntry.Entry.IsEncrypted == false)
                {
                    throw new FormatException();
                }
                if (encryptedEntry.Entry.Size != encryptedEntry.CryptoInfo.Size)
                {
                    throw new FormatException();
                }
                instance.EncryptedEntries.Add(encryptedEntry);
            }

            instance.PatchEntries.Clear();
            for (int i = 0; i < patchCount; i++)
            {
                var entry = PatchEntry.Read(input, endian);
                instance.PatchEntries.Add(entry);
            }

            if (input.Position != input.Length)
            {
                throw new FormatException();
            }

            return(instance);
        }