예제 #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);
             * }*/
        }
예제 #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);
             * }*/
        }
예제 #3
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);
        }
예제 #4
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));
        }
예제 #5
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);
        }
예제 #6
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);
            }
            return(decompiler);
        }