コード例 #1
0
        public Stream OpenIndexInfo(IndexEntry idxInfo, MD5Hash key, bool checkHash = true)
        {
            lock (_dataLocks[idxInfo.Index]) {
                Stream dataStream = GetDataStream(idxInfo.Index);
                dataStream.Position = idxInfo.Offset;

                using (BinaryReader reader = new BinaryReader(dataStream, Encoding.ASCII, true)) {
                    byte[] md5 = reader.ReadBytes(16);
                    Array.Reverse(md5);

                    if (checkHash)
                    {
                        if (!key.EqualsTo9(md5))
                        {
                            throw new Exception("local data corrupted");
                        }
                    }

                    int size = reader.ReadInt32();

                    if (size != idxInfo.Size)
                    {
                        throw new Exception("local data corrupted");
                    }

                    //byte[] unkData1 = reader.ReadBytes(2);
                    //byte[] unkData2 = reader.ReadBytes(8);
                    dataStream.Position += 10;

                    byte[] data = reader.ReadBytes(idxInfo.Size - 30);

                    return(new MemoryStream(data));
                }
            }
        }
コード例 #2
0
        protected Stream GetLocalDataStreamInternal(IndexEntry idxInfo, MD5Hash key)
        {
            if (idxInfo == null)
            {
                throw new Exception("local index missing");
            }

            Stream dataStream = GetDataStream(idxInfo.Index);

            dataStream.Position = idxInfo.Offset;

            using (BinaryReader reader = new BinaryReader(dataStream, Encoding.ASCII, true))
            {
                byte[] md5 = reader.ReadBytes(16);
                Array.Reverse(md5);

                if (!key.EqualsTo9(md5))
                {
                    throw new Exception("local data corrupted");
                }

                int size = reader.ReadInt32();

                if (size != idxInfo.Size)
                {
                    throw new Exception("local data corrupted");
                }

                //byte[] unkData1 = reader.ReadBytes(2);
                //byte[] unkData2 = reader.ReadBytes(8);
                dataStream.Position += 10;

                byte[] data = reader.ReadBytes(idxInfo.Size - 30);

                return(new MemoryStream(data));
            }
        }