private BlockStatement DecompileMethod(MethodBody body, out MethodSpecificContext methodContext) { methodContext = null; try { stackVariable3 = new MethodSpecificContext(body); stackVariable5 = this.typeContext; if (stackVariable5 == null) { dummyVar0 = stackVariable5; stackVariable5 = new TypeSpecificContext(body.get_Method().get_DeclaringType()); } V_1 = new DecompilationContext(stackVariable3, stackVariable5, this.language); V_2 = this.language.CreatePipeline(V_1); methodContext = V_2.Run(body, this.language).get_MethodContext(); V_0 = V_2.get_Body(); } catch (Exception exception_0) { V_3 = exception_0; this.get_ExceptionsWhileDecompiling().Add(body.get_Method()); methodContext = new MethodSpecificContext(body); V_0 = new BlockStatement(); V_0.AddStatement(new ExceptionStatement(V_3, body.get_Method())); this.OnExceptionThrown(V_3); } return(V_0); }
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 BlockStatement FinishDecompilationOfMethod(BlockStatement block, DecompilationContext context, out MethodSpecificContext methodContext) { methodContext = null; BlockStatement fullyDecompiledBlock; try { BlockDecompilationPipeline pipeline = this.language.CreatePropertyPipeline(context.MethodContext.Method, context); methodContext = pipeline.Run(context.MethodContext.Method.Body, block, this.language).MethodContext; fullyDecompiledBlock = pipeline.Body; } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(context.MethodContext.Method); methodContext = new MethodSpecificContext(context.MethodContext.Method.Body); fullyDecompiledBlock = new BlockStatement(); fullyDecompiledBlock.AddStatement(new ExceptionStatement(ex, context.MethodContext.Method)); OnExceptionThrown(ex); } return(fullyDecompiledBlock); }
public VariableInliningPattern(CodePatternsContext patternsContext, MethodSpecificContext methodContext, IVariablesToNotInlineFinder finder) : base(patternsContext, methodContext.Method.Module.TypeSystem) { this.methodContext = methodContext; this.inliner = new RestrictedVariableInliner(typeSystem); this.finder = finder; }
private DecompilationContext GetNewContext(MethodBody body) { MethodSpecificContext methodSpecificContext = new MethodSpecificContext(body); TypeSpecificContext typeSpecificContext = new TypeSpecificContext(body.Method.DeclaringType); return(new DecompilationContext(methodSpecificContext, typeSpecificContext)); }
public Ast.Statements.BlockStatement Process(Decompiler.DecompilationContext context, Ast.Statements.BlockStatement body) { this.methodContext = context.MethodContext; mappedInstructions.UnionWith(body.UnderlyingSameMethodInstructions); Visit(body); return body; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { this.methodContext = context.MethodContext; ClearState(); this.foreachBody = new BlockStatement(); Visit(body); return body; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { this.methodContext = context.MethodContext; Visit(body); return body; }
public UsageBasedExpressionFixer(MethodSpecificContext methodContext) { this.methodContext = methodContext; TypeReference returnType = methodContext.Method.ReturnType; this.currentTypeSystem = methodContext.Method.Module.TypeSystem; this.isBoolReturnType = returnType.FullName == currentTypeSystem.Boolean.FullName; this.isCharReturnType = returnType.FullName == currentTypeSystem.Char.FullName; }
internal void AddInnerMethodParametersToContext(MethodSpecificContext innerMethodContext) { this.ParameterDefinitionToNameMap.AddRange(innerMethodContext.ParameterDefinitionToNameMap); foreach (ParameterDefinition parameter in innerMethodContext.Method.Parameters) { this.ParameterDefinitionToNameMap[parameter] = parameter.Name; } }
public DecompilationContext(MethodSpecificContext methodContext, TypeSpecificContext typeContext, ModuleSpecificContext moduleContext, AssemblySpecificContext assemblyContext, ILanguage language) { this.MethodContext = methodContext; this.TypeContext = typeContext; this.ModuleContext = moduleContext; this.AssemblyContext = assemblyContext; this.Language = language; this.IsStopped = false; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { methodContext = context.MethodContext; Visit(body); body = CallSiteInvocationReplacer.ReplaceInvocations(body, fieldToCallSiteInfoMap, variableToCallSiteInfoMap, statementsToRemove, methodContext.Method.Module.TypeSystem); RemoveStatements(); return body; }
public UsageBasedExpressionFixer(MethodSpecificContext methodContext) { base(); this.methodContext = methodContext; V_0 = methodContext.get_Method().get_ReturnType(); this.currentTypeSystem = methodContext.get_Method().get_Module().get_TypeSystem(); this.isBoolReturnType = String.op_Equality(V_0.get_FullName(), this.currentTypeSystem.get_Boolean().get_FullName()); this.isCharReturnType = String.op_Equality(V_0.get_FullName(), this.currentTypeSystem.get_Char().get_FullName()); return; }
public DecompilationContext(MethodSpecificContext methodContext, TypeSpecificContext typeContext, ModuleSpecificContext moduleContext, AssemblySpecificContext assemblyContext, ILanguage language) { base(); this.set_MethodContext(methodContext); this.set_TypeContext(typeContext); this.set_ModuleContext(moduleContext); this.set_AssemblyContext(assemblyContext); this.set_Language(language); this.set_IsStopped(false); return; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { this.methodContext = context.MethodContext; this.originalStatements = body.Statements; if (Match()) { body.Statements = asyncStatements; } return body; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { this.context = context.MethodContext; foreach (KeyValuePair<int, IList<Expression>> blockPair in context.MethodContext.Expressions.BlockExpressions) { parentExpressions.Clear(); foreach (Expression expr in blockPair.Value) { Visit(expr); } } return body; }
public virtual BlockStatement Process(DecompilationContext context, BlockStatement block) { this.methodContext = context.MethodContext; this.typeContext = context.TypeContext; //this.suggestedNames.UnionWith(methodContext.UsedNames); //this.suggestedNames.UnionWith(context.VariableNames); Preprocess(); VisitBlockStatement(block); ReplaceDeclarations(block); //this.methodContext.UsedNames.UnionWith(suggestedNames); CollectVariableNames(); return block; }
public Ast.Statements.BlockStatement Process(DecompilationContext context, Ast.Statements.BlockStatement body) { this.moveNextMethodContext = context.MethodContext; this.theCFG = this.moveNextMethodContext.ControlFlowGraph; moveNextMethodContext.IsMethodBodyChanged = true; StateMachineUtilities.FixInstructionConnections(theCFG.Blocks); if (!ProcessCFG()) { ((BaseLanguage)Language).StopPipeline(); } return body; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { if (!context.MethodContext.Method.IsConstructor || body.Statements.Count == 0) { return body; } this.methodContext = context.MethodContext; this.typeSystem = methodContext.Method.Module.TypeSystem; this.methodBodyBlock = body; this.context = context; ProcessCtorInvocation(); return body; }
internal void AddInnerMethodParametersToContext(MethodSpecificContext innerMethodContext) { this.get_ParameterDefinitionToNameMap().AddRange <ParameterDefinition, string>(innerMethodContext.get_ParameterDefinitionToNameMap()); V_0 = innerMethodContext.get_Method().get_Parameters().GetEnumerator(); try { while (V_0.MoveNext()) { V_1 = V_0.get_Current(); this.get_ParameterDefinitionToNameMap().set_Item(V_1, V_1.get_Name()); } } finally { V_0.Dispose(); } return; }
private BlockStatement FinishDecompilationOfMethod(BlockStatement block, DecompilationContext context, out MethodSpecificContext methodContext) { methodContext = null; try { V_1 = this.language.CreatePropertyPipeline(context); methodContext = V_1.Run(context.get_MethodContext().get_Method().get_Body(), block, this.language).get_MethodContext(); V_0 = V_1.get_Body(); } catch (Exception exception_0) { V_2 = exception_0; this.get_ExceptionsWhileDecompiling().Add(context.get_MethodContext().get_Method()); methodContext = new MethodSpecificContext(context.get_MethodContext().get_Method().get_Body()); V_0 = new BlockStatement(); V_0.AddStatement(new ExceptionStatement(V_2, context.get_MethodContext().get_Method())); this.OnExceptionThrown(V_2); } return(V_0); }
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); }
public ClosureVariablesRemover(MethodSpecificContext methodContext) { this.methodContext = methodContext; }
private BlockStatement FinishDecompilationOfMethod(BlockStatement block, DecompilationContext context, out MethodSpecificContext methodContext) { methodContext = null; BlockStatement fullyDecompiledBlock; try { BlockDecompilationPipeline pipeline = this.language.CreatePropertyPipeline(context); methodContext = pipeline.Run(context.MethodContext.Method.Body, block, this.language).MethodContext; fullyDecompiledBlock = pipeline.Body; } catch (Exception ex) { this.ExceptionsWhileDecompiling.Add(context.MethodContext.Method); methodContext = new MethodSpecificContext(context.MethodContext.Method.Body); fullyDecompiledBlock = new BlockStatement(); fullyDecompiledBlock.AddStatement(new ExceptionStatement(ex, context.MethodContext.Method)); OnExceptionThrown(ex); } return fullyDecompiledBlock; }
public ForeachArrayMatcher(Statement statement, Statement nextStatement, MethodSpecificContext methodContext) { this.statement = statement; this.nextStatement = nextStatement; this.methodContext = methodContext; }
public DecompiledMember(string memberName, Statement statement, MethodSpecificContext context) { this.MemberFullName = memberName; this.Statement = statement; this.Context = context; }
public BlockStatement Process(DecompilationContext context, BlockStatement body) { this.methodContext = context.MethodContext; this.processStep = ProcessStep.Search; Visit(body); RemoveNonConditionVariables(); if (variables.Count > 0) { ReplaceConditionOnlyVariables(body); } this.methodContext = null; this.currentVariable = null; variables.Clear(); return body; }
private MethodSpecificContext CloneAndReplaceMethodBody(MethodSpecificContext context, MethodBody methodBody) { return new MethodSpecificContext(context.AnalysisResults, context.YieldData, context.AsyncData, context.IsMethodBodyChanged, new Dictionary<string, Statement>(context.GotoLabels), new List<GotoStatement>(context.GotoStatements), context.StackData, context.IsBaseConstructorInvokingConstructor, context.EnableEventAnalysis, methodBody, new Collection<VariableDefinition>(context.Variables), context.ControlFlowGraph, context.Expressions, context.LogicalConstructsTree, context.LogicalConstructsContext, context.CtorInvokeExpression, new Dictionary<Statement, ILogicalConstruct>(context.StatementToLogicalConstruct), new Dictionary<ILogicalConstruct, List<Statement>>(context.LogicalConstructToStatements), new Dictionary<VariableDefinition, string>(context.VariableDefinitionToNameMap), new HashSet<string>(context.VariableNamesCollection), new Dictionary<ParameterDefinition,string>(context.ParameterDefinitionToNameMap), new HashSet<VariableDefinition>(context.VariablesToRename), new Dictionary<FieldDefinition, Expression>(context.FieldToExpression), context.LambdaVariablesCount, new Dictionary<VariableDefinition, AssignmentType>(context.VariableAssignmentData), new List<ParameterDefinition>(context.OutParametersToAssign), context.IsDestructor, context.DestructorStatements, new HashSet<VariableDefinition>(context.UndeclaredLinqVariables), new Dictionary<VariableReference, Dictionary<FieldDefinition, Expression>>(context.ClosureVariableToFieldValue), new HashSet<VariableDefinition>(context.VariablesToNotDeclare)); }
public GeneratedMethod(MethodDefinition method, Statement body, MethodSpecificContext context) { this.Method = method; this.Body = body; this.Context = context; }
public override ICodeNode VisitObjectCreationExpression(ObjectCreationExpression node) { if (state == State.ReplaceDelegate && node.Arguments != null && node.Arguments.Count == 2 && node.Arguments[0].CodeNodeType == CodeNodeType.VariableReferenceExpression && node.Arguments[1].CodeNodeType == CodeNodeType.MethodReferenceExpression && delegateCopies.Contains((node.Arguments[0] as VariableReferenceExpression).Variable)) { //final check inserted here for optimization TypeDefinition objectType = node.Constructor.DeclaringType.Resolve(); if (objectType == null || objectType.BaseType == null || objectType.BaseType.FullName != "System.MulticastDelegate") { return base.VisitObjectCreationExpression(node); } MethodReference methodReference = (node.Arguments[1] as MethodReferenceExpression).Method; MethodDefinition methodDefinition = (node.Arguments[1] as MethodReferenceExpression).MethodDefinition; MethodSpecificContext delegateMethodContext = new MethodSpecificContext(methodDefinition.Body); DecompilationContext innerContext = new DecompilationContext(delegateMethodContext, context.TypeContext, context.ModuleContext, context.AssemblyContext); delegateMethodContext.FieldToExpression = fieldDefToAssignedValueMap; BlockStatement methodStatements = methodDefinition.Body.DecompileLambda(Language, innerContext); if ((methodStatements.Statements.Count == 1) && (methodStatements.Statements[0].CodeNodeType == CodeNodeType.ExpressionStatement) && ((methodStatements.Statements[0] as ExpressionStatement).Expression.CodeNodeType == CodeNodeType.ReturnExpression)) { ReturnExpression returnExpression = (methodStatements.Statements[0] as ExpressionStatement).Expression as ReturnExpression; ShortFormReturnExpression shortFormReturnExpression = new ShortFormReturnExpression(returnExpression.Value, returnExpression.MappedInstructions); methodStatements = new BlockStatement(); methodStatements.Statements.Add(new ExpressionStatement(shortFormReturnExpression)); } this.context.MethodContext.VariableDefinitionToNameMap.AddRange(innerContext.MethodContext.VariableDefinitionToNameMap); this.context.MethodContext.VariableNamesCollection.UnionWith(innerContext.MethodContext.VariableNamesCollection); this.context.MethodContext.AddInnerMethodParametersToContext(innerContext.MethodContext); this.context.MethodContext.GotoStatements.AddRange(innerContext.MethodContext.GotoStatements); this.context.MethodContext.GotoLabels.AddRange(innerContext.MethodContext.GotoLabels); ExpressionCollection expressionCollection = new ExpressionCollection(); bool hasAnonymousParamterer = LambdaExpressionsHelper.HasAnonymousParameter(methodDefinition.Parameters); foreach (ParameterDefinition parameter in methodDefinition.Parameters) { expressionCollection.Add(new LambdaParameterExpression(parameter, !hasAnonymousParamterer, null)); } delegatesFound.Add(methodStatements); LambdaExpression lambdaExpression = new LambdaExpression(expressionCollection, methodStatements, methodDefinition.IsAsync(), methodDefinition.IsFunction(), methodReference.Parameters, false, node.Arguments[1].MappedInstructions) { ExpressionType = objectType }; DelegateCreationExpression result = new DelegateCreationExpression(node.Constructor.DeclaringType, lambdaExpression, node.Arguments[0], node.MappedInstructions); return result; } return base.VisitObjectCreationExpression(node); }
public NullCoalescingPattern(CodePatternsContext patternsContext, MethodSpecificContext methodContext) : base(patternsContext, methodContext.Method.Module.TypeSystem) { this.methodContext = methodContext; }
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), this.language); DecompilationPipeline pipeline = this.language.CreatePipeline(decompilationContext); methodContext = pipeline.Run(body, this.language).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; }
public BlockStatement Process(DecompilationContext context, BlockStatement block) { this.methodContext = context.MethodContext; PopulateNotAssigned(); codeNodeTypes.Push(CodeNodeType.BlockStatement); VisitBlockStatement(block); codeNodeTypes.Pop(); BlockStatement result = ReplaceDeclarations(block); return result; }
public DecompilationContext(MethodSpecificContext methodContext, TypeSpecificContext typeContext, ILanguage language) { this(methodContext, typeContext, new ModuleSpecificContext(), new AssemblySpecificContext(), language); return; }
private DecompilationContext GetNewContext(MethodBody body, ILanguage language) { MethodSpecificContext methodSpecificContext = new MethodSpecificContext(body); TypeSpecificContext typeSpecificContext = new TypeSpecificContext(body.Method.DeclaringType); return new DecompilationContext(methodSpecificContext, typeSpecificContext, language); }
private DecompilationContext GetNewContext(MethodBody body, ILanguage language) { stackVariable1 = new MethodSpecificContext(body); V_0 = new TypeSpecificContext(body.get_Method().get_DeclaringType()); return(new DecompilationContext(stackVariable1, V_0, language)); }
public LinqQueriesRebuilder(MethodSpecificContext methodContext) { this.methodContext = methodContext; }
internal static BlockStatement DecompileAsyncStateMachine(this MethodBody body, MethodSpecificContext enclosingMethodContext, out AsyncData asyncData) { DecompilationContext decompilationContext; BlockStatement theBlockStatement = body.DecompileStateMachine(enclosingMethodContext, new RemoveAsyncStateMachineStep(), (DecompilationContext context) => context.MethodContext.AsyncData, out decompilationContext); asyncData = decompilationContext.MethodContext.AsyncData; return(theBlockStatement); }
public DecompiledMember(string memberName, Telerik.JustDecompiler.Ast.Statements.Statement statement, MethodSpecificContext context) { base(); this.set_MemberFullName(memberName); this.set_Statement(statement); this.set_Context(context); return; }