-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBoxOpCode.cs
More file actions
34 lines (29 loc) · 1.1 KB
/
Copy pathBoxOpCode.cs
File metadata and controls
34 lines (29 loc) · 1.1 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 AsmResolver.DotNet;
using AsmResolver.DotNet.Code.Cil;
using AsmResolver.DotNet.Signatures;
using AsmResolver.DotNet.Signatures.Types;
using AsmResolver.PE.DotNet.Cil;
using AsmResolver.PE.DotNet.Metadata.Tables.Rows;
using static AsmResolver.PE.DotNet.Cil.CilOpCodes;
namespace UseEveryOpCode.OpCodes;
public class BoxOpCode : IOpCode
{
public IList<CilInstruction> CallingInstructions => new List<CilInstruction>();
public MethodDefinition? Generate(TypeDefinition typeDefinition)
{
var method = new MethodDefinition(CilOpCodes.Box.ToString(), MethodAttributes.Public | MethodAttributes.Static,
new MethodSignature(CallingConventionAttributes.Default, typeDefinition.Module!.CorLibTypeFactory.Void,
Enumerable.Empty<TypeSignature>()));
method.CilMethodBody = new CilMethodBody(method)
{
Instructions =
{
{ Ldc_I4_0 },
{ Box, typeDefinition.Module!.CorLibTypeFactory.Int32.ToTypeDefOrRef() },
{ Pop },
{ Ret }
}
};
return method;
}
}