private BlockStatement DecompileMethod(MethodBody body, out MethodSpecificContext methodContext) { methodContext = null; BlockStatement block; try { DecompilationContext decompilationContext = new DecompilationContext(new MethodSpecificContext(body), this.typeContext ?? new TypeSpecificContext(body.Method.DeclaringType)); DecompilationPipeline pipeline = this.language.CreatePipeline(body.Method, decompilationContext); methodContext = pipeline.Run(body).MethodContext; block = pipeline.Body; } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(body.Method); methodContext = new MethodSpecificContext(body); block = new BlockStatement(); block.AddStatement(new ExceptionStatement(ex, body.Method)); OnExceptionThrown(ex); } return(block); }
private bool CheckMethodAndDecompile(MethodDefinition methodDef, out BlockStatement methodBody) { if (!methodDef.HasParameters || methodDef.Parameters.Count != 1) { methodBody = null; return(false); } DecompilationPipeline pipeline = BaseLanguage.IntermediateRepresenationPipeline; pipeline.Run(methodDef.Body); methodBody = pipeline.Body; return(true); }
private BlockStatement DecompileMethodPartially(MethodBody body, out DecompilationContext context, bool needDecompiledMember = false) { context = null; if (this.IsCachingEnabled && this.cacheService.IsDecompiledMemberInCache(body.Method, this.language, this.renameInvalidMembers)) { CachedDecompiledMember cachedDecompiledMember = this.cacheService.GetDecompiledMemberFromCache(body.Method, this.language, this.renameInvalidMembers); return(cachedDecompiledMember.Member.Statement as BlockStatement); } //Performance improvement ControlFlowGraph cfg = new ControlFlowGraphBuilder(body.Method).CreateGraph(); if (cfg.Blocks.Length > 2) { return(null); } BlockStatement block; try { DecompilationPipeline pipeline; DecompilationContext decompilationContext = new DecompilationContext(new MethodSpecificContext(body), this.typeContext ?? new TypeSpecificContext(body.Method.DeclaringType)); if (!needDecompiledMember) { decompilationContext.MethodContext.EnableEventAnalysis = false; } pipeline = new DecompilationPipeline(BaseLanguage.IntermediateRepresenationPipeline.Steps, decompilationContext); context = pipeline.Run(body); block = pipeline.Body; } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(body.Method); block = new BlockStatement(); block.AddStatement(new ExceptionStatement(ex, body.Method)); OnExceptionThrown(ex); } return(block); }
private static BlockStatement DecompileStateMachine(this MethodBody body, DecompilationContext enclosingContext, BaseStateMachineRemoverStep removeStateMachineStep, Func<DecompilationContext, IStateMachineData> stateMachineDataSelector, out DecompilationContext decompilationContext) { DecompilationPipeline thePipeline = GetStateMachineRemovalPipeline(removeStateMachineStep, stateMachineDataSelector); decompilationContext = thePipeline.Run(body, enclosingContext.Language); enclosingContext.MethodContext.Variables.AddRange(decompilationContext.MethodContext.Variables); enclosingContext.MethodContext.VariableDefinitionToNameMap.AddRange(decompilationContext.MethodContext.VariableDefinitionToNameMap); enclosingContext.MethodContext.AddInnerMethodParametersToContext(decompilationContext.MethodContext); enclosingContext.MethodContext.VariableAssignmentData.AddRange(decompilationContext.MethodContext.VariableAssignmentData); enclosingContext.MethodContext.GotoLabels.AddRange(decompilationContext.MethodContext.GotoLabels); enclosingContext.MethodContext.GotoStatements.AddRange(decompilationContext.MethodContext.GotoStatements); BlockStatement theBlockStatement = thePipeline.Body; return theBlockStatement; }
private BlockStatement GetStatements(MethodBody body) { //Performance improvement ControlFlowGraph cfg = new ControlFlowGraphBuilder(body.Method).CreateGraph(); if (cfg.Blocks.Length > 2) { return(null); } DecompilationPipeline pipeline = new DecompilationPipeline(BaseLanguage.IntermediateRepresenationPipeline.Steps, new DecompilationContext(new MethodSpecificContext(body) { EnableEventAnalysis = false }, new TypeSpecificContext(body.Method.DeclaringType))); pipeline.Run(body); return(pipeline.Body); }
private BlockStatement DecompileMethodPartially(MethodBody body, out DecompilationContext context, bool needDecompiledMember = false) { context = null; if (this.get_IsCachingEnabled() && this.cacheService.IsDecompiledMemberInCache(body.get_Method(), this.language, this.renameInvalidMembers)) { return(this.cacheService.GetDecompiledMemberFromCache(body.get_Method(), this.language, this.renameInvalidMembers).get_Member().get_Statement() as BlockStatement); } if ((int)(new ControlFlowGraphBuilder(body.get_Method())).CreateGraph().get_Blocks().Length > 2) { return(null); } try { stackVariable13 = new MethodSpecificContext(body); stackVariable15 = this.typeContext; if (stackVariable15 == null) { dummyVar0 = stackVariable15; stackVariable15 = new TypeSpecificContext(body.get_Method().get_DeclaringType()); } V_2 = new DecompilationContext(stackVariable13, stackVariable15, this.language); if (!needDecompiledMember) { V_2.get_MethodContext().set_EnableEventAnalysis(false); } V_1 = new DecompilationPipeline(BaseLanguage.get_IntermediateRepresenationPipeline().get_Steps(), V_2); context = V_1.Run(body, this.language); V_0 = V_1.get_Body(); } catch (Exception exception_0) { V_3 = exception_0; this.get_ExceptionsWhileDecompiling().Add(body.get_Method()); V_0 = new BlockStatement(); V_0.AddStatement(new ExceptionStatement(V_3, body.get_Method())); this.OnExceptionThrown(V_3); } return(V_0); }
private static BlockStatement DecompileStateMachine(this MethodBody body, MethodSpecificContext enclosingMethodContext, IStateMachineRemoverStep removeStateMachineStep, Func <DecompilationContext, IStateMachineData> stateMachineDataSelector, out DecompilationContext decompilationContext) { ILanguage language = CSharp.GetLanguage(CSharpVersion.V4); removeStateMachineStep.Language = language; DecompilationPipeline thePipeline = GetStateMachineRemovalPipeline(removeStateMachineStep, stateMachineDataSelector); decompilationContext = thePipeline.Run(body, language); enclosingMethodContext.Variables.AddRange(decompilationContext.MethodContext.Variables); enclosingMethodContext.VariableDefinitionToNameMap.AddRange(decompilationContext.MethodContext.VariableDefinitionToNameMap); enclosingMethodContext.AddInnerMethodParametersToContext(decompilationContext.MethodContext); enclosingMethodContext.VariableAssignmentData.AddRange(decompilationContext.MethodContext.VariableAssignmentData); enclosingMethodContext.GotoLabels.AddRange(decompilationContext.MethodContext.GotoLabels); enclosingMethodContext.GotoStatements.AddRange(decompilationContext.MethodContext.GotoStatements); BlockStatement theBlockStatement = thePipeline.Body; return(theBlockStatement); }
private BlockStatement GetStatements(MethodBody body) { //Performance improvement ControlFlowGraph cfg = new ControlFlowGraphBuilder(body.Method).CreateGraph(); if (cfg.Blocks.Length > 2) { return null; } DecompilationPipeline pipeline = new DecompilationPipeline(BaseLanguage.IntermediateRepresenationPipeline.Steps, new DecompilationContext(new MethodSpecificContext(body) { EnableEventAnalysis = false }, new TypeSpecificContext(body.Method.DeclaringType))) ; pipeline.Run(body); return pipeline.Body; }
static BlockStatement RunPipeline(DecompilationPipeline pipeline, ILanguage language, MethodBody body, out DecompilationContext context) { context = pipeline.Run(body, language); return(pipeline.Body); }
private BlockStatement DecompileMethodPartially(MethodBody body, out DecompilationContext context, bool needDecompiledMember = false) { context = null; if (this.IsCachingEnabled && this.cacheService.IsDecompiledMemberInCache(body.Method, this.language, this.renameInvalidMembers)) { CachedDecompiledMember cachedDecompiledMember = this.cacheService.GetDecompiledMemberFromCache(body.Method, this.language, this.renameInvalidMembers); return cachedDecompiledMember.Member.Statement as BlockStatement; } //Performance improvement ControlFlowGraph cfg = new ControlFlowGraphBuilder(body.Method).CreateGraph(); if (cfg.Blocks.Length > 2) { return null; } BlockStatement block; try { DecompilationPipeline pipeline; DecompilationContext decompilationContext = new DecompilationContext(new MethodSpecificContext(body), this.typeContext ?? new TypeSpecificContext(body.Method.DeclaringType), this.language); if (!needDecompiledMember) { decompilationContext.MethodContext.EnableEventAnalysis = false; } pipeline = new DecompilationPipeline(BaseLanguage.IntermediateRepresenationPipeline.Steps, decompilationContext); context = pipeline.Run(body, this.language); block = pipeline.Body; } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(body.Method); block = new BlockStatement(); block.AddStatement(new ExceptionStatement(ex, body.Method)); OnExceptionThrown(ex); } return block; }