New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompiling types in non-main modules #1282

Closed
gatodevelop opened this Issue Sep 18, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@gatodevelop

gatodevelop commented Sep 18, 2018

The types at the same rows in the main module are decompiled.
If this cannot be done, an exception should be thrown.

@siegfriedpammer

This comment has been minimized.

Show comment
Hide comment
@siegfriedpammer

siegfriedpammer Oct 9, 2018

Member

Can you please provide an example? Thank you very much!

Member

siegfriedpammer commented Oct 9, 2018

Can you please provide an example? Thank you very much!

@gatodevelop

This comment has been minimized.

Show comment
Hide comment
@gatodevelop

gatodevelop Oct 9, 2018

Source:

using System;
using System.Linq;
using System.Reflection;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;

static class MainClass {
    static void Main() {
        var decompiler = new CSharpDecompiler(
            Assembly.GetExecutingAssembly().Location, new DecompilerSettings());
        var module = decompiler.TypeSystem.Modules[1];
        var typeDefinition = module.TypeDefinitions.ElementAt(1);
        var fullTypeName = typeDefinition.FullTypeName; // Interop
        var syntaxTree = decompiler.DecompileType(fullTypeName);
        Console.WriteLine(syntaxTree);
    }
}

Output:

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.TypeSystem;
using System;
using System.Linq;
using System.Reflection;

internal static class MainClass
{
    private static void Main ()
    {
        CSharpDecompiler cSharpDecompiler = new CSharpDecompiler (Assembly.GetExecutingAssembly ().Location, new DecompilerSettings ());
        IModule module = cSharpDecompiler.TypeSystem.Modules [1];
        ITypeDefinition typeDefinition = module.TypeDefinitions.ElementAt (1);
        FullTypeName fullTypeName = typeDefinition.FullTypeName;
        SyntaxTree value = cSharpDecompiler.DecompileType (fullTypeName);
        Console.WriteLine (value);
    }
}

gatodevelop commented Oct 9, 2018

Source:

using System;
using System.Linq;
using System.Reflection;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;

static class MainClass {
    static void Main() {
        var decompiler = new CSharpDecompiler(
            Assembly.GetExecutingAssembly().Location, new DecompilerSettings());
        var module = decompiler.TypeSystem.Modules[1];
        var typeDefinition = module.TypeDefinitions.ElementAt(1);
        var fullTypeName = typeDefinition.FullTypeName; // Interop
        var syntaxTree = decompiler.DecompileType(fullTypeName);
        Console.WriteLine(syntaxTree);
    }
}

Output:

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.TypeSystem;
using System;
using System.Linq;
using System.Reflection;

internal static class MainClass
{
    private static void Main ()
    {
        CSharpDecompiler cSharpDecompiler = new CSharpDecompiler (Assembly.GetExecutingAssembly ().Location, new DecompilerSettings ());
        IModule module = cSharpDecompiler.TypeSystem.Modules [1];
        ITypeDefinition typeDefinition = module.TypeDefinitions.ElementAt (1);
        FullTypeName fullTypeName = typeDefinition.FullTypeName;
        SyntaxTree value = cSharpDecompiler.DecompileType (fullTypeName);
        Console.WriteLine (value);
    }
}
@siegfriedpammer

This comment has been minimized.

Show comment
Hide comment
@siegfriedpammer

siegfriedpammer Oct 10, 2018

Member

Now I understand, thank you!

@dgrunwald Do you think we should support decompiling code from any loaded module or clarify APIs, documentation and implementations (i.e. explicit module checks and throwing exceptions) that this is not supported? AFAIK we only load metadata for modules other than the main module, so fixing this by explicitly stating that it's not possible, seems to be the best idea. I don't want to change the decompiler engine too much.

Member

siegfriedpammer commented Oct 10, 2018

Now I understand, thank you!

@dgrunwald Do you think we should support decompiling code from any loaded module or clarify APIs, documentation and implementations (i.e. explicit module checks and throwing exceptions) that this is not supported? AFAIK we only load metadata for modules other than the main module, so fixing this by explicitly stating that it's not possible, seems to be the best idea. I don't want to change the decompiler engine too much.

@dgrunwald

This comment has been minimized.

Show comment
Hide comment
@dgrunwald

dgrunwald Oct 10, 2018

Member

The assembly being decompiled must be the main assembly of the type system; anything else would cause the type system to misbehave.
Yes, we should throw an exception in this case. (I thought we already did so -- did this get lost in the SRM port?)

Member

dgrunwald commented Oct 10, 2018

The assembly being decompiled must be the main assembly of the type system; anything else would cause the type system to misbehave.
Yes, we should throw an exception in this case. (I thought we already did so -- did this get lost in the SRM port?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment