using dnlib.DotNet.Emit; using NUnit.Framework; using System.Collections.Generic; using System.Linq; namespace Obfuz.Emit { public abstract class FunctionBase : IFunction { public abstract void CreateArguments(DataNodeType type, object value, CreateExpressionOptions options, List args); public abstract void CompileSelf(CompileContext ctx, List inputs, List output); public virtual void Compile(CompileContext ctx, List inputs, ConstValue result) { foreach (var input in inputs) { input.Compile(ctx); } CompileSelf(ctx, inputs, ctx.output); } public virtual IDataNode CreateExpr(DataNodeType type, object value, CreateExpressionOptions options) { var args = new List(); CreateArguments(type, value, options, args); options.depth += 1; var argNodes = new List(); foreach (ConstValue cv in args) { var argNode = options.expressionCreator.CreateRandom(cv.type, cv.value, options); argNodes.Add(argNode); } return new ConstExpression(this, args.Select(a => options.expressionCreator.CreateRandom(a.type, a.value, options)).ToList(), new ConstValue(type, value)); } } }