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


C# ILSpy.DecompilationOptions类代码示例

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


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

示例1: DecompileMethod

        public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            var xMethod = GetXMethodDefinition(method);
            var ilMethod = xMethod as XBuilder.ILMethodDefinition;

            CompiledMethod cmethod;

            if (ilMethod == null || !ilMethod.OriginalMethod.HasBody)
            {
                output.Write("");
                output.WriteLine("// not an il method or method without body.");
                return;
            }
            
            var methodSource = new MethodSource(xMethod, ilMethod.OriginalMethod);
            var target = (DexTargetPackage) AssemblyCompiler.TargetPackage;
            var dMethod = (MethodDefinition)xMethod.GetReference(target);
            DexMethodBodyCompiler.TranslateToRL(AssemblyCompiler, target, methodSource, dMethod, GenerateSetNextInstructionCode, out cmethod);

            var rlBody = cmethod.RLBody;

            // Optimize RL code
            string lastApplied = RLTransformations.Transform(target.DexFile, rlBody, StopOptimizationAfter == -1?int.MaxValue:StopOptimizationAfter);
            if(lastApplied != null)
                output.WriteLine("// Stop after " + lastApplied);

            PrintMethod(cmethod, output, options);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:RLLanguage.cs

示例2: 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(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(v.Name, v);
				if (v.Type != null) {
					output.Write(" : ");
					if (v.IsPinned)
						output.Write("pinned ");
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				output.WriteLine();
			}
			output.WriteLine();
			
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output);
				output.WriteLine();
			}
		}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:34,代码来源:ILAstLanguage.cs

示例3: WriteResourceToFile

		public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options)
		{
			var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.AssemblyDefinition, stream);
			fileName = Path.ChangeExtension(fileName, ".xaml");
			document.Save(Path.Combine(options.SaveAsProjectDirectory, fileName));
			return fileName;
		}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:7,代码来源:BamlResourceNodeFactory.cs

示例4: DecompileMethod

        public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ICSharpCode.Decompiler.ITextOutput output, DecompilationOptions options)
        {
            var cmethod = GetCompiledMethod(method);

            if ((cmethod != null) && (cmethod.DexMethod != null))
            {
                try
                {
                    var f = new MethodBodyDisassemblyFormatter(cmethod.DexMethod, MapFile);
                    var formatOptions = FormatOptions.EmbedSourceCode | FormatOptions.ShowJumpTargets;
                    if(ShowFullNames) formatOptions |= FormatOptions.FullTypeNames;
                    if(DebugOperandTypes) formatOptions |= FormatOptions.DebugOperandTypes;
                    
                    var s = f.Format(formatOptions);
                    output.Write(s);
                }
                catch (Exception)
                {
                    output.Write("\n\n// Formatting error. Using Fallback.\n\n");
                    FallbackFormatting(output, cmethod);    
                }
                
            }
            else
            {
                output.Write("Method not found in dex");
                output.WriteLine();
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:29,代码来源:DexLanguage.cs

示例5: Execute

		public override void Execute(object parameter)
		{
			MainWindow.Instance.TextView.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				Parallel.ForEach(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct }, delegate(LoadedAssembly asm) {
					if (!asm.HasLoadError) {
						Stopwatch w = Stopwatch.StartNew();
						Exception exception = null;
						using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) {
							try {
                                var options = new DecompilationOptions { FullDecompilation = true, CancellationToken = ct };
                                var textOutput = new Decompiler.PlainTextOutput(writer);
                                textOutput.SetIndentationString(options.DecompilerSettings.IndentString);
								new CSharpLanguage().DecompileAssembly(asm, textOutput, options);
							}
							catch (Exception ex) {
								writer.WriteLine(ex.ToString());
								exception = ex;
							}
						}
						lock (output) {
							output.Write(asm.ShortName + " - " + w.Elapsed);
							if (exception != null) {
								output.Write(" - ");
								output.Write(exception.GetType().Name);
							}
							output.WriteLine();
						}
					}
				});
				return output;
			}, ct), task => MainWindow.Instance.TextView.ShowText(task.Result));
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:33,代码来源:DecompileAllCommand.cs

示例6: DecompileAssembly

        public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options)
        {
            output.WriteLine("// " + fileName);
            output.WriteLine();

            new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).WriteAssemblyHeader(assembly);
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:7,代码来源:ILLanguage.cs

示例7: DecompileMethod

		public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
		{
			WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true));
			AstBuilder codeDomBuilder = CreateAstBuilder(options, method.DeclaringType);
			codeDomBuilder.AddMethod(method);
			codeDomBuilder.GenerateCode(output, transformAbortCondition);
		}
开发者ID:tanujmathur,项目名称:ILSpy,代码行数:7,代码来源:CSharpLanguage.cs

示例8: DecompileMethod

		public override void DecompileMethod(MethodDef method, ITextOutput output, DecompilationOptions options)
		{
			WriteComment(output, "Method: ");
			output.WriteDefinition(IdentifierEscaper.Escape(method.FullName), method, TextTokenType.Comment, false);
			output.WriteLine();

			if (!method.HasBody) {
				return;
			}
			
			StartKeywordBlock(output, ".body", method);

			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
			ilMethod.Body = astBuilder.Build(method, inlineVariables, context);
			
			if (abortBeforeStep != null) {
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}
			
			if (context.CurrentMethodIsAsync) {
				output.Write("async", TextTokenType.Keyword);
				output.Write('/', TextTokenType.Operator);
				output.WriteLine("await", TextTokenType.Keyword);
			}
			
			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.WriteDefinition(IdentifierEscaper.Escape(v.Name), v, v.IsParameter ? TextTokenType.Parameter : TextTokenType.Local);
				if (v.Type != null) {
					output.WriteSpace();
					output.Write(':', TextTokenType.Operator);
					output.WriteSpace();
					if (v.IsPinned) {
						output.Write("pinned", TextTokenType.Keyword);
						output.WriteSpace();
					}
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				if (v.IsGenerated) {
					output.WriteSpace();
					output.Write('[', TextTokenType.Operator);
					output.Write("generated", TextTokenType.Keyword);
					output.Write(']', TextTokenType.Operator);
				}
				output.WriteLine();
			}
			
			var memberMapping = new MemberMapping(method);
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output, memberMapping);
				if (!node.WritesNewLine)
					output.WriteLine();
			}
			output.AddDebugSymbols(memberMapping);
			EndKeywordBlock(output);
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:59,代码来源:ILAstLanguage.cs

示例9: PrintMethod

        private void PrintMethod(CompiledMethod cmethod, ITextOutput output, DecompilationOptions options)
        {
            if ((cmethod != null) && (cmethod.RLBody != null))
            {
                var body = cmethod.RLBody;
                var basicBlocks = BasicBlock.Find(body);

                foreach (var block in basicBlocks)
                {
                    output.Write(string.Format("D_{0:X4}:", block.Entry.Index));
                    output.WriteLine();
                    output.Indent();
                    foreach (var ins in block.Instructions)
                    {
                        if (ShowHasSeqPoint)
                        {
                            if (ins.SequencePoint != null)
                                output.Write(ins.SequencePoint.IsSpecial ? "!" : "~");
                        }

                        output.Write(ins.ToString());
                        output.WriteLine();
                    }
                    output.Unindent();
                }

                if (body.Exceptions.Any())
                {
                    output.WriteLine();
                    output.Write("Exception handlers:");
                    output.WriteLine();
                    output.Indent();
                    foreach (var handler in body.Exceptions)
                    {
                        output.Write(string.Format("{0:x4}-{1:x4}", handler.TryStart.Index, handler.TryEnd.Index));
                        output.WriteLine();
                        output.Indent();
                        foreach (var c in handler.Catches)
                        {
                            output.Write(string.Format("{0} => {1:x4}", c.Type, c.Instruction.Index));
                            output.WriteLine();
                        }
                        if (handler.CatchAll != null)
                        {
                            output.Write(string.Format("{0} => {1:x4}", "<any>", handler.CatchAll.Index));
                            output.WriteLine();
                        }
                        output.Unindent();
                    }
                    output.Unindent();
                }
            }
            else
            {
                output.Write("Method not found in dex");
                output.WriteLine();
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:58,代码来源:RLLanguage.cs

示例10: Decompile

 public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
 {
     App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureChildrenFiltered));
     language.WriteCommentLine(output, "PE");
     language.WriteCommentLine(output, "All tree nodes below use the hex editor to modify the PE file");
     foreach (HexTreeNode node in Children) {
         language.WriteCommentLine(output, string.Empty);
         node.Decompile(language, output, options);
     }
 }
开发者ID:johnjohnsp1,项目名称:dnSpy,代码行数:10,代码来源:PETreeNode.cs

示例11: CreateReflectionDisassembler

		ReflectionDisassembler CreateReflectionDisassembler(ITextOutput output, DecompilationOptions options, ModuleDef ownerModule) {
			var disOpts = new DisassemblerOptions(options.CancellationToken, ownerModule);
			if (options.DecompilerSettings.ShowILComments)
				disOpts.GetOpCodeDocumentation = GetOpCodeDocumentation;
			if (options.DecompilerSettings.ShowXmlDocumentation)
				disOpts.GetXmlDocComments = GetXmlDocComments;
			disOpts.CreateInstructionBytesReader = InstructionBytesReader.Create;
			disOpts.ShowTokenAndRvaComments = options.DecompilerSettings.ShowTokenAndRvaComments;
			disOpts.ShowILBytes = options.DecompilerSettings.ShowILBytes;
			disOpts.SortMembers = options.DecompilerSettings.SortMembers;
			return new ReflectionDisassembler(output, detectControlStructure, disOpts);
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:12,代码来源:ILLanguage.cs

示例12: DecompileMethod

		public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
		{
			WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true));
			AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: method.DeclaringType, isSingleMember: true);
			if (method.IsConstructor && !method.IsStatic && !method.DeclaringType.IsValueType) {
				// also fields and other ctors so that the field initializers can be shown as such
				AddFieldsAndCtors(codeDomBuilder, method.DeclaringType, method.IsStatic);
				RunTransformsAndGenerateCode(codeDomBuilder, output, options, new SelectCtorTransform(method));
			} else {
				codeDomBuilder.AddMethod(method);
				RunTransformsAndGenerateCode(codeDomBuilder, output, options);
			}
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:13,代码来源:CSharpLanguage.cs

示例13: DecompileAssembly

 public virtual void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
 {
     WriteCommentLine(output, assembly.FileName);
     if (assembly.AssemblyDefinition != null) {
         if (assembly.AssemblyDefinition.IsContentTypeWindowsRuntime) {
             WriteCommentLine(output, assembly.AssemblyDefinition.Name + " [WinRT]");
         } else {
             WriteCommentLine(output, assembly.AssemblyDefinition.FullName);
         }
     } else {
         WriteCommentLine(output, assembly.ModuleDefinition.Name);
     }
 }
开发者ID:jorik041,项目名称:dnSpy-retired,代码行数:13,代码来源:Language.cs

示例14: DecompileAssembly

        public AssemblyCompiler AssemblyCompiler { get { return compiler.AssemblyCompiler; } }
        public MapFileLookup MapFile { get { return compiler.MapFile; }  }


        public static bool GenerateSetNextInstructionCode
        {
            get { return compiler.GenerateSetNextInstructionCode; }
            set { compiler.GenerateSetNextInstructionCode = value; }
        }


        public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
        {
            compiler.CompileIfRequired(assembly.AssemblyDefinition);
开发者ID:Xtremrules,项目名称:dot42,代码行数:14,代码来源:CompiledLanguage.cs

示例15: DecompileEvent

		public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options)
		{
			ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
			rd.DisassembleEvent(ev);
			if (ev.AddMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.AddMethod);
			}
			if (ev.RemoveMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.RemoveMethod);
			}
			foreach (var m in ev.OtherMethods) {
				output.WriteLine();
				rd.DisassembleMethod(m);
			}
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:17,代码来源:ILLanguage.cs


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