示例#1
0
        private static IList <byte[]> DecryptMsg(IStorageWrapper iw, string path, byte[] pass)
        {
            List <byte[]> msgList = new List <byte[]>();

            int num = 0;

            int[] pos = null;
            int[] len = null;
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Index.msj"))
            {
                if (fileObject == null)
                {
                    return(msgList);
                }
                int fileLen = (int)fileObject.Length;
                num = fileLen / 4;
                pos = new int[num + 1];
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    for (int i = 0; i < num; ++i)
                    {
                        pos[i] = br.ReadInt32();
                    }
                }
            }
            using (IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, path, "Data.msj"))
            {
                if (fileObject != null)
                {
                    int fileLen = (int)fileObject.Length;
                    len      = new int[num];
                    pos[num] = fileLen;
                    for (int i = 0; i < num; ++i)
                    {
                        len[i] = pos[i + 1] - pos[i];
                    }
                    using (BinaryReader br = new BinaryReader(fileObject))
                    {
                        for (int i = 0; i < num; ++i)
                        {
                            fileObject.Seek(pos[i], SeekOrigin.Begin);
                            byte[] data = br.ReadBytes(len[i]);
                            byte[] msg  = Decrypt(data, pass, 0);
                            msgList.Add(msg);
                        }
                    }
                }
            }
            return(msgList);
        }
示例#2
0
        private static byte[] GetGlobalPass(IStorageWrapper iw, string QQID)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] dataID = new byte[QQID.Length];
            for (int i = 0; i < QQID.Length; ++i)
            {
                dataID[i] = (byte)(QQID[i]);
            }
            byte[] hashID = md5.ComputeHash(dataID);
            IBaseStorageWrapper.FileObjects.FileObject fileObject = GetStorageFileObject(iw, "Matrix", "Matrix.db");
            if (fileObject != null)
            {
                using (BinaryReader br = new BinaryReader(fileObject))
                {
                    byte[] data = br.ReadBytes((int)fileObject.Length);
                    long   len  = data.Length;
                    if (len < 6 || data[0] != 0x51 || data[1] != 0x44)
                    {
                        return(null);
                    }
                    if (len >= 32768)
                    {
                        return(null);
                    }

                    bool bl = false;
                    int  i  = 6;
                    while (i < len)
                    {
                        bl = false;
                        byte type = data[i++];
                        if (i + 2 > len)
                        {
                            break;
                        }
                        int  len1 = data[i] + data[i + 1] * 256;
                        byte xor1 = (byte)(data[i] ^ data[i + 1]);
                        i += 2;
                        if (i + len1 > len)
                        {
                            break;
                        }
                        for (int j = 0; j < len1; ++j)
                        {
                            data[i + j] = (byte)(~(data[i + j] ^ xor1));
                        }
                        if (len1 == 3 && data[i] == 0x43 && data[i + 1] == 0x52 && data[i + 2] == 0x4B)
                        {
                            bl = true;
                        }
                        i += len1;

                        if (type > 7)
                        {
                            break;
                        }
                        if (i + 4 > len)
                        {
                            break;
                        }
                        int  len2 = data[i] + data[i + 1] * 256 + data[i + 2] * 256 * 256 + data[i + 3] * 256 * 256 * 256;
                        byte xor2 = (byte)(data[i] ^ data[i + 1]);
                        i += 4;
                        if (i + len2 > len)
                        {
                            break;
                        }
                        if (type == 6 || type == 7)
                        {
                            for (int j = 0; j < len2; ++j)
                            {
                                data[i + j] = (byte)(~(data[i + j] ^ xor2));
                            }
                        }
                        if (bl && len2 == 0x20)
                        {
                            byte[] dataT = new byte[len2];
                            for (int j = 0; j < len2; ++j)
                            {
                                dataT[j] = data[i + j];
                            }
                            return(Decrypt(dataT, hashID, 0));
                        }
                        i += len2;
                    }
                    if (i != len)
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }