예제 #1
0
        static uint?GetOperandMDToken(InstructionOperandVM op)
        {
            switch (op.InstructionOperandType)
            {
            case InstructionOperandType.None:
            case InstructionOperandType.SByte:
            case InstructionOperandType.Byte:
            case InstructionOperandType.Int32:
            case InstructionOperandType.Int64:
            case InstructionOperandType.Single:
            case InstructionOperandType.Double:
            case InstructionOperandType.String:
            case InstructionOperandType.BranchTarget:
            case InstructionOperandType.SwitchTargets:
            case InstructionOperandType.Local:
            case InstructionOperandType.Parameter:
                return(null);

            case InstructionOperandType.Field:
            case InstructionOperandType.Method:
            case InstructionOperandType.Token:
            case InstructionOperandType.Type:
                var token = op.Other as IMDTokenProvider;
                return(token == null ? (uint?)null : token.MDToken.ToUInt32());

            case InstructionOperandType.MethodSig:
                var msig = op.Other as MethodSig;
                return(msig == null ? (uint?)null : msig.OriginalToken);

            default:
                throw new InvalidOperationException();
            }
        }
예제 #2
0
 public InstructionVM(ModuleDef ownerModule)
 {
     this.ownerModule = ownerModule;
     this.instructionOperandVM = new InstructionOperandVM();
     this.InstructionOperandVM.PropertyChanged += (a, b) => HasErrorUpdated();
     this.codeVM = new ListVM<Code>(codeList, (a, b) => OnCodeUpdated());
 }
예제 #3
0
 public InstructionVM(ModuleDef ownerModule)
 {
     this.ownerModule          = ownerModule;
     this.instructionOperandVM = new InstructionOperandVM();
     this.InstructionOperandVM.PropertyChanged += (a, b) => HasErrorUpdated();
     this.codeVM = new ListVM <Code>(codeList, (a, b) => OnCodeUpdated());
 }
예제 #4
0
        void AddType(InstructionOperandVM opvm)
        {
            var    picker = new DnlibTypePicker(Window.GetWindow(listBox));
            object op     = opvm.Other as ITypeDefOrRef ?? (object)cilBodyVM.TypeSigCreatorOptions.OwnerType;

            if (picker.GetDnlibType(dnSpy_AsmEditor_Resources.Pick_Type, new FlagsDocumentTreeNodeFilter(VisibleMembersFlags.TypeDef), op, cilBodyVM.OwnerModule) is ITypeDefOrRef type)
            {
                opvm.Other = type;
            }
        }
예제 #5
0
        void AddType(InstructionOperandVM opvm)
        {
            var picker = new DnlibTypePicker(Window.GetWindow(listBox));
            var type   = picker.GetDnlibType(new FlagsTreeViewNodeFilter(VisibleMembersFlags.TypeDef), opvm.Other as ITypeDefOrRef, cilBodyVM.OwnerModule);

            if (type != null)
            {
                opvm.Other = type;
            }
        }
예제 #6
0
        void AddMethodDef(InstructionOperandVM opvm)
        {
            var picker = new DnlibTypePicker(Window.GetWindow(listBox));
            var method = picker.GetDnlibType(new FlagsTreeViewNodeFilter(VisibleMembersFlags.MethodDef), opvm.Other as IMethod, cilBodyVM.OwnerModule);

            if (method != null)
            {
                opvm.Other = method;
            }
        }
예제 #7
0
        void AddType(InstructionOperandVM opvm)
        {
            var picker = new DnlibTypePicker(Window.GetWindow(listBox));
            var type   = picker.GetDnlibType(dnSpy_AsmEditor_Resources.Pick_Type, new FlagsFileTreeNodeFilter(VisibleMembersFlags.TypeDef), opvm.Other as ITypeDefOrRef, cilBodyVM.OwnerModule);

            if (type != null)
            {
                opvm.Other = type;
            }
        }
예제 #8
0
        void AddMethodDef(InstructionOperandVM opvm)
        {
            var picker = new DnlibTypePicker(Window.GetWindow(listBox));
            var method = picker.GetDnlibType(dnSpy_AsmEditor_Resources.Pick_Method, new FlagsFileTreeNodeFilter(VisibleMembersFlags.MethodDef), opvm.Other as IMethod, cilBodyVM.OwnerModule);

            if (method != null)
            {
                opvm.Other = method;
            }
        }
예제 #9
0
        void AddMethodDef(InstructionOperandVM opvm)
        {
            var    picker = new DnlibTypePicker(Window.GetWindow(listBox));
            object op     = opvm.Other as IMethod ?? (object)cilBodyVM.TypeSigCreatorOptions.OwnerType;
            var    method = picker.GetDnlibType(dnSpy_AsmEditor_Resources.Pick_Method, new FlagsDocumentTreeNodeFilter(VisibleMembersFlags.MethodDef), op, cilBodyVM.OwnerModule) as IMethod;

            if (method != null)
            {
                opvm.Other = method;
            }
        }
예제 #10
0
 void OnInstructionOperandVMChanged(InstructionOperandVM oldValue, InstructionOperandVM newValue)
 {
     if (oldValue != null)
     {
         oldValue.PropertyChanged -= instructionOperandVM_PropertyChanged;
     }
     if (newValue != null)
     {
         newValue.PropertyChanged += instructionOperandVM_PropertyChanged;
         InitializeOperandType(newValue);
     }
 }
예제 #11
0
        void AddTypeSpec(InstructionOperandVM opvm)
        {
            var creator = new TypeSigCreator(Window.GetWindow(listBox));
            var opts    = cilBodyVM.TypeSigCreatorOptions.Clone(dnSpy_AsmEditor_Resources.CreateTypeSpec);
            var newSig  = creator.Create(opts, (opvm.Other as ITypeDefOrRef).ToTypeSig(), out bool canceled);

            if (canceled)
            {
                return;
            }

            opvm.Other = newSig.ToTypeDefOrRef();
        }
예제 #12
0
        void EditMethodSig(InstructionOperandVM opvm)
        {
            var creator = new CreateMethodPropertySig(Window.GetWindow(listBox));
            var opts    = new MethodSigCreatorOptions(cilBodyVM.TypeSigCreatorOptions.Clone(dnSpy_AsmEditor_Resources.CreateMethodSig));

            opts.CanHaveSentinel = true;
            var sig = (MethodSig)creator.Create(opts, opvm.Other as MethodSig);

            if (sig != null)
            {
                opvm.Other = sig;
            }
        }
예제 #13
0
 public void InitializeFrom(InstructionOperandVM other)
 {
     InstructionOperandType = other.InstructionOperandType;
     SByte.StringValue      = other.SByte.StringValue;
     Byte.StringValue       = other.Byte.StringValue;
     Int32.StringValue      = other.Int32.StringValue;
     Int64.StringValue      = other.Int64.StringValue;
     Single.StringValue     = other.Single.StringValue;
     Double.StringValue     = other.Double.StringValue;
     String.StringValue     = other.String.StringValue;
     Other           = other.Other;
     OperandListItem = other.OperandListItem;
 }
예제 #14
0
        void EditSwitchOperand(InstructionOperandVM opvm)
        {
            var data = new SwitchOperandVM(cilBodyVM.InstructionsListVM, opvm.Other as InstructionVM[]);
            var win  = new SwitchOperandDlg();

            win.DataContext = data;
            win.Owner       = Window.GetWindow(listBox) ?? Application.Current.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            opvm.Other = data.GetSwitchList();
        }
예제 #15
0
        void AddFieldMemberRef(InstructionOperandVM opvm)
        {
            MemberRef mr = opvm.Other as MemberRef;

            if (opvm.Other is FieldDef fd)
            {
                mr = cilBodyVM.OwnerModule.Import(fd);
            }
            if (mr != null && mr.FieldSig == null)
            {
                mr = null;
            }
            AddMemberRef(opvm, mr, true);
        }
예제 #16
0
        void AddMethodSpec(InstructionOperandVM opvm)
        {
            var ms      = opvm.Other as MethodSpec;
            var opts    = ms == null ? new MethodSpecOptions() : new MethodSpecOptions(ms);
            var vm      = new MethodSpecVM(opts, cilBodyVM.TypeSigCreatorOptions);
            var creator = new EditMethodSpec(Window.GetWindow(listBox));

            vm = creator.Edit(dnSpy_AsmEditor_Resources.EditMethodSpec, vm);
            if (vm == null)
            {
                return;
            }

            opvm.Other = vm.CreateMethodSpecOptions().Create(cilBodyVM.OwnerModule);
        }
예제 #17
0
        void AddMemberRef(InstructionOperandVM opvm, MemberRef mr, bool isField)
        {
            var opts    = mr == null ? new MemberRefOptions() : new MemberRefOptions(mr);
            var vm      = new MemberRefVM(opts, cilBodyVM.TypeSigCreatorOptions, isField);
            var creator = new EditMemberRef(Window.GetWindow(listBox));
            var title   = isField ? dnSpy_AsmEditor_Resources.EditFieldMemberRef : dnSpy_AsmEditor_Resources.EditMethodMemberRef;

            vm = creator.Edit(title, vm);
            if (vm == null)
            {
                return;
            }

            opvm.Other = vm.CreateMemberRefOptions().Create(cilBodyVM.OwnerModule);
        }
예제 #18
0
        public void ImportFrom(ModuleDef ownerModule, InstructionOperandVM other)
        {
            InstructionOperandType = other.InstructionOperandType;

            switch (other.InstructionOperandType)
            {
            case MethodBody.InstructionOperandType.None:    break;

            case MethodBody.InstructionOperandType.SByte:   SByte.StringValue = other.SByte.StringValue; break;

            case MethodBody.InstructionOperandType.Byte:    Byte.StringValue = other.Byte.StringValue; break;

            case MethodBody.InstructionOperandType.Int32:   Int32.StringValue = other.Int32.StringValue; break;

            case MethodBody.InstructionOperandType.Int64:   Int64.StringValue = other.Int64.StringValue; break;

            case MethodBody.InstructionOperandType.Single:  Single.StringValue = other.Single.StringValue; break;

            case MethodBody.InstructionOperandType.Double:  Double.StringValue = other.Double.StringValue; break;

            case MethodBody.InstructionOperandType.String:  String.StringValue = other.String.StringValue; break;

            case MethodBody.InstructionOperandType.Field:   Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Method:  Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Token:   Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.Type:    Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.MethodSig: Other = Import(ownerModule, other.Other); break;

            case MethodBody.InstructionOperandType.BranchTarget: OperandListItem = InstructionVM.Null; break;

            case MethodBody.InstructionOperandType.SwitchTargets: Other = Array.Empty <InstructionVM>(); break;

            case MethodBody.InstructionOperandType.Local:   OperandListItem = LocalVM.Null; break;

            case MethodBody.InstructionOperandType.Parameter: OperandListItem = BodyUtils.NullParameter; break;

            default: throw new InvalidOperationException();
            }
        }
예제 #19
0
        void AddMethodMemberRef(InstructionOperandVM opvm)
        {
            MemberRef mr = opvm.Other as MemberRef;
            var       md = opvm.Other as MethodDef;

            if (opvm.Other is MethodSpec ms)
            {
                mr = ms.Method as MemberRef;
                md = ms.Method as MethodDef;
            }
            if (md != null)
            {
                mr = cilBodyVM.OwnerModule.Import(md);
            }
            if (mr != null && mr.MethodSig == null)
            {
                mr = null;
            }
            AddMemberRef(opvm, mr, false);
        }
예제 #20
0
        void IEditOperand.Edit(object parameter, InstructionOperandVM opvm)
        {
            MenuCommandFlags flags;

            switch (opvm.InstructionOperandType)
            {
            case InstructionOperandType.Field:
                flags = MenuCommandFlags.FieldDef | MenuCommandFlags.FieldMemberRef;
                ShowMenu(parameter, opvm, flags);
                break;

            case InstructionOperandType.Method:
                flags = MenuCommandFlags.MethodDef | MenuCommandFlags.MethodMemberRef | MenuCommandFlags.MethodSpec;
                ShowMenu(parameter, opvm, flags);
                break;

            case InstructionOperandType.Token:
                flags = MenuCommandFlags.FieldDef | MenuCommandFlags.FieldMemberRef |
                        MenuCommandFlags.MethodDef | MenuCommandFlags.MethodMemberRef | MenuCommandFlags.MethodSpec |
                        MenuCommandFlags.TypeDef | MenuCommandFlags.TypeRef | MenuCommandFlags.TypeSpec;
                ShowMenu(parameter, opvm, flags);
                break;

            case InstructionOperandType.Type:
                flags = MenuCommandFlags.TypeDef | MenuCommandFlags.TypeRef | MenuCommandFlags.TypeSpec;
                ShowMenu(parameter, opvm, flags);
                break;

            case InstructionOperandType.MethodSig:
                EditMethodSig(opvm);
                break;

            case InstructionOperandType.SwitchTargets:
                EditSwitchOperand(opvm);
                break;

            default:
                throw new InvalidOperationException();
            }
        }
예제 #21
0
        static void Write(this ITextColorWriter output, InstructionOperandVM opvm)
        {
            switch (opvm.InstructionOperandType)
            {
            case MethodBody.InstructionOperandType.None:
                break;

            case MethodBody.InstructionOperandType.SByte:   output.Write(BoxedTextColor.Number, opvm.SByte.StringValue); break;

            case MethodBody.InstructionOperandType.Byte:    output.Write(BoxedTextColor.Number, opvm.Byte.StringValue); break;

            case MethodBody.InstructionOperandType.Int32:   output.Write(BoxedTextColor.Number, opvm.Int32.StringValue); break;;

            case MethodBody.InstructionOperandType.Int64:   output.Write(BoxedTextColor.Number, opvm.Int64.StringValue); break;;

            case MethodBody.InstructionOperandType.Single:  output.Write(BoxedTextColor.Number, opvm.Single.StringValue); break;;

            case MethodBody.InstructionOperandType.Double:  output.Write(BoxedTextColor.Number, opvm.Double.StringValue); break;;

            case MethodBody.InstructionOperandType.String:  output.Write(BoxedTextColor.String, opvm.String.StringValue); break;;

            case MethodBody.InstructionOperandType.Field:
            case MethodBody.InstructionOperandType.Method:
            case MethodBody.InstructionOperandType.Token:
            case MethodBody.InstructionOperandType.Type:
            case MethodBody.InstructionOperandType.MethodSig:
            case MethodBody.InstructionOperandType.SwitchTargets:
            case MethodBody.InstructionOperandType.BranchTarget:
            case MethodBody.InstructionOperandType.Local:
            case MethodBody.InstructionOperandType.Parameter:
                WriteObject(output, opvm.Value, WriteObjectFlags.ShortInstruction);
                break;

            default: throw new InvalidOperationException();
            }
        }
예제 #22
0
        void ShowMenu(object parameter, InstructionOperandVM opvm, MenuCommandFlags flags)
        {
            var ctxMenu = new ContextMenu();

            ctxMenu.SetResourceReference(DsImage.BackgroundBrushProperty, "ContextMenuRectangleFill");

            MenuItem menuItem;

            if ((flags & (MenuCommandFlags.TypeDef | MenuCommandFlags.TypeRef)) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Type,
                    Command = new RelayCommand(a => AddType(opvm)),
                });
                Add16x16Image(menuItem, DsImages.ClassPublic, true);
            }
            if ((flags & MenuCommandFlags.TypeSpec) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_TypeSpec,
                    Command = new RelayCommand(a => AddTypeSpec(opvm)),
                });
                Add16x16Image(menuItem, DsImages.Template, true);
            }
            if ((flags & MenuCommandFlags.MethodDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Method,
                    Command = new RelayCommand(a => AddMethodDef(opvm)),
                });
                Add16x16Image(menuItem, DsImages.MethodPublic, true);
            }
            if ((flags & MenuCommandFlags.MethodMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Method_MemberRef,
                    Command = new RelayCommand(a => AddMethodMemberRef(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.MethodSpec) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_MethodSpec,
                    Command = new RelayCommand(a => AddMethodSpec(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.FieldDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Field,
                    Command = new RelayCommand(a => AddFieldDef(opvm)),
                });
                Add16x16Image(menuItem, DsImages.FieldPublic, true);
            }
            if ((flags & MenuCommandFlags.FieldMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Field_MemberRef,
                    Command = new RelayCommand(a => AddFieldMemberRef(opvm)),
                });
            }

            ctxMenu.Placement       = PlacementMode.Bottom;
            ctxMenu.PlacementTarget = parameter as UIElement;
            ctxMenu.IsOpen          = true;
        }
예제 #23
0
		void InitializeOperandType(InstructionOperandVM instructionOperandVM) {
			switch (instructionOperandVM.InstructionOperandType) {
			case InstructionOperandType.None:
				Content = null;
				break;

			case InstructionOperandType.SByte:
			case InstructionOperandType.Byte:
			case InstructionOperandType.Int32:
			case InstructionOperandType.Int64:
			case InstructionOperandType.Single:
			case InstructionOperandType.Double:
			case InstructionOperandType.String:
				// Don't cache the TextBox as a field in this class. The error border disappears when
				// switching from a textbox opcode to a non-textbox opcode and back to the textbox
				// again. Only solution seems to be to create a new textbox.
				var textBox = Content as TextBox;
				if (textBox == null) {
					textBox = new TextBox();
					var binding = new Binding("InstructionOperandVM.Text.StringValue") {
						Source = this,
						ValidatesOnDataErrors = true,
						ValidatesOnExceptions = true,
						UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
					};
					textBox.SetBinding(TextBox.TextProperty, binding);
					binding = new Binding("TextBoxStyle") {
						Source = this,
					};
					textBox.SetBinding(TextBox.StyleProperty, binding);
					Content = textBox;
				}
				break;

			case InstructionOperandType.Field:
			case InstructionOperandType.Method:
			case InstructionOperandType.Token:
			case InstructionOperandType.Type:
			case InstructionOperandType.MethodSig:
			case InstructionOperandType.SwitchTargets:
				var button = Content as FastClickButton;
				if (button == null) {
					button = new FastClickButton();
					var binding = new Binding("InstructionOperandVM.Other") {
						Source = this,
						Mode = BindingMode.OneWay,
						Converter = CilObjectConverter.Instance,
						ValidatesOnDataErrors = true,
						ValidatesOnExceptions = true,
						UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
					};
					button.SetBinding(Button.ContentProperty, binding);
					binding = new Binding("ButtonStyle") {
						Source = this,
					};
					button.SetBinding(Button.StyleProperty, binding);
					binding = new Binding("ButtonCommand") {
						Source = this,
					};
					button.SetBinding(Button.CommandProperty, binding);
					button.CommandParameter = button;
					Content = button;
				}
				break;

			case InstructionOperandType.BranchTarget:
			case InstructionOperandType.Local:
			case InstructionOperandType.Parameter:
				var comboBox = Content as ComboBox;
				if (comboBox == null) {
					comboBox = new ComboBox();
					comboBox.ItemTemplate = (DataTemplate)GetValue(ComboBoxItemTemplateProperty);
					ComboBoxAttachedProps.SetSelectionBoxItemTemplate(comboBox, (DataTemplate)GetValue(ComboBoxSelectionBoxItemTemplateProperty));
					var binding = new Binding("InstructionOperandVM.OperandListVM.Items") {
						Source = this,
					};
					comboBox.SetBinding(ComboBox.ItemsSourceProperty, binding);
					binding = new Binding("InstructionOperandVM.OperandListVM.SelectedIndex") {
						Source = this,
						ValidatesOnDataErrors = true,
						ValidatesOnExceptions = true,
						UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
					};
					comboBox.SetBinding(ComboBox.SelectedIndexProperty, binding);
					binding = new Binding("ComboBoxStyle") {
						Source = this,
					};
					comboBox.SetBinding(ComboBox.StyleProperty, binding);
					binding = new Binding("ComboBoxItemTemplate") {
						Source = this,
					};
					comboBox.SetBinding(ComboBox.ItemTemplateProperty, binding);
					binding = new Binding("ComboBoxSelectionBoxItemTemplate") {
						Source = this,
					};
					comboBox.SetBinding(ComboBoxAttachedProps.SelectionBoxItemTemplateProperty, binding);
					Content = comboBox;
				}
				break;

			default:
				throw new InvalidOperationException();
			}
		}
예제 #24
0
		void OnInstructionOperandVMChanged(InstructionOperandVM oldValue, InstructionOperandVM newValue) {
			if (oldValue != null)
				oldValue.PropertyChanged -= instructionOperandVM_PropertyChanged;
			if (newValue != null) {
				newValue.PropertyChanged += instructionOperandVM_PropertyChanged;
				InitializeOperandType(newValue);
			}
		}
예제 #25
0
 void OnCodeUpdated()
 {
     InstructionOperandVM.UpdateOperandType(Code);
     OnPropertyChanged(nameof(Code));
     HasErrorUpdated();
 }
예제 #26
0
 public void InitializeFrom(InstructionOptions options)
 {
     Code = options.Code;
     InstructionOperandVM.WriteValue(Code, options.Operand);
     SequencePoint = options.SequencePoint;
 }
예제 #27
0
		public InstructionVM() {
			InstructionOperandVM = new InstructionOperandVM();
			InstructionOperandVM.PropertyChanged += (a, b) => HasErrorUpdated();
			CodeVM = new ListVM<Code>(codeList, (a, b) => OnCodeUpdated());
		}
예제 #28
0
 public InstructionVM()
 {
     InstructionOperandVM = new InstructionOperandVM();
     InstructionOperandVM.PropertyChanged += (a, b) => HasErrorUpdated();
     CodeVM = new ListVM <Code>(codeList, (a, b) => OnCodeUpdated());
 }
예제 #29
0
        void ShowMenu(object parameter, InstructionOperandVM opvm, MenuCommandFlags flags)
        {
            var ctxMenu = new ContextMenu();

            MenuItem menuItem;

            if ((flags & (MenuCommandFlags.TypeDef | MenuCommandFlags.TypeRef)) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = "_Type…",
                    Command = new RelayCommand(a => AddType(opvm)),
                });
                MainWindow.CreateMenuItemImage(menuItem, typeof(MethodBodyControl).Assembly, "Class", BackgroundType.ContextMenuItem, true);
            }
            if ((flags & MenuCommandFlags.TypeSpec) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = "Type_Spec…",
                    Command = new RelayCommand(a => AddTypeSpec(opvm)),
                });
                MainWindow.CreateMenuItemImage(menuItem, typeof(MethodBodyControl).Assembly, "Generic", BackgroundType.ContextMenuItem, true);
            }
            if ((flags & MenuCommandFlags.MethodDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = "_Method…",
                    Command = new RelayCommand(a => AddMethodDef(opvm)),
                });
                MainWindow.CreateMenuItemImage(menuItem, typeof(MethodBodyControl).Assembly, "Method", BackgroundType.ContextMenuItem, true);
            }
            if ((flags & MenuCommandFlags.MethodMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = "M_ethod MemberRef…",
                    Command = new RelayCommand(a => AddMethodMemberRef(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.MethodSpec) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = "Met_hodSpec…",
                    Command = new RelayCommand(a => AddMethodSpec(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.FieldDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = "_Field…",
                    Command = new RelayCommand(a => AddFieldDef(opvm)),
                });
                MainWindow.CreateMenuItemImage(menuItem, typeof(MethodBodyControl).Assembly, "Field", BackgroundType.ContextMenuItem, true);
            }
            if ((flags & MenuCommandFlags.FieldMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = "F_ield MemberRef…",
                    Command = new RelayCommand(a => AddFieldMemberRef(opvm)),
                });
            }

            ctxMenu.Placement       = PlacementMode.Bottom;
            ctxMenu.PlacementTarget = parameter as UIElement;
            ctxMenu.IsOpen          = true;
        }
예제 #30
0
		public void InitializeFrom(InstructionOperandVM other) {
			InstructionOperandType = other.InstructionOperandType;
			SByte.StringValue = other.SByte.StringValue;
			Byte.StringValue = other.Byte.StringValue;
			Int32.StringValue = other.Int32.StringValue;
			Int64.StringValue = other.Int64.StringValue;
			Single.StringValue = other.Single.StringValue;
			Double.StringValue = other.Double.StringValue;
			String.StringValue = other.String.StringValue;
			Other = other.Other;
			OperandListItem = other.OperandListItem;
		}
예제 #31
0
		public void ImportFrom(ModuleDef ownerModule, InstructionOperandVM other) {
			InstructionOperandType = other.InstructionOperandType;

			switch (other.InstructionOperandType) {
			case MethodBody.InstructionOperandType.None:	break;
			case MethodBody.InstructionOperandType.SByte:	SByte.StringValue = other.SByte.StringValue; break;
			case MethodBody.InstructionOperandType.Byte:	Byte.StringValue = other.Byte.StringValue; break;
			case MethodBody.InstructionOperandType.Int32:	Int32.StringValue = other.Int32.StringValue; break;
			case MethodBody.InstructionOperandType.Int64:	Int64.StringValue = other.Int64.StringValue; break;
			case MethodBody.InstructionOperandType.Single:	Single.StringValue = other.Single.StringValue; break;
			case MethodBody.InstructionOperandType.Double:	Double.StringValue = other.Double.StringValue; break;
			case MethodBody.InstructionOperandType.String:	String.StringValue = other.String.StringValue; break;
			case MethodBody.InstructionOperandType.Field:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Method:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Token:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.Type:	Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.MethodSig: Other = Import(ownerModule, other.Other); break;
			case MethodBody.InstructionOperandType.BranchTarget: OperandListItem = InstructionVM.Null; break;
			case MethodBody.InstructionOperandType.SwitchTargets: Other = Array.Empty<InstructionVM>(); break;
			case MethodBody.InstructionOperandType.Local:	OperandListItem = LocalVM.Null; break;
			case MethodBody.InstructionOperandType.Parameter: OperandListItem = BodyUtils.NullParameter; break;
			default: throw new InvalidOperationException();
			}
		}
예제 #32
0
        void InitializeOperandType(InstructionOperandVM instructionOperandVM)
        {
            switch (instructionOperandVM.InstructionOperandType)
            {
            case InstructionOperandType.None:
                Content = null;
                break;

            case InstructionOperandType.SByte:
            case InstructionOperandType.Byte:
            case InstructionOperandType.Int32:
            case InstructionOperandType.Int64:
            case InstructionOperandType.Single:
            case InstructionOperandType.Double:
            case InstructionOperandType.String:
                // Don't cache the TextBox as a field in this class. The error border disappears when
                // switching from a textbox opcode to a non-textbox opcode and back to the textbox
                // again. Only solution seems to be to create a new textbox.
                var textBox = Content as TextBox;
                if (textBox == null)
                {
                    textBox = new TextBox();
                    var binding = new Binding("InstructionOperandVM.Text.StringValue")
                    {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    textBox.SetBinding(TextBox.TextProperty, binding);
                    binding = new Binding("TextBoxStyle")
                    {
                        Source = this,
                    };
                    textBox.SetBinding(TextBox.StyleProperty, binding);
                    Content = textBox;
                }
                break;

            case InstructionOperandType.Field:
            case InstructionOperandType.Method:
            case InstructionOperandType.Token:
            case InstructionOperandType.Type:
            case InstructionOperandType.MethodSig:
            case InstructionOperandType.SwitchTargets:
                var button = Content as FastClickButton;
                if (button == null)
                {
                    button = new FastClickButton();
                    var binding = new Binding("InstructionOperandVM.Other")
                    {
                        Source                = this,
                        Mode                  = BindingMode.OneWay,
                        Converter             = CilObjectConverter.Instance,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    button.SetBinding(Button.ContentProperty, binding);
                    binding = new Binding("ButtonStyle")
                    {
                        Source = this,
                    };
                    button.SetBinding(Button.StyleProperty, binding);
                    binding = new Binding("ButtonCommand")
                    {
                        Source = this,
                    };
                    button.SetBinding(Button.CommandProperty, binding);
                    button.CommandParameter = button;
                    Content = button;
                }
                break;

            case InstructionOperandType.BranchTarget:
            case InstructionOperandType.Local:
            case InstructionOperandType.Parameter:
                var comboBox = Content as ComboBox;
                if (comboBox == null)
                {
                    comboBox = new ComboBox();
                    comboBox.ItemTemplate = (DataTemplate)GetValue(ComboBoxItemTemplateProperty);
                    ComboBoxAttachedProps.SetSelectionBoxItemTemplate(comboBox, (DataTemplate)GetValue(ComboBoxSelectionBoxItemTemplateProperty));
                    var binding = new Binding("InstructionOperandVM.OperandListVM.Items")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, binding);
                    binding = new Binding("InstructionOperandVM.OperandListVM.SelectedIndex")
                    {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    comboBox.SetBinding(ComboBox.SelectedIndexProperty, binding);
                    binding = new Binding("ComboBoxStyle")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.StyleProperty, binding);
                    binding = new Binding("ComboBoxItemTemplate")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemTemplateProperty, binding);
                    binding = new Binding("ComboBoxSelectionBoxItemTemplate")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBoxAttachedProps.SelectionBoxItemTemplateProperty, binding);
                    Content = comboBox;
                }
                break;

            default:
                throw new InvalidOperationException();
            }
        }
예제 #33
0
        void ShowMenu(object parameter, InstructionOperandVM opvm, MenuCommandFlags flags)
        {
            var ctxMenu = new ContextMenu();

            MenuItem menuItem;

            if ((flags & (MenuCommandFlags.TypeDef | MenuCommandFlags.TypeRef)) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Type,
                    Command = new RelayCommand(a => AddType(opvm)),
                });
                Add16x16Image(menuItem, "Class", true, true);
            }
            if ((flags & MenuCommandFlags.TypeSpec) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_TypeSpec,
                    Command = new RelayCommand(a => AddTypeSpec(opvm)),
                });
                Add16x16Image(menuItem, "Generic", true, true);
            }
            if ((flags & MenuCommandFlags.MethodDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Method,
                    Command = new RelayCommand(a => AddMethodDef(opvm)),
                });
                Add16x16Image(menuItem, "Method", true, true);
            }
            if ((flags & MenuCommandFlags.MethodMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Method_MemberRef,
                    Command = new RelayCommand(a => AddMethodMemberRef(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.MethodSpec) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_MethodSpec,
                    Command = new RelayCommand(a => AddMethodSpec(opvm)),
                });
            }
            if ((flags & MenuCommandFlags.FieldDef) != 0)
            {
                ctxMenu.Items.Add(menuItem = new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Field,
                    Command = new RelayCommand(a => AddFieldDef(opvm)),
                });
                Add16x16Image(menuItem, "Field", true, true);
            }
            if ((flags & MenuCommandFlags.FieldMemberRef) != 0)
            {
                ctxMenu.Items.Add(new MenuItem()
                {
                    Header  = dnSpy_AsmEditor_Resources.EditOperand_Field_MemberRef,
                    Command = new RelayCommand(a => AddFieldMemberRef(opvm)),
                });
            }

            ctxMenu.Placement       = PlacementMode.Bottom;
            ctxMenu.PlacementTarget = parameter as UIElement;
            ctxMenu.IsOpen          = true;
        }