混淆函数体不应该包含 $Obfuz$前缀的类

backup
walon 2025-05-14 11:18:07 +08:00
parent ca3c15c44e
commit b216ed1eb3
4 changed files with 28 additions and 8 deletions

13
Editor/ConstValues.cs Normal file
View File

@ -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$";
}
}

View File

@ -1,5 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
using dnlib.DotNet.Emit; using dnlib.DotNet.Emit;
using Obfuz.Editor;
using Obfuz.Emit; using Obfuz.Emit;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
@ -74,13 +75,13 @@ namespace Obfuz.Data
{ {
_module.EnableTypeDefFindCache = false; _module.EnableTypeDefFindCache = false;
ITypeDefOrRef objectTypeRef = _module.Import(typeof(object)); 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); _module.Types.Add(_holderTypeDef);
_holderTypeDefs.Add(_holderTypeDef); _holderTypeDefs.Add(_holderTypeDef);
_module.EnableTypeDefFindCache = true; _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; field.DeclaringType = _holderTypeDef;
return new ConstFieldInfo return new ConstFieldInfo
{ {

View File

@ -1,4 +1,5 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Editor;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -35,6 +36,10 @@ namespace Obfuz
{ {
return true; return true;
} }
if (method.Name.StartsWith(ConstValues.ObfuzMetadataNamePrefix))
{
return true;
}
if (ShouldBeIgnoredByCustomAttribute(method)) if (ShouldBeIgnoredByCustomAttribute(method))
{ {
return true; return true;
@ -44,10 +49,10 @@ namespace Obfuz
public bool IsInWhiteList(TypeDef type) public bool IsInWhiteList(TypeDef type)
{ {
//if (type.Name.StartsWith("$Obfuz$")) if (type.Name.StartsWith(ConstValues.ObfuzMetadataNamePrefix))
//{ {
// continue; return true;
//} }
if (IsInWhiteList(type.Module)) if (IsInWhiteList(type.Module))
{ {
return true; return true;

View File

@ -1,5 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
using dnlib.DotNet.Emit; using dnlib.DotNet.Emit;
using Obfuz.Editor;
using Obfuz.Emit; using Obfuz.Emit;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
@ -108,7 +109,7 @@ namespace Obfuz.ObfusPasses.CallObfus
private TypeDef CreateProxyTypeDef() 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; typeDef.Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed;
_module.EnableTypeDefFindCache = false; _module.EnableTypeDefFindCache = false;
_module.Types.Add(typeDef); _module.Types.Add(typeDef);
@ -122,7 +123,7 @@ namespace Obfuz.ObfusPasses.CallObfus
{ {
_proxyTypeDef = CreateProxyTypeDef(); _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, MethodImplAttributes.IL | MethodImplAttributes.Managed,
MethodAttributes.Static | MethodAttributes.Private); MethodAttributes.Static | MethodAttributes.Private);
methodDef.DeclaringType = _proxyTypeDef; methodDef.DeclaringType = _proxyTypeDef;