private void ResolveBranches() { foreach (var instruction in _instructions) { var operandType = instruction.OpCode.OperandType; if (operandType != OperandType.InlineBrTarget) { if (operandType == OperandType.InlineSwitch) { goto Label_005A; } if (operandType != OperandType.ShortInlineBrTarget) { continue; } } instruction.Operand = GetInstruction(_instructions, (int) instruction.Operand); continue; Label_005A: var numArray = (int[]) instruction.Operand; var instructionArray = new Instruction[numArray.Length]; for (var i = 0; i < numArray.Length; i++) { instructionArray[i] = GetInstruction(_instructions, numArray[i]); } instruction.Operand = instructionArray; } }
private static void AppendLabel(StringBuilder builder, Instruction instruction) { builder.Append("IL_"); builder.Append(instruction.Offset.ToString("x4")); }
private void ReadOperand(Instruction instruction) { switch (instruction.OpCode.OperandType) { case OperandType.InlineBrTarget: instruction.Operand = _il.ReadInt32() + _il.Position; return; case OperandType.InlineField: case OperandType.InlineMethod: case OperandType.InlineTok: case OperandType.InlineType: instruction.Operand = _module.ResolveMember(_il.ReadInt32(), _typeArguments, _methodArguments); return; case OperandType.InlineI: instruction.Operand = _il.ReadInt32(); return; case OperandType.InlineI8: instruction.Operand = _il.ReadInt64(); return; case OperandType.InlineNone: return; case OperandType.InlineR: instruction.Operand = _il.ReadDouble(); return; case OperandType.InlineSig: instruction.Operand = _module.ResolveSignature(_il.ReadInt32()); return; case OperandType.InlineString: instruction.Operand = _module.ResolveString(_il.ReadInt32()); return; case OperandType.InlineSwitch: { var num = _il.ReadInt32(); var num2 = _il.Position + (4*num); var numArray = new int[num]; for (var i = 0; i < num; i++) { numArray[i] = _il.ReadInt32() + num2; } instruction.Operand = numArray; return; } case OperandType.InlineVar: instruction.Operand = GetVariable(instruction, _il.ReadInt16()); return; case OperandType.ShortInlineBrTarget: instruction.Operand = ((sbyte) _il.ReadByte()) + _il.Position; return; case OperandType.ShortInlineI: if (!(instruction.OpCode == OpCodes.Ldc_I4_S)) { instruction.Operand = _il.ReadByte(); return; } instruction.Operand = (sbyte) _il.ReadByte(); return; case OperandType.ShortInlineR: instruction.Operand = _il.ReadSingle(); return; case OperandType.ShortInlineVar: instruction.Operand = GetVariable(instruction, _il.ReadByte()); return; } throw new NotSupportedException(); }
private void ReadInstructions() { Instruction instruction = null; while (_il.Position < _il.Buffer.Length) { var instruction2 = new Instruction(_il.Position, ReadOpCode()); ReadOperand(instruction2); if (instruction != null) { instruction2.Previous = instruction; instruction.Next = instruction2; } _instructions.Add(instruction2); instruction = instruction2; } ResolveBranches(); }
private object GetVariable(Instruction instruction, int index) { if (TargetsLocalVariable(instruction.OpCode)) return GetLocalVariable(index); return GetParameter(index); }
internal void Reset(Instruction instruction) { Instruction = instruction; IsMatch = true; }
internal MatchContext(Instruction instruction) { Reset(instruction); }