From b216ed1eb3bb07cf48783e1142aef29a4d18dba9 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 14 May 2025 11:18:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=B7=E6=B7=86=E5=87=BD=E6=95=B0=E4=BD=93?= =?UTF-8?q?=E4=B8=8D=E5=BA=94=E8=AF=A5=E5=8C=85=E5=90=AB=20$Obfuz$?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/ConstValues.cs | 13 +++++++++++++ Editor/Data/ConstFieldAllocator.cs | 5 +++-- Editor/NotObfuscatedMethodWhiteList.cs | 13 +++++++++---- Editor/ObfusPasses/CallObfus/CallProxyAllocator.cs | 5 +++-- 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 Editor/ConstValues.cs diff --git a/Editor/ConstValues.cs b/Editor/ConstValues.cs new file mode 100644 index 0000000..21c7c5f --- /dev/null +++ b/Editor/ConstValues.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Obfuz.Editor +{ + public static class ConstValues + { + public const string ObfuzMetadataNamePrefix = "$Obfuz$"; + } +} diff --git a/Editor/Data/ConstFieldAllocator.cs b/Editor/Data/ConstFieldAllocator.cs index aacd5c9..9d1f30c 100644 --- a/Editor/Data/ConstFieldAllocator.cs +++ b/Editor/Data/ConstFieldAllocator.cs @@ -1,5 +1,6 @@ using dnlib.DotNet; using dnlib.DotNet.Emit; +using Obfuz.Editor; using Obfuz.Emit; using Obfuz.Utils; using System; @@ -74,13 +75,13 @@ namespace Obfuz.Data { _module.EnableTypeDefFindCache = false; ITypeDefOrRef objectTypeRef = _module.Import(typeof(object)); - _holderTypeDef = new TypeDefUser($"$Obfuz$ConstFieldHolder${_holderTypeDefs.Count}", objectTypeRef); + _holderTypeDef = new TypeDefUser($"{ConstValues.ObfuzMetadataNamePrefix}ConstFieldHolder${_holderTypeDefs.Count}", objectTypeRef); _module.Types.Add(_holderTypeDef); _holderTypeDefs.Add(_holderTypeDef); _module.EnableTypeDefFindCache = true; } - var field = new FieldDefUser($"$RVA_Value{_holderTypeDef.Fields.Count}", new FieldSig(GetTypeSigOfValue(value)), FieldAttributes.Static | FieldAttributes.Private | FieldAttributes.InitOnly); + var field = new FieldDefUser($"{ConstValues.ObfuzMetadataNamePrefix}RVA_Value{_holderTypeDef.Fields.Count}", new FieldSig(GetTypeSigOfValue(value)), FieldAttributes.Static | FieldAttributes.Private | FieldAttributes.InitOnly); field.DeclaringType = _holderTypeDef; return new ConstFieldInfo { diff --git a/Editor/NotObfuscatedMethodWhiteList.cs b/Editor/NotObfuscatedMethodWhiteList.cs index 98e5186..93b43f2 100644 --- a/Editor/NotObfuscatedMethodWhiteList.cs +++ b/Editor/NotObfuscatedMethodWhiteList.cs @@ -1,4 +1,5 @@ using dnlib.DotNet; +using Obfuz.Editor; using Obfuz.Utils; using System; using System.Collections.Generic; @@ -35,6 +36,10 @@ namespace Obfuz { return true; } + if (method.Name.StartsWith(ConstValues.ObfuzMetadataNamePrefix)) + { + return true; + } if (ShouldBeIgnoredByCustomAttribute(method)) { return true; @@ -44,10 +49,10 @@ namespace Obfuz public bool IsInWhiteList(TypeDef type) { - //if (type.Name.StartsWith("$Obfuz$")) - //{ - // continue; - //} + if (type.Name.StartsWith(ConstValues.ObfuzMetadataNamePrefix)) + { + return true; + } if (IsInWhiteList(type.Module)) { return true; diff --git a/Editor/ObfusPasses/CallObfus/CallProxyAllocator.cs b/Editor/ObfusPasses/CallObfus/CallProxyAllocator.cs index ec1831c..36b1f53 100644 --- a/Editor/ObfusPasses/CallObfus/CallProxyAllocator.cs +++ b/Editor/ObfusPasses/CallObfus/CallProxyAllocator.cs @@ -1,5 +1,6 @@ using dnlib.DotNet; using dnlib.DotNet.Emit; +using Obfuz.Editor; using Obfuz.Emit; using Obfuz.Utils; using System; @@ -108,7 +109,7 @@ namespace Obfuz.ObfusPasses.CallObfus private TypeDef CreateProxyTypeDef() { - var typeDef = new TypeDefUser("$Obfuz$ProxyCall", _module.CorLibTypes.Object.ToTypeDefOrRef()); + var typeDef = new TypeDefUser($"{ConstValues.ObfuzMetadataNamePrefix}ProxyCall", _module.CorLibTypes.Object.ToTypeDefOrRef()); typeDef.Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed; _module.EnableTypeDefFindCache = false; _module.Types.Add(typeDef); @@ -122,7 +123,7 @@ namespace Obfuz.ObfusPasses.CallObfus { _proxyTypeDef = CreateProxyTypeDef(); } - MethodDef methodDef = new MethodDefUser($"$Obfuz$ProxyCall$Dispatch${_proxyTypeDef.Methods.Count}", methodSig, + MethodDef methodDef = new MethodDefUser($"{ConstValues.ObfuzMetadataNamePrefix}ProxyCall$Dispatch${_proxyTypeDef.Methods.Count}", methodSig, MethodImplAttributes.IL | MethodImplAttributes.Managed, MethodAttributes.Static | MethodAttributes.Private); methodDef.DeclaringType = _proxyTypeDef;