private void TryDetectLuaEnc(byte[] luaBinary) { Wz_Crypto crypto = this.WzFile.WzStructure.encryption; byte[] tempBuffer = new byte[Math.Min(luaBinary.Length, 64)]; char[] tempStr = new char[tempBuffer.Length]; //测试各种加密方式 判断符合度最高的 int maxCharCount = 0; var maxCharEnc = Wz_Crypto.Wz_CryptoKeyType.Unknown; foreach (var enc in new[] { Wz_Crypto.Wz_CryptoKeyType.GMS, Wz_Crypto.Wz_CryptoKeyType.KMS, Wz_Crypto.Wz_CryptoKeyType.BMS }) { Buffer.BlockCopy(luaBinary, 0, tempBuffer, 0, tempBuffer.Length); crypto.EncType = enc; crypto.keys.Decrypt(tempBuffer, 0, tempBuffer.Length); int count = Encoding.UTF8.GetChars(tempBuffer, 0, tempBuffer.Length, tempStr, 0); int asciiCount = tempStr.Take(count).Count(chr => 32 <= chr && chr <= 127); if (maxCharCount < asciiCount) { maxCharEnc = enc; maxCharCount = asciiCount; } } crypto.EncType = maxCharEnc; this.checEnc = true; }
private void TryDetectEnc() { Wz_Crypto crypto = this.WzFile.WzStructure.encryption; if (crypto.EncType != Wz_Crypto.Wz_CryptoKeyType.Unknown) { if (IsIllegalTag()) { this.checEnc = true; return; } } crypto.EncType = Wz_Crypto.Wz_CryptoKeyType.KMS; if (IsIllegalTag()) { this.checEnc = true; return; } crypto.EncType = Wz_Crypto.Wz_CryptoKeyType.GMS; if (IsIllegalTag()) { this.checEnc = true; return; } crypto.EncType = Wz_Crypto.Wz_CryptoKeyType.BMS; if (IsIllegalTag()) { this.checEnc = true; return; } crypto.EncType = Wz_Crypto.Wz_CryptoKeyType.Unknown; }