塞西尔:与指令操作码代码值对应的指令操作数类型

8
有没有文档或者是我可以查阅的Cecil源代码部分,以便全面了解给定Code值时Cecil将使用哪些Operand类型?例如:我可以从MethodBodyRocks中得知Ldloc采用VariableDefinition类型的Operand,但是对于其他指令代码,我尚未能够追踪到这一点。请注意保留HTML标记。
2个回答

21

除了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

6
您可以在OpCodes.cs文件中查看每个操作码的定义。例如,对于Ldloc,您会看到OperandType.InlineVar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接