-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLoadLocalOpCode.cs
More file actions
33 lines (28 loc) · 1.29 KB
/
Copy pathLoadLocalOpCode.cs
File metadata and controls
33 lines (28 loc) · 1.29 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
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;
namespace UseEveryOpCode.OpCodes;
public class LoadLocalOpCode : IOpCode
{
private readonly CilOpCode _opCode;
public LoadLocalOpCode(CilOpCode opCode)
{
_opCode = opCode;
}
public IList<CilInstruction> CallingInstructions => new List<CilInstruction>();
public MethodDefinition? Generate(TypeDefinition typeDefinition)
{
var method = new MethodDefinition(_opCode.ToString().Replace(".","_"), MethodAttributes.Public | MethodAttributes.Static,
new MethodSignature(CallingConventionAttributes.Default, typeDefinition.Module!.CorLibTypeFactory.Void,
Enumerable.Empty<TypeSignature>()));
method.CilMethodBody = new CilMethodBody(method);
method.CilMethodBody.LocalVariables.Add(new CilLocalVariable(typeDefinition.Module.CorLibTypeFactory.Int32));
method.CilMethodBody.Instructions.Add(_opCode,method.CilMethodBody.LocalVariables.First());
method.CilMethodBody.Instructions.Add(CilOpCodes.Pop);
method.CilMethodBody.Instructions.Add(CilOpCodes.Ret);
return method;
}
}