Пример #1
0
        private void ReadSegment(long SegmentNumber)
        {
            if (SegmentNumber == CurrentSegmentNo)
            {
                return;
            }
            DataStream.Position = DataStreamStart + SegmentNumber * SegmentSize;

            byte[] CurrentSegmentEnc = new byte[Math.Min(SegmentSize, DataStream.Length - DataStream.Position)];
            DataStream.Read(CurrentSegmentEnc, CurrentSegmentEnc.Length);

            using (MemoryStream msDecrypt = new MemoryStream(CurrentSegmentEnc))
            {
                ICryptoTransform RealDecryptor = Decryptor;
                try
                {
                    if (RealDecryptor == null)
                    {
                        Key.CalcDataIV(SegmentNumber);
                        RealDecryptor = EncEngine.CreateDecryptor(Key.Key, Key.IV);
                    }
                    using (CryptoStream cs = new CryptoStream(msDecrypt, RealDecryptor, CryptoStreamMode.Read))
                    {
                        cs.Read(CurrentSegment, 0, CurrentSegmentEnc.Length);
                    }
                }
                finally
                {
                    if (RealDecryptor != Decryptor)
                    {
                        RealDecryptor.Dispose();
                    }
                }
            }

            CurrentSegmentNo = SegmentNumber;
        }
Пример #2
0
        private object GetOneProperty(TOle2File Ole2File, int PropType)
        {
            if ((PropType & (int)TPropertyTypes.VT_VECTOR) != 0)
            {
                byte[] i4 = new byte[4];
                Ole2File.Read(i4, i4.Length);

                object[] Vector = new object[BitOps.GetInt32(i4, 0)];
                for (int i = 0; i < Vector.Length; i++)
                {
                    Vector[i] = GetOneProperty(Ole2File, PropType & ~(int)TPropertyTypes.VT_VECTOR);
                }
                return(Vector);
            }

            switch ((TPropertyTypes)(PropType & 0xFF))
            {
            case TPropertyTypes.VT_EMPTY:
                return(null);

            case TPropertyTypes.VT_I2:
                byte[] i2 = new byte[2];
                Ole2File.Read(i2, i2.Length);
                return(BitConverter.ToInt16(i2, 0));

            case TPropertyTypes.VT_UI2:      //This is not really suported, but we need to convert the CodePage to a Signed int.
                byte[] ui2 = new byte[2];
                Ole2File.Read(ui2, ui2.Length);
                return((Int32)BitConverter.ToUInt16(ui2, 0));

            case TPropertyTypes.VT_I4:
                byte[] i4 = new byte[4];
                Ole2File.Read(i4, i4.Length);
                return(BitOps.GetInt32(i4, 0));

            case TPropertyTypes.VT_R4:
                byte[] d4 = new byte[4];
                Ole2File.Read(d4, d4.Length);
                return(BitConverter.ToSingle(d4, 0));

            case TPropertyTypes.VT_R8:
                byte[] d8 = new byte[8];
                Ole2File.Read(d8, d8.Length);
                return(BitConverter.ToDouble(d8, 0));

            case TPropertyTypes.VT_CY:
                byte[] cy = new byte[8];
                Ole2File.Read(cy, cy.Length);

                return(TCompactFramework.DecimalFromOACurrency(BitConverter.ToInt64(cy, 0)));

            case TPropertyTypes.VT_DATE:
                byte[] dd = new byte[8];
                Ole2File.Read(dd, dd.Length);
                DateTime Dt;
                if (!FlxDateTime.TryFromOADate(BitConverter.ToDouble(dd, 0), false, out Dt))
                {
                    return(DateTime.MinValue);
                }
                return(Dt.Date);

            case TPropertyTypes.VT_BSTR:
                byte[] sl = new byte[4];
                Ole2File.Read(sl, sl.Length);
                UInt32 StrLen = BitConverter.ToUInt32(sl, 0);
                if (StrLen <= 1)
                {
                    return(String.Empty);                  //StrLen includes the trailing #0
                }
                byte[] Str = new byte[StrLen - 1];
                Ole2File.Read(Str, Str.Length);
                Ole2File.SeekForward(Ole2File.Position + 1);     //go over the 0 byte. This is needed for vectors/arrays.
                return(new TUnconvertedString(Str, false));

            case TPropertyTypes.VT_BOOL:
                byte[] bl = new byte[2];
                Ole2File.Read(bl, bl.Length);
                return(BitConverter.ToInt16(bl, 0) == 0? false: true);

            case TPropertyTypes.VT_VARIANT:
                byte[] VariantTypeArray = new byte[4];
                Ole2File.Read(VariantTypeArray, VariantTypeArray.Length);
                Int32 VariantType = BitOps.GetInt32(VariantTypeArray, 0);
                return(GetOneProperty(Ole2File, VariantType));


            case TPropertyTypes.VT_I8:
                byte[] i8 = new byte[8];
                Ole2File.Read(i8, i8.Length);
                return(BitConverter.ToInt64(i8, 0));

            case TPropertyTypes.VT_LPSTR:
                byte[] sl2 = new byte[4];
                Ole2File.Read(sl2, sl2.Length);
                UInt32 StrLen2 = BitConverter.ToUInt32(sl2, 0);
                if (StrLen2 <= 1)
                {
                    return(String.Empty);                   //StrLen includes the trailing #0
                }
                byte[] Str2 = new byte[StrLen2 - 1];
                Ole2File.Read(Str2, Str2.Length);
                Ole2File.SeekForward(Ole2File.Position + 1);     //go over the 0 byte. This is needed for vectors/arrays.
                return(new TUnconvertedString(Str2, false));

            case TPropertyTypes.VT_LPWSTR:
                byte[] sl3 = new byte[4];
                Ole2File.Read(sl3, sl3.Length);
                UInt32 StrLen3 = BitConverter.ToUInt32(sl3, 0);
                if (StrLen3 <= 1)
                {
                    return(String.Empty);                   //StrLen includes the trailing #0
                }
                byte[] Str3 = new byte[(StrLen3 - 1) * 2];
                Ole2File.SeekForward(Ole2File.Position + 2);     //go over the 0 byte. This is needed for vectors/arrays.
                Ole2File.Read(Str3, Str3.Length);
                return(new TUnconvertedString(Str3, true));

            case TPropertyTypes.VT_FILETIME:
                byte[] ft = new byte[8];
                Ole2File.Read(ft, ft.Length);
                return(DateTime.FromFileTime(BitConverter.ToInt64(ft, 0)));

            case TPropertyTypes.VT_BLOB:
                byte[] blb = new byte[4];
                Ole2File.Read(blb, blb.Length);
                UInt32 BlobLen = BitConverter.ToUInt32(blb, 0);
                if (BlobLen <= 0)
                {
                    return(new byte[0]);                   //BlobLen does not includes trailing #0
                }
                byte[] Blob = new byte[BlobLen];
                Ole2File.Read(Blob, Blob.Length);
                return(Blob);
            }

            return(null);  //Not a supported type.
        }
Пример #3
0
 internal override void ReadHeader()
 {
     DataStream.Read(RecordHeader.Data, RecordHeader.Length);
 }