WatermarkPass不对DOTS函数注入水印指令

main
walon 2025-08-06 18:27:15 +08:00
parent 246a49f8ba
commit 739fcb24c5
4 changed files with 12 additions and 6 deletions

View File

@ -138,9 +138,12 @@ namespace Obfuz.ObfusPasses.Watermark
private void AddFieldAccessToSignatureHolder(ModuleDef module, EncryptionScopeInfo encryptionScope, WatermarkInfo watermarkInfo)
{
BurstCompileComputeCache burstCompileComputeCache = ObfuscationPassContext.Current.burstCompileComputeCache;
var insertTargetMethods = module.Types
.Where(t => !MetaUtil.HasBurstCompileAttribute(t))
.SelectMany(t => t.Methods)
.Where(m => m.HasBody && m.Body.Instructions.Count > 10)
.Where(m => m.HasBody && m.Body.Instructions.Count > 10 && !MetaUtil.HasBurstCompileAttribute(m)
&& !burstCompileComputeCache.IsBurstCompileMethodOrReferencedByBurstCompileMethod(m))
.ToList();
if (insertTargetMethods.Count == 0)
@ -149,7 +152,7 @@ namespace Obfuz.ObfusPasses.Watermark
return;
}
var random = encryptionScope.localRandomCreator(HashUtil.ComputeHash("AddFieldAccessToSignatureHolder"));
var random = encryptionScope.localRandomCreator(HashUtil.ComputeHash($"AddFieldAccessToSignatureHolder:{module.Name}"));
DefaultMetadataImporter importer = ObfuscationPassContext.Current.moduleEntityManager.GetEntity<DefaultMetadataImporter>(module);
foreach (var fieldDef in watermarkInfo.signatureHoldFields)
{
@ -195,7 +198,7 @@ namespace Obfuz.ObfusPasses.Watermark
Debug.LogWarning($"No suitable methods found in module '{module.Name}' to insert watermark IL sequences.");
return;
}
var random = encryptionScope.localRandomCreator(HashUtil.ComputeHash("AddWaterMarkILSequences"));
var random = encryptionScope.localRandomCreator(HashUtil.ComputeHash($"AddWaterMarkILSequences:{module.Name}"));
int[] signature = KeyGenerator.ConvertToIntKey(watermarkInfo.signature);
for (int intIndex = 0; intIndex < signature.Length;)
{

View File

@ -65,7 +65,7 @@ namespace Obfuz
{
return true;
}
if (method.CustomAttributes.Find(ConstValues.BurstCompileFullName) != null || _burstCompileComputeCache.IsBurstCompileMethodOrReferencedByBurstCompileMethod(method))
if (MetaUtil.HasBurstCompileAttribute(method) || _burstCompileComputeCache.IsBurstCompileMethodOrReferencedByBurstCompileMethod(method))
{
return true;
}
@ -88,7 +88,7 @@ namespace Obfuz
{
return true;
}
if (type.CustomAttributes.Find(ConstValues.BurstCompileFullName) != null)
if (MetaUtil.HasBurstCompileAttribute(type))
{
return true;
}

View File

@ -62,6 +62,7 @@ namespace Obfuz
public List<ModuleDef> modulesToObfuscate;
public List<ModuleDef> allObfuscationRelativeModules;
public ObfuzIgnoreScopeComputeCache obfuzIgnoreScopeComputeCache;
public BurstCompileComputeCache burstCompileComputeCache;
public ObfuscationMethodWhitelist whiteList;
public ConfigurablePassPolicy passPolicy;

View File

@ -288,6 +288,7 @@ namespace Obfuz
EncryptionScopeProvider = encryptionScopeProvider,
};
var obfuzIgnoreScopeComputeCache = new ObfuzIgnoreScopeComputeCache();
var burstCompileCache = new BurstCompileComputeCache(modulesToObfuscate, allObfuscationRelativeModules);
_ctx = new ObfuscationPassContext
{
coreSettings = _coreSettings,
@ -298,8 +299,9 @@ namespace Obfuz
moduleEntityManager = moduleEntityManager,
obfuzIgnoreScopeComputeCache = obfuzIgnoreScopeComputeCache,
burstCompileComputeCache = burstCompileCache,
whiteList = new ObfuscationMethodWhitelist(obfuzIgnoreScopeComputeCache, new BurstCompileComputeCache(modulesToObfuscate, allObfuscationRelativeModules)),
whiteList = new ObfuscationMethodWhitelist(obfuzIgnoreScopeComputeCache, burstCompileCache),
passPolicy = _passPolicy,
};
ObfuscationPassContext.Current = _ctx;