Skip to content
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

Add callvirt support for implicit interface method implementations #134

Merged

Conversation

puff
Copy link
Sponsor Contributor

@puff puff commented Oct 6, 2023

Using callvirt on implicit implementations of interface methods throws a MissingMethodException.
Example:

var module = ModuleDefinition.FromModule(typeof(Usage).Module);
var method = module.GetAllTypes().FirstOrDefault(x => x.Name == "Usage")?.Methods.First(x => x.Name == "Use");
var vm = new CilVirtualMachine(module, false);
vm.Invoker = DefaultInvokers.StepIn;
vm.Call(method, Array.Empty<BitVector>());

public interface ITestInterface<out T, in U> {
    public T TestMethod(U u);
}

public class TestClass : ITestInterface<int, long> {
    public static ITestInterface<int, long> Instance = new TestClass();
    
    public int TestMethod(long u) {
        return (int)u;
    }
}

public static class Usage {
    public static int Use() {
        ITestInterface<int, long> tc = new TestClass();
        return tc.TestMethod(44);
    }
}

The current TryFindImplicitImplementationInType doesn't work for this example as the method implementation doesn't have the ReuseSlot flag.

This PR fixes this by resolving the method with the called method's signature if it finds an interface that matches the called method's declaring type (always an interface).

@Washi1337 Washi1337 added bug Something isn't working emulation Issue related to the emulation modules of Echo. dotnet-asmresolver Issues related to the .NET back-end powered by AsmResolver labels Oct 10, 2023
@Washi1337 Washi1337 merged commit bb175d0 into Washi1337:master Nov 19, 2023
1 check passed
@Washi1337
Copy link
Owner

Sorry for the late response. Thanks for looking into it and fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dotnet-asmresolver Issues related to the .NET back-end powered by AsmResolver emulation Issue related to the emulation modules of Echo.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants