Parsing the IL of a Method Body
https://www.codeproject.com/articles/14058/parsing-the-il-of-a-method-body
Parsing the IL of a Method Body
https://www.codeproject.com/articles/14058/parsing-the-il-of-a-method-body
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| .ctor | 1 | MethodBodyReader constructor |
| IndexByOffset | 1 | 按 IL 偏移查指令下标;不存在返回 -1 |
| InstructionAt | 1 | 按 IL 偏移取指令;不存在返回 Nothing |
| ConstructInstructions | 1 | Constructs the array of ILInstructions according to the IL byte code. |
| ResolveOrToken | 1 | 解析元数据令牌;解析失败时退回令牌本身(而不是让整段 IL 解析崩掉), 上层遇到 Integer 类型的操作数即可判定"该指令不受支持"。 |
| Slice | 1 | 从原始 IL 字节里切出 [startIndex, endIndex) 段 |
| GetBodyCode | 1 | Gets the IL code of the method |
| GetRefferencedOperand | 1 | |
| Dispose | 1 | |
| GetEnumerator | 1 |
03 Properties
| Name | Overloads | Summary |
|---|---|---|
| Instructions | 1 | 解析得到的指令序列(按 IL 偏移升序) |
| MaxStackSize | 1 | 方法的最大求值栈深度 |
| Locals | 1 | 局部变量表(下标即 ldloc / stloc 的操作数) |
| ExceptionClauses | 1 | 异常处理子句 |
| HasExceptionHandlers | 1 | 该方法是否含有 try / catch / finally 等异常结构 |
04 Fields
| Name | Overloads | Summary |
|---|---|---|
| ilBytes | 1 | 方法的原始 IL 字节(用于回填 ILInstruction.OperandData) |
| _locals | 1 | 局部变量表,下标即 ldloc / stloc 的操作数 |
| _exceptionClauses | 1 | 异常处理子句(切分基本块时不能跨越 try/handler 边界) |
| offsetIndex | 1 | IL 偏移 -> 指令下标 |
05 Members
MethodInfo)MethodBodyReader constructor
| Name | Type | Description |
|---|---|---|
mi | MethodInfo | The System.Reflection defined MethodInfo |
Int32)按 IL 偏移查指令下标;不存在返回 -1
Int32)按 IL 偏移取指令;不存在返回 Nothing
Module)Constructs the array of ILInstructions according to the IL byte code.
| Name | Type | Description |
|---|---|---|
module | Module | - |
解析元数据令牌;解析失败时退回令牌本身(而不是让整段 IL 解析崩掉), 上层遇到 Integer 类型的操作数即可判定"该指令不受支持"。
Int32, Int32)从原始 IL 字节里切出 [startIndex, endIndex) 段
Gets the IL code of the method
解析得到的指令序列(按 IL 偏移升序)
方法的最大求值栈深度
局部变量表(下标即 ldloc / stloc 的操作数)
异常处理子句
该方法是否含有 try / catch / finally 等异常结构
方法的原始 IL 字节(用于回填 ILInstruction.OperandData)
局部变量表,下标即 ldloc / stloc 的操作数
异常处理子句(切分基本块时不能跨越 try/handler 边界)
IL 偏移 -> 指令下标
Module, Int32)