• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DecompilerContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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.CreateDependencyGraph(method);
			ta.IdentifySingleLoadVariables();
			ta.RunInference();
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:11,代码来源:TypeAnalysis.cs


示例17: RunTransformationsUntil

		public static void RunTransformationsUntil(AstNode node, Predicate<IAstTransform> abortCondition, DecompilerContext context)
		{
			if (node == null)
				return;
			
			foreach (var transform in CreatePipeline(context)) {
				context.CancellationToken.ThrowIfCancellationRequested();
				if (abortCondition != null && abortCondition(transform))
					return;
				transform.Run(node);
			}
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:12,代码来源:TransformationPipeline.cs


示例18: RunTransformationsUntil

		public static void RunTransformationsUntil(AstNode node, Predicate<IAstTransform> abortCondition, DecompilerContext context)
		{
			if (node == null)
				return;
			
			foreach (var transform in CreatePipeline(context)) {
				context.VerifyProgress();
				if (abortCondition != null && abortCondition(transform))
					return;
				transform.Run(node);
			}
		}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:12,代码来源:TransformationPipeline.cs


示例19: Run

		public static void Run(DecompilerContext context, ILBlock method)
		{
			PeepholeTransforms transforms = new PeepholeTransforms();
			transforms.context = context;
			transforms.method = method;
			
			PeepholeTransform[] blockTransforms = {
				ArrayInitializers.Transform(method),
				transforms.CachedDelegateInitialization
			};
			Func<ILExpression, ILExpression>[] exprTransforms = {
				EliminateDups,
				HandleDecimalConstants
			};
			// Traverse in post order so that nested blocks are transformed first. This is required so that
			// patterns on the parent block can assume that all nested blocks are already transformed.
			foreach (var node in TreeTraversal.PostOrder<ILNode>(method, c => c != null ? c.GetChildren() : null)) {
				ILBlock block = node as ILBlock;
				ILExpression expr;
				if (block != null) {
					// go through the instructions in reverse so that transforms can build up nested structures inside-out
					for (int i = block.Body.Count - 1; i >= 0; i--) {
						context.CancellationToken.ThrowIfCancellationRequested();
						expr = block.Body[i] as ILExpression;
						if (expr != null) {
							// apply expr transforms to top-level expr in block
							foreach (var t in exprTransforms)
								expr = t(expr);
							block.Body[i] = expr;
						}
						// apply block transforms
						foreach (var t in blockTransforms) {
							t(block, ref i);
							Debug.Assert(i <= block.Body.Count && i >= 0);
							if (i == block.Body.Count) // special case: retry all transforms
								break;
						}
					}
				}
				expr = node as ILExpression;
				if (expr != null) {
					// apply expr transforms to all arguments
					for (int i = 0; i < expr.Arguments.Count; i++) {
						ILExpression arg = expr.Arguments[i];
						foreach (var t in exprTransforms)
							arg = t(arg);
						expr.Arguments[i] = arg;
					}
				}
			}
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:51,代码来源:PeepholeTransform.cs


示例20: SimpleControlFlow

		public SimpleControlFlow(DecompilerContext context, ILBlock method)
		{
			this.context = context;
			this.typeSystem = context.CurrentMethod.Module.TypeSystem;
			
			foreach(ILLabel target in method.GetSelfAndChildrenRecursive<ILExpression>(e => e.IsBranch()).SelectMany(e => e.GetBranchTargets())) {
				labelGlobalRefCount[target] = labelGlobalRefCount.GetOrDefault(target) + 1;
			}
			foreach(ILBasicBlock bb in method.GetSelfAndChildrenRecursive<ILBasicBlock>()) {
				foreach(ILLabel label in bb.GetChildren().OfType<ILLabel>()) {
					labelToBasicBlock[label] = bb;
				}
			}
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:14,代码来源:SimpleControlFlow.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DecoratedScrolledWindow类代码示例发布时间:2022-05-24
下一篇:
C# DecompilationOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap