示例#1
0
        //this is only here for testing purposes, this needs to be moved
        public bool BlankPassword(PSTFile pst)
        {
            var toMatch = new byte[] { 0xFF, 0x67 };

            foreach (var entry in this.DataEntries)
            {
                if (entry.Key[0] == toMatch[0] && entry.Key[1] == toMatch[1])
                {
                    pst.CloseMMF();
                    //DatatEncoder.CryptPermute(ref this._data.Parent.Data, this._data.Parent.Data.Length, true);

                    using (var stream = new FileStream(pst.Path, FileMode.Open))
                    {
                        var dataBlockOffset = entry.DataOffset;

                        //this._data.Parent.Data[dataBlockOffset] = 0x00;
                        //this._data.Parent.Data[dataBlockOffset + 1] = 0x00;
                        this._data.Parent.Data[dataBlockOffset + 2] = 0x00;
                        this._data.Parent.Data[dataBlockOffset + 3] = 0x00;
                        this._data.Parent.Data[dataBlockOffset + 4] = 0x00;
                        this._data.Parent.Data[dataBlockOffset + 5] = 0x00;

                        DatatEncoder.CryptPermute(this._data.Parent.Data, this._data.Parent.Data.Length, true, pst);

                        var testCRC = (new CRC32()).ComputeCRC(0, this._data.Parent.Data, (uint)this._data.Parent.Data.Length);
                        stream.Seek((long)(this._data.Parent.PstOffset + entry.DataOffset), SeekOrigin.Begin);

                        stream.Write(
                            new []
                        {
                            //this._data.Parent.Data[dataBlockOffset],
                            //this._data.Parent.Data[dataBlockOffset + 1],
                            this._data.Parent.Data[dataBlockOffset + 2],
                            this._data.Parent.Data[dataBlockOffset + 3],
                            this._data.Parent.Data[dataBlockOffset + 4],
                            this._data.Parent.Data[dataBlockOffset + 5]
                        }, 0, 4);

                        var newCRC = (new CRC32()).ComputeCRC(0, this._data.Parent.Data, (uint)this._data.Parent.Data.Length);

                        DatatEncoder.CryptPermute(this._data.Parent.Data, this._data.Parent.Data.Length, false, pst);
                        var crcoffset = (int)(this._data.Parent.PstOffset + this._data.Parent.CRCOffset);
                        stream.Seek(crcoffset, SeekOrigin.Begin);
                        var temp = BitConverter.GetBytes(newCRC);
                        stream.Write(new []
                        {
                            temp[0], temp[1], temp[2], temp[3]
                        }, 0, 4);
                    }

                    pst.OpenMMF();
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public bool RemovePassword()
        {
            var       messageStore  = new PropertyContext(SpecialNIDs.NID_MESSAGE_STORE, this);
            var       rootDataNode  = messageStore.BTH.Root.Data;
            const int unknown2Bytes = 2;
            var       passwordKey   = new byte[] { 0xFF, 0x67 };

            foreach (var entry in rootDataNode.DataEntries)
            {
                if (entry.Key.SequenceEqual(passwordKey))
                {
                    var dataBlockOffset = (int)entry.DataOffset + (int)rootDataNode.Data.BlockOffset + unknown2Bytes;
                    var slice           = rootDataNode.Data.Parent.Data.Skip(dataBlockOffset).Take(4).ToList();
                    var isProtected     = !slice.SequenceEqual(new byte[] { 0, 0, 0, 0 });
                    if (!isProtected)
                    {
                        return(false);
                    }

                    CloseMMF();

                    using (var stream = new FileStream(Path, FileMode.Open))
                    {
                        rootDataNode.Data.Parent.Data[dataBlockOffset]     = 0x00;
                        rootDataNode.Data.Parent.Data[dataBlockOffset + 1] = 0x00;
                        rootDataNode.Data.Parent.Data[dataBlockOffset + 2] = 0x00;
                        rootDataNode.Data.Parent.Data[dataBlockOffset + 3] = 0x00;

                        DatatEncoder.CryptPermute(rootDataNode.Data.Parent.Data, rootDataNode.Data.Parent.Data.Length, true, Header.EncodingAlgotihm);

                        // seems to always be [65, 65, 65, 65]
                        var permutationBytes = rootDataNode.Data.Parent.Data.Skip(dataBlockOffset).Take(4).ToArray();
                        stream.Seek((long)rootDataNode.Data.Parent.PstOffset + dataBlockOffset, SeekOrigin.Begin);
                        stream.Write(permutationBytes, 0, 4);

                        var newCRC = new CRC32().ComputeCRC(0, rootDataNode.Data.Parent.Data, (uint)rootDataNode.Data.Parent.Data.Length);
                        DatatEncoder.CryptPermute(rootDataNode.Data.Parent.Data, rootDataNode.Data.Parent.Data.Length, false, Header.EncodingAlgotihm);
                        var crcoffset = (long)(rootDataNode.Data.Parent.PstOffset + rootDataNode.Data.Parent.CRCOffset);
                        stream.Seek(crcoffset, SeekOrigin.Begin);
                        var crcBuffer = BitConverter.GetBytes(newCRC);
                        stream.Write(crcBuffer, 0, 4);
                    }
                    OpenMMF();
                    return(true);
                }
            }
            return(false);
        }