public override void Apply(IObfuscationContext context) { var module = context.Assembly.MainModule; for (int i = 0; i < Random.Next(3, 30); i++) { TypeDefinition targetType; do { targetType = module.Types[Random.Next(module.Types.Count)]; } while (targetType.IsInterface); var junkMethod = new MethodDefinition("junkMethod" + i, MethodAttributes.Static, module.TypeSystem.Void); var parameterCount = Random.Next(-4, 4); if (parameterCount < 0) { parameterCount = 0; } for (int j = 0; j < parameterCount; j++) { junkMethod.Parameters.Add(new ParameterDefinition(module.TypeSystem.Object)); } targetType.Methods.Add(junkMethod); MsilBodyGenerator.AssignRandomMethodBody(junkMethod); } }
public static void AssignRandomMethodBody(MethodDefinition method) { var generator = new MsilBodyGenerator(method); var blockCount = Random.Next(1, 6); for (int i = 0; i < blockCount; i++) { generator.AppendBlock(); } generator.FinalizeMethod(); }