Exemplo n.º 1
0
        private void AppendProperty(OofHistory.PropId propId, byte[] propertyValue)
        {
            this.data[this.dataPosition++] = (byte)propId;
            ushort num = (ushort)propertyValue.Length;

            ExBitConverter.Write(num, this.data, this.dataPosition);
            this.dataPosition += 2;
            Buffer.BlockCopy(propertyValue, 0, this.data, this.dataPosition, (int)num);
            this.dataPosition += (int)num;
        }
Exemplo n.º 2
0
 private static bool MatchProperty(byte[] buffer, byte currentPropId, OofHistory.PropId propId, ushort currentPropertySize, byte[] propValue, ref int index)
 {
     if (currentPropId == (byte)propId && (int)currentPropertySize == propValue.Length)
     {
         for (ushort num = 0; num < currentPropertySize; num += 1)
         {
             if (propValue[(int)num] != buffer[index++])
             {
                 index += (int)(currentPropertySize - num - 1);
                 return(false);
             }
         }
         return(true);
     }
     index += (int)currentPropertySize;
     return(false);
 }
Exemplo n.º 3
0
        internal static void RemoveOofHistoryEntriesWithProperty(MailboxSession itemStore, bool oofEnabled, OofHistory.PropId propId, byte[] propValue)
        {
            MapiFolder mapiFolder  = null;
            MapiFolder mapiFolder2 = null;
            MapiStream mapiStream  = null;
            bool       flag        = false;

            byte[] initialBytes = oofEnabled ? OofHistory.InitialBytesOofStateOn : OofHistory.InitialBytesOofStateOff;
            try
            {
                if (OofHistory.TryOpenFolder(itemStore, out mapiFolder, out mapiFolder2))
                {
                    long hashCode = (long)itemStore.GetHashCode();
                    bool flag2;
                    mapiStream = OofHistory.OpenAndLockStream(mapiFolder2, initialBytes, hashCode, out flag2);
                    flag       = true;
                    if (!flag2)
                    {
                        int num;
                        if (OofHistory.TryGetStreamLengthForEntryRemoval(hashCode, mapiStream, out num))
                        {
                            byte[] buffer;
                            if (OofHistory.TryReadAllFromStream(hashCode, mapiStream, num, out buffer))
                            {
                                int num2 = OofHistory.RemoveEntriesWithProperty(num, buffer, propId, propValue, hashCode);
                                if (num2 < num)
                                {
                                    mapiStream.Seek(0L, SeekOrigin.Begin);
                                    mapiStream.Write(buffer, 0, num2);
                                    mapiStream.SetLength((long)num2);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mapiStream != null)
                {
                    try
                    {
                        if (flag)
                        {
                            mapiStream.UnlockRegion(0L, 1L, 1);
                        }
                    }
                    finally
                    {
                        mapiStream.Dispose();
                    }
                }
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                    mapiFolder = null;
                }
                if (mapiFolder2 != null)
                {
                    mapiFolder2.Dispose();
                    mapiFolder2 = null;
                }
            }
        }
Exemplo n.º 4
0
        private static bool MatchAnyPropertiesInEntry(byte[] buffer, OofHistory.PropId propId, byte[] propValue, byte propertyCount, int historyLength, uint currentEntry, long hashCode, ref int index, out bool isCorrupt)
        {
            isCorrupt = false;
            bool flag = false;

            for (byte b = 0; b < propertyCount; b += 1)
            {
                if (index >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property id of property ",
                        b,
                        " entry ",
                        currentEntry
                    }));
                    isCorrupt = true;
                    return(false);
                }
                byte b2 = buffer[index++];
                if (index + 2 >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property size of property ",
                        b,
                        " entry ",
                        currentEntry,
                        " property id ",
                        b2,
                        " index ",
                        index
                    }));
                    isCorrupt = true;
                    return(false);
                }
                ushort num = BitConverter.ToUInt16(buffer, index);
                index += 2;
                if (index + (int)num > historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property content of property ",
                        b,
                        " entry ",
                        currentEntry,
                        " property id ",
                        b2,
                        " property size ",
                        num,
                        " index ",
                        index
                    }));
                    isCorrupt = true;
                    return(false);
                }
                if (flag)
                {
                    index += (int)num;
                }
                else if (OofHistory.MatchProperty(buffer, b2, propId, num, propValue, ref index))
                {
                    flag = true;
                }
            }
            return(flag);
        }
Exemplo n.º 5
0
        private static int RemoveEntriesWithProperty(int historyLength, byte[] buffer, OofHistory.PropId propId, byte[] propValue, long hashCode)
        {
            int  num = 6;
            int  currentEntryStart = 6;
            int  result            = 6;
            uint num2 = BitConverter.ToUInt32(buffer, 2);

            if (10000U < num2)
            {
                num2 = 10000U;
            }
            uint num3 = num2;

            for (uint num4 = 0U; num4 < num2; num4 += 1U)
            {
                if (num >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, "Unable to get property count of entry " + num4);
                    return(result);
                }
                byte propertyCount = buffer[num++];
                bool flag;
                if (OofHistory.MatchAnyPropertiesInEntry(buffer, propId, propValue, propertyCount, historyLength, num4, hashCode, ref num, out flag))
                {
                    num3 -= 1U;
                }
                else
                {
                    if (flag)
                    {
                        return(result);
                    }
                    OofHistory.HandleNonMatchingProperty(buffer, num, currentEntryStart, ref result);
                }
                currentEntryStart = num;
            }
            if (num3 < num2)
            {
                ExBitConverter.Write(num3, buffer, 2);
            }
            return(result);
        }
Exemplo n.º 6
0
        public void ReadEntry()
        {
            this.ThrowIfNotInitialized();
            if (!this.HasMoreEntries)
            {
                throw new InvalidOperationException("There are no more entries to read.");
            }
            if (this.currentEntryAddressBytes == null)
            {
                this.currentEntryAddressBytes = new VirtualList <byte>(true);
            }
            if (this.currentEntryRuleIdBytes == null)
            {
                this.currentEntryRuleIdBytes = new VirtualList <byte>(true);
            }
            if (!this.EnsureDataSufficiency(1))
            {
                throw new OofHistoryCorruptionException(string.Concat(new object[]
                {
                    "Insufficient data in stream to read property count for entry ",
                    this.entriesRead,
                    " at buffer position ",
                    this.dataPosition
                }));
            }
            byte b = this.data[this.dataPosition++];

            for (byte b2 = 0; b2 < b; b2 += 1)
            {
                if (!this.EnsureDataSufficiency(3))
                {
                    throw new OofHistoryCorruptionException(string.Concat(new object[]
                    {
                        "Insufficient data in stream to read property id and size. Current entry ",
                        this.entriesRead,
                        ", current property: ",
                        b2,
                        ", total entries: ",
                        this.entryCount
                    }));
                }
                OofHistory.PropId propId = (OofHistory.PropId) this.data[this.dataPosition];
                ushort            num    = BitConverter.ToUInt16(this.data, this.dataPosition + 1);
                if (num > 1000)
                {
                    throw new OofHistoryCorruptionException(string.Concat(new object[]
                    {
                        "Current entry: ",
                        this.entriesRead,
                        "Property with id ",
                        propId,
                        " has property size: ",
                        num,
                        ", which is over the maximum allowed size of ",
                        1000
                    }));
                }
                this.dataPosition += 3;
                if (!this.EnsureDataSufficiency((int)num))
                {
                    throw new OofHistoryCorruptionException(string.Concat(new object[]
                    {
                        "Insufficient data in stream to match property values.  Current entry: ",
                        this.entriesRead,
                        ", property with id ",
                        this.data[this.dataPosition],
                        " has property size: ",
                        num
                    }));
                }
                switch (propId)
                {
                case OofHistory.PropId.SenderAddress:
                    this.currentEntryAddressBytes.SetRange(this.data, this.dataPosition, (int)num);
                    break;

                case OofHistory.PropId.GlobalRuleId:
                    this.currentEntryRuleIdBytes.SetRange(this.data, this.dataPosition, (int)num);
                    break;
                }
                this.dataPosition += (int)num;
            }
            this.entriesRead++;
        }