Esempio n. 1
0
        public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options)
        {
            var    dis    = CreateDisassembler(output, options);
            PEFile module = property.ParentModule.PEFile;

            dis.AssemblyResolver = module.GetAssemblyResolver();
            dis.DebugInfo        = module.GetDebugInfoOrNull();
            dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken);
            var pd        = module.Metadata.GetPropertyDefinition((PropertyDefinitionHandle)property.MetadataToken);
            var accessors = pd.GetAccessors();

            if (!accessors.Getter.IsNil)
            {
                output.WriteLine();
                dis.DisassembleMethod(module, accessors.Getter);
            }
            if (!accessors.Setter.IsNil)
            {
                output.WriteLine();
                dis.DisassembleMethod(module, accessors.Setter);
            }

            /*foreach (var m in property.OtherMethods) {
             *      output.WriteLine();
             *      dis.DisassembleMethod(m);
             * }*/
        }
Esempio n. 2
0
        public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options)
        {
            var    dis    = CreateDisassembler(output, options);
            PEFile module = ev.ParentModule.PEFile;

            dis.AssemblyResolver = module.GetAssemblyResolver();
            dis.DebugInfo        = module.GetDebugInfoOrNull();
            dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken);

            var ed        = ((MetadataReader)module.Metadata).GetEventDefinition((EventDefinitionHandle)ev.MetadataToken);
            var accessors = ed.GetAccessors();

            if (!accessors.Adder.IsNil)
            {
                output.WriteLine();
                dis.DisassembleMethod(module, accessors.Adder);
            }
            if (!accessors.Remover.IsNil)
            {
                output.WriteLine();
                dis.DisassembleMethod(module, accessors.Remover);
            }
            if (!accessors.Raiser.IsNil)
            {
                output.WriteLine();
                dis.DisassembleMethod(module, accessors.Raiser);
            }

            /*foreach (var m in ev.OtherMethods) {
             *      output.WriteLine();
             *      dis.DisassembleMethod(m);
             * }*/
        }
Esempio n. 3
0
        static CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options)
        {
            CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings);

            decompiler.CancellationToken = options.CancellationToken;
            return(decompiler);
        }
Esempio n. 4
0
        public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options)
        {
            var    dis    = CreateDisassembler(output, options);
            PEFile module = field.ParentModule.PEFile;

            dis.AssemblyResolver = module.GetAssemblyResolver();
            dis.DebugInfo        = module.GetDebugInfoOrNull();
            dis.DisassembleField(module, (FieldDefinitionHandle)field.MetadataToken);
        }
Esempio n. 5
0
        public override void DecompileNamespace(string nameSpace, IEnumerable <ITypeDefinition> types, ITextOutput output, DecompilationOptions options)
        {
            var    dis    = CreateDisassembler(output, options);
            PEFile module = types.FirstOrDefault()?.ParentModule.PEFile;

            dis.AssemblyResolver = module.GetAssemblyResolver();
            dis.DebugInfo        = module.GetDebugInfoOrNull();
            dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken));
        }
Esempio n. 6
0
        public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options)
        {
            var    dis    = CreateDisassembler(output, options);
            PEFile module = type.ParentModule.PEFile;

            dis.AssemblyResolver = module.GetAssemblyResolver();
            dis.DebugInfo        = module.GetDebugInfoOrNull();
            dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken);
        }
Esempio n. 7
0
        CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options)
        {
            CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings);

            decompiler.CancellationToken = options.CancellationToken;
            while (decompiler.AstTransforms.Count > transformCount)
            {
                decompiler.AstTransforms.RemoveAt(decompiler.AstTransforms.Count - 1);
            }
            return(decompiler);
        }
Esempio n. 8
0
        internal static void AddBaseTypes(SharpTreeNodeCollection children, PEFile module, ITypeDefinition typeDefinition)
        {
            TypeDefinitionHandle handle     = (TypeDefinitionHandle)typeDefinition.MetadataToken;
            DecompilerTypeSystem typeSystem = new DecompilerTypeSystem(module, module.GetAssemblyResolver(),
                                                                       TypeSystemOptions.Default | TypeSystemOptions.Uncached);
            var t = typeSystem.MainModule.ResolveEntity(handle) as ITypeDefinition;

            foreach (var td in t.GetAllBaseTypeDefinitions().Reverse().Skip(1))
            {
                if (t.Kind != TypeKind.Interface || t.Kind == td.Kind)
                {
                    children.Add(new BaseTypesEntryNode(td));
                }
            }
        }
Esempio n. 9
0
        CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options)
        {
            CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings);

            decompiler.CancellationToken = options.CancellationToken;
            decompiler.DebugInfoProvider = module.GetDebugInfoOrNull();
            while (decompiler.AstTransforms.Count > transformCount)
            {
                decompiler.AstTransforms.RemoveAt(decompiler.AstTransforms.Count - 1);
            }
            if (options.EscapeInvalidIdentifiers)
            {
                decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers());
            }
            return(decompiler);
        }
Esempio n. 10
0
        ITypeDefinition TryResolve(PEFile module, EntityHandle handle, IType type, bool mayRetry = true)
        {
            DecompilerTypeSystem typeSystem = new DecompilerTypeSystem(module, module.GetAssemblyResolver(),
                                                                       TypeSystemOptions.Default | TypeSystemOptions.Uncached);
            var t = typeSystem.MainModule.ResolveEntity(handle) as ITypeDefinition;

            if (t != null)
            {
                showExpander = t.DirectBaseTypes.Any();
                var other = t.ParentModule.PEFile.GetTypeSystemWithCurrentOptionsOrNull();
                Debug.Assert(other != null);
                t = other.FindType(t.FullTypeName).GetDefinition();
            }
            else
            {
                showExpander = mayRetry;
            }
            RaisePropertyChanged(nameof(Text));
            RaisePropertyChanged(nameof(ShowExpander));
            return(t);
        }
Esempio n. 11
0
 public DecompilerTypeSystem ConstructTypeSystem(PEFile module)
 {
     return(new DecompilerTypeSystem(module, module.GetAssemblyResolver(assemblyListSnapshot, loadOnDemand: false)));
 }