From 4c71d74b77c9eb62a0323698c9a0db3b641a917e Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 11 四月 2024 17:21:45 +0800
Subject: [PATCH] 0312 加密处理

---
 Assets/Launch/LoadDll.cs                                |   15 ++++++-
 Assets/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs |   56 +++++++++++++++++++++++++++-
 2 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/Assets/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs b/Assets/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs
index 8c51804..3c8416f 100644
--- a/Assets/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs
+++ b/Assets/Editor/AssetBundleBrowser/AssetBundleBuildTab.cs
@@ -14,7 +14,8 @@
 using Path = System.IO.Path;
 using HybridCLR.Editor.HotUpdate;
 using HybridCLR.Editor;
-
+using System.Text;
+
 namespace UnityEngine.AssetBundles
 {
     [System.Serializable]
@@ -699,6 +700,7 @@
 
         private void MakeBytesVersionFile()
         {
+            ChangeBytes();
             var fileInfos = new List<FileInfo>();
             FileExtersion.GetAllDirectoryFileInfos(StringUtility.Contact(m_UserData.m_OutputPath, "/logicbytes"), fileInfos);
             BytesVersionMaker.WriteAssetsVersionFile(Path.Combine(Directory.GetParent(Application.dataPath).FullName, m_UserData.m_OutputPath), fileInfos);
@@ -908,10 +910,60 @@
         {
             var fileInfos = new List<FileInfo>();
             FileExtersion.GetAllDirectoryFileInfos(m_UserData.m_OutputPath, fileInfos);
-            AssetsVersionMaker.WriteAssetsVersionFile(Path.Combine(Directory.GetParent(Application.dataPath).FullName, m_UserData.m_OutputPath), fileInfos);
+            AssetsVersionMaker.WriteAssetsVersionFile(Path.Combine(Directory.GetParent(Application.dataPath).FullName, m_UserData.m_OutputPath), fileInfos);
+
             Debug.Log("鐢熸垚AssetsVersion.txt鏂囦欢瀹屾瘯");
         }
 
+        void ChangeBytes()
+        {
+            string path = StringUtility.Contact(m_UserData.m_OutputPath, "/logicbytes/");
+            // 鍘熷DLL瀛楄妭鍐呭鏂囦欢鐨勮矾寰�  
+            string originalDllBytesFilePath = path + "Assembly-CSharp.dll.bytes";
+
+            // 涓存椂鏂囦欢鐨勮矾寰勶紝鐢ㄤ簬鍐欏叆"abc"鍚庡啀杩藉姞鍘熷DLL瀛楄妭鍐呭  
+            string tempFilePath = path + "temp_Assembly-CSharp.dll.bytes";
+
+            // 瑕佸啓鍏ョ殑瀛楃涓�"abc"  
+            string contentToWrite = "abc";
+
+            // 灏�"abc"杞崲涓哄瓧鑺傛暟缁�  
+            byte[] abcBytes = Encoding.ASCII.GetBytes(contentToWrite);
+
+            // 璇诲彇鍘熷DLL瀛楄妭鍐呭鍒板瓧鑺傛暟缁�  
+            byte[] originalDllBytes = File.ReadAllBytes(originalDllBytesFilePath);
+
+            // 灏�"abc"鍐欏叆涓存椂鏂囦欢  
+            using (FileStream fs = new FileStream(tempFilePath, FileMode.Create, FileAccess.Write))
+            {
+                fs.Write(abcBytes, 0, abcBytes.Length);
+
+                // 杩藉姞鍘熷DLL瀛楄妭鍐呭鍒颁复鏃舵枃浠�  
+                fs.Write(originalDllBytes, 0, originalDllBytes.Length);
+            }
+
+            ReplaceFile(tempFilePath, originalDllBytesFilePath);
+        }
+
+        public void ReplaceFile(string sourceFile, string targetFile)
+        {
+            // 纭繚婧愭枃浠跺瓨鍦�  
+            if (!File.Exists(sourceFile))
+            {
+                throw new FileNotFoundException("婧愭枃浠舵湭鎵惧埌锛�" + sourceFile);
+            }
+
+            // 濡傛灉鐩爣鏂囦欢瀛樺湪锛屽垯鍒犻櫎瀹�  
+            if (File.Exists(targetFile))
+            {
+                File.Delete(targetFile);
+            }
+
+            // 灏嗘簮鏂囦欢閲嶅懡鍚嶄负鐩爣鏂囦欢  
+            File.Move(sourceFile, targetFile);
+        }
+
+
         static int packageIndex
         {
             get { return LocalSave.GetInt("ClientPackageIndex", 1); }
diff --git a/Assets/Launch/LoadDll.cs b/Assets/Launch/LoadDll.cs
index 75523a1..4855112 100644
--- a/Assets/Launch/LoadDll.cs
+++ b/Assets/Launch/LoadDll.cs
@@ -106,8 +106,19 @@
 #endif
                 else
                 {
-                    // Or retrieve results as binary data
-                    byte[] assetData = www.downloadHandler.data;
+                    // 鐗规畩澶勭悊
+                    byte[] assetData;
+                    if (asset == "Assembly-CSharp.dll.bytes")
+                    {
+                        assetData = new byte[www.downloadHandler.data.Length - 3];
+                        Array.Copy(assetData, 3, www.downloadHandler.data, 0, www.downloadHandler.data.Length);
+
+                    }
+                    else
+                    { 
+                        assetData = www.downloadHandler.data;
+                    }
+
                     Debug.Log($"dll:{asset}  size:{assetData.Length}");
                     s_assetDatas[asset] = assetData;
                 }

--
Gitblit v1.8.0