public override bool Rewrite( CodeDescriptor decompilee, Expression waitObject, Analysis.IDecompiler stack, IFunctionBuilder builder) { var fspec = new FunctionSpec(typeof(void)) { IntrinsicRep = IntrinsicFunctions.Wait(WaitParams.EWaitKind.WaitFor) }; builder.Call(fspec, waitObject); return(true); }
public override bool Rewrite(CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, IFunctionBuilder builder) { Array arr = (Array)args[0].Sample; if (arr == null) { throw new InvalidOperationException("Unable to deduce array length"); } int numElems = arr.Length; Type tTE = arr.GetType().GetElementType(); Type tTA; callee.IsFunction(out tTA); FunctionCall newCall = IntrinsicFunctions.NewArray(tTE, LiteralReference.CreateConstant(numElems), arr); FunctionSpec fspec = (FunctionSpec)newCall.Callee; IntrinsicFunction ifun = fspec.IntrinsicRep; ArrayParams aparams = (ArrayParams)ifun.Parameter; for (int i = 0; i < numElems; i++) { aparams.Elements[i] = IntrinsicFunctions.GetArrayElement( args[0].Expr, LiteralReference.CreateConstant(i)); } object sample = null; try { sample = callee.Invoke(arr); } catch (Exception) { } Expression conv = IntrinsicFunctions.Cast(newCall, arr.GetType(), tTA); stack.Push(conv, sample); return(true); }
public override bool Rewrite(Meta.CodeDescriptor decompilee, SysDOM.Expression waitObject, Analysis.IDecompiler stack, SysDOM.IFunctionBuilder builder) { var evt = waitObject.ResultType.GetSampleInstance(); var peevent = evt as PredicatedEvent; if (peevent == null) { throw new InvalidOperationException("Unable to resolve awaited PredicatedEvent"); } var pred = peevent._pred; var rwc = pred.Method.GetCustomOrInjectedAttribute <RewriteCall>(); if (rwc == null) { throw new InvalidOperationException("Awaited predicate is not synthesizable."); } var lr = LiteralReference.CreateConstant(pred.Target); var se = new StackElement(lr, pred.Target, Analysis.Msil.EVariability.Constant); var pstk = stack.CreatePrivateStack(); if (!rwc.Rewrite(decompilee, pred.Method, new StackElement[] { se }, pstk, builder)) { throw new InvalidOperationException("Unable to implement awaited predicate."); } var predEx = pstk.Pop(); var fspec = new FunctionSpec(typeof(void)) { IntrinsicRep = IntrinsicFunctions.Wait(WaitParams.EWaitKind.WaitUntil) }; builder.Call(fspec, predEx.Expr); return(true); }
public override bool Rewrite(Meta.CodeDescriptor decompilee, SysDOM.Expression waitObject, Analysis.IDecompiler stack, SysDOM.IFunctionBuilder builder) { var evt = waitObject.ResultType.GetSampleInstance(); var mevent = evt as MultiEvent; if (mevent == null) { throw new InvalidOperationException("Unable to resolve awaited MultiEvent"); } var events = mevent._events.Cast <Event>(); var signals = events.Select(e => (SignalBase)e.Owner); var signalRefs = signals.Select(s => SignalRef.Create(s, SignalRef.EReferencedProperty.Instance)); var args = signalRefs.Select(sr => (LiteralReference)sr).ToArray(); var fspec = new FunctionSpec(typeof(void)) { IntrinsicRep = IntrinsicFunctions.Wait(WaitParams.EWaitKind.WaitOn) }; builder.Call(fspec, args); return(true); }
public override bool Rewrite(Meta.CodeDescriptor decompilee, SysDOM.Expression waitObject, Analysis.IDecompiler stack, SysDOM.IFunctionBuilder builder) { var evt = waitObject.ResultType.GetSampleInstance(); var sevent = evt as Event; if (sevent == null) { // This workaround is for the following situation: // Signal s; // await s; // This will actually await the "changed event" which is associated with the signal. However, decompilation // will treat the signal instance as the awaited object and pass a Signal instance instead of the event. // The code will try to restore the Event instance from the Awaiter. Awaiter awaiter = null; try { awaiter = ((object)AwaitableExtensionMethods.GetAwaiter((dynamic)evt)) as Awaiter; } catch { } if (awaiter == null) { throw new InvalidOperationException("Unable to resolve awaited MultiEvent"); } sevent = awaiter._event; } var signal = (SignalBase)sevent.Owner; var signalRef = SignalRef.Create(signal, SignalRef.EReferencedProperty.Instance); var arg = (LiteralReference)signalRef; var fspec = new FunctionSpec(typeof(void)) { IntrinsicRep = IntrinsicFunctions.Wait(WaitParams.EWaitKind.WaitOn) }; builder.Call(fspec, arg); return(true); }
public override bool Rewrite(Meta.CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, SysDOM.IFunctionBuilder builder) { stack.Push( Expression.Conditional(args[0].Expr, args[1].Expr, args[2].Expr), args[1].Sample); return(true); }
public override bool Rewrite(Meta.CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, IFunctionBuilder builder) { object[] outArgs; object sample; if (!stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out sample)) { throw new InvalidOperationException("Unable to create sample for ScSinCos call"); } if (args[1].Variability != Analysis.Msil.EVariability.Constant) { throw new InvalidOperationException("n argument of Rempow2 must be a constant"); } var fcall = IntrinsicFunctions.XILOpCode( new XILInstr(InstructionCodes.Rempow2, (int)args[1].Sample), TypeDescriptor.GetTypeOf(sample), new Expression[] { args[0].Expr }); stack.Push(fcall, sample); return(true); }