update test sample

pull/470/head
何冠峰 2025-02-12 16:27:51 +08:00
parent 7936ba31ea
commit a9a9368b9b
1 changed files with 62 additions and 58 deletions

View File

@ -4,6 +4,7 @@ using System.Text;
using UnityEngine;
using YooAsset;
#region 文件流
/// <summary>
/// 资源文件解密流
/// </summary>
@ -29,6 +30,35 @@ public class BundleStream : FileStream
}
}
/// <summary>
/// 文件流加密方式
/// </summary>
public class FileStreamEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{
if (fileInfo.BundleName.Contains("_gameres_audio"))
{
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
for (int i = 0; i < fileData.Length; i++)
{
fileData[i] ^= BundleStream.KEY;
}
EncryptResult result = new EncryptResult();
result.Encrypted = true;
result.EncryptedData = fileData;
return result;
}
else
{
EncryptResult result = new EncryptResult();
result.Encrypted = false;
return result;
}
}
}
/// <summary>
/// 资源文件流加载解密类
/// </summary>
@ -81,6 +111,37 @@ public class FileStreamDecryption : IDecryptionServices
return 1024;
}
}
#endregion
#region 文件偏移
/// <summary>
/// 文件偏移加密方式
/// </summary>
public class FileOffsetEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{
// 注意:只对音频资源包加密
if (fileInfo.BundleName.Contains("_gameres_audio"))
{
int offset = 32;
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
var encryptedData = new byte[fileData.Length + offset];
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
EncryptResult result = new EncryptResult();
result.Encrypted = true;
result.EncryptedData = encryptedData;
return result;
}
else
{
EncryptResult result = new EncryptResult();
result.Encrypted = false;
return result;
}
}
}
/// <summary>
/// 资源文件偏移加载解密类
@ -132,61 +193,4 @@ public class FileOffsetDecryption : IDecryptionServices
return 32;
}
}
/// <summary>
/// 文件偏移加密方式
/// </summary>
public class FileOffsetEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{
// 注意:只对音频资源包加密
if (fileInfo.BundleName.Contains("_gameres_audio"))
{
int offset = 32;
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
var encryptedData = new byte[fileData.Length + offset];
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
EncryptResult result = new EncryptResult();
result.Encrypted = true;
result.EncryptedData = encryptedData;
return result;
}
else
{
EncryptResult result = new EncryptResult();
result.Encrypted = false;
return result;
}
}
}
/// <summary>
/// 文件流加密方式
/// </summary>
public class FileStreamEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{
if (fileInfo.BundleName.Contains("_gameres_audio"))
{
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
for (int i = 0; i < fileData.Length; i++)
{
fileData[i] ^= BundleStream.KEY;
}
EncryptResult result = new EncryptResult();
result.Encrypted = true;
result.EncryptedData = fileData;
return result;
}
else
{
EncryptResult result = new EncryptResult();
result.Encrypted = false;
return result;
}
}
}
#endregion