public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { object[] outArgs; object rsample = null; if (callee is MethodInfo && !callee.HasCustomOrInjectedAttribute<IDoNotCallOnDecompilation>()) { stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); } Type returnType; callee.IsFunctionOrCtor(out returnType); TypeDescriptor rtype; if (rsample != null) rtype = TypeDescriptor.GetTypeOf(rsample); else rtype = returnType; IntrinsicFunction ifun; FunctionCall fcall; if (args[1].Variability == EVariability.Constant && args[2].Variability == EVariability.Constant) { // constant arguments case int first = (int)TypeConversions.ConvertValue(args[1].Sample, typeof(int)); int second = (int)TypeConversions.ConvertValue(args[2].Sample, typeof(int)); var range = new Range(first, second, EDimDirection.Downto); ifun = new IntrinsicFunction(IntrinsicFunction.EAction.Slice, range) { MethodModel = callee }; var fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; fcall = new FunctionCall() { Callee = fspec, Arguments = new Expression[] { args[0].Expr }, ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; } else { ifun = new IntrinsicFunction(IntrinsicFunction.EAction.Slice) { MethodModel = callee }; var fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; fcall = new FunctionCall() { Callee = fspec, Arguments = args.Select(arg => arg.Expr).ToArray(), ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; } stack.Push(fcall, rsample); return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { IntrinsicFunction ifun = new IntrinsicFunction(Kind, Parameter) { MethodModel = callee }; int skip = SkipFirstArg ? 1 : 0; Expression[] eargs = args.Skip(skip).Select(arg => arg.Expr).ToArray(); Type returnType; if (!callee.IsFunctionOrCtor(out returnType)) { FunctionSpec fspec = new FunctionSpec(typeof(void)) { CILRep = callee, IntrinsicRep = ifun }; builder.Call(fspec, eargs); } else { object[] outArgs; object rsample = null; if (callee is MethodInfo && !callee.HasCustomOrInjectedAttribute<IDoNotCallOnDecompilation>()) { stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); } TypeDescriptor rtype; if (rsample != null) rtype = TypeDescriptor.GetTypeOf(rsample); else rtype = returnType; FunctionSpec fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; FunctionCall fcall = new FunctionCall() { Callee = fspec, Arguments = eargs, ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; stack.Push(fcall, rsample); } return true; }