Example #1
0
        internal void UpdateBreakpointsInModule(DebugModule module)
        {
            BreakpointMethod[] copy = new BreakpointMethod[_unresolved.Count];
            _unresolved.CopyTo(copy);

            foreach (var bp in copy)
            {
                var methods = module.ResolveAllFunctionName(bp.ClassName, bp.MethodName);
                if (methods == null) continue; // Sorry about this null. TODO: Refactor.

                foreach (var method in methods)
                {
                    Logger.WriteLine("Setting breakpoint at {0}.{1}", bp.ClassName, bp.MethodName);
                    var token = (uint)method.MetaData.MetadataToken;
                    if (_breakpointsMap.ContainsKey(token)) continue;
                    var bpWrapper = method.SetBreakpoint();
                    bp.Breakpoint = bpWrapper.Interface;
                    _breakpointsMap[token] = bp;
                }
            }
        }
Example #2
0
        public static DebugClass FindType(this DebugProcess process, string typeName, out DebugModule mod)
        {
            mod = null;
            foreach (var domain in process.Domains)
            {
                foreach (var assembly in domain.Assemblies)
                {
                    foreach (var module in assembly.Modules)
                    {
                        var type = module.FindType(typeName);
                        if (type != null)
                        {
                            mod = module;
                            return type;
                        }
                    }
                }
            }

            return null;
        }
Example #3
0
 private void UpdateInjectorFunction(DebugModule module)
 {
     var function = module.ResolveFunctionName(InjectorSettings.InjectClassName, InjectorSettings.InjectMethodName);
     if (function != null)
     {
         _injectorFunction = function;
         Logger.WriteLine("Injector function resolved. Waiting for a chance to perform a call...");
     }
     else
     {
         Logger.WriteLine("The injecting module '{0}' was loaded, but method {1}.{2}() was not found in it",
             InjectorSettings.ModuleToInject, InjectorSettings.InjectClassName, InjectorSettings.InjectMethodName);
         Logger.WriteLine("Did you forget to update injector's configuration?");
     }
 }
Example #4
0
        private void ResolveNewMscrolibMethods(DebugModule mscorlib)
        {
            var assemblyLoadMethods = mscorlib.ResolveAllFunctionName("System.Reflection.Assembly", "Load");
            if (assemblyLoadMethods != null)
            {
                foreach (var method in assemblyLoadMethods)
                {
                    var methodParams = method.MetaData.GetParameters();
                    if (methodParams.Length == 1 && methodParams[0].Name == "rawAssembly")
                    {
                        _loadAssemblyMethod = method;

                        _byteCorType = mscorlib.FindType("System.Byte").GetDebugType();

                        Logger.WriteLine("Assembly.Load(byte[] rawAssembly) - method address resolved.");
                    }
                }
            }
            else
            {
                Logger.WriteLine("Could not find Assembly.Load() method in mscorlib. Something is wrong.");
            }
        }
Example #5
0
        private void OnDebuggerModuleLoaded(object sender, DebuggerModuleLoadedEventArgs e)
        {
            var module = new DebugModule(e.Module);

            if (module.Is(InjectorSettings.ModuleToInject))
            {
                UpdateInjectorFunction(module);
            }
            else if (module.Is(@"mscorlib\.dll") && !IsModuleInDomain(module, "DefaultDomain"))
            {
                ResetOldMscrolibMethods();
                ResolveNewMscrolibMethods(module);
            }

            _breakpointManager.UpdateBreakpointsInModule(module);
        }
Example #6
0
 private bool IsModuleInDomain(DebugModule module, string domainName)
 {
     return module.Assembly.Domain.Name == domainName;
 }