Class CilInstruction
- Namespace
- AsmResolver.PE.DotNet.Cil
- Assembly
- AsmResolver.PE.dll
Represents a single instruction in a managed CIL method body.
public class CilInstruction
- Inheritance
-
CilInstruction
- Inherited Members
Constructors
CilInstruction(CilOpCode)
Creates a new CIL instruction with no operand.
public CilInstruction(CilOpCode opCode)
Parameters
opCode
CilOpCodeThe operation to perform.
Remarks
This constructor does not do any verification on the correctness of the instruction.
CilInstruction(CilOpCode, object?)
Creates a new CIL instruction with an operand..
public CilInstruction(CilOpCode opCode, object? operand)
Parameters
Remarks
This constructor does not do any verification on the correctness of the instruction.
CilInstruction(int, CilOpCode)
Creates a new CIL instruction with no operand.
public CilInstruction(int offset, CilOpCode opCode)
Parameters
offset
intThe offset of the instruction, relative to the start of the method body's code.
opCode
CilOpCodeThe operation to perform.
Remarks
This constructor does not do any verification on the correctness of the instruction.
CilInstruction(int, CilOpCode, object?)
Creates a new CIL instruction with an operand..
public CilInstruction(int offset, CilOpCode opCode, object? operand)
Parameters
offset
intThe offset of the instruction, relative to the start of the method body's code.
opCode
CilOpCodeThe operation to perform.
operand
objectThe operand.
Remarks
This constructor does not do any verification on the correctness of the instruction.
Properties
Offset
Gets or sets the offset to the start of the instruction, relative to the start of the code.
public int Offset { get; set; }
Property Value
OpCode
Gets or sets the operation to perform.
public CilOpCode OpCode { get; set; }
Property Value
Operand
Gets or sets the operand of the instruction, if available.
public object? Operand { get; set; }
Property Value
Size
Gets the size in bytes of the CIL instruction.
public int Size { get; }
Property Value
Methods
CreateLabel()
Creates a new label to the current instruction.
public ICilLabel CreateLabel()
Returns
- ICilLabel
The label.
CreateLdcI4(int)
Create a new instruction pushing the provided integer value, using the smallest possible operation code and operand size.
public static CilInstruction CreateLdcI4(int value)
Parameters
value
intThe constant to push.
Returns
- CilInstruction
The instruction.
Equals(CilInstruction)
Determines whether the provided instruction is considered equal to the current instruction.
protected bool Equals(CilInstruction other)
Parameters
other
CilInstructionThe instruction to compare against.
Returns
- bool
true
if the instructions are equal,false
otherwise.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetLdcI4Constant()
When this instruction is an ldc.i4 variant, gets the in32 constant that is being pushed onto the stack.
public int GetLdcI4Constant()
Returns
GetLdcI4OpCodeOperand(int)
Determines the smallest possible operation code and operand required to push the provided integer constant.
public static (CilOpCode code, object? operand) GetLdcI4OpCodeOperand(int value)
Parameters
value
intThe constant to push.
Returns
IsBranch()
Determines whether the instruction is a branching instruction (either conditional or unconditional).
public bool IsBranch()
Returns
IsConditionalBranch()
Determines whether the instruction is a conditional branch instruction.
public bool IsConditionalBranch()
Returns
IsLdarg()
Determines whether the instruction is using a variant of the ldarg opcodes.
public bool IsLdarg()
Returns
IsLdcI4()
Determines whether the instruction is an instruction pushing an int32 constant onto the stack.
public bool IsLdcI4()
Returns
IsLdloc()
Determines whether the instruction is using a variant of the ldloc opcodes.
public bool IsLdloc()
Returns
IsStarg()
Determines whether the instruction is using a variant of the starg opcodes.
public bool IsStarg()
Returns
IsStloc()
Determines whether the instruction is using a variant of the stloc opcodes.
public bool IsStloc()
Returns
IsUnconditionalBranch()
Determines whether the instruction is an unconditional branch instruction.
public bool IsUnconditionalBranch()
Returns
ReplaceWith(CilOpCode)
Replaces the operation code used by the instruction with a new one, and clears the operand.
public void ReplaceWith(CilOpCode opCode)
Parameters
opCode
CilOpCodeThe new operation code.
Remarks
This method may be useful when patching a method body, where reusing the instruction object is favourable. This can prevent breaking any references to the instruction (e.g. branch or exception handler targets).
ReplaceWith(CilOpCode, object?)
Replaces the operation code and operand used by the instruction with new ones.
public void ReplaceWith(CilOpCode opCode, object? operand)
Parameters
Remarks
This method may be useful when patching a method body, where reusing the instruction object is favourable. This can prevent breaking any references to the instruction (e.g. branch or exception handler targets).
ReplaceWithNop()
Clears the operand and replaces the operation code with a Nop (No-Operation).
public void ReplaceWithNop()
Remarks
This method may be useful when patching a method body, where reusing the instruction object is favourable. This can prevent breaking any references to the instruction (e.g. branch or exception handler targets).
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.