コード例 #1
0
ファイル: SevenZip.cs プロジェクト: tzinmein/trrntzipDN
        public void DeepScan()
        {
            const int bufferSize = 4096 * 128;

            byte[] buffer = new byte[bufferSize];

            for (int index = 0; index < _localFiles.Count; index++)
            {
                if (_localFiles[index].isDirectory || _localFiles[index].UncompressedSize == 0)
                {
                    _localFiles[index].md5        = new byte[] { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e };
                    _localFiles[index].sha1       = new byte[] { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 };
                    _localFiles[index].FileStatus = ZipReturn.ZipGood;

                    continue;
                }

                ulong     sizetogo;
                Stream    inStream;
                ZipReturn zr = ZipFileOpenReadStream(index, out inStream, out sizetogo);
                if (zr != ZipReturn.ZipGood)
                {
                    continue;
                }

                if (inStream == null)
                {
                    continue;
                }

                CRC  crc32 = new CRC();
                MD5  lmd5  = System.Security.Cryptography.MD5.Create();
                SHA1 lsha1 = System.Security.Cryptography.SHA1.Create();

                while (sizetogo > 0)
                {
                    int sizenow = sizetogo > (ulong)bufferSize ? bufferSize : (int)sizetogo;
                    inStream.Read(buffer, 0, sizenow);

                    crc32.Update(buffer, 0, (uint)sizenow);
                    lmd5.TransformBlock(buffer, 0, sizenow, null, 0);
                    lsha1.TransformBlock(buffer, 0, sizenow, null, 0);

                    sizetogo = sizetogo - (ulong)sizenow;
                }

                lmd5.TransformFinalBlock(buffer, 0, 0);
                lsha1.TransformFinalBlock(buffer, 0, 0);

                byte[] testcrc = Util.uinttobytes(crc32.GetDigest());
                _localFiles[index].md5  = lmd5.Hash;
                _localFiles[index].sha1 = lsha1.Hash;

                _localFiles[index].FileStatus = Util.ByteArrCompare(_localFiles[index].crc, testcrc) ? ZipReturn.ZipGood : ZipReturn.ZipCRCDecodeError;
            }
        }
コード例 #2
0
ファイル: SevenZip.cs プロジェクト: tzinmein/trrntzipDN
        private void CloseWriting7Zip(ICodeProgress p = null)
        {
            if (_compressed)
            {
                _lzmaStream.Close();
            }

            _packStreamSize = (UInt64)_zipFs.Position - _packStreamStart;

            Create7ZStructure();

            byte[] newHeaderByte;
            using (Stream headerMem = new MemoryStream())
            {
                using (BinaryWriter headerBw = new BinaryWriter(headerMem))
                {
                    _header.WriteHeader(headerBw);
                    newHeaderByte      = new byte[headerMem.Length];
                    headerMem.Position = 0;
                    headerMem.Read(newHeaderByte, 0, newHeaderByte.Length);
                }
            }

            CRC mainHeadercrc = new CRC();

            mainHeadercrc.Update(newHeaderByte, 0, (uint)newHeaderByte.Length);
            UInt32 mainHeaderCRC = mainHeadercrc.GetDigest();

            UInt64       headerpos = (UInt64)_zipFs.Position;
            BinaryWriter bw        = new BinaryWriter(_zipFs);

            bw.Write(newHeaderByte);

            _signatureHeader.WriteFinal(bw, headerpos, (ulong)newHeaderByte.Length, mainHeaderCRC);

            WriteRomVault7Zip(bw, headerpos, (ulong)newHeaderByte.Length, mainHeaderCRC);

            _zipFs.Flush();
            _zipFs.Close();
            _zipFs.Dispose();
        }