예제 #1
0
		public void LoadInternal() {
			ILSpySettings settings = ILSpySettings.Load();
			var bpsx = settings["Breakpoints"];
			BreakpointManager.Instance.Clear();
			foreach (var bpx in bpsx.Elements("Breakpoint")) {
				uint? token = (uint?)bpx.Attribute("Token");
				string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
				string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
				bool isDynamic = (bool?)bpx.Attribute("IsDynamic") ?? false;
				bool isInMemory = (bool?)bpx.Attribute("IsInMemory") ?? false;
				uint? ilOffset = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");//TODO: Remove "From" some time after this commit
				bool? isEnabled = (bool?)bpx.Attribute("IsEnabled");

				if (token == null)
					continue;
				if (string.IsNullOrEmpty(moduleFullPath))
					continue;
				if (ilOffset == null)
					continue;
				if (isEnabled == null)
					continue;

				var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory);
				var key = MethodKey.Create(token.Value, snModule);
				var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value);
				BreakpointManager.Instance.Add(bp);
			}
		}
예제 #2
0
        internal void RefreshIfNameError(SerializedDnModule serMod)
        {
            if (!NameError)
            {
                return;
            }

            var dnbp = Breakpoint.DnBreakpoint as DnILCodeBreakpoint;

            if (dnbp == null)
            {
                return;
            }
            if (dnbp.Module != serMod)
            {
                return;
            }

            // If we still can't resolve the method, there's no need to refresh the name field
            if (GetMethodDef(true) == null)
            {
                return;
            }

            RefreshNameField();
        }
예제 #3
0
 internal DnCodeBreakpoint(SerializedDnModule module, uint token, uint offset)
 {
     this.module = module;
     this.token = token;
     this.offset = offset;
     this.code = null;
 }
예제 #4
0
 internal DnILCodeBreakpoint(SerializedDnModule module, uint token, uint ilOffset, IBreakpointCondition bpCond)
     : base(bpCond)
 {
     this.module = module;
     this.token = token;
     this.ilOffset = ilOffset;
 }
예제 #5
0
 internal DnModule(DnAssembly ownerAssembly, ICorDebugModule module, int incrementedId, int moduleOrder)
 {
     this.ownerAssembly = ownerAssembly;
     this.module = new CorModule(module);
     this.incrementedId = incrementedId;
     this.moduleOrder = moduleOrder;
     this.serializedDnModule = this.module.SerializedDnModule;
 }
예제 #6
0
 internal DnCodeBreakpoint(CorCode code, uint offset)
 {
     this.module = GetModule(code);
     var func = code.Function;
     this.token = func == null ? 0 : func.Token;
     this.offset = offset;
     this.code = code;
 }
예제 #7
0
파일: MethodKey.cs 프로젝트: ottrur/dnSpy
 MethodKey(uint token, ModuleDef module)
 {
     this.token = token;
     if (string.IsNullOrEmpty(module.Location))
     {
         throw new ArgumentException("Module has no path");
     }
     this.module = new SerializedDnModule(Path.GetFullPath(module.Location));
 }
예제 #8
0
        void LoadInternal()
        {
            var section = settingsManager.GetOrCreateSection(SETTINGS_GUID);

            breakpointManager.Clear();
            foreach (var bpx in section.SectionsWithName("Breakpoint"))
            {
                uint?  token          = bpx.Attribute <uint?>("Token");
                string asmFullName    = bpx.Attribute <string>("AssemblyFullName");
                string moduleName     = bpx.Attribute <string>("ModuleName");
                bool?  isDynamic      = bpx.Attribute <bool?>("IsDynamic");
                bool?  isInMemory     = bpx.Attribute <bool?>("IsInMemory");
                bool   moduleNameOnly = bpx.Attribute <bool?>("ModuleNameOnly") ?? false;
                uint?  ilOffset       = bpx.Attribute <uint?>("ILOffset");
                bool?  isEnabled      = bpx.Attribute <bool?>("IsEnabled");

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

                var snModule = SerializedDnModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value, moduleNameOnly);
                var key      = new SerializedDnToken(snModule, token.Value);

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

                var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value);
                breakpointManager.Add(bp);
            }
        }
예제 #9
0
		DnModule GetDnModule(SerializedDnModule serMod) {
			var dbg = theDebugger.Value.Debugger;
			if (dbg == null)
				return null;
			//TODO: This method should have an AppDomain parameter.
			foreach (var m in dbg.Modules) {
				if (m.SerializedDnModule.Equals(serMod))
					return m;
			}
			return null;
		}
예제 #10
0
        IDnSpyFile LoadNonDiskFile(SerializedDnModule serMod, bool canLoadDynFile)
        {
            if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory)
            {
                var dnModule = GetDnModule(serMod);
                if (dnModule != null)
                {
                    return(inMemoryModuleManager.Value.LoadFile(dnModule, canLoadDynFile));
                }
            }

            return(null);
        }
예제 #11
0
        internal static SerializedDnModule Create(IFileTreeView fileTreeView, ModuleDef module)
        {
            if (module == null)
            {
                return(new SerializedDnModule());
            }
            var modNode = fileTreeView.FindNode(module);

            if (modNode == null)
            {
                return(SerializedDnModule.CreateFromFile(module));
            }
            return(modNode.DnSpyFile.ToSerializedDnModule());
        }
예제 #12
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 assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath"));
                string moduleFullPath   = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath"));
                bool   isDynamic        = (bool?)bpx.Attribute("IsDynamic") ?? false;
                bool   isInMemory       = (bool?)bpx.Attribute("IsInMemory") ?? false;
                uint?  ilOffset         = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");       //TODO: Remove "From" some time after this commit
                bool?  isEnabled        = (bool?)bpx.Attribute("IsEnabled");

                if (token == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(moduleFullPath))
                {
                    continue;
                }
                if (ilOffset == null)
                {
                    continue;
                }
                if (isEnabled == null)
                {
                    continue;
                }

                var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory);
                var key      = MethodKey.Create(token.Value, snModule);

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

                var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value);
                BreakpointManager.Instance.Add(bp);
            }
        }
예제 #13
0
		internal void RefreshIfNameError(SerializedDnModule serMod) {
			if (!NameError)
				return;

			var dnbp = Breakpoint.DnBreakpoint as DnILCodeBreakpoint;
			if (dnbp == null)
				return;
			if (dnbp.Module != serMod)
				return;

			// If we still can't resolve the method, there's no need to refresh the name field
			if (GetMethodDef(true) == null)
				return;

			RefreshNameField();
		}
예제 #14
0
        public static SerializedDnModule ToSerializedDnModule(this IDnSpyFile file)
        {
            var sdm = file as ISerializedDnModule;

            if (sdm != null)
            {
                return(sdm.SerializedDnModule ?? new SerializedDnModule());
            }
            var mod = file.ModuleDef;

            if (mod == null)
            {
                return(new SerializedDnModule());
            }
            return(SerializedDnModule.CreateFromFile(mod));
        }
예제 #15
0
        DnModule GetDnModule(SerializedDnModule serMod)
        {
            var dbg = theDebugger.Value.Debugger;

            if (dbg == null)
            {
                return(null);
            }
            //TODO: This method should have an AppDomain parameter.
            foreach (var m in dbg.Modules)
            {
                if (m.SerializedDnModule.Equals(serMod))
                {
                    return(m);
                }
            }
            return(null);
        }
예제 #16
0
        IDnSpyFile LoadExisting(SerializedDnModule serMod)
        {
            foreach (var file in AllActiveDnSpyFiles)
            {
                var serModFile = file.ToSerializedDnModule();
                if (serModFile.Equals(serMod))
                {
                    return(file);
                }
            }

            foreach (var file in AllDnSpyFiles)
            {
                var serModFile = file.ToSerializedDnModule();
                if (serModFile.Equals(serMod))
                {
                    return(file);
                }
            }

            return(null);
        }
예제 #17
0
 IEnumerable<DnModule> GetLoadedDnModules(SerializedDnModule module)
 {
     foreach (var process in processes.GetAll()) {
         foreach (var appDomain in process.AppDomains) {
             foreach (var assembly in appDomain.Assemblies) {
                 foreach (var dnMod in assembly.Modules) {
                     if (dnMod.SerializedDnModule.Equals(module))
                         yield return dnMod;
                 }
             }
         }
     }
 }
예제 #18
0
		public static void GoToIL(IFileTabManager fileTabManager, IModuleLoader moduleLoader, SerializedDnModule serAsm, uint token, uint ilOffset, bool newTab) {
			var file = moduleLoader.LoadModule(serAsm, true);
			GoToIL(fileTabManager, file, token, ilOffset, newTab);
		}
예제 #19
0
        public static void GoToIL(IFileTabManager fileTabManager, IModuleLoader moduleLoader, SerializedDnModule serAsm, uint token, uint ilOffset, bool newTab)
        {
            var file = moduleLoader.LoadModule(serAsm, true);

            GoToIL(fileTabManager, file, token, ilOffset, newTab);
        }
예제 #20
0
파일: MethodKey.cs 프로젝트: ottrur/dnSpy
 public static MethodKey Create(uint token, SerializedDnModule module)
 {
     return(new MethodKey(token, module));
 }
예제 #21
0
 void SetILBreakpoint(SerializedDnModule serMod, uint token)
 {
     Debug.Assert(token != 0 && breakpoint == null);
     DnBreakpoint bp = null;
     bp = debugger.CreateBreakpoint(serMod, token, 0, ctx2 => {
         debugger.RemoveBreakpoint(bp);
         return true;
     });
 }
예제 #22
0
파일: MethodKey.cs 프로젝트: ottrur/dnSpy
 MethodKey(uint token, SerializedDnModule module)
 {
     this.module = module;
     this.token  = token;
 }
예제 #23
0
 public static SerializedDnSpyModule ToSerializedDnSpyModule(this SerializedDnModule self)
 {
     return(SerializedDnSpyModule.Create(self.AssemblyFullName, self.ModuleName, self.IsDynamic, self.IsInMemory));
 }
예제 #24
0
        IDnSpyFile LoadExisting(SerializedDnModule serMod)
        {
            foreach (var file in AllActiveDnSpyFiles) {
                var serModFile = file.ToSerializedDnModule();
                if (serModFile.Equals(serMod))
                    return file;
            }

            foreach (var file in AllDnSpyFiles) {
                var serModFile = file.ToSerializedDnModule();
                if (serModFile.Equals(serMod))
                    return file;
            }

            return null;
        }
예제 #25
0
        IDnSpyFile LoadNonDiskFile(SerializedDnModule serMod, bool canLoadDynFile)
        {
            if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory) {
                var dnModule = GetDnModule(serMod);
                if (dnModule != null)
                    return inMemoryModuleManager.Value.LoadFile(dnModule, canLoadDynFile);
            }

            return null;
        }
예제 #26
0
		internal DnNativeCodeBreakpoint(SerializedDnModule module, uint token, uint offset, Func<NativeCodeBreakpointConditionContext, bool> cond)
			: base(module, token, offset) {
			this.cond = cond ?? defaultCond;
		}
예제 #27
0
        public IDnSpyFile LoadModule(SerializedDnModule serMod, bool canLoadDynFile, bool diskFileOk = false)
        {
            const bool isAutoLoaded = true;

            IDnSpyFile file;
            if (diskFileOk) {
                file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile);
                if (file != null)
                    return file;
            }
            else {
                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, serMod.ModuleNameOnly);

            if (!string.IsNullOrEmpty(asmFilename)) {
                file = fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(asmFilename), isAutoLoaded);
                if (file == null)
                    file = fileManager.Resolve(new AssemblyNameInfo(serMod.AssemblyFullName), null);
                if (file != null) {
                    // Common case is a one-file assembly or first module of a multifile assembly
                    if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                        return file;

                    foreach (var child in file.Children) {
                        if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                            return child;
                    }
                }
            }

            return fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(moduleFilename), isAutoLoaded);
        }
예제 #28
0
        LoadedAssembly LoadAssembly(string asmName, SerializedDnModule module, bool open)
        {
            if (module.IsInMemory)
                return null;//TODO: Support in-memory modules
            string moduleFilename = module.Name;
            lock (assemblyList.GetLockObj()) {
                var loadedAsm = open ? assemblyList.OpenAssemblyDelay(asmName, true) : assemblyList.FindAssemblyByFileName(asmName);
                if (loadedAsm == null)
                    return null;

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

                var loadedMod = assemblyListTreeNode.FindModule(loadedAsm, moduleFilename);
                if (loadedMod != null)
                    return loadedMod;

                Debug.Fail("Shouldn't be here.");
                return open ? assemblyList.OpenAssemblyDelay(moduleFilename, true) : null;
            }
        }
예제 #29
0
 public LoadedAssembly TryLoadAssembly(string asmName, SerializedDnModule module)
 {
     return LoadAssembly(asmName, module, false);
 }
예제 #30
0
        public IDnSpyFile LoadModule(SerializedDnModule serMod, bool canLoadDynFile, bool diskFileOk = false)
        {
            const bool isAutoLoaded = true;

            IDnSpyFile file;

            if (diskFileOk)
            {
                file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile);
                if (file != null)
                {
                    return(file);
                }
            }
            else
            {
                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);

            if (!string.IsNullOrEmpty(asmFilename))
            {
                file = fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(asmFilename), isAutoLoaded);
                if (file == null)
                {
                    file = fileManager.Resolve(new AssemblyNameInfo(serMod.AssemblyFullName), null);
                }
                if (file != null)
                {
                    // Common case is a one-file assembly or first module of a multifile assembly
                    if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                    {
                        return(file);
                    }

                    foreach (var child in file.Children)
                    {
                        if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase))
                        {
                            return(child);
                        }
                    }
                }
            }

            return(fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(moduleFilename), isAutoLoaded));
        }
예제 #31
0
 public SerializedDnToken(SerializedDnModule module, uint token)
 {
     this.module = module;
     this.token  = token;
 }
예제 #32
0
 /// <summary>
 /// Creates an IL instruction breakpoint
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="token">Method token</param>
 /// <param name="ilOffset">IL offset</param>
 /// <param name="cond">Condition</param>
 /// <returns></returns>
 public DnILCodeBreakpoint CreateBreakpoint(SerializedDnModule module, uint token, uint ilOffset, Predicate<BreakpointConditionContext> cond)
 {
     DebugVerifyThread();
     return CreateBreakpoint(module, token, ilOffset, new DelegateBreakpointCondition(cond));
 }
예제 #33
0
 /// <summary>
 /// Creates an IL instruction breakpoint
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="token">Method token</param>
 /// <param name="ilOffset">IL offset</param>
 /// <param name="bpCond">Condition or null</param>
 /// <returns></returns>
 public DnILCodeBreakpoint CreateBreakpoint(SerializedDnModule module, uint token, uint ilOffset, IBreakpointCondition bpCond = null)
 {
     DebugVerifyThread();
     var bp = new DnILCodeBreakpoint(module, token, ilOffset, bpCond);
     ilCodeBreakpointList.Add(module, bp);
     foreach (var dnMod in GetLoadedDnModules(module))
         bp.AddBreakpoint(dnMod);
     return bp;
 }
예제 #34
0
 public SerializedDnToken(SerializedDnModule module, MDToken mdToken)
     : this(module, mdToken.Raw)
 {
 }