新增 RemoveObfuzAttributesPass.cs,在最后一个阶段清理掉所有 [ObfuzIgnore]
parent
0cbe09287d
commit
a171592172
|
@ -0,0 +1,70 @@
|
||||||
|
using dnlib.DotNet;
|
||||||
|
using dnlib.DotNet.Emit;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Obfuz.ObfusPasses.CleanUp
|
||||||
|
{
|
||||||
|
public class RemoveObfuzAttributesPass : ObfuscationPassBase
|
||||||
|
{
|
||||||
|
public override ObfuscationPassType Type => ObfuscationPassType.None;
|
||||||
|
|
||||||
|
public override void Start()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Stop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void RemoveObfuzAttributes(IHasCustomAttribute provider)
|
||||||
|
{
|
||||||
|
CustomAttributeCollection customAttributes = provider.CustomAttributes;
|
||||||
|
if (customAttributes.Count == 0)
|
||||||
|
return;
|
||||||
|
var toRemove = new List<CustomAttribute>();
|
||||||
|
customAttributes.RemoveAll("Obfuz.ObfuzIgnoreAttribute");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Process()
|
||||||
|
{
|
||||||
|
var ctx = ObfuscationPassContext.Current;
|
||||||
|
foreach (ModuleDef mod in ctx.toObfuscatedModules)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(mod);
|
||||||
|
foreach (TypeDef type in mod.GetTypes())
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(type);
|
||||||
|
foreach (FieldDef field in type.Fields)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(field);
|
||||||
|
}
|
||||||
|
foreach (MethodDef method in type.Methods)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(method);
|
||||||
|
foreach (Parameter param in method.Parameters)
|
||||||
|
{
|
||||||
|
if (param.ParamDef != null)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(param.ParamDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (PropertyDef property in type.Properties)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(property);
|
||||||
|
}
|
||||||
|
foreach (EventDef eventDef in type.Events)
|
||||||
|
{
|
||||||
|
RemoveObfuzAttributes(eventDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,6 +69,7 @@ namespace Obfuz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pipeline1.AddPass(new CleanUpInstructionPass());
|
_pipeline1.AddPass(new CleanUpInstructionPass());
|
||||||
|
_pipeline2.AddPass(new RemoveObfuzAttributesPass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveKey(byte[] secret, string secretOutputPath)
|
public static void SaveKey(byte[] secret, string secretOutputPath)
|
||||||
|
|
Loading…
Reference in New Issue