Beispiel #1
0
        public ProjectFileReader(Stream stream, OnInputPassword inputPassword = null)
        {
            reader = new BinaryReader(stream, Encoding.GetEncoding("gbk"));
            int magic1 = reader.ReadInt32();
            int magic2 = reader.ReadInt32();

            if (magic1 == 0x454C5457) //WTLE
            {
                if (magic2 != 0x00020001)
                {
                    throw new Exception("不支持此类加密文件");
                }
                string tip      = reader.ReadStringWithLengthPrefix();
                string password = inputPassword?.Invoke(tip);
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("没有输入密码 或 未正确响应InputPassword事件");
                }
                var cryptECReadStream = new CryptECReadStream(stream, password, stream.Position);
                reader = new BinaryReader(cryptECReadStream, Encoding.GetEncoding("gbk"));
                if (!reader.ReadBytes(32).SequenceEqual(cryptECReadStream.PasswordHash_ASCII))
                {
                    throw new Exception("密码错误");
                }
                cryptEc = true;

                magic1 = reader.ReadInt32();
                magic2 = reader.ReadInt32();
            }
            if (magic1 != 0x54574E43 || magic2 != 0x47525045) //CNWTEPRG
            {
                throw new Exception("不是易语言工程文件");
            }
        }
        public ProjectFileReader(Stream stream, OnInputPassword inputPassword = null)
        {
            reader = new BinaryReader(stream, Encoding.GetEncoding("gbk"));
            int magic1 = reader.ReadInt32();
            int magic2 = reader.ReadInt32();

            if (magic1 == 0x454C5457) // WTLE
            {
                if (magic2 != 0x00020001)
                {
                    throw new Exception("不支持此类加密文件");
                }
                int    tip_bytes = reader.ReadInt32();
                string tip       = reader.ReadStringWithFixedLength(Encoding.GetEncoding("gbk"), tip_bytes);
                string password  = inputPassword?.Invoke(tip);
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("没有输入密码 或 未正确响应InputPassword事件");
                }
                int lengthOfRead      = 4 /* [int]magic1 */ + 4 /* [int]magic2 */ + 4 /* [int]tip_bytes */ + tip_bytes;
                var cryptECReadStream = new CryptECReadStream(stream, password, lengthOfRead, lengthOfRead);
                reader = new BinaryReader(cryptECReadStream);

                if (!reader.ReadBytes(32).SequenceEqual(cryptECReadStream.PasswordHash))
                {
                    throw new Exception("密码错误");
                }
                CryptEc = true;

                magic1 = reader.ReadInt32();
                magic2 = reader.ReadInt32();
            }
            if (magic1 != 0x54574E43 || magic2 != 0x47525045) // CNWTEPRG
            {
                throw new Exception("不是易语言工程文件");
            }
        }