Esempio n. 1
0
        void LoadInternal()
        {
            DNSpySettings settings = DNSpySettings.Load();
            var           bpsx     = settings[SETTINGS_NAME];

            BreakpointManager.Instance.Clear();
            foreach (var bpx in bpsx.Elements("Breakpoint"))
            {
                uint?  token       = (uint?)bpx.Attribute("Token");
                string asmFullName = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullName"));
                string moduleName  = SessionSettings.Unescape((string)bpx.Attribute("ModuleName"));
                bool?  isDynamic   = (bool?)bpx.Attribute("IsDynamic");
                bool?  isInMemory  = (bool?)bpx.Attribute("IsInMemory");
                uint?  ilOffset    = (uint?)bpx.Attribute("ILOffset");
                bool?  isEnabled   = (bool?)bpx.Attribute("IsEnabled");

                if (token == null)
                {
                    continue;
                }
                if (isDynamic == null || isInMemory == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(asmFullName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleName))
                {
                    continue;
                }
                if (ilOffset == null)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }

                var snModule = SerializedDnSpyModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value);
                var key      = new SerializedDnSpyToken(snModule, token.Value);

                if (!isInMemory.Value && !isDynamic.Value)
                {
                    var s = SessionSettings.Unescape((string)bpx.Attribute("Method"));
                    if (s == null || s != GetMethodAsString(key))
                    {
                        continue;
                    }
                }

                var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
                BreakpointManager.Instance.Add(bp);
            }
        }
Esempio n. 2
0
		static DnModule GetDnModule(SerializedDnSpyModule serMod) {
			var dbg = DebugManager.Instance.Debugger;
			if (dbg == null)
				return null;
			//TODO: This method should have an AppDomain parameter.
			foreach (var m in dbg.Modules) {
				if (m.SerializedDnModule.ToSerializedDnSpyModule().Equals(serMod))
					return m;
			}
			return null;
		}
Esempio n. 3
0
        DnSpyFile LoadNonDiskFile(SerializedDnSpyModule serMod, bool canLoadDynFile)
        {
            if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory)
            {
                var dnModule = GetDnModule(serMod);
                if (dnModule != null)
                {
                    return(InMemoryModuleManager.Instance.LoadFile(dnModule, canLoadDynFile));
                }
            }

            return(null);
        }
Esempio n. 4
0
        public SerializedDnSpyModule GetSerializedDnSpyModule(ModuleDef module)
        {
            if (module == null)
            {
                return(new SerializedDnSpyModule());
            }
            var modNode = FindModuleNode(module);

            if (modNode == null)
            {
                return(SerializedDnSpyModule.CreateFromFile(module));
            }
            return(modNode.DnSpyFile.SerializedDnSpyModule ?? SerializedDnSpyModule.CreateFromFile(module));
        }
Esempio n. 5
0
        static DnModule GetDnModule(SerializedDnSpyModule serMod)
        {
            var dbg = DebugManager.Instance.Debugger;

            if (dbg == null)
            {
                return(null);
            }
            //TODO: This method should have an AppDomain parameter.
            foreach (var m in dbg.Modules)
            {
                if (m.SerializedDnModule.ToSerializedDnSpyModule().Equals(serMod))
                {
                    return(m);
                }
            }
            return(null);
        }
Esempio n. 6
0
        DnSpyFile LoadExisting(SerializedDnSpyModule serMod)
        {
            foreach (var file in AllActiveDnSpyFiles)
            {
                var serModFile = file.SerializedDnSpyModule;
                if (serModFile != null && serModFile.Value.Equals(serMod))
                {
                    return(file);
                }
            }

            foreach (var file in AllDnSpyFiles)
            {
                var serModFile = file.SerializedDnSpyModule;
                if (serModFile != null && serModFile.Value.Equals(serMod))
                {
                    return(file);
                }
            }

            return(null);
        }
Esempio n. 7
0
		public static void GoToIL(SerializedDnSpyModule serAsm, uint token, uint ilOffset, bool newTab) {
			var file = ModuleLoader.Instance.LoadModule(serAsm, true);
			GoToIL(file, token, ilOffset, newTab);
		}
 public static SerializedDnSpyModule ToSerializedDnSpyModule(this SerializedDnModule self)
 {
     return(SerializedDnSpyModule.Create(self.AssemblyFullName, self.ModuleName, self.IsDynamic, self.IsInMemory));
 }
Esempio n. 9
0
		public DnSpyFile LoadModule(SerializedDnSpyModule serMod, bool canLoadDynFile, bool diskFileOk = false) {
			const bool isAutoLoaded = true;

			if (diskFileOk) {
				var file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile);
				if (file != null)
					return file;
			}
			else {
				var file = LoadNonDiskFile(serMod, canLoadDynFile) ?? LoadExisting(serMod);
				if (file != null)
					return file;
			}

			if (serMod.IsDynamic || serMod.IsInMemory)
				return null;

			string moduleFilename = serMod.ModuleName;
			if (!File.Exists(moduleFilename))
				return null;
			string asmFilename = GetAssemblyFilename(moduleFilename, serMod.AssemblyFullName);
			var dnspyFileList = MainWindow.Instance.DnSpyFileList;
			lock (dnspyFileList.GetLockObj()) {
				if (string.IsNullOrEmpty(asmFilename))
					return dnspyFileList.OpenFileDelay(moduleFilename, isAutoLoaded);

				var file = dnspyFileList.OpenFileDelay(asmFilename, isAutoLoaded);
				if (file == null)
					return null;

				// Common case is a one-file assembly or first module of a multifile assembly
				if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
					return file;

				var loadedMod = MainWindow.Instance.DnSpyFileListTreeNode.FindModule(file, moduleFilename);
				if (loadedMod != null)
					return loadedMod;

				Debug.Fail("Shouldn't be here.");
				return dnspyFileList.OpenFileDelay(moduleFilename, isAutoLoaded);
			}
		}
Esempio n. 10
0
		DnSpyFile LoadExisting(SerializedDnSpyModule serMod) {
			foreach (var file in AllActiveDnSpyFiles) {
				var serModFile = file.SerializedDnSpyModule;
				if (serModFile != null && serModFile.Value.Equals(serMod))
					return file;
			}

			foreach (var file in AllDnSpyFiles) {
				var serModFile = file.SerializedDnSpyModule;
				if (serModFile != null && serModFile.Value.Equals(serMod))
					return file;
			}

			return null;
		}
Esempio n. 11
0
		DnSpyFile LoadNonDiskFile(SerializedDnSpyModule serMod, bool canLoadDynFile) {
			if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory) {
				var dnModule = GetDnModule(serMod);
				if (dnModule != null)
					return InMemoryModuleManager.Instance.LoadFile(dnModule, canLoadDynFile);
			}

			return null;
		}
Esempio n. 12
0
        public static void GoToIL(SerializedDnSpyModule serAsm, uint token, uint ilOffset, bool newTab)
        {
            var file = ModuleLoader.Instance.LoadModule(serAsm, true);

            GoToIL(file, token, ilOffset, newTab);
        }
Esempio n. 13
0
        public DnSpyFile LoadModule(SerializedDnSpyModule serMod, bool canLoadDynFile, bool diskFileOk = false)
        {
            const bool isAutoLoaded = true;

            if (diskFileOk)
            {
                var file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile);
                if (file != null)
                {
                    return(file);
                }
            }
            else
            {
                var file = LoadNonDiskFile(serMod, canLoadDynFile) ?? LoadExisting(serMod);
                if (file != null)
                {
                    return(file);
                }
            }

            if (serMod.IsDynamic || serMod.IsInMemory)
            {
                return(null);
            }

            string moduleFilename = serMod.ModuleName;

            if (!File.Exists(moduleFilename))
            {
                return(null);
            }
            string asmFilename   = GetAssemblyFilename(moduleFilename, serMod.AssemblyFullName);
            var    dnspyFileList = MainWindow.Instance.DnSpyFileList;

            lock (dnspyFileList.GetLockObj()) {
                if (string.IsNullOrEmpty(asmFilename))
                {
                    return(dnspyFileList.OpenFileDelay(moduleFilename, isAutoLoaded));
                }

                var file = dnspyFileList.OpenFileDelay(asmFilename, isAutoLoaded);
                if (file == null)
                {
                    return(null);
                }

                // Common case is a one-file assembly or first module of a multifile assembly
                if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                {
                    return(file);
                }

                var loadedMod = MainWindow.Instance.DnSpyFileListTreeNode.FindModule(file, moduleFilename);
                if (loadedMod != null)
                {
                    return(loadedMod);
                }

                Debug.Fail("Shouldn't be here.");
                return(dnspyFileList.OpenFileDelay(moduleFilename, isAutoLoaded));
            }
        }