public void Visit(CilInstructionWithNoValue instruction) { if (_options.ShowBytes) { WriteBytes(string.Empty, instruction); } _writer.WriteLine(string.Format("{0}", instruction.opCode)); }
private static IEnumerable <CilInstruction> DecodeMethodBody(BlobReader ilReader, MetadataReader metadataReader, CilTypeProvider provider, CilMethodDefinition methodDefinition) { ilReader.Reset(); int intOperand; ushort shortOperand; int ilOffset = 0; CilInstruction instruction = null; while (ilReader.Offset < ilReader.Length) { OpCode opCode; int expectedSize; byte _byte = ilReader.ReadByte(); /*If the byte read is 0xfe it means is a two byte instruction, * so since it is going to read the second byte to get the actual * instruction it has to check that the offset is still less than the length.*/ if (_byte == 0xfe && ilReader.Offset < ilReader.Length) { opCode = CilDecoderHelpers.Instance.twoByteOpCodes[ilReader.ReadByte()]; expectedSize = 2; } else { opCode = CilDecoderHelpers.Instance.oneByteOpCodes[_byte]; expectedSize = 1; } switch (opCode.OperandType) { //The instruction size is the expected size (1 or 2 depending if it is a one or two byte instruction) + the size of the operand. case OperandType.InlineField: intOperand = ilReader.ReadInt32(); string fieldInfo = GetFieldInformation(metadataReader, intOperand, provider); instruction = new CilStringInstruction(opCode, fieldInfo, intOperand, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.InlineString: intOperand = ilReader.ReadInt32(); bool isPrintable; string str = GetArgumentString(metadataReader, intOperand, out isPrintable); instruction = new CilStringInstruction(opCode, str, intOperand, expectedSize + (int)CilInstructionSize.Int32, isPrintable); break; case OperandType.InlineMethod: intOperand = ilReader.ReadInt32(); string methodCall = SolveMethodName(metadataReader, intOperand, provider); instruction = new CilStringInstruction(opCode, methodCall, intOperand, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.InlineType: intOperand = ilReader.ReadInt32(); string type = GetTypeInformation(metadataReader, intOperand, provider); instruction = new CilStringInstruction(opCode, type, intOperand, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.InlineTok: intOperand = ilReader.ReadInt32(); string tokenType = GetInlineTokenType(metadataReader, intOperand, provider); instruction = new CilStringInstruction(opCode, tokenType, intOperand, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.InlineI: instruction = new CilInt32Instruction(opCode, ilReader.ReadInt32(), -1, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.InlineI8: instruction = new CilInt64Instruction(opCode, ilReader.ReadInt64(), -1, expectedSize + (int)CilInstructionSize.Int64); break; case OperandType.InlineR: instruction = new CilDoubleInstruction(opCode, ilReader.ReadDouble(), -1, expectedSize + (int)CilInstructionSize.Double); break; case OperandType.InlineSwitch: instruction = CreateSwitchInstruction(ref ilReader, expectedSize, ilOffset, opCode); break; case OperandType.ShortInlineBrTarget: instruction = new CilInt16BranchInstruction(opCode, ilReader.ReadSByte(), ilOffset, expectedSize + (int)CilInstructionSize.Byte); break; case OperandType.InlineBrTarget: instruction = new CilBranchInstruction(opCode, ilReader.ReadInt32(), ilOffset, expectedSize + (int)CilInstructionSize.Int32); break; case OperandType.ShortInlineI: instruction = new CilByteInstruction(opCode, ilReader.ReadByte(), -1, expectedSize + (int)CilInstructionSize.Byte); break; case OperandType.ShortInlineR: instruction = new CilSingleInstruction(opCode, ilReader.ReadSingle(), -1, expectedSize + (int)CilInstructionSize.Single); break; case OperandType.InlineNone: instruction = new CilInstructionWithNoValue(opCode, expectedSize); break; case OperandType.ShortInlineVar: byte token = ilReader.ReadByte(); instruction = new CilInt16VariableInstruction(opCode, GetVariableName(opCode, token, methodDefinition), token, expectedSize + (int)CilInstructionSize.Byte); break; case OperandType.InlineVar: shortOperand = ilReader.ReadUInt16(); instruction = new CilVariableInstruction(opCode, GetVariableName(opCode, shortOperand, methodDefinition), shortOperand, expectedSize + (int)CilInstructionSize.Int16); break; case OperandType.InlineSig: intOperand = ilReader.ReadInt32(); instruction = new CilStringInstruction(opCode, GetSignature(metadataReader, intOperand, provider), intOperand, expectedSize + (int)CilInstructionSize.Int32); break; default: break; } ilOffset += instruction.Size; yield return(instruction); } }