Example #1
0
 MethodDefOptions CopyTo(MethodDefOptions options)
 {
     options.ImplAttributes = ImplAttributes;
     options.Attributes     = Attributes;
     options.Name           = Name;
     options.MethodSig      = MethodSig;
     options.ImplMap        = PinvokeImpl ? ImplMap : null;
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     options.DeclSecurities.Clear();
     options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
     options.ParamDefs.Clear();
     options.ParamDefs.AddRange(ParamDefsVM.Collection.Select(a => a.CreateParamDefOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Overrides.Clear();
     options.Overrides.AddRange(MethodOverridesVM.Collection.Select(a => a.CreateMethodOverrideOptions().Create()));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
     {
         options.Attributes |= MethodAttributes.HasSecurity;
     }
     else
     {
         options.Attributes &= ~MethodAttributes.HasSecurity;
     }
     return(options);
 }
Example #2
0
		public EditedMethodUpdater(Lazy<IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, MethodDef originalMethod, Emit.MethodBody newBody, MethodDefOptions methodDefOptions) {
			this.methodAnnotations = methodAnnotations;
			ownerNode = modNode.Context.DocumentTreeView.FindNode(originalMethod);
			if (ownerNode == null)
				throw new InvalidOperationException();
			method = originalMethod;
			originalMethodState = new MethodState(originalMethod, methodAnnotations.Value.IsBodyModified(method));
			newMethodState = new MethodState(newBody, methodDefOptions, true);
		}
Example #3
0
        static void Execute(Lazy <IUndoCommandService> undoCommandService, IAppService appService, IDocumentTreeNodeData[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var ownerNode = nodes[0];

            if (!(ownerNode is ITypeNode))
            {
                ownerNode = (IDocumentTreeNodeData)ownerNode.TreeNode.Parent.Data;
            }
            var typeNode = ownerNode as ITypeNode;

            Debug.Assert(typeNode != null);
            if (typeNode == null)
            {
                throw new InvalidOperationException();
            }

            var module = typeNode.GetModule();

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }

            bool isInstance = !(typeNode.TypeDef.IsAbstract && typeNode.TypeDef.IsSealed);
            var  sig        = isInstance ? MethodSig.CreateInstance(module.CorLibTypes.Void) : MethodSig.CreateStatic(module.CorLibTypes.Void);
            var  options    = MethodDefOptions.Create("MyMethod", sig);

            if (typeNode.TypeDef.IsInterface)
            {
                options.Attributes |= MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot;
            }

            var data = new MethodOptionsVM(options, module, appService.DecompilerService, typeNode.TypeDef, null);
            var win  = new MethodOptionsDlg();

            win.Title       = dnSpy_AsmEditor_Resources.CreateMethodCommand2;
            win.DataContext = data;
            win.Owner       = appService.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var cmd = new CreateMethodDefCommand(typeNode, data.CreateMethodDefOptions());

            undoCommandService.Value.Add(cmd);
            appService.DocumentTabService.FollowReference(cmd.methodNode);
        }
Example #4
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
            {
                return;
            }

            var ownerNode = nodes[0];

            if (!(ownerNode is TypeTreeNode))
            {
                ownerNode = (ILSpyTreeNode)ownerNode.Parent;
            }
            var typeNode = ownerNode as TypeTreeNode;

            Debug.Assert(typeNode != null);
            if (typeNode == null)
            {
                throw new InvalidOperationException();
            }

            var module = ILSpyTreeNode.GetModule(typeNode);

            Debug.Assert(module != null);
            if (module == null)
            {
                throw new InvalidOperationException();
            }

            bool isInstance = !(typeNode.TypeDef.IsAbstract && typeNode.TypeDef.IsSealed);
            var  sig        = isInstance ? MethodSig.CreateInstance(module.CorLibTypes.Void) : MethodSig.CreateStatic(module.CorLibTypes.Void);
            var  options    = MethodDefOptions.Create("MyMethod", sig);

            if (typeNode.TypeDef.IsInterface)
            {
                options.Attributes |= MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot;
            }

            var data = new MethodOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDef, null);
            var win  = new MethodOptionsDlg();

            win.Title       = CMD_NAME;
            win.DataContext = data;
            win.Owner       = MainWindow.Instance;
            if (win.ShowDialog() != true)
            {
                return;
            }

            var cmd = new CreateMethodDefCommand(typeNode, data.CreateMethodDefOptions());

            UndoCommandManager.Instance.Add(cmd);
            MainWindow.Instance.JumpToReference(cmd.methodNode);
        }
Example #5
0
 void InitializeFrom(MethodDefOptions options)
 {
     ImplAttributes            = options.ImplAttributes;
     Attributes                = options.Attributes;
     Name                      = options.Name;
     MethodSig                 = options.MethodSig;
     ImplMap                   = options.ImplMap;
     CodeType.SelectedItem     = (Method.CodeType)((int)(options.ImplAttributes & MethodImplAttributes.CodeTypeMask) >> 0);
     ManagedType.SelectedItem  = (Method.ManagedType)((int)(options.ImplAttributes & MethodImplAttributes.ManagedMask) >> 2);
     MethodAccess.SelectedItem = (Method.MethodAccess)((int)(options.Attributes & MethodAttributes.MemberAccessMask) >> 0);
     VtableLayout.SelectedItem = (Method.VtableLayout)((int)(options.Attributes & MethodAttributes.VtableLayoutMask) >> 8);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     ParamDefsVM.InitializeFrom(options.ParamDefs);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     MethodOverridesVM.InitializeFrom(options.Overrides);
 }
Example #6
0
        MethodDefSettingsCommand(IMethodNode methodNode, MethodDefOptions options)
        {
            this.methodNode  = methodNode;
            this.newOptions  = options;
            this.origOptions = new MethodDefOptions(methodNode.MethodDef);

            this.origParentNode       = (IDocumentTreeNodeData)methodNode.TreeNode.Parent.Data;
            this.origParentChildIndex = this.origParentNode.TreeNode.Children.IndexOf(methodNode.TreeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
            {
                throw new InvalidOperationException();
            }

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.nameChanged)
            {
                this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(methodNode.GetModule()).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDef)).Select(a => new Field.MemberRefInfo(a)).ToArray();
            }
        }
Example #7
0
        public MethodOptionsVM(MethodDefOptions options, ModuleDef ownerModule, IDecompilerService decompilerService, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, decompilerService)
            {
                IsLocal = false,
                CanAddGenericTypeVar   = true,
                CanAddGenericMethodVar = ownerMethod == null || ownerMethod.GenericParameters.Count > 0,
                OwnerType   = ownerType,
                OwnerMethod = ownerMethod,
            };

            if (ownerType != null && ownerType.GenericParameters.Count == 0)
            {
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            }

            var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions);

            methodSigCreatorOptions.IsPropertySig = false;
            MethodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions);
            MethodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged;
            MethodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged;
            MethodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.ShowTypeFullName = true;
            MethodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr      = false;

            CustomAttributesVM = new CustomAttributesVM(ownerModule, decompilerService, ownerType, ownerMethod);
            DeclSecuritiesVM   = new DeclSecuritiesVM(ownerModule, decompilerService, ownerType, ownerMethod);
            ParamDefsVM        = new ParamDefsVM(ownerModule, decompilerService, ownerType, ownerMethod);
            GenericParamsVM    = new GenericParamsVM(ownerModule, decompilerService, ownerType, ownerMethod);
            MethodOverridesVM  = new MethodOverridesVM(ownerModule, decompilerService, ownerType, ownerMethod);

            origOptions = options;

            ImplMapVM = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            ImplMapVM.IsEnabled = PinvokeImpl;
            Reinitialize();
        }
Example #8
0
		MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options) {
			this.methodNode = methodNode;
			this.newOptions = options;
			this.origOptions = new MethodDefOptions(methodNode.MethodDef);

			this.origParentNode = (ILSpyTreeNode)methodNode.Parent;
			this.origParentChildIndex = this.origParentNode.Children.IndexOf(methodNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.nameChanged)
				this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(ILSpyTreeNode.GetModule(methodNode)).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDef)).Select(a => new Field.MemberRefInfo(a)).ToArray();
		}
Example #9
0
		CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options) {
			this.ownerNode = ownerNode;
			this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDef.Module));
		}
Example #10
0
 CreateMethodDefCommand(ITypeNode ownerNode, MethodDefOptions options)
 {
     this.ownerNode  = ownerNode;
     this.methodNode = ownerNode.Create(options.CreateMethodDef(ownerNode.TypeDef.Module));
 }
Example #11
0
			public MethodState(Emit.MethodBody body, MethodDefOptions methodDefOptions, bool isBodyModified) {
				this.body = body;
				this.methodDefOptions = methodDefOptions;
				this.isBodyModified = isBodyModified;
			}
Example #12
0
 MethodDefOptions CopyTo(MethodDefOptions options)
 {
     options.ImplAttributes = ImplAttributes;
     options.Attributes = Attributes;
     options.Name = Name;
     options.MethodSig = MethodSig;
     options.ImplMap = PinvokeImpl ? ImplMap : null;
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     options.DeclSecurities.Clear();
     options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
     options.ParamDefs.Clear();
     options.ParamDefs.AddRange(ParamDefsVM.Collection.Select(a => a.CreateParamDefOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Overrides.Clear();
     options.Overrides.AddRange(MethodOverridesVM.Collection.Select(a => a.CreateMethodOverrideOptions().Create()));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
         options.Attributes |= MethodAttributes.HasSecurity;
     else
         options.Attributes &= ~MethodAttributes.HasSecurity;
     return options;
 }
Example #13
0
        public MethodOptionsVM(MethodDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
                IsLocal = false,
                CanAddGenericTypeVar = true,
                CanAddGenericMethodVar = ownerMethod == null || ownerMethod.GenericParameters.Count > 0,
                OwnerType = ownerType,
                OwnerMethod = ownerMethod,
            };
            if (ownerType != null && ownerType.GenericParameters.Count == 0)
                typeSigCreatorOptions.CanAddGenericTypeVar = false;

            var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions);
            methodSigCreatorOptions.IsPropertySig = false;
            this.methodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions);
            this.methodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.ShowTypeFullName = true;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr = false;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language, ownerType, ownerMethod);
            this.declSecuritiesVM = new DeclSecuritiesVM(ownerModule, language, ownerType, ownerMethod);
            this.paramDefsVM = new ParamDefsVM(ownerModule, language, ownerType, ownerMethod);
            this.genericParamsVM = new GenericParamsVM(ownerModule, language, ownerType, ownerMethod);
            this.methodOverridesVM = new MethodOverridesVM(ownerModule, language, ownerType, ownerMethod);

            this.origOptions = options;

            this.implMapVM = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            ImplMapVM.IsEnabled = PinvokeImpl;
            Reinitialize();
        }
Example #14
0
		public EditedMethod(MethodDef originalMethod, Emit.MethodBody newBody, MethodDefOptions methodDefOptions) {
			OriginalMethod = originalMethod;
			NewBody = newBody;
			MethodDefOptions = methodDefOptions;
		}
Example #15
0
 CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options)
 {
     this.ownerNode  = ownerNode;
     this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDefinition.Module));
 }
Example #16
0
 void InitializeFrom(MethodDefOptions options)
 {
     ImplAttributes = options.ImplAttributes;
     Attributes = options.Attributes;
     Name = options.Name;
     MethodSig = options.MethodSig;
     ImplMap = options.ImplMap;
     CodeType.SelectedItem = (Method.CodeType)((int)(options.ImplAttributes & MethodImplAttributes.CodeTypeMask) >> 0);
     ManagedType.SelectedItem = (Method.ManagedType)((int)(options.ImplAttributes & MethodImplAttributes.ManagedMask) >> 2);
     MethodVisibility.SelectedItem = (Method.MethodVisibility)((int)(options.Attributes & MethodAttributes.MemberAccessMask) >> 0);
     VtableLayout.SelectedItem = (Method.VtableLayout)((int)(options.Attributes & MethodAttributes.VtableLayoutMask) >> 8);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     ParamDefsVM.InitializeFrom(options.ParamDefs);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     MethodOverridesVM.InitializeFrom(options.Overrides);
 }
Example #17
0
			public MethodState(MethodDef method, bool isBodyModified) {
				body = method.MethodBody;
				methodDefOptions = new MethodDefOptions(method);
				this.isBodyModified = isBodyModified;
			}