예제 #1
0
            public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
            {
                base.DecompileMethod(method, output, options);
                var module    = method.ParentModule.PEFile;
                var metadata  = module.Metadata;
                var methodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken);

                if (!methodDef.HasBody())
                {
                    return;
                }
                IAssemblyResolver assemblyResolver = module.GetAssemblyResolver();
                var typeSystem = new DecompilerTypeSystem(module, assemblyResolver);
                var reader     = new ILReader(typeSystem.MainModule);

                reader.UseDebugSymbols = options.DecompilerSettings.UseDebugSymbols;
                var        methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
                ILFunction il         = reader.ReadIL((SRM.MethodDefinitionHandle)method.MetadataToken, methodBody, kind: ILFunctionKind.TopLevelFunction, cancellationToken: options.CancellationToken);
                var        decompiler = new CSharpDecompiler(typeSystem, options.DecompilerSettings)
                {
                    CancellationToken = options.CancellationToken
                };
                ILTransformContext context = decompiler.CreateILTransformContext(il);

                context.Stepper.StepLimit = options.StepLimit;
                context.Stepper.IsDebug   = options.IsDebug;
                try
                {
                    il.RunTransforms(transforms, context);
                }
                catch (StepLimitReachedException)
                {
                }
                catch (Exception ex)
                {
                    output.WriteLine(ex.ToString());
                    output.WriteLine();
                    output.WriteLine("ILAst after the crash:");
                }
                finally
                {
                    // update stepper even if a transform crashed unexpectedly
                    if (options.StepLimit == int.MaxValue)
                    {
                        Stepper = context.Stepper;
                        OnStepperUpdated(new EventArgs());
                    }
                }
                (output as ISmartTextOutput)?.AddButton(Images.ViewCode, "Show Steps", delegate {
                    Docking.DockWorkspace.Instance.ShowToolPane(DebugStepsPaneModel.PaneContentId);
                });
                output.WriteLine();
                il.WriteTo(output, DebugSteps.Options);
            }
예제 #2
0
            public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
            {
                base.DecompileMethod(method, output, options);
                if (!method.HasBody)
                {
                    return;
                }
                var typeSystem             = new DecompilerTypeSystem(method.Module);
                var specializingTypeSystem = typeSystem.GetSpecializingTypeSystem(new SimpleTypeResolveContext(typeSystem.Resolve(method)));
                var reader = new ILReader(specializingTypeSystem);

                reader.UseDebugSymbols = options.DecompilerSettings.UseDebugSymbols;
                ILFunction         il      = reader.ReadIL(method.Body, options.CancellationToken);
                ILTransformContext context = new ILTransformContext(il, typeSystem, options.DecompilerSettings)
                {
                    CancellationToken = options.CancellationToken
                };

                context.Stepper.StepLimit = options.StepLimit;
                context.Stepper.IsDebug   = options.IsDebug;
                try {
                    il.RunTransforms(transforms, context);
                } catch (StepLimitReachedException) {
                } catch (Exception ex) {
                    output.WriteLine(ex.ToString());
                    output.WriteLine();
                    output.WriteLine("ILAst after the crash:");
                } finally {
                    // update stepper even if a transform crashed unexpectedly
                    if (options.StepLimit == int.MaxValue)
                    {
                        Stepper = context.Stepper;
                        OnStepperUpdated(new EventArgs());
                    }
                }
                (output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseFieldSugar)));
                output.WriteLine();
                (output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseLogicOperationSugar)));
                output.WriteLine();
                (output as ISmartTextOutput)?.AddButton(Images.ViewCode, "Show Steps", delegate {
                    DebugSteps.Show();
                });
                output.WriteLine();
                il.WriteTo(output, writingOptions);
            }
예제 #3
0
            public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
            {
                base.DecompileMethod(method, output, options);
                if (!method.HasBody)
                {
                    return;
                }
                var      typeSystem = new DecompilerTypeSystem(method.Module);
                ILReader reader     = new ILReader(typeSystem);

                reader.UseDebugSymbols = options.DecompilerSettings.UseDebugSymbols;
                ILFunction         il      = reader.ReadIL(method.Body, options.CancellationToken);
                ILTransformContext context = new ILTransformContext {
                    Settings          = options.DecompilerSettings,
                    TypeSystem        = typeSystem,
                    CancellationToken = options.CancellationToken
                };

                context.Stepper.StepLimit = options.StepLimit;
                context.Stepper.IsDebug   = options.IsDebug;
                try {
                    il.RunTransforms(transforms, context);
                } catch (StepLimitReachedException) {
                } finally {
                    // update stepper even if a transform crashed unexpectedly
                    if (options.StepLimit == int.MaxValue)
                    {
                        Stepper = context.Stepper;
                        OnStepperUpdated(new EventArgs());
                    }
                }
                (output as ISmartTextOutput)?.AddButton(Images.ViewCode, "Show Steps", delegate {
                    DebugSteps.Show();
                });
                output.WriteLine();
                il.WriteTo(output);
            }