add: add EncryptFieldAttribute

before-split
walon 2025-05-20 11:08:07 +08:00
parent 0f6207b0ae
commit 685f5f5530
5 changed files with 38 additions and 0 deletions

View File

@ -29,6 +29,7 @@ namespace Obfuz.ObfusPasses.CleanUp
return;
var toRemove = new List<CustomAttribute>();
customAttributes.RemoveAll("Obfuz.ObfuzIgnoreAttribute");
customAttributes.RemoveAll("Obfuz.EncryptFieldAttribute");
}
public override void Process()

View File

@ -29,6 +29,14 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
public override bool NeedEncrypt(FieldDef field)
{
if (MetaUtil.HasEncryptFieldAttribute(field))
{
return true;
}
if (MetaUtil.HasObfuzIgnoreAttribute(field) || MetaUtil.HasObfuzIgnoreAttribute(field.DeclaringType))
{
return false;
}
var rule = _configParser.GetFieldRule(field);
return rule != null;
}

View File

@ -788,5 +788,10 @@ namespace Obfuz.Utils
{
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute");
}
public static bool HasEncryptFieldAttribute(IHasCustomAttribute obj)
{
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.EncryptFieldAttribute");
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Obfuz
{
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
public class EncryptFieldAttribute : Attribute
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30f22110938816d4cb7e9cc9a176fd1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: