From b84d158fac58fc0ccd4c4a1a87b983e4dacd4e40 Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 16 Jun 2025 17:02:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ReflectionCompatibilityDet?= =?UTF-8?q?ector=E5=A4=84=E7=90=86Enum.TryParse=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=94T=E5=8C=85=E5=90=AB=E6=B3=9B=E5=9E=8B=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=97=B6=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReflectionCompatibilityDetector.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Editor/ObfusPasses/SymbolObfus/ReflectionCompatibilityDetector.cs b/Editor/ObfusPasses/SymbolObfus/ReflectionCompatibilityDetector.cs index b78b0c6..08aae89 100644 --- a/Editor/ObfusPasses/SymbolObfus/ReflectionCompatibilityDetector.cs +++ b/Editor/ObfusPasses/SymbolObfus/ReflectionCompatibilityDetector.cs @@ -190,17 +190,25 @@ namespace Obfuz.ObfusPasses.SymbolObfus private void AnalyzeEnum(IMethod method, TypeDef typeDef) { const int extraSearchInstructionCount = 3; - TypeDef parseType = GetMethodGenericParameter(method)?.ToTypeDefOrRef()?.ResolveTypeDef(); + TypeSig parseTypeSig = GetMethodGenericParameter(method); + TypeDef parseType = parseTypeSig?.ToTypeDefOrRef().ResolveTypeDef(); switch (method.Name) { case "Parse": { - if (parseType != null) + if (parseTypeSig != null) { // Enum.Parse(string name) or Enum.Parse(string name, bool caseInsensitive) - if (IsAnyEnumItemRenamed(parseType)) + if (parseType != null) { - Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse field of T:{parseType.FullName} is renamed."); + if (IsAnyEnumItemRenamed(parseType)) + { + Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse field of T:{parseType.FullName} is renamed."); + } + } + else + { + Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.Parse field of T should not be renamed."); } } else @@ -220,12 +228,19 @@ namespace Obfuz.ObfusPasses.SymbolObfus } case "TryParse": { - if (parseType != null) + if (parseTypeSig != null) { // Enum.TryParse(string name, out T result) or Enum.TryParse(string name, bool ignoreCase, out T result) - if (IsAnyEnumItemRenamed(parseType)) + if (parseType != null) { - Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse field of T:{parseType.FullName} is renamed."); + if (IsAnyEnumItemRenamed(parseType)) + { + Debug.LogError($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse field of T:{parseType.FullName} is renamed."); + } + } + else + { + Debug.LogWarning($"[ReflectionCompatibilityDetector] Reflection compatibility issue in {_curCallingMethod}: Enum.TryParse field of T should not be renamed."); } } else