Skip to content

Commit

Permalink
updated to v2.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed May 17, 2024
1 parent 7e947ba commit cc7eb56
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class CryptogramSetting : ScriptableObject
public byte tXorKey = 1;
public byte jXorKey = 1;

[Separator("HT2XORPlus")]
public byte hXorPlusKey = 1;
public byte tXorPlusKey = 1;
public byte j1XorPlusKey = 1;
public byte j2XorPlusKey = 1;

[Separator("AES")]
public string aesKey = "aes_key";
public string aesIv = "aes_iv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
using UnityEditor;
using UnityEngine;
using YooAsset.Editor;
using static OxGFrame.AssetLoader.Editor.CryptogramSettingWindow;

namespace OxGFrame.AssetLoader.Editor
{
public class BundleCryptogramUtilityWindow : EditorWindow
{
public enum CryptogramType
{
Offset,
Xor,
HT2Xor,
Aes
}

private static BundleCryptogramUtilityWindow _instance = null;
internal static BundleCryptogramUtilityWindow GetInstance()
{
Expand Down Expand Up @@ -60,12 +53,25 @@ private void OnEnable()

private void _LoadSettingsData()
{
// Offset
this.randomSeed = this._setting.randomSeed;
this.dummySize = this._setting.dummySize;

// XOR
this.xorKey = this._setting.xorKey;

// HT2XOR
this.hXorKey = this._setting.hXorKey;
this.tXorKey = this._setting.tXorKey;
this.jXorKey = this._setting.jXorKey;

// HT2XORPlus
this.hXorPlusKey = this._setting.hXorPlusKey;
this.tXorPlusKey = this._setting.tXorPlusKey;
this.j1XorPlusKey = this._setting.j1XorPlusKey;
this.j2XorPlusKey = this._setting.j2XorPlusKey;

// AES
this.aesKey = this._setting.aesKey;
this.aesIv = this._setting.aesIv;
}
Expand Down Expand Up @@ -118,12 +124,16 @@ private void _CryptogramType(CryptogramType cryptogramType)
case CryptogramType.HT2Xor:
this._DrawHT2XorView();
break;
case CryptogramType.HT2XorPlus:
this._DrawHT2XorPlusView();
break;
case CryptogramType.Aes:
this._DrawAesView();
break;
}
}

#region Offset
[SerializeField]
public int randomSeed = 1;
[SerializeField]
Expand Down Expand Up @@ -155,7 +165,9 @@ private void _DrawOffsetView()

EditorGUILayout.EndVertical();
}
#endregion

#region Xor
[SerializeField]
public int xorKey = 0;
private void _DrawXorView()
Expand Down Expand Up @@ -183,7 +195,9 @@ private void _DrawXorView()

EditorGUILayout.EndVertical();
}
#endregion

#region HT2Xor
[SerializeField]
public int hXorKey = 0;
[SerializeField]
Expand Down Expand Up @@ -221,7 +235,55 @@ private void _DrawHT2XorView()

EditorGUILayout.EndVertical();
}
#endregion

#region HT2XorPlus
[SerializeField]
public int hXorPlusKey = 0;
[SerializeField]
public int tXorPlusKey = 0;
[SerializeField]
public int j1XorPlusKey = 0;
[SerializeField]
public int j2XorPlusKey = 0;
private void _DrawHT2XorPlusView()
{
EditorGUILayout.Space();

GUIStyle style = new GUIStyle();
var bg = new Texture2D(1, 1);
ColorUtility.TryParseHtmlString("#1e3836", out Color color);
Color[] pixels = Enumerable.Repeat(color, Screen.width * Screen.height).ToArray();
bg.SetPixels(pixels);
bg.Apply();
style.normal.background = bg;
EditorGUILayout.BeginVertical(style);
var centeredStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
centeredStyle.alignment = TextAnchor.UpperCenter;
GUILayout.Label(new GUIContent("Head-Tail 2 XOR Plus Settings"), centeredStyle);
EditorGUILayout.Space();

EditorGUIUtility.labelWidth = 200;
this.hXorPlusKey = EditorGUILayout.IntField("Head XOR Plus KEY (0 ~ 255)", this.hXorPlusKey);
if (this.hXorPlusKey < 0) this.hXorPlusKey = 0;
else if (this.hXorPlusKey > 255) this.hXorPlusKey = 255;
this.tXorPlusKey = EditorGUILayout.IntField("Tail XOR Plus KEY (0 ~ 255)", this.tXorPlusKey);
if (this.tXorPlusKey < 0) this.tXorPlusKey = 0;
else if (this.tXorPlusKey > 255) this.tXorPlusKey = 255;
this.j1XorPlusKey = EditorGUILayout.IntField("Jump 1 XOR Plus KEY (0 ~ 255)", this.j1XorPlusKey);
if (this.j1XorPlusKey < 0) this.j1XorPlusKey = 0;
else if (this.j1XorPlusKey > 255) this.j1XorPlusKey = 255;
this.j2XorPlusKey = EditorGUILayout.IntField("Jump 2 XOR Plus KEY (0 ~ 255)", this.j2XorPlusKey);
if (this.j2XorPlusKey < 0) this.j2XorPlusKey = 0;
else if (this.j2XorPlusKey > 255) this.j2XorPlusKey = 255;

this._DrawOperateButtonsView(this.cryptogramType);

EditorGUILayout.EndVertical();
}
#endregion

#region AES
[SerializeField]
public string aesKey = "file_key";
[SerializeField]
Expand Down Expand Up @@ -250,6 +312,7 @@ private void _DrawAesView()

EditorGUILayout.EndVertical();
}
#endregion

private void _DrawOperateButtonsView(CryptogramType cryptogramType)
{
Expand All @@ -273,6 +336,10 @@ private void _DrawOperateButtonsView(CryptogramType cryptogramType)
CryptogramUtility.HT2XorDecryptBundleFiles(this.sourceFolder, (byte)this.hXorKey, (byte)this.tXorKey, (byte)this.jXorKey);
EditorUtility.DisplayDialog("Crytogram Message", "[Head-Tail 2 XOR] Decrypt Process.", "OK");
break;
case CryptogramType.HT2XorPlus:
CryptogramUtility.HT2XorPlusDecryptBundleFiles(this.sourceFolder, (byte)this.hXorPlusKey, (byte)this.tXorPlusKey, (byte)this.j1XorPlusKey, (byte)this.j2XorPlusKey);
EditorUtility.DisplayDialog("Crytogram Message", "[Head-Tail 2 XOR Plus] Decrypt Process.", "OK");
break;
case CryptogramType.Aes:
if (string.IsNullOrEmpty(this.aesKey) || string.IsNullOrEmpty(this.aesIv))
{
Expand Down Expand Up @@ -304,6 +371,10 @@ private void _DrawOperateButtonsView(CryptogramType cryptogramType)
CryptogramUtility.HT2XorEncryptBundleFiles(this.sourceFolder, (byte)this.hXorKey, (byte)this.tXorKey, (byte)this.jXorKey);
EditorUtility.DisplayDialog("Crytogram Message", "[Head-Tail 2 XOR] Encrypt Process.", "OK");
break;
case CryptogramType.HT2XorPlus:
CryptogramUtility.HT2XorPlusEncryptBundleFiles(this.sourceFolder, (byte)this.hXorPlusKey, (byte)this.tXorPlusKey, (byte)this.j1XorPlusKey, (byte)this.j2XorPlusKey);
EditorUtility.DisplayDialog("Crytogram Message", "[Head-Tail 2 XOR Plus] Encrypt Process.", "OK");
break;
case CryptogramType.Aes:
if (string.IsNullOrEmpty(this.aesKey) || string.IsNullOrEmpty(this.aesIv))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum CryptogramType
Offset,
Xor,
HT2Xor,
HT2XorPlus,
Aes
}

Expand Down Expand Up @@ -74,12 +75,25 @@ private void OnGUI()

private void _LoadSettingsData()
{
// Offset
this.randomSeed = this._setting.randomSeed;
this.dummySize = this._setting.dummySize;

// XOR
this.xorKey = this._setting.xorKey;

// HT2XOR
this.hXorKey = this._setting.hXorKey;
this.tXorKey = this._setting.tXorKey;
this.jXorKey = this._setting.jXorKey;

// HT2XORPlus
this.hXorPlusKey = this._setting.hXorPlusKey;
this.tXorPlusKey = this._setting.tXorPlusKey;
this.j1XorPlusKey = this._setting.j1XorPlusKey;
this.j2XorPlusKey = this._setting.j2XorPlusKey;

// AES
this.aesKey = this._setting.aesKey;
this.aesIv = this._setting.aesIv;
}
Expand All @@ -97,12 +111,16 @@ private void _CryptogramType(CryptogramType cryptogramType)
case CryptogramType.HT2Xor:
this._DrawHT2XorView();
break;
case CryptogramType.HT2XorPlus:
this._DrawHT2XorPlusView();
break;
case CryptogramType.Aes:
this._DrawAesView();
break;
}
}

#region Offset
[SerializeField]
public int randomSeed = 1;
[SerializeField]
Expand Down Expand Up @@ -135,7 +153,9 @@ private void _DrawOffsetView()

EditorGUILayout.EndVertical();
}
#endregion

#region Xor
[SerializeField]
public int xorKey = 0;
private void _DrawXorView()
Expand Down Expand Up @@ -165,7 +185,9 @@ private void _DrawXorView()

EditorGUILayout.EndVertical();
}
#endregion

#region HT2Xor
[SerializeField]
public int hXorKey = 0;
[SerializeField]
Expand Down Expand Up @@ -205,7 +227,57 @@ private void _DrawHT2XorView()

EditorGUILayout.EndVertical();
}
#endregion

#region HT2Xor Plus
[SerializeField]
public int hXorPlusKey = 0;
[SerializeField]
public int tXorPlusKey = 0;
[SerializeField]
public int j1XorPlusKey = 0;
[SerializeField]
public int j2XorPlusKey = 0;
private void _DrawHT2XorPlusView()
{
EditorGUILayout.Space();

GUIStyle style = new GUIStyle();
var bg = new Texture2D(1, 1);
ColorUtility.TryParseHtmlString("#1e3836", out Color color);
Color[] pixels = Enumerable.Repeat(color, Screen.width * Screen.height).ToArray();
bg.SetPixels(pixels);
bg.Apply();
style.normal.background = bg;
EditorGUILayout.BeginVertical(style);
var centeredStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
centeredStyle.alignment = TextAnchor.UpperCenter;
GUILayout.Label(new GUIContent("Head-Tail 2 XOR Plus Settings"), centeredStyle);
EditorGUILayout.Space();

EditorGUI.BeginChangeCheck();
EditorGUIUtility.labelWidth = 200;
this.hXorPlusKey = EditorGUILayout.IntField("Head XOR Plus KEY (0 ~ 255)", this.hXorPlusKey);
if (this.hXorPlusKey < 0) this.hXorPlusKey = 0;
else if (this.hXorPlusKey > 255) this.hXorPlusKey = 255;
this.tXorPlusKey = EditorGUILayout.IntField("Tail XOR Plus KEY (0 ~ 255)", this.tXorPlusKey);
if (this.tXorPlusKey < 0) this.tXorPlusKey = 0;
else if (this.tXorPlusKey > 255) this.tXorPlusKey = 255;
this.j1XorPlusKey = EditorGUILayout.IntField("Jump 1 XOR Plus KEY (0 ~ 255)", this.j1XorPlusKey);
if (this.j1XorPlusKey < 0) this.j1XorPlusKey = 0;
else if (this.j1XorPlusKey > 255) this.j1XorPlusKey = 255;
this.j2XorPlusKey = EditorGUILayout.IntField("Jump 2 XOR Plus KEY (0 ~ 255)", this.j2XorPlusKey);
if (this.j2XorPlusKey < 0) this.j2XorPlusKey = 0;
else if (this.j2XorPlusKey > 255) this.j2XorPlusKey = 255;
if (EditorGUI.EndChangeCheck()) this._isDirty = true;

this._DrawOperateButtonsView(this.cryptogramType);

EditorGUILayout.EndVertical();
}
#endregion

#region AES
[SerializeField]
public string aesKey = "aes_key";
[SerializeField]
Expand Down Expand Up @@ -236,6 +308,7 @@ private void _DrawAesView()

EditorGUILayout.EndVertical();
}
#endregion

private void _DrawOperateButtonsView(CryptogramType cryptogramType)
{
Expand Down Expand Up @@ -288,6 +361,18 @@ private void _SaveData(CryptogramType cryptogramType, bool isShowDialog = false)

if (isShowDialog) EditorUtility.DisplayDialog("Crytogram Message", "Saved [Head-Tail 2 XOR] Setting.", "OK");
break;
case CryptogramType.HT2XorPlus:
this._setting.hXorPlusKey = (byte)this.hXorPlusKey;
this._setting.tXorPlusKey = (byte)this.tXorPlusKey;
this._setting.j1XorPlusKey = (byte)this.j1XorPlusKey;
this._setting.j2XorPlusKey = (byte)this.j2XorPlusKey;

this._isDirty = false;
EditorUtility.SetDirty(this._setting);
AssetDatabase.SaveAssets();

if (isShowDialog) EditorUtility.DisplayDialog("Crytogram Message", "Saved [Head-Tail 2 XOR Plus] Setting.", "OK");
break;
case CryptogramType.Aes:
if (string.IsNullOrEmpty(this.aesKey) || string.IsNullOrEmpty(this.aesIv))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
}
}

public class HT2XorPlusEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();

string filePath = fileInfo.FilePath;

byte hXorKey = cryptogramSettings.hXorPlusKey;
byte tXorKey = cryptogramSettings.tXorPlusKey;
byte j1XorKey = cryptogramSettings.j1XorPlusKey;
byte j2XorKey = cryptogramSettings.j2XorPlusKey;

byte[] fileData = File.ReadAllBytes(filePath);

if (FileCryptogram.HT2XORPlus.HT2XorPlusEncryptBytes(fileData, hXorKey, tXorKey, j1XorKey, j2XorKey))
{
Debug.Log($"HT2XorPlusCryptogram => hXorKey: {hXorKey}, tXorKey: {tXorKey}, j1XorKey: {j1XorKey}, j2XorKey: {j2XorKey}");

EncryptResult result = new EncryptResult();
result.Encrypted = true;
result.EncryptedData = fileData;
return result;
}
else
{
EncryptResult result = new EncryptResult();
result.Encrypted = false;
return result;
}
}
}

public class AesEncryption : IEncryptionServices
{
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class CryptogramType
public const string OFFSET = "OFFSET";
public const string XOR = "XOR";
public const string HT2XOR = "HT2XOR";
public const string HT2XORPLUS = "HT2XORPLUS";
public const string AES = "AES";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OxGFrame.AssetLoader.Bundle
[Serializable]
public class DecryptInfo : IDisposable
{
[SerializeField, Tooltip("Bundle decryption (case-insensitive).\n\n[NONE], \n[OFFSET, dummySize], \n[XOR, key], \n[HT2XOR, headKey, tailKey, jumpKey], \n[AES, key, iv]\n\nex: \n\"none\" \n\"offset, 12\" \n\"xor, 23\" \n\"ht2xor, 34, 45, 56\" \n\"aes, key, iv\"")]
[SerializeField, Tooltip("Bundle decryption (case-insensitive).\n\n[NONE], \n[OFFSET, dummySize], \n[XOR, key], \n[HT2XOR, headKey, tailKey, jumpKey], \n[HT2XORPLUS, headKey, tailKey, jump1Key, jump2Key], \n[AES, key, iv]\n\nex: \n\"none\" \n\"offset, 12\" \n\"xor, 23\" \n\"ht2xor, 34, 45, 56\" \n\"ht2xorplus, 34, 45, 56, 78\" \n\"aes, key, iv\"")]
private string _decryptArgs = BundleConfig.CryptogramType.NONE;
[SerializeField, Tooltip("Can encrypt string data in memory.")]
public bool secureString = true;
Expand Down
Loading

0 comments on commit cc7eb56

Please sign in to comment.