Exemple #1
0
        //public byte[] ToBuffer()
        //{
        //	byte[] result = new byte[Length]; //не забути про доповнення кратне 16
        //	byte[] trash = new byte[13];
        //	CryptoRandom.GetBytes(trash);
        //	Buffer.BlockCopy(_IV, 0, result, 0, _IV.Length);
        //	byte BlockStatus = (byte)(Convert.ToByte(!Exists) * 128 + (int)CryptoRandom.Random(128));
        //	Buffer.BlockCopy(BitConverter.GetBytes(BlockStatus), 0, result, 16, 1);
        //	Buffer.BlockCopy(trash, 0, result, 17, trash.Length);
        //	Buffer.BlockCopy(BitConverter.GetBytes(_InfSize), 0, result, 30, 2);
        //	Buffer.BlockCopy(BitConverter.GetBytes((byte)ElType * 128 + (int)CryptoRandom.Random(128)), 0, result, 32, 1);

        //	return result;
        //}

        //Перші 17 байт (нешифровані)
        public byte[] ToBufferFirstBlock()
        {
            byte[] result = new byte[17];
            Buffer.BlockCopy(_IV, 0, result, 0, _IV.Length);
            result[16] = (byte)(Convert.ToByte(!Exists) * 128 + (int)CryptoRandom.Random(128));

            return(result);
        }
Exemple #2
0
        public byte[] ToBufferEncryptBlock()
        {
            byte[] result = new byte[16];
            CryptoRandom.GetBytes(result);
            Buffer.BlockCopy(BitConverter.GetBytes(_InfSize), 0, result, 13, 2);
            Buffer.BlockCopy(BitConverter.GetBytes((byte)ElType * 128 + (int)CryptoRandom.Random(128)), 0, result, 15, 1);

            return(result);
        }
Exemple #3
0
        public ulong GetFreeSpacePos(UInt64 size, long fileSize, bool withWrite = true)
        {
            lock (_freeSpaceMapLocker)
            {
                if (size == 0)
                {
                    return(CryptoRandom.Random(UInt64.MaxValue - 2) + 2);
                }

                if (!_realTimeCalculating && !_isAnalysed)
                {
                    throw new Exception("Не було проведено аналіз вільного місця. Використай метод FreeSpaceAnalyse()");
                }

                UInt64 result = (ulong)fileSize;

                int indexBySize = _GetIndexBySize(size);

                if (indexBySize < 0)
                {
                    return(result);
                }

                SPoint sPoint = _freeSpaceMapSize[indexBySize];

                result = sPoint.Start;

                if (!withWrite)
                {
                    return(result);
                }

                _freeSpaceMapSize.RemoveAt(indexBySize);

                if ((sPoint.Size - size) == 0)
                {
                    int indexByPos = _GetIndexByPos(sPoint.Start);
                    _freeSpaceMapPos.RemoveAt(indexByPos);
                    return(result);
                }

                sPoint.Start += size;
                sPoint.Size  -= size;

                _InsertSPointToSizeMap(sPoint);

                return(result);
            }
        }
Exemple #4
0
        protected override void SaveInf()
        {
            byte[] UTF8Name   = Encoding.UTF8.GetBytes(_Name);
            int    realLength = FileInfLength + UTF8Name.Length;
            ushort newInfSize = Header.GetNewInfSizeByBufLength(realLength);

            byte[] buf = new byte[newInfSize];
            Buffer.BlockCopy(BitConverter.GetBytes(_FileStartPos), 0, buf, 0, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(_IconStartPos), 0, buf, 8, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(_FileSize), 0, buf, 16, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(_IconSize), 0, buf, 24, 4);
            byte isCompressed = (byte)(Convert.ToByte(!_IsCompressed) * 128 + (int)CryptoRandom.Random(128));

            Buffer.BlockCopy(BitConverter.GetBytes(isCompressed), 0, buf, 28, 1);
            Buffer.BlockCopy(_Hash, 0, buf, 29, 16);
            Buffer.BlockCopy(_PHash, 0, buf, 45, 8);
            Buffer.BlockCopy(BitConverter.GetBytes(_ParentID), 0, buf, 53, 8);
            Buffer.BlockCopy(BitConverter.GetBytes((UInt16)UTF8Name.Length), 0, buf, 61, 2);
            Buffer.BlockCopy(UTF8Name, 0, buf, 63, UTF8Name.Length);

            header.SaveInfo(buf, realLength);
        }
Exemple #5
0
 protected UInt64 GenID()
 {
     return(CryptoRandom.Random(UInt64.MaxValue - 2) + 2);
 }
Exemple #6
0
        public void Restore()
        {
            _Exists = true;

            if (writedInFile)
            {
                _headersFileStream.WriteByte((long)_StartPos + 16, (byte)(Convert.ToByte(!_Exists) * 128 + (int)CryptoRandom.Random(128)));
            }
        }