コード例 #1
0
        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);
        }
コード例 #2
0
 private void btnHelp_Click(object sender, EventArgs e)
 {
     ClassEditHelper.InitDropdownTypes(cboType, _method.Module);
     cboType.DroppedDown = true;
 }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        private void cboOpCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnSelectMethod.Enabled = false;

            if (cboOpCode.SelectedItem == null)
            {
                DisableOperand();
                return;
            }

            OpCode op = (OpCode)cboOpCode.SelectedItem;

            lblOpCodeInfo.Text = String.Format("FlowControl: {0}\nOpCodeType: {1}\nOperandType: {2}", op.FlowControl.ToString(), op.OpCodeType.ToString(), op.OperandType.ToString());
            Collection <Instruction> ic = _method.Body.Instructions;

            switch (op.OperandType)
            {
            case OperandType.InlineBrTarget:
            case OperandType.ShortInlineBrTarget:
                InitInstructions(cboOperand);
                break;

            case OperandType.InlineString:
                cboOperand.Enabled = true;
                cboOperand.Items.Clear();
                cboOperand.DropDownStyle = ComboBoxStyle.DropDown;
                if (_ins.Operand != null)
                {
                    cboOperand.Items.Add(_ins.Operand);
                    cboOperand.SelectedIndex = 0;
                }
                break;

            case OperandType.InlineNone:
                DisableOperand();
                break;

            case OperandType.InlineI:
            case OperandType.InlineI8:
            case OperandType.ShortInlineI:
            case OperandType.InlineR:
            case OperandType.ShortInlineR:
                cboOperand.Enabled = true;
                cboOperand.Items.Clear();
                cboOperand.DropDownStyle = ComboBoxStyle.DropDown;
                cboOperand.Items.Add(InsUtils.GetOperandText(ic, _insIndex));
                cboOperand.SelectedIndex = 0;
                break;

            case OperandType.InlineSwitch:
                cboOperand.Enabled = true;
                cboOperand.Items.Clear();
                cboOperand.DropDownStyle = ComboBoxStyle.DropDown;
                cboOperand.Items.Add(InsUtils.GetOperandText(ic, _insIndex));
                cboOperand.SelectedIndex = 0;
                Instruction[] switchIns = _ins.Operand as Instruction[];
                cboOperand.Items.Add("----------------------------------------");
                for (int i = 0; i < switchIns.Length; i++)
                {
                    cboOperand.Items.Add(
                        String.Format("{0} (0x{0:x}): {1}", i, InsUtils.GetInstructionText(ic, ic.IndexOf(switchIns[i])))
                        );
                }
                break;

            case OperandType.InlineField:
                if (_ins.Operand == null || _method.DeclaringType.Fields.Contains(_ins.Operand as FieldDefinition))
                {
                    InitFields(cboOperand);
                }
                else
                {
                    cboOperand.Enabled = true;
                    cboOperand.Items.Clear();
                    cboOperand.DropDownStyle = ComboBoxStyle.DropDownList;
                    cboOperand.Items.Add(InsUtils.GetOperandText(ic, _insIndex));
                    cboOperand.SelectedIndex = 0;
                }
                break;

            case OperandType.InlineVar:
            case OperandType.ShortInlineVar:
                InitVars(cboOperand);
                break;

            case OperandType.ShortInlineArg:
            case OperandType.InlineArg:
                InitParams(cboOperand);
                break;

            case OperandType.InlineMethod:
                InitMethods(cboOperand);
                btnSelectMethod.Enabled = true;
                break;

            case OperandType.InlineType:
                cboOperand.Enabled = true;
                cboOperand.Items.Clear();
                cboOperand.DropDownStyle = ComboBoxStyle.DropDown;
                if (_ins.Operand != null)
                {
                    cboOperand.Items.Add(_ins.Operand);
                    cboOperand.SelectedIndex = 0;
                }
                ClassEditHelper.InitDropdownTypes(cboOperand, _method.Module);
                break;

            default:
                cboOperand.Enabled = true;
                cboOperand.Items.Clear();
                cboOperand.DropDownStyle = ComboBoxStyle.DropDownList;
                if (_ins.Operand != null)
                {
                    cboOperand.Items.Add(_ins.Operand);
                    cboOperand.SelectedIndex = 0;
                }
                break;
            }
        }