c# - cecil : Instruction. Instruction.OpCode.Code值对应的操作数类型

标签 c# mono cil il mono.cecil

是否有任何文档或 cecil 源代码的一部分可供我引用以全面了解 cecil 将针对给定的代码 使用哪些Operand 类型> 值(value)?例如:我可以从 MethodBodyRocks 中了解到 Ldloc 采用 VariableDefinition 类型的 Operand,但我还没有能够找到一些其他指令代码。

最佳答案

要添加到 poupou 的回答中,OpCodes.cs显示为每个指令代码分配了哪个OperandType。使用此 OperandType 您可以查询 CodeReader.ReadOperand查看如何使用这些 OperandType 来确定构造哪个具体对象类型。另请注意,CodeReader.ReadCode 在返回之前使用 CodeReader.ResolveBranches 将一些操作数从指令偏移量转换为 Instruction 对象。

我创建了这个表,它比每次都通过源代码挖掘要方便得多(这个表中没有涵盖的任何内容都应该有一个 InlineNone OperandType):

Instruction.OpCode.Code|Instruction.OpCode.OperandType|Instruction.Operand class
Ldarg_S                |ShortInlineArg                |ParameterDefinition
Ldarga_S               |ShortInlineArg                |ParameterDefinition
Starg_S                |ShortInlineArg                |ParameterDefinition
Ldloc_S                |ShortInlineVar                |VariableDefinition
Ldloca_S               |ShortInlineVar                |VariableDefinition
Stloc_S                |ShortInlineVar                |VariableDefinition
Ldc_I4_S               |ShortInlineI                  |sbyte <===== NOTE: special case
Ldc_I4                 |InlineI                       |int32
Ldc_I8                 |InlineI8                      |int64
Ldc_R4                 |ShortInlineR                  |single
Ldc_R8                 |InlineR                       |float (64 bit)
Jmp                    |InlineMethod                  |MethodReference
Call                   |InlineMethod                  |MethodReference
Calli                  |InlineSig                     |CallSite
Br_S                   |ShortInlineBrTarget           |Instruction
Brfalse_S              |ShortInlineBrTarget           |Instruction
Brtrue_S               |ShortInlineBrTarget           |Instruction
Beq_S                  |ShortInlineBrTarget           |Instruction
Bge_S                  |ShortInlineBrTarget           |Instruction
Bgt_S                  |ShortInlineBrTarget           |Instruction
Ble_S                  |ShortInlineBrTarget           |Instruction
Blt_S                  |ShortInlineBrTarget           |Instruction
Bne_Un_S               |ShortInlineBrTarget           |Instruction
Bge_Un_S               |ShortInlineBrTarget           |Instruction
Bgt_Un_S               |ShortInlineBrTarget           |Instruction
Ble_Un_S               |ShortInlineBrTarget           |Instruction
Blt_Un_S               |ShortInlineBrTarget           |Instruction
Br                     |InlineBrTarget                |Instruction
Brfalse                |InlineBrTarget                |Instruction
Brtrue                 |InlineBrTarget                |Instruction
Beq                    |InlineBrTarget                |Instruction
Bge                    |InlineBrTarget                |Instruction
Bgt                    |InlineBrTarget                |Instruction
Ble                    |InlineBrTarget                |Instruction
Blt                    |InlineBrTarget                |Instruction
Bne_Un                 |InlineBrTarget                |Instruction
Bge_Un                 |InlineBrTarget                |Instruction
Bgt_Un                 |InlineBrTarget                |Instruction
Ble_Un                 |InlineBrTarget                |Instruction
Blt_Un                 |InlineBrTarget                |Instruction
Switch                 |InlineSwitch                  |Instruction array
Callvirt               |InlineMethod                  |MethodReference
Cpobj                  |InlineType                    |TypeReference
Ldobj                  |InlineType                    |TypeReference
Ldstr                  |InlineString                  |string
Newobj                 |InlineMethod                  |MethodReference
Castclass              |InlineType                    |TypeReference
Isinst                 |InlineType                    |TypeReference
Unbox                  |InlineType                    |TypeReference
Ldfld                  |InlineField                   |FieldReference
Ldflda                 |InlineField                   |FieldReference
Stfld                  |InlineField                   |FieldReference
Ldsfld                 |InlineField                   |FieldReference
Ldsflda                |InlineField                   |FieldReference
Stsfld                 |InlineField                   |FieldReference
Stobj                  |InlineType                    |TypeReference
Box                    |InlineType                    |TypeReference
Newarr                 |InlineType                    |TypeReference
Ldelema                |InlineType                    |TypeReference
Ldelem_Any             |InlineType                    |TypeReference
Stelem_Any             |InlineType                    |TypeReference
Unbox_Any              |InlineType                    |TypeReference
Refanyval              |InlineType                    |TypeReference
Mkrefany               |InlineType                    |TypeReference
Ldtoken                |InlineTok                     |IMetadataTokenProvider
Leave                  |InlineBrTarget                |Instruction
Leave_S                |ShortInlineBrTarget           |Instruction
Ldftn                  |InlineMethod                  |MethodReference
Ldvirtftn              |InlineMethod                  |MethodReference
Ldarg                  |InlineArg                     |ParameterDefinition
Ldarga                 |InlineArg                     |ParameterDefinition
Starg                  |InlineArg                     |ParameterDefinition
Ldloc                  |InlineVar                     |VariableDefinition
Ldloca                 |InlineVar                     |VariableDefinition
Stloc                  |InlineVar                     |VariableDefinition
Unaligned              |ShortInlineI                  |byte
Initobj                |InlineType                    |TypeReference
Constrained            |InlineType                    |TypeReference
No                     |ShortInlineI                  |byte
Sizeof                 |InlineType                    |TypeReference

关于c# - cecil : Instruction. Instruction.OpCode.Code值对应的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7212255/

相关文章:

C# 到 VB6 COM 事件 ("object or class does not support the set of events")

c# - 将 System.Object 作为类型过滤器发出的一般 catch 子句在现实世界中有何影响?

c# - DbContext 已被释放

c# - 我怎样才能找出是什么在制造垃圾?

c# - 未知的解决方案项目类型 : {42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23}

macos - 新手问题 : GTK# (Mono) on OSX

c# - 在 C# 中将 CIL 代码更改为 native 代码

c# - 尝试使用 Action.Method arg 运行 DynamicMethod 时出现 VerificationException

c# - 使用 SOAP Web 服务时如何在 C# 中设置密码类型

c# - 在 NUnit 中捕获断言失败的正确方法