本文整理汇总了C#中Microsoft.Cci.UtilityDataStructures.MemoryReader.ReadOpcode方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryReader.ReadOpcode方法的具体用法?C# MemoryReader.ReadOpcode怎么用?C# MemoryReader.ReadOpcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Cci.UtilityDataStructures.MemoryReader
的用法示例。
在下文中一共展示了MemoryReader.ReadOpcode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CountCilInstructions
static int CountCilInstructions(MemoryReader memReader) {
int count = 0;
while (memReader.NotEndOfBytes) {
count++;
OperationCode cilOpCode = memReader.ReadOpcode();
switch (cilOpCode) {
case OperationCode.Ldarg_S:
case OperationCode.Ldarga_S:
case OperationCode.Starg_S:
case OperationCode.Ldloc_S:
case OperationCode.Ldloca_S:
case OperationCode.Stloc_S:
case OperationCode.Ldc_I4_S:
case OperationCode.Br_S:
case OperationCode.Brfalse_S:
case OperationCode.Brtrue_S:
case OperationCode.Beq_S:
case OperationCode.Bge_S:
case OperationCode.Bgt_S:
case OperationCode.Ble_S:
case OperationCode.Blt_S:
case OperationCode.Bne_Un_S:
case OperationCode.Bge_Un_S:
case OperationCode.Bgt_Un_S:
case OperationCode.Ble_Un_S:
case OperationCode.Blt_Un_S:
case OperationCode.Leave_S:
case OperationCode.Unaligned_:
case OperationCode.No_:
memReader.SkipBytes(1);
break;
case OperationCode.Ldarg:
case OperationCode.Ldarga:
case OperationCode.Starg:
case OperationCode.Ldloc:
case OperationCode.Ldloca:
case OperationCode.Stloc:
memReader.SkipBytes(2);
break;
case OperationCode.Ldc_I4:
case OperationCode.Jmp:
case OperationCode.Call:
case OperationCode.Calli:
case OperationCode.Br:
case OperationCode.Brfalse:
case OperationCode.Brtrue:
case OperationCode.Beq:
case OperationCode.Bge:
case OperationCode.Bgt:
case OperationCode.Ble:
case OperationCode.Blt:
case OperationCode.Bne_Un:
case OperationCode.Bge_Un:
case OperationCode.Bgt_Un:
case OperationCode.Ble_Un:
case OperationCode.Blt_Un:
case OperationCode.Callvirt:
case OperationCode.Cpobj:
case OperationCode.Ldobj:
case OperationCode.Ldstr:
case OperationCode.Newobj:
case OperationCode.Castclass:
case OperationCode.Isinst:
case OperationCode.Unbox:
case OperationCode.Ldfld:
case OperationCode.Ldflda:
case OperationCode.Stfld:
case OperationCode.Ldsfld:
case OperationCode.Ldsflda:
case OperationCode.Stsfld:
case OperationCode.Stobj:
case OperationCode.Box:
case OperationCode.Newarr:
case OperationCode.Ldelema:
case OperationCode.Ldelem:
case OperationCode.Stelem:
case OperationCode.Unbox_Any:
case OperationCode.Refanyval:
case OperationCode.Mkrefany:
case OperationCode.Ldtoken:
case OperationCode.Leave:
case OperationCode.Ldftn:
case OperationCode.Ldvirtftn:
case OperationCode.Initobj:
case OperationCode.Constrained_:
case OperationCode.Sizeof:
case OperationCode.Ldc_R4:
memReader.SkipBytes(4);
break;
case OperationCode.Ldc_I8:
case OperationCode.Ldc_R8:
memReader.SkipBytes(8);
break;
case OperationCode.Switch:
int numTargets = (int)memReader.ReadUInt32();
memReader.SkipBytes(4*numTargets);
break;
default:
break;
}
//.........这里部分代码省略.........
示例2: PopulateCilInstructions
bool PopulateCilInstructions() {
MethodBodyDocument document = new MethodBodyDocument(this.MethodDefinition);
MemoryReader memReader = new MemoryReader(this.MethodIL.EncodedILMemoryBlock);
var numInstructions = CountCilInstructions(memReader);
if (numInstructions == 0) return true;
CilInstruction[] instrList = new CilInstruction[numInstructions];
int instructionNumber = 0;
while (memReader.NotEndOfBytes) {
object/*?*/ value = null;
uint offset = (uint)memReader.Offset;
OperationCode cilOpCode = memReader.ReadOpcode();
switch (cilOpCode) {
case OperationCode.Nop:
case OperationCode.Break:
break;
case OperationCode.Ldarg_0:
case OperationCode.Ldarg_1:
case OperationCode.Ldarg_2:
case OperationCode.Ldarg_3:
value = this.GetParameter((uint)(cilOpCode - OperationCode.Ldarg_0));
break;
case OperationCode.Ldloc_0:
case OperationCode.Ldloc_1:
case OperationCode.Ldloc_2:
case OperationCode.Ldloc_3:
value = this.GetLocal((uint)(cilOpCode - OperationCode.Ldloc_0));
break;
case OperationCode.Stloc_0:
case OperationCode.Stloc_1:
case OperationCode.Stloc_2:
case OperationCode.Stloc_3:
value = this.GetLocal((uint)(cilOpCode - OperationCode.Stloc_0));
break;
case OperationCode.Ldarg_S:
case OperationCode.Ldarga_S:
case OperationCode.Starg_S:
value = this.GetParameter(memReader.ReadByte());
break;
case OperationCode.Ldloc_S:
case OperationCode.Ldloca_S:
case OperationCode.Stloc_S:
value = this.GetLocal(memReader.ReadByte());
break;
case OperationCode.Ldnull:
case OperationCode.Ldc_I4_M1:
case OperationCode.Ldc_I4_0:
case OperationCode.Ldc_I4_1:
case OperationCode.Ldc_I4_2:
case OperationCode.Ldc_I4_3:
case OperationCode.Ldc_I4_4:
case OperationCode.Ldc_I4_5:
case OperationCode.Ldc_I4_6:
case OperationCode.Ldc_I4_7:
case OperationCode.Ldc_I4_8:
break;
case OperationCode.Ldc_I4_S:
value = (int)memReader.ReadSByte();
break;
case OperationCode.Ldc_I4:
value = memReader.ReadInt32();
break;
case OperationCode.Ldc_I8:
value = memReader.ReadInt64();
break;
case OperationCode.Ldc_R4:
value = memReader.ReadSingle();
break;
case OperationCode.Ldc_R8:
value = memReader.ReadDouble();
break;
case OperationCode.Dup:
case OperationCode.Pop:
break;
case OperationCode.Jmp:
value = this.GetMethod(memReader.ReadUInt32());
break;
case OperationCode.Call: {
IMethodReference methodReference = this.GetMethod(memReader.ReadUInt32());
IArrayTypeReference/*?*/ arrayType = methodReference.ContainingType as IArrayTypeReference;
if (arrayType != null) {
// For Get(), Set() and Address() on arrays, the runtime provides method implementations.
// Hence, CCI2 replaces these with pseudo instrcutions Array_Set, Array_Get and Array_Addr.
// All other methods on arrays will not use pseudo instruction and will have methodReference as their operand.
if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Set.UniqueKey) {
cilOpCode = OperationCode.Array_Set;
value = arrayType;
} else if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Get.UniqueKey) {
cilOpCode = OperationCode.Array_Get;
value = arrayType;
} else if (methodReference.Name.UniqueKey == this.PEFileToObjectModel.NameTable.Address.UniqueKey) {
cilOpCode = OperationCode.Array_Addr;
value = arrayType;
} else {
value = methodReference;
}
} else {
value = methodReference;
}
}
break;
//.........这里部分代码省略.........