baxi 3 tygodni temu
rodzic
commit
a751eb7f11

+ 4 - 2
CHANGELOG.md

@@ -13,6 +13,8 @@
 - Include shared StreamingAssets directly during player builds and provide an Editor/player path helper.
 - Include repeatable iOS export validation; other platforms retain their SDK support without build validation in this migration.
 
-## 1.0.1
+## 1.0.2
 
-- Update Xcode Project Folders 
+- Fix the Obfuscator settings page's 14 hardcoded GUI resource paths to load textures from the package; include a repeatable DLL/PDB patch tool.
+- Update Xcode Project Folders
+- Explicitly select AppRuntimes for obfuscation after UPM migration; validate renamed types and methods in the assembly consumed by IL2CPP.

+ 4 - 0
README.md

@@ -52,6 +52,10 @@ iOS 导出后会自动移除 `Frameworks` 和 `Libraries` 中的 `come.app.runti
 
 GUPS 的 DLL 使用宿主 `Assets/GUPS/Obfuscator` 作为可写目录。Package 会在编辑器启动及构建开始前创建 Settings、Cache、Log、Temp 目录和对应元数据;缺少 `Settings/Obfuscator_Settings.json` 时复制包内默认配置,已有配置及 GUID 保持不变。SDK 代码继续由 Package 管理,构建过程中不会写入包目录。包内默认配置启用混淆,空工程验证也会实际运行混淆流程。
 
+GUPS 默认只自动选择 `Assets` 下的程序集;迁入 UPM 后需在 **Project Settings → GuardingPearSoftware → Obfuscator → Settings** 的 **Obfuscate external assemblies** 中加入 `AppRuntimes`。包内默认模板已包含此项;已存在的工程配置会被保留,旧工程需补充此项(JSON 键为 `Obfuscate_Assembly_Additional_Assembly_Array`)。无需开启全部 Packages 程序集的混淆。验证会检查 GUPS 实际选中的程序集,以及 IL2CPP 输入 DLL 中的类型和方法名,避免仅凭“构建成功”或生成日志判断混淆生效。
+
+Obfuscator 设置页的图标、开关及折叠按钮直接读取 Package 内的 `ThirdParty/GUPS/Obfuscator/Editor/Gui/Resources`。其路径硬编码在厂商 `GUPS.Obfuscator.Editor.dll` 中,本包已将 14 处 GUI 资源路径调整为 Package 路径,并保留调试符号;配置、日志等可写路径仍使用宿主目录。以后替换该 SDK 的 DLL/PDB 后,执行 `Tools~/Patch-GupsGuiResources.ps1 -UnityPath <Unity.exe绝对路径>` 重新应用路径修补;脚本会检查资源存在、其他 IL 指令及模块标识不变,重复执行不会再次修改文件。
+
 ## 配置与使用
 
 包内 `Editor/DefaultSettings` 保存来自 `unity_ab_framework` 当前配置的三份默认模板。Unity 编辑器启动、安装包或脚本重编译后,会在资源导入完成时检查并补齐缺失配置:

+ 23 - 0
Tests~/Editor/AppRuntimesGupsValidation.cs

@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 using System.Linq;
+using System.Text.RegularExpressions;
 using GUPS.Obfuscator;
 using Newtonsoft.Json.Linq;
 using UnityEditor;
@@ -54,6 +55,28 @@ public static class AppRuntimesGupsValidation
             Require(Directory.GetFiles("Assets/GUPS/Obfuscator/Log", "*", SearchOption.AllDirectories)
                 .Any(path => !path.EndsWith(".meta", StringComparison.OrdinalIgnoreCase)), "GUPS produced a build report");
         }
+        if (Enabled()) VerifyPlayerAssembly();
+    }
+
+    public static void VerifyPlayerAssembly()
+    {
+        string log = File.ReadAllText("Assets/GUPS/Obfuscator/Log/iOS.txt");
+        var selected = Regex.Match(log, @"Found to obfuscate assemblies \(\d+\):\r?\n(?<paths>(?:  - [^\r\n]+\r?\n)+)");
+        Require(selected.Success && selected.Groups["paths"].Value.Contains("AppRuntimes.dll"),
+            "GUPS selected the package runtime assembly (not just Assembly-CSharp)");
+        var renamed = Regex.Match(log, @"Found a new Type Name \[\[AppRuntimes\] AppRuntimes\] : (?<name>[^\r\n]+)");
+        Require(renamed.Success && renamed.Groups["name"].Value != "AppRuntimes", "GUPS renamed the AppRuntimes type");
+
+        // Inspect the assembly actually consumed by IL2CPP, rather than Editor DLLs or just a successful log.
+        using (var assembly = GUPS.Mono.Cecil.AssemblyDefinition.ReadAssembly("Library/Bee/artifacts/iOS/ManagedStripped/AppRuntimes.dll"))
+        {
+            Require(!assembly.MainModule.Types.Any(type => type.Name == "AppRuntimes"), "Original runtime type name absent from player assembly");
+            var runtime = assembly.MainModule.Types.Single(type => type.Name == renamed.Groups["name"].Value);
+            Require(runtime.Methods.Count > 0 && !runtime.Methods.Any(method => method.Name == "CheckVersion"),
+                "Runtime methods are renamed in the IL2CPP input assembly");
+            Require(assembly.MainModule.Types.Any(type => type.Name == "AppSettings"), "Serialized settings retain their protected type name");
+        }
+        Debug.Log("APP_RUNTIMES_OBFUSCATION_VALIDATION_PASS");
     }
 
     private static bool Enabled() => string.Equals((string)JObject.Parse(File.ReadAllText(GupsProjectSettings.SettingsPath))

BIN
ThirdParty/GUPS/Obfuscator/Editor/Plugins/GUPS.Obfuscator.Editor.dll


BIN
ThirdParty/GUPS/Obfuscator/Editor/Plugins/GUPS.Obfuscator.Editor.pdb


+ 14 - 1
ThirdParty/GUPS/Obfuscator/Settings/Obfuscator_Settings.json

@@ -107,6 +107,19 @@
           "Key" : "Obfuscate_Assembly_In_Assets_AssemblyDefinitionFiles",
           "Value" : "True",
           "Values" : null
+        },
+        {
+          "Type" : "Array_String",
+          "Key" : "Obfuscate_Assembly_Additional_Assembly_Array",
+          "Value" : null,
+          "Values" : [
+          ]
+        },
+        {
+          "Type" : "Bool",
+          "Key" : "Obfuscate_Assembly_In_Packages_AssemblyDefinitionFiles",
+          "Value" : "True",
+          "Values" : null
         }
       ]
     },
@@ -663,4 +676,4 @@
       "Values" : null
     }
   ]
-}
+}

+ 91 - 0
Tools~/Patch-GupsGuiResources.ps1

@@ -0,0 +1,91 @@
+param(
+    [Parameter(Mandatory = $true)][string]$UnityPath
+)
+
+$ErrorActionPreference = 'Stop'
+$taskPackage = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
+$taskCecil = Join-Path (Split-Path -Parent $UnityPath) 'Data/Managed/Unity.Cecil.dll'
+if (-not (Test-Path -LiteralPath $taskCecil)) { throw "Unity Cecil library not found: $taskCecil" }
+Add-Type -Path $taskCecil
+
+$taskRelativeDll = 'ThirdParty/GUPS/Obfuscator/Editor/Plugins/GUPS.Obfuscator.Editor.dll'
+$taskDll = Join-Path $taskPackage $taskRelativeDll
+$taskOldPrefix = 'Assets/GUPS/Obfuscator/Editor/Gui/Resources/'
+$taskNewPrefix = 'Packages/come.app.runtimes/ThirdParty/GUPS/Obfuscator/Editor/Gui/Resources/'
+$taskResources = Join-Path $taskPackage 'ThirdParty/GUPS/Obfuscator/Editor/Gui/Resources'
+
+function Get-InstructionSnapshot($Assembly) {
+    foreach ($taskType in $Assembly.MainModule.GetTypes()) {
+        foreach ($taskMethod in $taskType.Methods) {
+            if (-not $taskMethod.HasBody) { continue }
+            $taskMethod.FullName
+            foreach ($taskInstruction in $taskMethod.Body.Instructions) { $taskInstruction.ToString() }
+        }
+    }
+}
+
+$taskReader = [Mono.Cecil.ReaderParameters]::new()
+$taskReader.ReadSymbols = $true
+$taskReader.InMemory = $true
+$taskAssembly = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($taskDll, $taskReader)
+$taskStage = $null
+try {
+    if ($taskAssembly.Name.HasPublicKey) { throw 'The vendor DLL is now signed; review the SDK update before patching.' }
+    $taskBefore = (Get-InstructionSnapshot $taskAssembly) -join "`n"
+    $taskChanged = 0
+    $taskFound = [Collections.Generic.HashSet[string]]::new()
+    foreach ($taskType in $taskAssembly.MainModule.GetTypes()) {
+        foreach ($taskMethod in $taskType.Methods) {
+            if (-not $taskMethod.HasBody) { continue }
+            foreach ($taskInstruction in $taskMethod.Body.Instructions) {
+                if ($taskInstruction.OpCode.Name -ne 'ldstr') { continue }
+                $taskValue = [string]$taskInstruction.Operand
+                if ($taskValue.StartsWith($taskOldPrefix, [StringComparison]::Ordinal)) {
+                    $taskValue = $taskNewPrefix + $taskValue.Substring($taskOldPrefix.Length)
+                    $taskInstruction.Operand = $taskValue
+                    $taskChanged++
+                }
+                if ($taskValue.StartsWith($taskNewPrefix, [StringComparison]::Ordinal)) {
+                    $taskResource = $taskValue.Substring($taskNewPrefix.Length)
+                    if (-not (Test-Path -LiteralPath (Join-Path $taskResources $taskResource) -PathType Leaf)) {
+                        throw "Missing GUPS GUI resource: $taskResource"
+                    }
+                    [void]$taskFound.Add($taskResource)
+                }
+            }
+        }
+    }
+    if ($taskFound.Count -ne 14) { throw "Expected 14 GUI resources, found $($taskFound.Count). Review the SDK update." }
+    if ($taskChanged -eq 0) { Write-Output 'PASS: all 14 GUPS GUI paths already target the package.'; return }
+
+    # Stage and verify the DLL/PDB before replacing either shipped file. No runtime
+    # instructions may change except these resource strings; preserve debug symbols.
+    $taskStage = Join-Path ([IO.Path]::GetTempPath()) ('GupsGuiPatch-' + [Guid]::NewGuid().ToString('N'))
+    [IO.Directory]::CreateDirectory($taskStage) | Out-Null
+    $taskStagedDll = Join-Path $taskStage 'GUPS.Obfuscator.Editor.dll'
+    $taskWriter = [Mono.Cecil.WriterParameters]::new()
+    $taskWriter.WriteSymbols = $true
+    $taskAssembly.Write($taskStagedDll, $taskWriter)
+    $taskCheck = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($taskStagedDll, $taskReader)
+    try {
+        $taskAfter = (Get-InstructionSnapshot $taskCheck) -join "`n"
+        if ($taskAfter -cne $taskBefore.Replace($taskOldPrefix, $taskNewPrefix)) { throw 'Unexpected IL changes in patched DLL.' }
+        if (-not $taskCheck.MainModule.HasSymbols -or $taskCheck.MainModule.Mvid -ne $taskAssembly.MainModule.Mvid) {
+            throw 'Debug symbols or module identity changed unexpectedly.'
+        }
+    } finally { $taskCheck.Dispose() }
+    $taskAssembly.Dispose()
+    [IO.File]::Copy($taskStagedDll, $taskDll, $true)
+    [IO.File]::Copy([IO.Path]::ChangeExtension($taskStagedDll, '.pdb'), [IO.Path]::ChangeExtension($taskDll, '.pdb'), $true)
+    Write-Output "PASS: patched $taskChanged GUI resource paths; other IL, module identity and symbols verified."
+} finally {
+    $taskAssembly.Dispose()
+    if ($taskStage) {
+        # Only remove the two exact staging files, never recurse over a computed path.
+        foreach ($taskName in @('GUPS.Obfuscator.Editor.dll', 'GUPS.Obfuscator.Editor.pdb')) {
+            $taskFile = Join-Path $taskStage $taskName
+            if (Test-Path -LiteralPath $taskFile) { Remove-Item -LiteralPath $taskFile }
+        }
+        [IO.Directory]::Delete($taskStage, $false)
+    }
+}

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "come.app.runtimes",
-  "version": "1.0.1",
+  "version": "1.0.2",
   "displayName": "AppRuntimes",
   "description": "Shared AppRuntimes library with bundled UniTask, UniWebView, Facebook SDK, External Dependency Manager and GUPS.",
   "unity": "6000.3",