private void ApplyOperand(MemberReference tr) { // TypeDefinition > TypeReference, so this should work lblTMFPicker.Text = CecilFormatter.TryFormat(tr); ((InstructionInfo)instructionEditor.DragItem).NewInstruction.Operand = tr; RedrawBoth(); }
protected override void DrawBuffer(Graphics g) { if (g == null) { throw new ArgumentNullException(nameof(g)); } int split = (int)g.MeasureString("999>999", Font).Width; if (Delete) { g.DrawString(OldInstructionNum + ">X", Font, Brushes.Black, 0, 1); } else if (NewInstructionNum == -1) { g.DrawString("(" + DragFrom + ")", Font, Brushes.Black, 0, 1); } else if (IsOld && InstructionNumPatch) { g.DrawString(OldInstructionNum + ">" + NewInstructionNum, Font, Brushes.Black, 0, 1); } else if (IsNew) { g.DrawString("=" + NewInstructionNum.ToString(), Font, Brushes.Black, 0, 1); } else { g.DrawString(NewInstructionNum.ToString(), Font, Brushes.Black, 0, 1); } if (Delete) { g.DrawLine(Pens.Red, 0, 0, split, Size.Height); g.DrawLine(Pens.Red, 0, Size.Height, split, 0); } g.DrawLine(Pens.Black, split, 0, split, Size.Height); g.DrawString(NewInstruction.OpCode.Name, Font, InstructionOpCodePatch ? Brushes.Red : Brushes.Black, split + 2, 1); g.DrawLine(Pens.Black, 100, 0, 100, Size.Height); if (OperandMismatch) { g.FillRectangle(hbrMismatch, 102, 0, Size.Width - 102, Size.Height); } if (NewInstruction.Operand == null) { g.DrawString("-", Font, InstructionOperandPatch ? Brushes.Red : Brushes.Black, 102, 1); } else { g.DrawString(CecilFormatter.TryFormat(NewInstruction.Operand), Font, InstructionOperandPatch ? Brushes.Red : Brushes.Black, 102, 1); } }
private void OpCodeToInputType(Instruction instr, bool readOperand) { #region Read PickOperandType switch (instr.OpCode.OperandType) { case OperandType.InlineArg: case OperandType.ShortInlineArg: currentPOT = PickOperandType.ParameterReference; break; case OperandType.InlineBrTarget: case OperandType.ShortInlineBrTarget: currentPOT = PickOperandType.InstructionReference; break; case OperandType.InlineField: currentPOT = PickOperandType.FieldReference; break; case OperandType.InlineI: currentPOT = PickOperandType.Int32; break; case OperandType.InlineI8: currentPOT = PickOperandType.Int64; break; case OperandType.InlineMethod: currentPOT = PickOperandType.MethodReference; break; case OperandType.InlineNone: currentPOT = PickOperandType.None; break; case OperandType.InlineR: currentPOT = PickOperandType.Double; break; case OperandType.InlineString: currentPOT = PickOperandType.String; break; case OperandType.InlineSwitch: currentPOT = PickOperandType.InstructionArrReference; break; case OperandType.InlineTok: currentPOT = PickOperandType.TMFReferenceDynamic; break; case OperandType.InlineType: currentPOT = PickOperandType.TypeReference; break; case OperandType.InlineVar: case OperandType.ShortInlineVar: currentPOT = PickOperandType.VariableReference; break; case OperandType.ShortInlineI: if (instr.OpCode == OpCodes.Ldc_I4_S) { currentPOT = PickOperandType.SByte; } else { currentPOT = PickOperandType.Byte; } break; case OperandType.ShortInlineR: currentPOT = PickOperandType.Single; break; case OperandType.InlinePhi: case OperandType.InlineSig: default: Log.Write(Log.Level.Warning, $"OperandType \"{instr.OpCode.Name}\" is not processed"); break; } #endregion #region Show the corresponding control foreach (Control c in OperandCList) { c.Visible = false; } switch (currentPOT) { case PickOperandType.Byte: case PickOperandType.SByte: case PickOperandType.Int32: case PickOperandType.Int64: case PickOperandType.Single: case PickOperandType.Double: case PickOperandType.String: if (readOperand) { txtOperand.Text = instr.Operand.ToString(); } txtOperand.Visible = true; break; case PickOperandType.InstructionReference: InitCbxOperand(); if (readOperand) { Instruction pr = instr.Operand as Instruction; if (pr != null) { cbxOperand.SelectedIndex = mInstructBox.Items.FindIndex(x => ((InstructionInfo)x).NewInstruction == pr); } } cbxOperand.Visible = true; break; case PickOperandType.InstructionArrReference: lblTMFPicker.Text = "<Instruction Array>"; panTMFPicker.Visible = true; break; case PickOperandType.VariableReference: InitCbxOperand(); if (readOperand) { ParameterReference pr = instr.Operand as ParameterReference; if (pr != null) { cbxOperand.SelectedIndex = pr.Index; } } cbxOperand.Visible = true; break; case PickOperandType.ParameterReference: InitCbxOperand(); if (readOperand) { VariableReference vr = instr.Operand as VariableReference; if (vr != null) { cbxOperand.SelectedIndex = vr.Index; } } cbxOperand.Visible = true; break; case PickOperandType.None: case PickOperandType.FieldReference: case PickOperandType.MethodReference: case PickOperandType.TypeReference: case PickOperandType.TMFReferenceDynamic: if (readOperand) { lblTMFPicker.Text = CecilFormatter.TryFormat(instr.Operand); } btnTMFPicker.Text = currentPOT == PickOperandType.None ? "Clear" : "Pick"; panTMFPicker.Visible = true; break; default: Log.Write(Log.Level.Warning, $"PickOperadType \"{currentPOT}\" is not processed"); break; } #endregion lblOperandType.Text = currentPOT.ToString(); // TODO: read from dict MakeItemAvailable(); Controls_Reorganize(); }