public BlockStatement Process(DecompilationContext context, BlockStatement body)
 {
     theRebuilder = new AnonymousDelegateRebuilder(context, body);
     VisitBlockStatement(body);
     theRebuilder.CleanUpVariableCopyAssignments();
     return body;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement block)
		{
			this.context = context;
			fixer = new SwitchByStringFixer(context.MethodContext.Method.Module.TypeSystem);
			Visit(block);
			return block;
		}
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{		
			MethodDefinition method = context.MethodContext.Method;
			if (method.IsGetter || method.IsSetter)
			{
				PropertyDefinition property;
				if (!context.TypeContext.MethodToPropertyMap.TryGetValue(method, out property))
				{
					throw new Exception("PropertyDefinition not found in method to property map.");
				}

				if (property.ShouldStaySplit())
				{
					string methodDefinitionNewName = Constants.JustDecompileGenerated + "_" + method.Name;
					context.TypeContext.MethodDefinitionToNameMap.Add(method, methodDefinitionNewName);

					FieldDefinition backingField = Utilities.GetCompileGeneratedBackingField(property);
					if (backingField != null)
					{
						string backingFieldNewName = backingField.Name.Replace("<" + property.Name + ">", Constants.JustDecompileGenerated + "_" + property.Name + "_");
						if (!context.TypeContext.BackingFieldToNameMap.ContainsKey(backingField))
						{
							context.TypeContext.BackingFieldToNameMap.Add(backingField, backingFieldNewName);
						}
					}
				}
			}

			return body;
		}
 public FilterMethodToBeDecompiled(MethodDefinition method, CatchClause catchClause, DecompilationContext context, BlockStatement block)
 {
     this.Method = method;
     this.CatchClause = catchClause;
     this.Context = context;
     this.Block = block;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			MethodDefinition method = context.MethodContext.Method;
			if (method.Name == "Finalize" && method.IsVirtual)
			{
				if (body.Statements.Count == 1 && body.Statements[0] is TryStatement)
				{
					TryStatement tryFinally = body.Statements[0] as TryStatement;

					if (tryFinally.Finally != null && tryFinally.Finally.Body.Statements.Count == 1 && tryFinally.Finally.Body.Statements[0] is ExpressionStatement)
					{
						ExpressionStatement finallyStatementExpressionStatement = tryFinally.Finally.Body.Statements[0] as ExpressionStatement;

						if (finallyStatementExpressionStatement.Expression is MethodInvocationExpression)
						{
							MethodDefinition baseDestructor = (finallyStatementExpressionStatement.Expression as MethodInvocationExpression).MethodExpression.MethodDefinition;

							if (baseDestructor != null)
							{
								if (baseDestructor.Name == "Finalize" && baseDestructor.DeclaringType.FullName == method.DeclaringType.BaseType.FullName)
								{
									context.MethodContext.IsDestructor = true;
									context.MethodContext.DestructorStatements = new BlockStatement() { Statements = tryFinally.Try.Statements };
								}
							}
						}
					}

				}
			}

			return body;
		}
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
			this.decompiledMethodReturnType = context.MethodContext.Method.ReturnType;
			Visit(body);
			return body;
		}
 /// <summary>
 /// The entry point for the step.
 /// </summary>
 /// <param name="context">The decompilation context.</param>
 /// <param name="body">The body of the method.</param>
 /// <returns>Returns the updated body of the method.</returns>
 public BlockStatement Process(DecompilationContext context, BlockStatement body)
 {
     MethodSpecificContext methodContext = context.MethodContext;
     foreach (int key in methodContext.Expressions.BlockExpressions.Keys)
     {
         IList<Expression> expressionList = methodContext.Expressions.BlockExpressions[key];
         Code lastInstructionCode = methodContext.ControlFlowGraph.InstructionToBlockMapping[key].Last.OpCode.Code;
         bool endsWithConditionalJump = lastInstructionCode == Code.Brtrue || lastInstructionCode == Code.Brtrue_S ||
                                        lastInstructionCode == Code.Brfalse || lastInstructionCode == Code.Brfalse_S;
         for (int i = 0; i < expressionList.Count; i++)
         {
             expressionList[i] = (Expression)Visit(expressionList[i]);
         }
         if (endsWithConditionalJump)
         {
             expressionList[expressionList.Count - 1] = (Expression)
                 FixBranchingExpression(expressionList[expressionList.Count - 1], methodContext.ControlFlowGraph.InstructionToBlockMapping[key].Last);
         }
         //if (lastInstructionCode == Code.Switch)
         //{
         //    //the type of this expression is needed if the switch instruction causes IrregularSwitchLC
         //    //so that correct expressions can be produced for case's conditions
         //    //Expression lastExpression = expressionList[expressionList.Count - 1];
         //}
     }
     return body;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement block)
		{
            this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
			this.context = context;
            BlockStatement newBlock = (BlockStatement)VisitBlockStatement(block);
            return newBlock;
		}
 public Ast.Statements.BlockStatement Process(DecompilationContext context, Ast.Statements.BlockStatement body)
 {
     this.decompilationContext = context;
     this.theCFG = context.MethodContext.ControlFlowGraph;
     ProcessTheControlFlowGraph();
     return body;
 }
 public BlockStatement Process(DecompilationContext context, BlockStatement body)
 {
     this.context = context;
     this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
     InsertTopLevelParameterAssignments(body);
     return body;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
        {
            this.methodContext = context.MethodContext;

            Visit(body);

            return body;
        }
Exemplo n.º 12
0
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.context = context;
            this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
            this.patternsContext = new CodePatternsContext(body);
			body = (BlockStatement)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.context = context;
			this.theBody = body;
			Visit((ICodeNode)body);
			CleanUpUnusedDeclarations();
			return body;
		}
 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 BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.context = context;
			Visit(body);
            if(this.context.MethodContext.CtorInvokeExpression != null)
            {
                Visit(this.context.MethodContext.CtorInvokeExpression);
            }
			return body;
		}
 public BlockStatement Process(DecompilationContext context, BlockStatement body)
 {
     this.context = context;
     this.fieldsToRemove = new Dictionary<FieldDefinition, Expression>();
     this.variablesToRemove = new Dictionary<VariableReference, Expression>();
     this.initializationsToRemove = new Dictionary<VariableReference, Statement>();
     BlockStatement result = (BlockStatement)Visit(body);
     RemoveInitializations();
     return result;
 }
        public BlockDecompilationPipeline(IEnumerable<IDecompilationStep> steps, DecompilationContext context)
            : base(steps)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.Context = context;
        }
        public BlockStatement Process(DecompilationContext context, BlockStatement body)
        {
            TypeSystem typeSystem = context.MethodContext.Method.Module.TypeSystem;
            this.operatorStep = new OperatorStep(this, typeSystem);
            this.removePIDStep = new RemovePrivateImplementationDetailsStep(typeSystem);
            this.rebuildEventsStep = new RebuildEventsStep(typeSystem);
            this.propertyRecognizer = new PropertyRecognizer(typeSystem, context.TypeContext, Language);
            this.rebuildAnonymousInitializersStep = new RebuildAnonymousTypesInitializersStep(this, typeSystem);
			this.fixSwitchConditionStep = new FixSwitchConditionStep(context);
            return (BlockStatement)VisitBlockStatement(body);
        }
        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.decompilationContext = context;
     if (Match(body.Statements))
     {
         body.Statements = newStatements;
         body = (BlockStatement)Visit(body);
         RemoveLastIfYieldBreak(body.Statements);
         return body;
     }
     return body;
 }
        public BlockStatement Process(DecompilationContext context, BlockStatement body)
        {
            if (!context.MethodContext.Body.ExceptionHandlers.Any(eh => eh.HandlerType == ExceptionHandlerType.Filter))
            {
                return body;
            }

            this.context = context;
            body = (BlockStatement)Visit(body);
            RemoveVariablesUsedOnlyInFilters();
            DecompileMethods();
            return body;
        }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			NotSupportedUnaryOperatorFinder notSupportedUnaryOperatorFinder = new NotSupportedUnaryOperatorFinder();

			notSupportedUnaryOperatorFinder.Visit(body);

			if (notSupportedUnaryOperatorFinder.IsAddressUnaryOperatorFound)
			{
				throw new ArgumentException(string.Format("The unary opperator {0} is not supported in VisualBasic", notSupportedUnaryOperatorFinder.FoundUnaryOperator));
			}

			return body;
		}
        public BlockStatement Process(DecompilationContext context, BlockStatement body)
        {
            this.context = context;

            VisitExpressions();

            TransformExpressions(new VariableReplacer(variableToAssignExpression));
            TransformExpressions(new Dereferencer());

            RemoveVariablesFromContext();

            return body;
        }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			DependsOnAnalysisVisitor visitor = new DependsOnAnalysisVisitor(context.MethodContext.AnalysisResults.TypesDependingOn, context.MethodContext.AnalysisResults.AmbiguousCastsToObject);
			visitor.Visit(body);
			if(context.TypeContext.AssignmentData != null)
			{
				foreach (InitializationAssignment fieldAsssignment in context.TypeContext.AssignmentData.Values)
				{
					visitor.Visit(fieldAsssignment.AssignmentExpression);
				}
			}
			return body;
		}
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
			this.decompiledMethodReturnType = context.MethodContext.Method.ReturnType;
			Visit(body);

			if (context.MethodContext.CtorInvokeExpression != null)
			{
				Visit(context.MethodContext.CtorInvokeExpression);
			}

			return body;
		}
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			MethodDefinition method = context.MethodContext.Method;

			if (!method.IsUnsafe && method.HasBody && IsUnsafe(method.Body.Instructions))
			{
				UnsafeBlockStatement unsafeStatement = new UnsafeBlockStatement(body.Statements);
				body.Statements = new StatementCollection();
				body.AddStatement(unsafeStatement);
			}

			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;
        }
Exemplo n.º 31
0
        public static BlockStatement Decompile(this MethodBody body, ILanguage language, out DecompilationContext context, TypeSpecificContext typeContext = null)
        {
            DecompilationPipeline pipeline;
            if (typeContext != null)
            {
                pipeline = language.CreatePipeline(new DecompilationContext(new MethodSpecificContext(body), typeContext, language));
            }
            else
            {
                pipeline = language.CreatePipeline();
            }

            return RunPipeline(pipeline, language, body, out context);
        }
Exemplo n.º 32
0
 internal static BlockStatement DecompileLambda(this MethodBody body, ILanguage language, DecompilationContext context)
 {
     MethodDefinition method = null;
     if (body != null)
     {
         method = body.Method;
     }
     DecompilationPipeline pipeline = language.CreateLambdaPipeline(context);
     return RunPipeline(pipeline, language, body, out context);
 }
Exemplo n.º 33
0
 public DecompilationPipeline(IEnumerable <IDecompilationStep> steps, DecompilationContext context)
 {
     this.Context = context;
     this.steps   = new List <IDecompilationStep>(steps);
 }
Exemplo n.º 34
0
 static BlockStatement RunPipeline(DecompilationPipeline pipeline, ILanguage language, MethodBody body, out DecompilationContext context)
 {
     context = pipeline.Run(body, language);
     return(pipeline.Body);
 }
Exemplo n.º 35
0
        public static BlockStatement Decompile(this MethodBody body, ILanguage language, out DecompilationContext context, TypeSpecificContext typeContext = null)
        {
            MethodDefinition method = null;

            if (body != null)
            {
                method = body.Method;
            }

            DecompilationPipeline pipeline;

            if (typeContext != null)
            {
                pipeline = language.CreatePipeline(method, new DecompilationContext(new MethodSpecificContext(body), typeContext));
            }
            else
            {
                pipeline = language.CreatePipeline(method);
            }

            return(RunPipeline(pipeline, language, body, out context));
        }
Exemplo n.º 36
0
        internal static BlockStatement DecompileAsyncStateMachine(this MethodBody body, DecompilationContext enclosingContext,
            out AsyncData asyncData)
        {
            DecompilationContext decompilationContext;
            BlockStatement theBlockStatement = body.DecompileStateMachine(enclosingContext, new RemoveAsyncStateMachineStep(),
                (DecompilationContext context) => context.MethodContext.AsyncData, out decompilationContext);

            asyncData = decompilationContext.MethodContext.AsyncData;
            return theBlockStatement;
        }
Exemplo n.º 37
0
        /// <summary>
        /// Decompiles <paramref name="body"/>, using the preset <paramref name="context"/>.
        /// </summary>
        /// <param name="body">The body of the method, to be decompiled.</param>
        /// <param name="language">The language to which is decompiled.</param>
        /// <param name="context">The context for the decompilation.</param>
        /// <returns>Returns the expression-statement tree, representing the decompiled method.</returns>
        public static BlockStatement Decompile(this MethodBody body, ILanguage language, DecompilationContext context)
        {
            MethodDefinition method = null;

            if (body != null)
            {
                method = body.Method;
            }
            DecompilationPipeline pipeline = language.CreatePipeline(method, context);

            return(RunPipeline(pipeline, language, body, out context));
        }