private TypeReference ParseTypeReference() { TypeReference tr = ClassEditHelper.ParseTypeReference(cboType.SelectedItem, _method.Module); if (tr == null) { tr = ClassEditHelper.ParseTypeReference(cboType.Text.Trim(), _method.Module); } if (tr != null) { switch (cboSpecification.SelectedItem as string) { case "Array": tr = new ArrayType(tr); break; case "Reference": tr = new ByReferenceType(tr); break; case "Pointer": tr = new PointerType(tr); break; default: break; } } return(tr); }
private void btnOK_Click(object sender, EventArgs e) { if (cboOpCode.SelectedItem == null) { SimpleMessage.ShowInfo("Please select proper OpCode."); return; } try { OpCode op = (OpCode)cboOpCode.SelectedItem; switch (op.OperandType) { case OperandType.InlineBrTarget: case OperandType.ShortInlineBrTarget: _ins.OpCode = op; _ins.Operand = _method.Body.Instructions[cboOperand.SelectedIndex]; break; case OperandType.InlineString: _ins.OpCode = op; _ins.Operand = cboOperand.Text; break; case OperandType.InlineNone: _ins.OpCode = op; _ins.Operand = null; break; case OperandType.InlineI: _ins.OpCode = op; _ins.Operand = SimpleParse.ParseInt(cboOperand.Text); break; case OperandType.ShortInlineI: _ins.OpCode = op; if (op.Code == Code.Ldc_I4_S) { _ins.Operand = SimpleParse.ParseSByte(cboOperand.Text); } else { _ins.Operand = SimpleParse.ParseByte(cboOperand.Text); } break; case OperandType.InlineR: _ins.OpCode = op; _ins.Operand = Double.Parse(cboOperand.Text); break; case OperandType.ShortInlineR: _ins.OpCode = op; _ins.Operand = Single.Parse(cboOperand.Text); break; case OperandType.InlineI8: _ins.OpCode = op; _ins.Operand = SimpleParse.ParseLong(cboOperand.Text); break; case OperandType.InlineField: _ins.OpCode = op; _ins.Operand = cboOperand.SelectedItem; break; case OperandType.InlineVar: case OperandType.ShortInlineVar: _ins.OpCode = op; _ins.Operand = cboOperand.SelectedItem; break; case OperandType.ShortInlineArg: case OperandType.InlineArg: _ins.OpCode = op; _ins.Operand = cboOperand.SelectedItem; break; case OperandType.InlineMethod: _ins.OpCode = op; if (cboOperand.SelectedItem is MethodReference) { MethodReference mr = (MethodReference)cboOperand.SelectedItem; if (mr.DeclaringType.Module.FullyQualifiedName != _method.DeclaringType.Module.FullyQualifiedName) { _ins.Operand = _method.DeclaringType.Module.Import(mr); } else { _ins.Operand = mr; } } else { MethodInfo mi; MethodReference mr; switch (cboOperand.Text) { case METHOD_MESSAGEBOX: mi = typeof(System.Windows.Forms.MessageBox).GetMethod("Show", new Type[] { typeof(string) }); mr = _method.DeclaringType.Module.Import(mi); _ins.Operand = mr; break; } } break; case OperandType.InlineSwitch: { string opStr = cboOperand.Text; if (opStr != null) { string[] ops = opStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (ops != null && ops.Length > 0) { Instruction[] opIns = new Instruction[ops.Length]; for (int i = 0; i < ops.Length; i++) { int opIndex = -1; if (int.TryParse(ops[i], out opIndex)) { if (opIndex >= 0 && opIndex < _method.Body.Instructions.Count) { opIns[i] = _method.Body.Instructions[opIndex]; } else { opIndex = -1; } } if (opIndex == -1) { throw new Exception("Invalid instruction index" + ops[i]); } } _ins.Operand = null; _ins.Operand = opIns; } } } break; case OperandType.InlineType: _ins.OpCode = op; if (cboOperand.SelectedItem == null) { _ins.Operand = ClassEditHelper.ParseTypeReference(cboOperand.Text, _method.Module); } else { _ins.Operand = ClassEditHelper.ParseTypeReference(cboOperand.SelectedItem, _method.Module); } break; default: if (_ins.OpCode.OperandType != op.OperandType) { SimpleMessage.ShowInfo(op.Name + " not implemented"); return; } else { _ins.OpCode = op; if (cboOperand.SelectedIndex >= 0) { _ins.Operand = cboOperand.SelectedItem; } else { _ins.Operand = null; } } break; } switch (_mode) { case EditModes.Edit: break; case EditModes.InsertAfter: _ilp.InsertAfter(_method.Body.Instructions[_insIndex], _ins); break; case EditModes.InsertBefore: _ilp.InsertBefore(_method.Body.Instructions[_insIndex], _ins); break; } InsUtils.ComputeOffsets(_method.Body.Instructions); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { SimpleMessage.ShowException(ex); } }