Show / Hide Table of Contents

Class CilReader

Sequentially processes CIL bytecode, reading instructions from the method body

Inheritance
System.Object
CilReader
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: CilTools.BytecodeAnalysis
Assembly: CilTools.BytecodeAnalysis.dll
Syntax
public class CilReader

Constructors

CilReader(Byte[])

Creates new CilReader object that uses specified byte array as source

Declaration
public CilReader(byte[] src)
Parameters
Type Name Description
System.Byte[] src

An array of bytecode to read from

Exceptions
Type Condition
System.ArgumentNullException

Source array is null

System.ArgumentException

Source array is empty

CilReader(MethodBase)

Creates new CilReader that uses a body of specified method as a source

Declaration
public CilReader(MethodBase src)
Parameters
Type Name Description
System.Reflection.MethodBase src

A MethodBase object that specifies a method to read from

Exceptions
Type Condition
System.ArgumentNullException

Source method is null

CilParserException

GetMethodBody returned null

Fields

cilbytes

Raw CIL bytes which this object processes

Declaration
protected byte[] cilbytes
Field Value
Type Description
System.Byte[]

current_ordinal

An ordinal number of the next instruction

Declaration
protected uint current_ordinal
Field Value
Type Description
System.UInt32

current_pos

Current position in the source array

Declaration
protected int current_pos
Field Value
Type Description
System.Int32

method

A method which body this object reads

Declaration
protected MethodBase method
Field Value
Type Description
System.Reflection.MethodBase

state

Current state of this object

Declaration
protected CilReaderState state
Field Value
Type Description
CilReaderState

Properties

Method

Gets a method which body this CilReader object reads

Declaration
public MethodBase Method { get; }
Property Value
Type Description
System.Reflection.MethodBase

State

Gets a current state of this CilReader object

Declaration
public CilReaderState State { get; }
Property Value
Type Description
CilReaderState

Methods

GetInstructions(Byte[])

Reads all instructions from specified array of bytecode

Declaration
public static IEnumerable<CilInstruction> GetInstructions(byte[] src)
Parameters
Type Name Description
System.Byte[] src

Source byte array

Returns
Type Description
System.Collections.Generic.IEnumerable<CilInstruction>

A collection of CIL instructions

Exceptions
Type Condition
System.ArgumentNullException

Source array is null

System.ArgumentException

Source array is empty

System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Unknown error occured

GetInstructions(MethodBase)

Reads all instructions from specified method's body

Declaration
public static IEnumerable<CilInstruction> GetInstructions(MethodBase m)
Parameters
Type Name Description
System.Reflection.MethodBase m

Source method

Returns
Type Description
System.Collections.Generic.IEnumerable<CilInstruction>

A collection of CIL instructions that form the body of this method

Exceptions
Type Condition
System.ArgumentNullException

Source method is null

System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Failed to retrieve method body for the method

Read()

Reads next instruction from source

Declaration
public CilInstruction Read()
Returns
Type Description
CilInstruction

CilInstruction retrieved from the source

Exceptions
Type Condition
System.InvalidOperationException

This CilReader is in faulty state or reached the end of source byte array

System.NotSupportedException

CilReader encountered unknown opcode

ReadAll()

Reads all instructions from source until the end is reached

Declaration
public IEnumerable<CilInstruction> ReadAll()
Returns
Type Description
System.Collections.Generic.IEnumerable<CilInstruction>

A collection of CIL instructions

Exceptions
Type Condition
System.NotSupportedException

CilReader encountered unknown opcode

CilParserException

Unknown error occured

Back to top CIL Tools (published from sources in GitHub repository).
Generated by DocFX