public ProjectFileReader(string filename, string password) { var stream = File.OpenRead(filename); reader = new BinaryReader(stream, Encoding.GetEncoding("gbk")); int num = reader.ReadInt32(); int num2 = reader.ReadInt32(); if (num == 1162630231) { if (num2 != 131073) { throw new Exception("不支持此类加密文件"); } string arg = reader.ReadStringWithLengthPrefix(); CryptECReadStream 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; num = reader.ReadInt32(); num2 = reader.ReadInt32(); } if (num == 1415007811 && num2 == 1196576837) { return; } 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("不支持此类加密文件"); } 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("不是易语言工程文件"); } }