forked from michael811125/OxGFrame
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a6e951
commit 4130a1c
Showing
18 changed files
with
461 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ MonoBehaviour: | |
xorKey: 1 | ||
hXorKey: 1 | ||
tXorKey: 1 | ||
jXorKey: 1 | ||
aesKey: aes_key | ||
aesIv: aes_iv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
329 changes: 329 additions & 0 deletions
329
.../OxGFrame/AssetLoader/Scripts/Editor/Bundle/EditorWindow/BundleCryptogramUtilityWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,329 @@ | ||
using OxGFrame.AssetLoader.Utility; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using YooAsset.Editor; | ||
|
||
namespace OxGFrame.AssetLoader.Editor | ||
{ | ||
public class BundleCryptogramUtilityWindow : EditorWindow | ||
{ | ||
public enum CryptogramType | ||
{ | ||
OFFSET, | ||
XOR, | ||
HT2XOR, | ||
AES | ||
} | ||
|
||
private static BundleCryptogramUtilityWindow _instance = null; | ||
internal static BundleCryptogramUtilityWindow GetInstance() | ||
{ | ||
if (_instance == null) _instance = GetWindow<BundleCryptogramUtilityWindow>(); | ||
return _instance; | ||
} | ||
|
||
[SerializeField] | ||
public CryptogramType cryptogramType; | ||
|
||
[SerializeField] | ||
public string sourceFolder; | ||
|
||
private CryptogramSetting _settings; | ||
|
||
internal static string PROJECT_PATH; | ||
internal static string KEY_SAVER; | ||
|
||
private static Vector2 _windowSize = new Vector2(800f, 150f); | ||
|
||
[MenuItem(BundleHelper.MenuRoot + "Bundle Cryptogram Utility (For Verify)", false, 699)] | ||
public static void ShowWindow() | ||
{ | ||
PROJECT_PATH = Application.dataPath; | ||
KEY_SAVER = $"{PROJECT_PATH}_{nameof(BundleCryptogramUtilityWindow)}"; | ||
|
||
_instance = null; | ||
GetInstance().titleContent = new GUIContent("Bundle Cryptogram Utility"); | ||
GetInstance().Show(); | ||
GetInstance().minSize = _windowSize; | ||
} | ||
|
||
private void OnEnable() | ||
{ | ||
this._settings = EditorTool.LoadSettingData<CryptogramSetting>(); | ||
this._LoadSettingsData(); | ||
this.sourceFolder = EditorStorage.GetData(KEY_SAVER, $"sourceFolder", Path.Combine($"{Application.dataPath}/", AssetBundleBuilderHelper.GetDefaultBuildOutputRoot())); | ||
this.cryptogramType = (CryptogramType)Convert.ToInt32(EditorStorage.GetData(KEY_SAVER, "cryptogramType", "0")); | ||
} | ||
|
||
private void _LoadSettingsData() | ||
{ | ||
this.randomSeed = this._settings.randomSeed; | ||
this.dummySize = this._settings.dummySize; | ||
this.xorKey = this._settings.xorKey; | ||
this.hXorKey = this._settings.hXorKey; | ||
this.tXorKey = this._settings.tXorKey; | ||
this.jXorKey = this._settings.jXorKey; | ||
this.aesKey = this._settings.aesKey; | ||
this.aesIv = this._settings.aesIv; | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
base.SaveChanges(); | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
EditorGUILayout.BeginHorizontal(); | ||
EditorGUI.BeginChangeCheck(); | ||
this.sourceFolder = EditorGUILayout.TextField("Source Folder", this.sourceFolder); | ||
if (EditorGUI.EndChangeCheck()) EditorStorage.SaveData(KEY_SAVER, "sourceFolder", this.sourceFolder); | ||
Color bc = GUI.backgroundColor; | ||
GUI.backgroundColor = new Color32(0, 255, 128, 255); | ||
if (GUILayout.Button("Open", GUILayout.MaxWidth(100f))) BundleUtility.OpenFolder(this.sourceFolder); | ||
GUI.backgroundColor = bc; | ||
bc = GUI.backgroundColor; | ||
GUI.backgroundColor = new Color32(83, 152, 255, 255); | ||
if (GUILayout.Button("Browse", GUILayout.MaxWidth(100f))) this._OpenSourceFolder(); | ||
GUI.backgroundColor = bc; | ||
EditorGUILayout.EndHorizontal(); | ||
|
||
EditorGUILayout.Space(); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
|
||
// cryptogram options area | ||
EditorGUI.BeginChangeCheck(); | ||
this.cryptogramType = (CryptogramType)EditorGUILayout.EnumPopup("Cryptogram Type", this.cryptogramType); | ||
if (EditorGUI.EndChangeCheck()) EditorStorage.SaveData(KEY_SAVER, "cryptogramType", ((int)this.cryptogramType).ToString()); | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
|
||
this._CryptogramType(this.cryptogramType); | ||
} | ||
|
||
private void _CryptogramType(CryptogramType cryptogramType) | ||
{ | ||
switch (cryptogramType) | ||
{ | ||
case CryptogramType.OFFSET: | ||
this._DrawOffsetView(); | ||
break; | ||
case CryptogramType.XOR: | ||
this._DrawXorView(); | ||
break; | ||
case CryptogramType.HT2XOR: | ||
this._DrawHT2XorView(); | ||
break; | ||
case CryptogramType.AES: | ||
this._DrawAesView(); | ||
break; | ||
} | ||
} | ||
|
||
[SerializeField] | ||
public int randomSeed = 1; | ||
[SerializeField] | ||
public int dummySize = 0; | ||
private void _DrawOffsetView() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
GUIStyle style = new GUIStyle(); | ||
var bg = new Texture2D(1, 1); | ||
ColorUtility.TryParseHtmlString("#1c589c", 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("Offset Settings"), centeredStyle); | ||
EditorGUILayout.Space(); | ||
|
||
this.randomSeed = EditorGUILayout.IntField(new GUIContent("Random Seed", "Fixed random values."), this.randomSeed); | ||
if (this.randomSeed <= 0) this.randomSeed = 1; | ||
|
||
this.dummySize = EditorGUILayout.IntField(new GUIContent("Offset Dummy Size", "Add dummy bytes into front of file (per byte = Random 0 ~ 255)."), this.dummySize); | ||
if (this.dummySize < 0) this.dummySize = 0; | ||
|
||
this._DrawOperateButtonsView(this.cryptogramType); | ||
|
||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
[SerializeField] | ||
public int xorKey = 0; | ||
private void _DrawXorView() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
GUIStyle style = new GUIStyle(); | ||
var bg = new Texture2D(1, 1); | ||
ColorUtility.TryParseHtmlString("#1c589c", 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("XOR Settings"), centeredStyle); | ||
EditorGUILayout.Space(); | ||
|
||
this.xorKey = EditorGUILayout.IntField("XOR KEY (0 ~ 255)", this.xorKey); | ||
if (this.xorKey < 0) this.xorKey = 0; | ||
else if (this.xorKey > 255) this.xorKey = 255; | ||
|
||
this._DrawOperateButtonsView(this.cryptogramType); | ||
|
||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
[SerializeField] | ||
public int hXorKey = 0; | ||
[SerializeField] | ||
public int tXorKey = 0; | ||
[SerializeField] | ||
public int jXorKey = 0; | ||
private void _DrawHT2XorView() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
GUIStyle style = new GUIStyle(); | ||
var bg = new Texture2D(1, 1); | ||
ColorUtility.TryParseHtmlString("#1c589c", 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 Settings"), centeredStyle); | ||
EditorGUILayout.Space(); | ||
|
||
this.hXorKey = EditorGUILayout.IntField("Head XOR KEY (0 ~ 255)", this.hXorKey); | ||
if (this.hXorKey < 0) this.hXorKey = 0; | ||
else if (this.hXorKey > 255) this.hXorKey = 255; | ||
this.tXorKey = EditorGUILayout.IntField("Tail XOR KEY (0 ~ 255)", this.tXorKey); | ||
if (this.tXorKey < 0) this.tXorKey = 0; | ||
else if (this.tXorKey > 255) this.tXorKey = 255; | ||
this.jXorKey = EditorGUILayout.IntField("Jump XOR KEY (0 ~ 255)", this.jXorKey); | ||
if (this.jXorKey < 0) this.jXorKey = 0; | ||
else if (this.jXorKey > 255) this.jXorKey = 255; | ||
|
||
this._DrawOperateButtonsView(this.cryptogramType); | ||
|
||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
[SerializeField] | ||
public string aesKey = "file_key"; | ||
[SerializeField] | ||
public string aesIv = "file_iv"; | ||
private void _DrawAesView() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
GUIStyle style = new GUIStyle(); | ||
var bg = new Texture2D(1, 1); | ||
ColorUtility.TryParseHtmlString("#1c589c", 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("AES Settings"), centeredStyle); | ||
EditorGUILayout.Space(); | ||
|
||
this.aesKey = EditorGUILayout.TextField("AES KEY", this.aesKey); | ||
this.aesIv = EditorGUILayout.TextField("AES IV", this.aesIv); | ||
|
||
this._DrawOperateButtonsView(this.cryptogramType); | ||
|
||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
private void _DrawOperateButtonsView(CryptogramType cryptogramType) | ||
{ | ||
EditorGUILayout.BeginHorizontal(); | ||
GUILayout.FlexibleSpace(); | ||
Color bc = GUI.backgroundColor; | ||
GUI.backgroundColor = new Color32(255, 185, 83, 255); | ||
if (GUILayout.Button("Decrypt", GUILayout.MaxWidth(100f))) | ||
{ | ||
switch (cryptogramType) | ||
{ | ||
case CryptogramType.OFFSET: | ||
CryptogramUtility.OffsetDecryptBundleFiles(this.sourceFolder, this.dummySize); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[OFFSET] Decrypt Process.", "OK"); | ||
break; | ||
case CryptogramType.XOR: | ||
CryptogramUtility.XorDecryptBundleFiles(this.sourceFolder, (byte)this.xorKey); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[XOR] Decrypt Process.", "OK"); | ||
break; | ||
case CryptogramType.HT2XOR: | ||
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.AES: | ||
if (string.IsNullOrEmpty(this.aesKey) || string.IsNullOrEmpty(this.aesIv)) | ||
{ | ||
EditorUtility.DisplayDialog("Crytogram Message", "[AES] KEY or IV is Empty!!! Can't process.", "OK"); | ||
break; | ||
} | ||
CryptogramUtility.AesDecryptBundleFiles(this.sourceFolder, this.aesKey, this.aesIv); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[AES] Decrypt Process.", "OK"); | ||
break; | ||
} | ||
} | ||
GUI.backgroundColor = bc; | ||
|
||
bc = GUI.backgroundColor; | ||
GUI.backgroundColor = new Color32(255, 74, 218, 255); | ||
if (GUILayout.Button("Encrypt", GUILayout.MaxWidth(100f))) | ||
{ | ||
switch (cryptogramType) | ||
{ | ||
case CryptogramType.OFFSET: | ||
CryptogramUtility.OffsetEncryptBundleFiles(this.sourceFolder, this.randomSeed, this.dummySize); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[OFFSET] Encrypt Process.", "OK"); | ||
break; | ||
case CryptogramType.XOR: | ||
CryptogramUtility.XorEncryptBundleFiles(this.sourceFolder, (byte)this.xorKey); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[XOR] Encrypt Process.", "OK"); | ||
break; | ||
case CryptogramType.HT2XOR: | ||
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.AES: | ||
if (string.IsNullOrEmpty(this.aesKey) || string.IsNullOrEmpty(this.aesIv)) | ||
{ | ||
EditorUtility.DisplayDialog("Crytogram Message", "[AES] KEY or IV is Empty!!! Can't process.", "OK"); | ||
break; | ||
} | ||
CryptogramUtility.AesEncryptBundleFiles(this.sourceFolder, this.aesKey, this.aesIv); | ||
EditorUtility.DisplayDialog("Crytogram Message", "[AES] Encrypt Process.", "OK"); | ||
break; | ||
} | ||
} | ||
GUI.backgroundColor = bc; | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
private void _OpenSourceFolder() | ||
{ | ||
string folderPath = EditorStorage.GetData(KEY_SAVER, "sourceFolder", Path.Combine($"{Application.dataPath}/", AssetBundleBuilderHelper.GetDefaultBuildOutputRoot())); | ||
this.sourceFolder = EditorUtility.OpenFolderPanel("Open Source Folder", folderPath, string.Empty); | ||
if (!string.IsNullOrEmpty(this.sourceFolder)) EditorStorage.SaveData(KEY_SAVER, "sourceFolder", this.sourceFolder); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rame/AssetLoader/Scripts/Editor/Bundle/EditorWindow/BundleCryptogramUtilityWindow.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.