当前位置: 首页>>代码示例>>C#>>正文


C# DecompilerContext类代码示例

本文整理汇总了C#中DecompilerContext的典型用法代码示例。如果您正苦于以下问题:C# DecompilerContext类的具体用法?C# DecompilerContext怎么用?C# DecompilerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DecompilerContext类属于命名空间,在下文中一共展示了DecompilerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

		public static void Run(DecompilerContext context, ILBlock method, List<ILNode> list_ILNode, Func<ILBlock, ILInlining> getILInlining)
		{
			if (!context.Settings.YieldReturn)
				return; // abort if enumerator decompilation is disabled
			var yrd = new YieldReturnDecompiler();
			yrd.context = context;
			if (!yrd.MatchEnumeratorCreationPattern(method))
				return;
			yrd.enumeratorType = yrd.enumeratorCtor.DeclaringType;
			#if DEBUG && CRASH_IN_DEBUG_MODE
			if (Debugger.IsAttached) {
				yrd.Run();
			} else {
				#endif
				try {
					yrd.Run();
				} catch (SymbolicAnalysisFailedException) {
					return;
				}
				#if DEBUG && CRASH_IN_DEBUG_MODE
			}
			#endif
			method.Body.Clear();
			method.EntryGoto = null;
			method.Body.AddRange(yrd.newBody);//TODO: Make sure that the removed ILRanges from Clear() above is saved in the new body
			
			// Repeat the inlining/copy propagation optimization because the conversion of field access
			// to local variables can open up additional inlining possibilities.
			var inlining = getILInlining(method);
			inlining.InlineAllVariables();
			inlining.CopyPropagation(list_ILNode);
		}
开发者ID:levisre,项目名称:dnSpy,代码行数:32,代码来源:YieldReturnDecompiler.cs

示例2: RunStep1

		public static void RunStep1(DecompilerContext context, ILBlock method)
		{
			if (!context.Settings.AsyncAwait)
				return; // abort if async decompilation is disabled
			var yrd = new AsyncDecompiler();
			yrd.context = context;
			if (!yrd.MatchTaskCreationPattern(method))
				return;
			#if DEBUG
			if (Debugger.IsAttached) {
				yrd.Run();
			} else {
				#endif
				try {
					yrd.Run();
				} catch (SymbolicAnalysisFailedException) {
					return;
				}
				#if DEBUG
			}
			#endif
			context.CurrentMethodIsAsync = true;
			
			method.Body.Clear();
			method.EntryGoto = null;
			method.Body.AddRange(yrd.newTopLevelBody);
			ILAstOptimizer.RemoveRedundantCode(method);
		}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:28,代码来源:AsyncDecompiler.cs

示例3: Run

		public static void Run(DecompilerContext context, ILBlock method)
		{
			if (!context.Settings.YieldReturn)
				return; // abort if enumerator decompilation is disabled
			var yrd = new YieldReturnDecompiler();
			yrd.context = context;
			if (!yrd.MatchEnumeratorCreationPattern(method))
				return;
			yrd.enumeratorType = yrd.enumeratorCtor.DeclaringType;
			#if DEBUG
			if (Debugger.IsAttached) {
				yrd.Run();
			} else {
				#endif
				try {
					yrd.Run();
				} catch (YieldAnalysisFailedException) {
					return;
				}
				#if DEBUG
			}
			#endif
			method.Body.Clear();
			method.EntryGoto = null;
			method.Body.AddRange(yrd.newBody);
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:26,代码来源:YieldReturnDecompiler.cs

示例4: CreateMethodBody

		HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
		
		public static BlockStatement CreateMethodBody(MethodDefinition methodDef, DecompilerContext context)
		{
			MethodDefinition oldCurrentMethod = context.CurrentMethod;
			Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
			context.CurrentMethod = methodDef;
			try {
				AstMethodBodyBuilder builder = new AstMethodBodyBuilder();
				builder.methodDef = methodDef;
				builder.context = context;
				builder.typeSystem = methodDef.Module.TypeSystem;
				if (Debugger.IsAttached) {
					return builder.CreateMethodBody();
				} else {
					try {
						return builder.CreateMethodBody();
					} catch (OperationCanceledException) {
						throw;
					} catch (Exception ex) {
						throw new ICSharpCode.Decompiler.DecompilerException(methodDef, ex);
					}
				}
			} finally {
				context.CurrentMethod = oldCurrentMethod;
			}
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:27,代码来源:AstMethodBodyBuilder.cs

示例5: Run

		public static void Run(DecompilerContext context, ILBlock method)
		{
			if (!context.Settings.YieldReturn)
				return; // abort if enumerator decompilation is disabled
			var yrd = new YieldReturnDecompiler();
			yrd.context = context;
			if (!yrd.MatchEnumeratorCreationPattern(method))
				return;
			yrd.enumeratorType = yrd.enumeratorCtor.DeclaringType;
			#if DEBUG
			if (Debugger.IsAttached) {
				yrd.Run();
			} else {
				#endif
				try {
					yrd.Run();
				} catch (SymbolicAnalysisFailedException) {
					return;
				}
				#if DEBUG
			}
			#endif
			method.Body.Clear();
			method.EntryGoto = null;
			method.Body.AddRange(yrd.newBody);
			
			// Repeat the inlining/copy propagation optimization because the conversion of field access
			// to local variables can open up additional inlining possibilities.
			ILInlining inlining = new ILInlining(method);
			inlining.InlineAllVariables();
			inlining.CopyPropagation();
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:32,代码来源:YieldReturnDecompiler.cs

示例6: Run

 public static void Run(DecompilerContext context, AstBlock method)
 {
     var ta = new TypeAnalysis(context);
     ta.CreateDependencyGraph(method);
     ta.IdentifySingleLoadVariables();
     ta.RunInference();
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:7,代码来源:TypeAnalysis.cs

示例7: RunTransformationsUntil

        public static void RunTransformationsUntil(AstNode node, Predicate<IAstTransform> abortCondition, DecompilerContext context)
        {
            if (node == null)
                return;
            for (int i = 0; i < 4; i++) {
                context.CancellationToken.ThrowIfCancellationRequested();
                if (Options.ReduceAstJumps) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
                    node.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
                }
                if (Options.ReduceAstLoops) {
                    node.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
                }
                if (Options.ReduceAstOther) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
                }
            }

            foreach (var transform in CreatePipeline(context)) {
                context.CancellationToken.ThrowIfCancellationRequested();
                if (abortCondition != null && abortCondition(transform))
                    return;
                transform.Run(node);
            }
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:25,代码来源:TransformationPipeline.cs

示例8: CreateMethodBody

		HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
		
		/// <summary>
		/// Creates the body for the method definition.
		/// </summary>
		/// <param name="methodDef">Method definition to decompile.</param>
		/// <param name="context">Decompilation context.</param>
		/// <param name="parameters">Parameter declarations of the method being decompiled.
		/// These are used to update the parameter names when the decompiler generates names for the parameters.</param>
		/// <param name="localVariables">Local variables storage that will be filled/updated with the local variables.</param>
		/// <returns>Block for the method body</returns>
		public static BlockStatement CreateMethodBody(MethodDefinition methodDef,
		                                              DecompilerContext context,
		                                              IEnumerable<ParameterDeclaration> parameters = null,
		                                              ConcurrentDictionary<int, IEnumerable<ILVariable>> localVariables = null)
		{
			if (localVariables == null)
				localVariables = new ConcurrentDictionary<int, IEnumerable<ILVariable>>();
			
			MethodDefinition oldCurrentMethod = context.CurrentMethod;
			Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
			context.CurrentMethod = methodDef;
			try {
				AstMethodBodyBuilder builder = new AstMethodBodyBuilder();
				builder.methodDef = methodDef;
				builder.context = context;
				builder.typeSystem = methodDef.Module.TypeSystem;
				if (Debugger.IsAttached) {
					return builder.CreateMethodBody(parameters, localVariables);
				} else {
					try {
						return builder.CreateMethodBody(parameters, localVariables);
					} catch (OperationCanceledException) {
						throw;
					} catch (Exception ex) {
						throw new ICSharpCode.Decompiler.DecompilerException(methodDef, ex);
					}
				}
			} finally {
				context.CurrentMethod = oldCurrentMethod;
			}
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:42,代码来源:AstMethodBodyBuilder.cs

示例9: CreateMethodBody

		HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
		
		/// <summary>
		/// Creates the body for the method definition.
		/// </summary>
		/// <param name="methodDef">Method definition to decompile.</param>
		/// <param name="context">Decompilation context.</param>
		/// <param name="parameters">Parameter declarations of the method being decompiled.
		/// These are used to update the parameter names when the decompiler generates names for the parameters.</param>
		/// <returns>Block for the method body</returns>
		public static BlockStatement CreateMethodBody(MethodDef methodDef,
		                                              DecompilerContext context,
		                                              IEnumerable<ParameterDeclaration> parameters,
													  out MemberMapping mm)
		{
			MethodDef oldCurrentMethod = context.CurrentMethod;
			Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
			context.CurrentMethod = methodDef;
			context.CurrentMethodIsAsync = false;
			try {
				AstMethodBodyBuilder builder = new AstMethodBodyBuilder();
				builder.methodDef = methodDef;
				builder.context = context;
				builder.corLib = methodDef.Module.CorLibTypes;
				if (Debugger.IsAttached) {
					return builder.CreateMethodBody(parameters, out mm);
				} else {
					try {
						return builder.CreateMethodBody(parameters, out mm);
					} catch (OperationCanceledException) {
						throw;
					} catch (Exception ex) {
						throw new ICSharpCode.Decompiler.DecompilerException(methodDef, ex);
					}
				}
			} finally {
				context.CurrentMethod = oldCurrentMethod;
			}
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:39,代码来源:AstMethodBodyBuilder.cs

示例10: DecompileMethod

		public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
		{
			if (!method.HasBody) {
				return;
			}
			
			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			ilMethod.Body = astBuilder.Build(method, inlineVariables);
			
			if (abortBeforeStep != null) {
				DecompilerContext context = new DecompilerContext { CurrentType = method.DeclaringType, CurrentMethod = method };
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			var allVariables = astBuilder.Variables
				.Concat(ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable).Where(v => v != null)).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(v.Name, v);
				if (v.Type != null) {
					output.Write(" : ");
					v.Type.WriteTo(output, true, true);
				}
				output.WriteLine();
			}
			output.WriteLine();
			
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output);
				output.WriteLine();
			}
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:32,代码来源:ILAstLanguage.cs

示例11: TryConvert

		public static Expression TryConvert(DecompilerContext context, Expression expr)
		{
			Expression converted = new ExpressionTreeConverter(context).Convert(expr);
			if (converted != null) {
				converted.AddAnnotation(new ExpressionTreeLambdaAnnotation());
			}
			return converted;
		}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:8,代码来源:ExpressionTreeConverter.cs

示例12: RunOnCore

        static void RunOnCore()
        {
            Console.Write("Dry run...");
            DateTime startDryRun = DateTime.UtcNow;
            {
                var _para = new ReaderParameters(ReadingMode.Immediate)
                {
                    AssemblyResolver = new AssemblyResolver(),
                    ReadSymbols = false
                };
                var sys = AssemblyDefinition.ReadAssembly(typeof(TestingLogic).Assembly.Location, _para);
                var _dc = new DecompilerContext(sys.MainModule);
                var _astb = new AstBuilder(_dc);
                _astb.AddAssembly(sys);
                _astb.RunTransformations();
                _astb.GenerateCode(new DummyOutput());
            }
            TimeSpan dryRunTime = DateTime.UtcNow - startDryRun;
            Console.WriteLine(" O.K. " + dryRunTime.TotalSeconds.ToString("0.000") + " s.");

            Console.Write("Press Esc to skip large assembly reading");
            if (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                Console.Write("Reading assembly...");
                DateTime startReading = DateTime.UtcNow;
                var msco = AssemblyDefinition.ReadAssembly(typeof(int).Assembly.Location);
                TimeSpan readAssemblyTime = DateTime.UtcNow - startReading;
                Console.WriteLine(" O.K. " + readAssemblyTime.TotalSeconds.ToString("0.000") + " s.");

                Console.Write("new DecompilerContext(), new AstBuilder()...");
                DateTime startNewContext = DateTime.UtcNow;
                var dc = new DecompilerContext(msco.MainModule);
                var astb = new AstBuilder(dc);
                TimeSpan newContextTime = DateTime.UtcNow - startNewContext;
                Console.WriteLine(" O.K. " + newContextTime.TotalSeconds.ToString("0.000") + " s.");

                Console.Write("AstBuilder.AddAssembly()...");
                DateTime startAddAssembly = DateTime.UtcNow;
                astb.AddAssembly(msco);
                TimeSpan decompilerInitTime = DateTime.UtcNow - startAddAssembly;
                Console.WriteLine(" O.K. " + decompilerInitTime.TotalSeconds.ToString("0.000") + " s.");

                Console.Write("AstBuilder.RunTransformations()...");
                DateTime startTransform = DateTime.UtcNow;
                astb.RunTransformations();
                TimeSpan transformTime = DateTime.UtcNow - startTransform;
                Console.WriteLine(" O.K. " + transformTime.TotalSeconds.ToString("0.000") + " s.");

                Console.Write("AstBuilder.GenerateCode()...");
                DateTime startGeneration = DateTime.UtcNow;
                astb.GenerateCode(new DummyOutput());
                TimeSpan generationTime = DateTime.UtcNow - startGeneration;
                Console.WriteLine(" O.K. " + generationTime.TotalSeconds.ToString("0.000") + " s.");

                Console.Write("Press any key to exit"); Console.ReadKey();
            }
        }
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:57,代码来源:TestingLogic.cs

示例13: TextTokenWriter

		public TextTokenWriter(ITextOutput output, DecompilerContext context)
		{
			if (output == null)
				throw new ArgumentNullException("output");
			if (context == null)
				throw new ArgumentNullException("context");
			this.output = output;
			this.context = context;
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:9,代码来源:TextTokenWriter.cs

示例14: CreatePipeline

		public static IAstTransform[] CreatePipeline(DecompilerContext context)
		{
			return new IAstTransform[] {
				new PushNegation(),
				new DelegateConstruction(context),
				new PatternStatementTransform(),
				new ConvertConstructorCallIntoInitializer(),
				new ReplaceMethodCallsWithOperators(),
			};
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:10,代码来源:TransformationPipeline.cs

示例15: Run

		public static void Run(DecompilerContext context, ILBlock method)
		{
			TypeAnalysis ta = new TypeAnalysis();
			ta.context = context;
			ta.module = context.CurrentMethod.Module;
			ta.typeSystem = ta.module.TypeSystem;
			ta.method = method;
			ta.InferTypes(method);
			ta.InferRemainingStores();
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:10,代码来源:TypeAnalysis.cs


注:本文中的DecompilerContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。