Beispiel #1
0
        bool MarkAsSaved(SaveMultiModuleVM vm, object[] docs)
        {
            bool allSaved = true;

            foreach (var doc in docs)
            {
                if (!vm.WasSaved(doc))
                {
                    allSaved = false;
                }
                else
                {
                    undoCommandManager.Value.MarkAsSaved(undoCommandManager.Value.GetUndoObject(doc));
                    var file = doc as IDnSpyFile;
                    if (file != null && string.IsNullOrEmpty(file.Filename))
                    {
                        var filename = vm.GetSavedFileName(doc);
                        if (!string.IsNullOrWhiteSpace(filename) && file.ModuleDef != null)
                        {
                            file.ModuleDef.Location = filename;
                            file.Filename           = filename;
                            var modNode = fileTabManager.FileTreeView.FindNode(file.ModuleDef) as IModuleFileNode;
                            Debug.Assert(modNode != null);
                            if (modNode != null)
                            {
                                modNode.TreeNode.RefreshUI();
                                fileTabManager.RefreshModifiedFile(modNode.DnSpyFile);
                            }
                        }
                    }
                }
            }
            return(allSaved);
        }
        void RefreshBodies(MemoryModuleDefFile file)
        {
            // Free all method bodies and clear cache so the new bodies are shown if any
            // got modified (eg. decrypted in memory)
            for (uint rid = 1; ; rid++)
            {
                var md = file.ModuleDef.ResolveToken(new MDToken(Table.Method, rid)) as MethodDef;
                if (md == null)
                {
                    break;
                }
                methodAnnotations.Value.SetBodyModified(md, false);
                md.FreeMethodBody();
            }
            fileTabManager.RefreshModifiedFile(file);

            // A breakpoint in an encrypted method will fail to be created. Now's a good time to
            // re-add any failed breakpoints.
            if (!file.Process.HasExited && file.Process.Debugger.ProcessState != DebuggerProcessState.Terminated)
            {
                foreach (var module in file.Process.Modules)
                {
                    if (module.Address == file.Address)
                    {
                        file.Process.Debugger.AddBreakpoints(module);
                    }
                }
            }
        }
        bool IUndoableDocumentsProvider.OnExecutedOneCommand(IUndoObject obj)
        {
            var file = TryGetDnSpyFile(obj);

            if (file != null)
            {
                var module = file.ModuleDef;
                if (module != null)
                {
                    module.ResetTypeDefFindCache();
                }
                fileTabManager.RefreshModifiedFile(file);
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        public void Update()
        {
            // If none of its children have been loaded, we can safely return without doing anything
            if (ModuleNode.TreeNode.LazyLoading)
            {
                return;
            }

            if (loadedClassTokens != null)
            {
                foreach (var a in loadedClassTokens)
                {
                    modifiedTypes.Add(a);
                }
            }
            var tokensList = new List <uint>(modifiedTypes);

            tokensList.Sort();

            bool needRedecompile = false;

            foreach (uint token in tokensList)
            {
                var td = CorModuleDefFile.DnModule.CorModuleDef.ResolveToken(token) as TypeDef;
                Debug.Assert(td != null);
                if (td == null)
                {
                    continue;
                }
                Update(td);
                needRedecompile = true;
            }

            if (needRedecompile)
            {
                // Force a re-decompile of every view that references this module. This could be
                // optimized if necessary
                fileTabManager.RefreshModifiedFile(CorModuleDefFile);
            }
        }