コード例 #1
0
ファイル: MethodBodyCommands.cs プロジェクト: net10010/dnSpy
 EditMethodBodyILCommand(IMethodAnnotations methodAnnotations, IMethodNode methodNode, MethodBodyOptions options)
 {
     this.methodAnnotations = methodAnnotations;
     this.methodNode        = methodNode;
     this.newOptions        = options;
     this.origMethodBody    = methodNode.MethodDef.MethodBody;
 }
コード例 #2
0
        public IEnumerable <MethodWithGCInfo> EnumerateCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            foreach (IMethodNode methodNode in MetadataManager.GetCompiledMethods(moduleToEnumerate, methodCategory))
            {
                MethodDesc       method         = methodNode.Method;
                MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
#if DEBUG
                EcmaModule  module      = ((EcmaMethod)method.GetTypicalMethodDefinition()).Module;
                ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true);

                IMethodNode      methodNodeDebug     = MethodEntrypoint(new MethodWithToken(method, moduleToken, constrainedType: null, unboxing: false, context: null), false, false, false);
                MethodWithGCInfo methodCodeNodeDebug = methodNodeDebug as MethodWithGCInfo;
                if (methodCodeNodeDebug == null && methodNodeDebug is DelayLoadMethodImport DelayLoadMethodImport)
                {
                    methodCodeNodeDebug = DelayLoadMethodImport.MethodCodeNode;
                }
                if (methodCodeNodeDebug == null && methodNodeDebug is PrecodeMethodImport precodeMethodImport)
                {
                    methodCodeNodeDebug = precodeMethodImport.MethodCodeNode;
                }
                Debug.Assert(methodCodeNodeDebug == methodCodeNode);
#endif

                if (methodCodeNode != null && !methodCodeNode.IsEmpty)
                {
                    yield return(methodCodeNode);
                }
            }
        }
コード例 #3
0
 public RuntimeDeterminedMethodNode(MethodDesc method, IMethodNode canonicalMethod)
 {
     Debug.Assert(!method.IsSharedByGenericInstantiations);
     Debug.Assert(method.IsRuntimeDeterminedExactMethod);
     Method = method;
     _canonicalMethodNode = canonicalMethod;
 }
コード例 #4
0
        private void SolveButton_Click(object sender, RoutedEventArgs e)
        {
            Lazy <IMethodAnnotations>  methodAnnotations  = (Lazy <IMethodAnnotations>)((object[])this.DataContext)[1];
            Lazy <IUndoCommandService> undoCommandService = (Lazy <IUndoCommandService>)((object[])this.DataContext)[2];
            IMethodNode methodNode = (IMethodNode)(((object[])this.DataContext)[0]);

            if (BlocksListView.SelectedItem == null)
            {
                return;
            }

            if (Consts.Items.Count > 0)
            {
                MsgBox.Instance.Show("Not all Consts are set");
                return;
            }

            var ctx   = cflowDeobfuscator.UnsolvedBlocks[BlocksListView.SelectedIndex].Context;
            var expr  = cflowDeobfuscator.UnsolvedBlocks[BlocksListView.SelectedIndex].Expression;
            var block = cflowDeobfuscator.UnsolvedBlocks[BlocksListView.SelectedIndex].Block;

            if (expr != null)
            {
                undoCommandService.Value.Add(new SolveBlock(methodAnnotations.Value, methodNode, ctx, expr, block));

                this.Close();
            }
        }
コード例 #5
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly)
        {
            ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly);

            objData.RequireInitialAlignment(4);
            objData.AddSymbol(this);

            if (BuildSealedVTableSlots(factory, relocsOnly))
            {
                for (int i = 0; i < _sealedVTableEntries.Count; i++)
                {
                    IMethodNode relocTarget = _sealedVTableEntries[i].GetTarget(factory, _type);

                    if (factory.Target.SupportsRelativePointers)
                    {
                        objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32);
                    }
                    else
                    {
                        objData.EmitPointerReloc(relocTarget);
                    }
                }
            }

            return(objData.ToObjectData());
        }
コード例 #6
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly)
        {
            ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly);

            objData.RequireInitialAlignment(4);
            objData.AddSymbol(this);

            if (BuildSealedVTableSlots(factory, relocsOnly))
            {
                for (int i = 0; i < _sealedVTableEntries.Count; i++)
                {
                    MethodDesc  canonImplMethod = _sealedVTableEntries[i].GetCanonMethodTarget(CanonicalFormKind.Specific);
                    IMethodNode relocTarget     = factory.MethodEntrypoint(canonImplMethod, _sealedVTableEntries[i].OwningType.IsValueType);

                    if (factory.Target.SupportsRelativePointers)
                    {
                        objData.EmitReloc(relocTarget, RelocType.IMAGE_REL_BASED_RELPTR32);
                    }
                    else
                    {
                        objData.EmitPointerReloc(relocTarget);
                    }
                }
            }

            return(objData.ToObjectData());
        }
コード例 #7
0
        public static DependencyList GetExactMethodInstantiationDependenciesForMethod(NodeFactory factory, MethodDesc method)
        {
            if (!IsMethodEligibleForTracking(method))
            {
                return(null);
            }

            DependencyList dependencies = new DependencyList();

            // Method entry point dependency
            bool        getUnboxingStub      = method.OwningType.IsValueType && !method.Signature.IsStatic;
            IMethodNode methodEntryPointNode = factory.MethodEntrypoint(method, getUnboxingStub);

            dependencies.Add(new DependencyListEntry(methodEntryPointNode, "Exact method instantiation entry"));

            // Get native layout dependencies for the declaring type
            dependencies.Add(new DependencyListEntry(factory.NecessaryTypeSymbol(method.OwningType), "Exact method instantiation entry"));

            // Get native layout dependencies for the method instantiation args
            foreach (var arg in method.Instantiation)
            {
                dependencies.Add(new DependencyListEntry(factory.NecessaryTypeSymbol(arg), "Exact method instantiation entry"));
            }

            // Get native layout dependencies for the method signature.
            NativeLayoutMethodNameAndSignatureVertexNode nameAndSig = factory.NativeLayout.MethodNameAndSignatureVertex(method.GetTypicalMethodDefinition());

            dependencies.Add(new DependencyListEntry(factory.NativeLayout.PlacedSignatureVertex(nameAndSig), "Exact method instantiation entry"));

            return(dependencies);
        }
コード例 #8
0
        public override IEnumerable <DependencyListEntry> GetStaticDependencies(NodeFactory context)
        {
            DependencyList dependencies = new DependencyList();

            dependencies.Add(new DependencyListEntry(_methodSig, "NativeLayoutMethodEntryVertexNode method signature"));
            if ((_flags & MethodEntryFlags.CreateInstantiatedSignature) != 0)
            {
                dependencies.Add(new DependencyListEntry(context.NecessaryTypeSymbol(_method.OwningType), "NativeLayoutMethodEntryVertexNode containing type"));
                foreach (var arg in _method.Instantiation)
                {
                    dependencies.Add(new DependencyListEntry(context.NecessaryTypeSymbol(arg), "NativeLayoutMethodEntryVertexNode instantiation argument type"));
                }
            }
            else
            {
                dependencies.Add(new DependencyListEntry(_containingTypeSig, "NativeLayoutMethodEntryVertexNode containing type signature"));
                if (_method.HasInstantiation)
                {
                    foreach (var arg in _instantiationArgsSig)
                    {
                        dependencies.Add(new DependencyListEntry(arg, "NativeLayoutMethodEntryVertexNode instantiation argument signature"));
                    }
                }
            }

            if ((_flags & MethodEntryFlags.SaveEntryPoint) != 0)
            {
                bool        getUnboxingStub      = _method.OwningType.IsValueType && !_method.Signature.IsStatic;
                IMethodNode methodEntryPointNode = context.MethodEntrypoint(_method, getUnboxingStub);
                dependencies.Add(new DependencyListEntry(methodEntryPointNode, "NativeLayoutMethodEntryVertexNode entrypoint"));
            }

            return(dependencies);
        }
コード例 #9
0
 private DelegateCreationInfo(IMethodNode constructor, MethodDesc targetMethod, TargetKind targetKind, IMethodNode thunk = null)
 {
     Constructor  = constructor;
     TargetMethod = targetMethod;
     _targetKind  = targetKind;
     Thunk        = thunk;
 }
コード例 #10
0
        public IEnumerable <MethodWithGCInfo> EnumerateCompiledMethods(EcmaModule moduleToEnumerate, CompiledMethodCategory methodCategory)
        {
            foreach (IMethodNode methodNode in MetadataManager.GetCompiledMethods(moduleToEnumerate, methodCategory))
            {
                MethodDesc       method         = methodNode.Method;
                MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
#if DEBUG
                IMethodNode      methodNodeDebug     = MethodEntrypoint(method);
                MethodWithGCInfo methodCodeNodeDebug = methodNodeDebug as MethodWithGCInfo;
                if (methodCodeNodeDebug == null && methodNodeDebug is LocalMethodImport localMethodImport)
                {
                    methodCodeNodeDebug = localMethodImport.MethodCodeNode;
                }
                if (methodCodeNodeDebug == null && methodNodeDebug is PrecodeMethodImport precodeMethodImport)
                {
                    methodCodeNodeDebug = precodeMethodImport.MethodCodeNode;
                }
                Debug.Assert(methodCodeNodeDebug == methodCodeNode);
#endif

                if (methodCodeNode != null && !methodCodeNode.IsEmpty)
                {
                    yield return(methodCodeNode);
                }
            }
        }
コード例 #11
0
            public void AddCompilationRoot(MethodDesc method, string reason)
            {
                MethodDesc  canonMethod      = method.GetCanonMethodTarget(CanonicalFormKind.Specific);
                IMethodNode methodEntryPoint = _factory.MethodEntrypoint(canonMethod);

                _rootAdder(methodEntryPoint, reason);
            }
コード例 #12
0
ファイル: UtcNodeFactory.cs プロジェクト: karelz/corert
        protected override IMethodNode CreateShadowConcreteMethodNode(MethodKey methodKey)
        {
            IMethodNode methodCodeNode = MethodEntrypoint(
                methodKey.Method.GetCanonMethodTarget(CanonicalFormKind.Specific),
                methodKey.IsUnboxingStub);

            return(new ShadowConcreteMethodNode(methodKey.Method, methodCodeNode));
        }
コード例 #13
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (_methods.Count == 0 || relocsOnly)
            {
                return new ObjectData(
                    data: Array.Empty<byte>(), 
                    relocs: Array.Empty<Relocation>(), 
                    alignment: 1, 
                    definedSymbols: new ISymbolDefinitionNode[] { this });
            }

            _methods.Sort(new CompilerComparer());
            GCRefMapBuilder builder = new GCRefMapBuilder(factory.Target, relocsOnly);
            builder.Builder.RequireInitialAlignment(4);
            builder.Builder.AddSymbol(this);

            // First, emit the initial ref map offset and reserve the offset map entries
            int offsetCount = _methods.Count / GCREFMAP_LOOKUP_STRIDE;
            builder.Builder.EmitInt((offsetCount + 1) * sizeof(int));

            ObjectDataBuilder.Reservation[] offsets = new ObjectDataBuilder.Reservation[offsetCount];
            for (int offsetIndex = 0; offsetIndex < offsetCount; offsetIndex++)
            {
                offsets[offsetIndex] = builder.Builder.ReserveInt();
            }

            // Next, generate the actual method GC ref maps and update the offset map
            int nextOffsetIndex = 0;
            int nextMethodIndex = GCREFMAP_LOOKUP_STRIDE - 1;
            for (int methodIndex = 0; methodIndex < _methods.Count; methodIndex++)
            {
                IMethodNode methodNode = _methods[methodIndex];
                if (methodNode == null)
                {
                    // Flush an empty GC ref map block to prevent
                    // the indexed records from falling out of sync with methods
                    builder.Flush();
                }
                else
                {
                    bool isUnboxingStub = false;
                    if (methodNode is DelayLoadHelperImport methodImport)
                    {
                        isUnboxingStub = ((MethodFixupSignature)methodImport.ImportSignature.Target).IsUnboxingStub;
                    }
                    builder.GetCallRefMap(methodNode.Method, isUnboxingStub);
                }
                if (methodIndex >= nextMethodIndex)
                {
                    builder.Builder.EmitInt(offsets[nextOffsetIndex], builder.Builder.CountBytes);
                    nextOffsetIndex++;
                    nextMethodIndex += GCREFMAP_LOOKUP_STRIDE;
                }
            }
            Debug.Assert(nextOffsetIndex == offsets.Length);

            return builder.Builder.ToObjectData();
        }
コード例 #14
0
 public ShadowConcreteMethodNode(MethodDesc method, IMethodNode canonicalMethod)
 {
     Debug.Assert(!method.IsSharedByGenericInstantiations);
     Debug.Assert(!method.IsRuntimeDeterminedExactMethod);
     Debug.Assert(canonicalMethod.Method.IsSharedByGenericInstantiations);
     Debug.Assert(canonicalMethod.Method == method.GetCanonMethodTarget(CanonicalFormKind.Specific));
     Method = method;
     CanonicalMethodNode = canonicalMethod;
 }
コード例 #15
0
 public SolveBlock(IMethodAnnotations methodAnnotations, IMethodNode methodNode, Context ctx, BoolExpr expr, Block block)
 {
     this.methodAnnotations = methodAnnotations;
     this.methodNode        = methodNode;
     this.origMethodBody    = methodNode.MethodDef.MethodBody;
     this.ctx   = ctx;
     this.expr  = expr;
     this.block = block;
 }
コード例 #16
0
 SolveMethod(IMethodAnnotations methodAnnotations, IMethodNode methodNode, List <DeadInstr> deadInstructions, CancellationToken token)
 {
     this.methodAnnotations = methodAnnotations;
     this.methodNode        = methodNode;
     this.origMethodBody    = methodNode.MethodDef.MethodBody;
     this.deadInstructions  = new DeadInstr[deadInstructions.Count];
     deadInstructions.CopyTo(this.deadInstructions);
     this.token = token;
 }
コード例 #17
0
ファイル: DelegateCreationInfo.cs プロジェクト: z77ma/runtime
 private DelegateCreationInfo(IMethodNode constructor, MethodDesc targetMethod, TargetKind targetKind, IMethodNode thunk = null)
 {
     Debug.Assert(targetKind != TargetKind.VTableLookup ||
                  MetadataVirtualMethodAlgorithm.FindSlotDefiningMethodForVirtualMethod(targetMethod) == targetMethod);
     Constructor  = constructor;
     TargetMethod = targetMethod;
     _targetKind  = targetKind;
     Thunk        = thunk;
 }
コード例 #18
0
            public void AddCompilationRoot(MethodDesc method, string reason)
            {
                MethodDesc canonMethod = method.GetCanonMethodTarget(CanonicalFormKind.Specific);

                if (_factory.CompilationModuleGroup.ContainsMethodBody(canonMethod, false))
                {
                    IMethodNode methodEntryPoint = _factory.CompiledMethodNode(canonMethod);
                    _rootAdder(methodEntryPoint, reason);
                }
            }
コード例 #19
0
            ProxyMethod(IMethodAnnotations methodAnnotations, IMethodNode methodNode, CancellationToken token)
            {
                this.methodAnnotations = methodAnnotations;
                this.methodNode        = methodNode;
                this.token             = token;

                this.methods         = new List <MethodDef>();
                this.origMethodBodys = new List <MethodBody>();
                this.isBodyModified  = new List <bool>();
            }
コード例 #20
0
            public void AddCompilationRoot(MethodDesc method, string reason, string exportName = null)
            {
                IMethodNode methodEntryPoint = _factory.CanonicalEntrypoint(method);

                _graph.AddRoot(methodEntryPoint, reason);

                if (exportName != null)
                {
                    _factory.NodeAliases.Add(methodEntryPoint, exportName);
                }
            }
コード例 #21
0
ファイル: MetadataGeneration.cs プロジェクト: SedarG/corert
        private void Graph_NewMarkedNode(DependencyNodeCore <NodeFactory> obj)
        {
            var eetypeNode = obj as EETypeNode;

            if (eetypeNode != null)
            {
                _typesWithEETypesGenerated.Add(eetypeNode.Type);
                AddGeneratedType(eetypeNode.Type);
                return;
            }

            IMethodNode methodNode = obj as MethodCodeNode;

            if (methodNode == null)
            {
                methodNode = obj as ShadowConcreteMethodNode <MethodCodeNode>;
            }

            if (methodNode != null)
            {
                MethodDesc method = methodNode.Method;
                if (method.IsCanonicalMethod(CanonicalFormKind.Specific))
                {
                    // Canonical methods are not interesting.
                    return;
                }

                AddGeneratedType(method.OwningType);
                _methodDefinitionsGenerated.Add(method.GetTypicalMethodDefinition());
                _methodsGenerated.Add(method);
                return;
            }

            var nonGcStaticSectionNode = obj as NonGCStaticsNode;

            if (nonGcStaticSectionNode != null && _nodeFactory.TypeSystemContext.HasLazyStaticConstructor(nonGcStaticSectionNode.Type))
            {
                _cctorContextsGenerated.Add(nonGcStaticSectionNode);
            }

            var gvmEntryNode = obj as TypeGVMEntriesNode;

            if (gvmEntryNode != null)
            {
                _typeGVMEntries.Add(gvmEntryNode);
            }

            var dictionaryNode = obj as GenericDictionaryNode;

            if (dictionaryNode != null)
            {
                _genericDictionariesGenerated.Add(dictionaryNode);
            }
        }
コード例 #22
0
 public DelegateCtorSignature(
     TypeDesc delegateType,
     IMethodNode targetMethod,
     ModuleToken methodToken,
     SignatureContext signatureContext)
 {
     _delegateType     = delegateType;
     _targetMethod     = targetMethod;
     _methodToken      = methodToken;
     _signatureContext = signatureContext;
 }
コード例 #23
0
        public override Vertex WriteVertex(NodeFactory factory)
        {
            Vertex containingType   = GetContainingTypeVertex(factory);
            Vertex methodSig        = _methodSig.WriteVertex(factory);
            Vertex methodNameAndSig = GetNativeWriter(factory).GetMethodNameAndSigSignature(_method.Name, methodSig);

            Vertex[]    args  = null;
            MethodFlags flags = 0;

            if (_method.HasInstantiation)
            {
                Debug.Assert(_instantiationArgsSig == null || (_instantiationArgsSig != null && _method.Instantiation.Length == _instantiationArgsSig.Length));

                flags |= MethodFlags.HasInstantiation;
                args   = new Vertex[_method.Instantiation.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    if ((_flags & MethodEntryFlags.CreateInstantiatedSignature) != 0)
                    {
                        IEETypeNode eetypeNode = factory.NecessaryTypeSymbol(_method.Instantiation[i]);
                        uint        typeIndex  = factory.MetadataManager.NativeLayoutInfo.ExternalReferences.GetIndex(eetypeNode);
                        args[i] = GetNativeWriter(factory).GetExternalTypeSignature(typeIndex);
                    }
                    else
                    {
                        args[i] = _instantiationArgsSig[i].WriteVertex(factory);
                    }
                }
            }

            uint fptrReferenceId = 0;

            if ((_flags & MethodEntryFlags.SaveEntryPoint) != 0)
            {
                flags |= MethodFlags.HasFunctionPointer;

                bool        getUnboxingStub      = _method.OwningType.IsValueType && !_method.Signature.IsStatic;
                IMethodNode methodEntryPointNode = factory.MethodEntrypoint(_method, getUnboxingStub);
                fptrReferenceId = factory.MetadataManager.NativeLayoutInfo.ExternalReferences.GetIndex(methodEntryPointNode);

                if (getUnboxingStub)
                {
                    flags |= MethodFlags.IsUnboxingStub;
                }
                if (_method.IsCanonicalMethod(CanonicalFormKind.Universal))
                {
                    flags |= MethodFlags.FunctionPointerIsUSG;
                }
            }

            return(GetNativeWriter(factory).GetMethodSignature((uint)flags, fptrReferenceId, containingType, methodNameAndSig, args));
        }
コード例 #24
0
 public EditedMethodBodyUpdater(Lazy <IMethodAnnotations> methodAnnotations, IModuleFileNode modNode, MethodDef originalMethod, Emit.MethodBody newBody, MethodImplAttributes newImplAttributes)
 {
     this.methodAnnotations = methodAnnotations;
     this.ownerNode         = modNode.Context.FileTreeView.FindNode(originalMethod);
     if (ownerNode == null)
     {
         throw new InvalidOperationException();
     }
     this.method            = originalMethod;
     this.originalBodyState = new BodyState(originalMethod, methodAnnotations.Value.IsBodyModified(method));
     this.newBodyState      = new BodyState(newBody, newImplAttributes, true);
 }
コード例 #25
0
        public static bool MethodHasAssociatedData(NodeFactory factory, IMethodNode methodNode)
        {
            // Instantiating unboxing stubs. We need to store their non-unboxing target pointer (looked up by runtime)
            ISpecialUnboxThunkNode unboxThunk = methodNode as ISpecialUnboxThunkNode;

            if (unboxThunk != null && unboxThunk.IsSpecialUnboxingThunk)
            {
                return(true);
            }

            return(false);
        }
コード例 #26
0
        private void Graph_NewMarkedNode(DependencyNodeCore <NodeFactory> obj)
        {
            var eetypeNode = obj as EETypeNode;

            if (eetypeNode != null)
            {
                _typesWithEETypesGenerated.Add(eetypeNode.Type);
                AddGeneratedType(eetypeNode.Type);
                return;
            }

            IMethodNode methodNode = obj as MethodCodeNode;

            if (methodNode == null)
            {
                methodNode = obj as ShadowConcreteMethodNode <MethodCodeNode>;
            }

            if (methodNode == null)
            {
                methodNode = obj as NonExternMethodSymbolNode;
            }

            if (methodNode != null)
            {
                MethodDesc method = methodNode.Method;

                AddGeneratedMethod(method);
                return;
            }

            var nonGcStaticSectionNode = obj as NonGCStaticsNode;

            if (nonGcStaticSectionNode != null && _typeSystemContext.HasLazyStaticConstructor(nonGcStaticSectionNode.Type))
            {
                _cctorContextsGenerated.Add(nonGcStaticSectionNode);
            }

            var gvmEntryNode = obj as TypeGVMEntriesNode;

            if (gvmEntryNode != null)
            {
                _typeGVMEntries.Add(gvmEntryNode);
            }

            var dictionaryNode = obj as GenericDictionaryNode;

            if (dictionaryNode != null)
            {
                _genericDictionariesGenerated.Add(dictionaryNode);
            }
        }
コード例 #27
0
        public DelegateCtorSignature(
            TypeDesc delegateType,
            IMethodNode targetMethod,
            ModuleToken methodToken)
        {
            _delegateType = delegateType;
            _targetMethod = targetMethod;
            _methodToken  = methodToken;

            // Ensure types in signature are loadable and resolvable, otherwise we'll fail later while emitting the signature
            CompilerTypeSystemContext compilerContext = (CompilerTypeSystemContext)delegateType.Context;

            compilerContext.EnsureLoadableType(delegateType);
            compilerContext.EnsureLoadableMethod(targetMethod.Method);
        }
コード例 #28
0
        public void AddCompilationRoot(MethodDesc method, string reason, string exportName = null)
        {
            MethodDesc  canonMethod      = method.GetCanonMethodTarget(CanonicalFormKind.Specific);
            IMethodNode methodEntryPoint = _factory.MethodEntrypoint(canonMethod);

            _rootAdder(methodEntryPoint, reason);

            if (exportName != null)
            {
                _factory.NodeAliases.Add(methodEntryPoint, exportName);
            }

            if (canonMethod != method && method.HasInstantiation)
            {
                _rootAdder(_factory.MethodGenericDictionary(method), reason);
            }
        }
コード例 #29
0
        public IEnumerable <MethodWithGCInfo> EnumerateCompiledMethods()
        {
            foreach (MethodDesc method in MetadataManager.GetCompiledMethods())
            {
                IMethodNode      methodNode     = MethodEntrypoint(method);
                MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
                if (methodCodeNode == null && methodNode is LocalMethodImport localMethodImport)
                {
                    methodCodeNode = localMethodImport.MethodCodeNode;
                }

                if (methodCodeNode != null && !methodCodeNode.IsEmpty)
                {
                    yield return(methodCodeNode);
                }
            }
        }
コード例 #30
0
        private static XmlMethodNode MethodNodeMap(IMethodNode methodNode)
        {
            var xmlMethodNode = new XmlMethodNode
            {
                ExecutionTime  = methodNode.ExecutionTime.TotalMilliseconds,
                ClassName      = methodNode.ClassName,
                MethodName     = methodNode.MethodName,
                ParametrCounts = methodNode.ParametrCounts,
                ChildNodes     = new List <XmlMethodNode>()
            };

            foreach (var method in methodNode.ChildNodes)
            {
                xmlMethodNode.ChildNodes.Add(MethodNodeMap(method));
            }
            return(xmlMethodNode);
        }
コード例 #31
0
ファイル: MethodDefCommands.cs プロジェクト: lovebanyi/dnSpy
		MethodDefSettingsCommand(IMethodNode methodNode, MethodDefOptions options) {
			this.methodNode = methodNode;
			this.newOptions = options;
			this.origOptions = new MethodDefOptions(methodNode.MethodDef);

			this.origParentNode = (IFileTreeNodeData)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();
		}
コード例 #32
0
ファイル: MethodDefCommands.cs プロジェクト: lovebanyi/dnSpy
		CreateMethodDefCommand(ITypeNode ownerNode, MethodDefOptions options) {
			this.ownerNode = ownerNode;
			this.methodNode = ownerNode.Create(options.CreateMethodDef(ownerNode.TypeDef.Module));
		}
コード例 #33
0
 private DelegateCreationInfo(IMethodNode constructor, ISymbolNode target, IMethodNode thunk = null)
 {
     Constructor = constructor;
     Target = target;
     Thunk = thunk;
 }
コード例 #34
0
ファイル: MethodDefCommands.cs プロジェクト: lovebanyi/dnSpy
			public void Restore(IMethodNode[] nodes) {
				Debug.Assert(infos != null);
				if (infos == null)
					throw new InvalidOperationException();
				Debug.Assert(infos.Length == nodes.Length);
				if (infos.Length != nodes.Length)
					throw new InvalidOperationException();

				for (int i = infos.Length - 1; i >= 0; i--) {
					var node = nodes[i];
					var info = infos[i];

					info.OwnerType.Methods.Insert(info.MethodIndex, node.MethodDef);

					for (int j = info.PropEventInfos.Count - 1; j >= 0; j--) {
						var pinfo = info.PropEventInfos[i];
						EventDef evt;
						switch (pinfo.PropEventType) {
						case ModelInfo.PropEventType.PropertyGetter:
							((PropertyDef)pinfo.PropOrEvent).GetMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.PropertySetter:
							((PropertyDef)pinfo.PropOrEvent).SetMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.PropertyOther:
							((PropertyDef)pinfo.PropOrEvent).OtherMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.EventAdd:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.AddMethod == null);
							if (evt.AddMethod != null)
								throw new InvalidOperationException();
							evt.AddMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventInvoke:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.InvokeMethod == null);
							if (evt.InvokeMethod != null)
								throw new InvalidOperationException();
							evt.InvokeMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventRemove:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.RemoveMethod == null);
							if (evt.RemoveMethod != null)
								throw new InvalidOperationException();
							evt.RemoveMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventOther:
							((EventDef)pinfo.PropOrEvent).OtherMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						default:
							throw new InvalidOperationException();
						}
					}
				}

				infos = null;
			}
コード例 #35
0
ファイル: MethodDefCommands.cs プロジェクト: lovebanyi/dnSpy
		DeleteMethodDefCommand(IMethodNode[] methodNodes) {
			this.nodes = new DeletableNodes<IMethodNode>(methodNodes);
		}
コード例 #36
0
ファイル: MethodBodyCommands.cs プロジェクト: lovebanyi/dnSpy
		MethodBodySettingsCommand(IMethodAnnotations methodAnnotations, IMethodNode methodNode, MethodBodyOptions options) {
			this.methodAnnotations = methodAnnotations;
			this.methodNode = methodNode;
			this.newOptions = options;
			this.origMethodBody = methodNode.MethodDef.MethodBody;
		}
コード例 #37
0
ファイル: MethodDefCommands.cs プロジェクト: lovebanyi/dnSpy
			public void Delete(IMethodNode[] nodes) {
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModelInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];

					var info = new ModelInfo(node.MethodDef);
					infos[i] = info;

					foreach (var prop in info.OwnerType.Properties) {
						info.AddMethods(prop, ModelInfo.PropEventType.PropertyGetter, prop.GetMethods, node.MethodDef);
						info.AddMethods(prop, ModelInfo.PropEventType.PropertySetter, prop.SetMethods, node.MethodDef);
						info.AddMethods(prop, ModelInfo.PropEventType.PropertyOther, prop.OtherMethods, node.MethodDef);
					}

					foreach (var evt in info.OwnerType.Events) {
						if (evt.AddMethod == node.MethodDef) {
							evt.AddMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventAdd, -1));
						}
						if (evt.InvokeMethod == node.MethodDef) {
							evt.InvokeMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventInvoke, -1));
						}
						if (evt.RemoveMethod == node.MethodDef) {
							evt.RemoveMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventRemove, -1));
						}
						info.AddMethods(evt, ModelInfo.PropEventType.EventOther, evt.OtherMethods, node.MethodDef);
					}

					info.OwnerType.Methods.RemoveAt(info.MethodIndex);
				}
			}