-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathCallHandler.cs
More file actions
34 lines (32 loc) · 1.4 KB
/
CallHandler.cs
File metadata and controls
34 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Collections.Generic;
using AsmResolver.DotNet;
using AsmResolver.PE.DotNet.Cil;
using Echo.Memory;
namespace Echo.Platforms.AsmResolver.Emulation.Dispatch.ObjectModel
{
/// <summary>
/// Implements a CIL instruction handler for <c>call</c> operations.
/// </summary>
[DispatcherTableEntry(CilCode.Call)]
public class CallHandler : CallHandlerBase
{
/// <inheritdoc />
protected override MethodDevirtualizationResult DevirtualizeMethodInternal(
CilExecutionContext context,
IMethodDescriptor method,
IList<BitVector> arguments)
{
// If we are constraining on a specific declaring type, we need to simulate a "virtual dispatch" on that type.
if (context.CurrentFrame.ConstrainedType?.TryResolve(context.RuntimeContext, out var constrainedType) is true)
{
if (method.TryResolve(context.RuntimeContext, out var resolvedBaseMethod) && resolvedBaseMethod.IsVirtual)
{
var implementationMethod = FindMethodImplementationInType(context.RuntimeContext, constrainedType, resolvedBaseMethod);
if (implementationMethod is not null)
return MethodDevirtualizationResult.Success(implementationMethod);
}
}
return MethodDevirtualizationResult.Success(method);
}
}
}