Esempio n. 1
0
 private static void Thread()
 {
     try
     {
         var application = new DebuggerApplication();
         var window = new DebuggerWindow(Context, HackPath);
         DebuggerApplication.IsReady = true;
         application.Run(window);
     }
     catch (Exception exception)
     {
         MessageBox.Show(
             "Fatal exception!" + Environment.NewLine +
             exception + Environment.NewLine +
             "Aborting execution!",
             typeof(DebuggerApplication) + ".Thread()", MessageBoxButton.OK, MessageBoxImage.Error);
         Process.GetCurrentProcess().Kill();
     }
 }
 private static void Thread()
 {
     try
     {
         var application = new DebuggerApplication();
         var window      = new DebuggerWindow(Context, HackPath);
         DebuggerApplication.IsReady = true;
         application.Run(window);
     }
     catch (Exception exception)
     {
         MessageBox.Show(
             "Fatal exception!" + Environment.NewLine +
             exception + Environment.NewLine +
             "Aborting execution!",
             typeof(DebuggerApplication) + ".Thread()", MessageBoxButton.OK, MessageBoxImage.Error);
         Process.GetCurrentProcess().Kill();
     }
 }
Esempio n. 3
0
        public void Run(RemoteHooking.IContext hookingContext, PluginContext context, Boolean isDebugging, String hackPath, String installPath)
        {
            try
            {
                if (isDebugging)
                {
                    DebuggerApplication.Start(context, hackPath);
                    while (!DebuggerApplication.IsReady)
                    {
                        Thread.Sleep(1); // Sleep(0) is a nono.
                    }
                }
                Trace.IndentSize = 2;

                // We autoflush our trace, so we get everything immediately. This
                // makes tracing a bit more expensive, but means we still get a log
                // even if there's a fatal crash.
                Trace.AutoFlush = true;

                // Everything traced will be written to "debug.log".
                Trace.Listeners.Add(new TextWriterTraceListener(Path.Combine(hackPath, "debug.log")));

                Trace.WriteLine("-------------------");
                Trace.WriteLine(DateTime.Now);
                Trace.WriteLine("-------------------");


                AppDomain.CurrentDomain.AssemblyResolve += (Object sender, ResolveEventArgs args) =>
                {
                    var path = String.Empty;
                    // extract the file name
                    var file = String.Empty;
                    if (args.Name.IndexOf(',') >= 0)
                    {
                        file = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
                    }
                    else if (args.Name.IndexOf(".dll") >= 0)
                    {
                        file = Path.GetFileName(args.Name);
                    }
                    else
                    {
                        return(null);
                    }

                    // locate the actual file
                    path = Directory.GetFiles(hackPath, file, SearchOption.AllDirectories).FirstOrDefault();
                    if (!String.IsNullOrEmpty(path))
                    {
                        return(Assembly.LoadFrom(path));
                    }

                    path = Directory.GetFiles(pluginsFolder, file, SearchOption.AllDirectories).FirstOrDefault();
                    if (!String.IsNullOrEmpty(path))
                    {
                        return(Assembly.LoadFrom(path));
                    }

                    return(null);
                };

                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (Object sender, ResolveEventArgs args) =>
                {
                    var path = String.Empty;
                    // extract the file name
                    var file = String.Empty;
                    if (args.Name.IndexOf(',') >= 0)
                    {
                        file = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
                    }
                    else if (args.Name.IndexOf(".dll") >= 0)
                    {
                        file = Path.GetFileName(args.Name);
                    }
                    else
                    {
                        return(null);
                    }

                    // locate the actual file
                    path = Directory.GetFiles(hackPath, file, SearchOption.AllDirectories).FirstOrDefault();
                    if (!String.IsNullOrEmpty(path))
                    {
                        return(Assembly.ReflectionOnlyLoadFrom(path));
                    }

                    path = Directory.GetFiles(pluginsFolder, file, SearchOption.AllDirectories).FirstOrDefault();
                    if (!String.IsNullOrEmpty(path))
                    {
                        return(Assembly.ReflectionOnlyLoadFrom(path));
                    }

                    return(null);
                };

                var sw = new Stopwatch();

                Trace.WriteLine("Preparing folders . . . ");
                Trace.Indent();
                sw.Restart();
                this.pluginsFolder = Path.Combine(hackPath, "plugins");
                if (!Directory.Exists(this.pluginsFolder))
                {
                    Directory.CreateDirectory(this.pluginsFolder);
                }
                sw.Stop();
                Trace.WriteLine("Install Path: " + installPath);
                Trace.WriteLine("Hack Path:    " + hackPath);
                if (installPath.Equals(hackPath, StringComparison.OrdinalIgnoreCase))
                {
                    Trace.WriteLine("WARNING: Install Path and Hack Path are the same. This is not supported.");
                }
                if (File.Exists(Path.Combine(installPath, "Launcher.exe")))
                {
                    Trace.WriteLine("WARNING: Launcher.exe detected in the Warcraft III folder. This is not supported.");
                }
                if (File.Exists(Path.Combine(installPath, "SharpCraft.dll")))
                {
                    Trace.WriteLine("WARNING: SharpCraft.dll detected in the Warcraft III folder. This is not supported.");
                }
                Trace.WriteLine("Done! (" + sw.Elapsed.TotalMilliseconds.ToString("0.00") + " ms)");
                Trace.Unindent();

                Trace.WriteLine("Loading plugins from '" + this.pluginsFolder + "' . . .");
                Trace.Indent();
                sw.Restart();
                PluginSystem.LoadPlugins(pluginsFolder, this.context);
                sw.Stop();
                Trace.WriteLine("Done! (" + sw.Elapsed.TotalMilliseconds.ToString("0.00") + " ms)");
                Trace.Unindent();


                // Prepare the OnGameLoad hook.
                this.LoadLibraryA = Memory.InstallHook(LocalHook.GetProcAddress("kernel32.dll", "LoadLibraryA"), new Kernel32.LoadLibraryAPrototype(this.LoadLibraryAHook), false, true);

                // Everyone has had their chance to inject stuff,
                // time to wake up the process.
                RemoteHooking.WakeUpProcess();

                // Let the thread stay alive, so all hooks stay alive as well.
                // This might need to be shutdown properly on exit.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    "Fatal exception!" + Environment.NewLine +
                    exception + Environment.NewLine +
                    "Aborting execution!",
                    this.GetType() + ".Run(...)", MessageBoxButton.OK, MessageBoxImage.Error);
                Process.GetCurrentProcess().Kill();
            }
        }
Esempio n. 4
0
        public void Run(RemoteHooking.IContext hookingContext, PluginContext context, Boolean isDebugging, String hackPath, String installPath)
        {
            try
            {
                if (isDebugging)
                {
                    DebuggerApplication.Start(context, hackPath);
                    while (!DebuggerApplication.IsReady)
                    {
                        Thread.Sleep(1); // Sleep(0) is a nono.
                    }
                }
                Trace.IndentSize = 2;

                // We autoflush our trace, so we get everything immediately. This
                // makes tracing a bit more expensive, but means we still get a log
                // even if there's a fatal crash.
                Trace.AutoFlush = true;

                // Everything traced will be written to "debug.log".
                Trace.Listeners.Add(new TextWriterTraceListener(Path.Combine(hackPath, "debug.log")));

                Trace.WriteLine("-------------------");
                Trace.WriteLine(DateTime.Now);
                Trace.WriteLine("-------------------");
                Trace.WriteLine(String.Empty);

                var sw = new Stopwatch();

                Trace.WriteLine("Initializing plugin system . . .");
                Trace.Indent();
                sw.Restart();
                PluginSystem.LoadPlugins(hackPath);
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                Trace.WriteLine("Initializing plugins . . .");
                Trace.Indent();
                sw.Restart();
                PluginSystem.Initialize(PluginContext.Common);
                PluginSystem.Initialize(context);
                Trace.Unindent();
                Trace.WriteLine(" - Done! (" + sw.ElapsedMilliseconds + " ms)");

                // Prepare the OnGameLoad hook.
                var address = LocalHook.GetProcAddress("kernel32.dll", "LoadLibraryA");
                Trace.Write("Installing LoadLibraryA hook @ 0x" + address.ToString("X8") + " . ");
                this.LoadLibraryA = Memory.InstallHook(address, new Kernel32.LoadLibraryAPrototype(this.LoadLibraryAHook), false, true);
                Trace.WriteLine("installed!");

                // Everyone has had their chance to inject stuff,
                // time to wake up the process.
                RemoteHooking.WakeUpProcess();

                // Let the thread stay alive, so all hooks stay alive as well.
                // This might need to be shutdown properly on exit.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    "Fatal exception!" + Environment.NewLine +
                    exception + Environment.NewLine +
                    "Aborting execution!",
                    this.GetType() + ".Run(...)", MessageBoxButton.OK, MessageBoxImage.Error);
                Process.GetCurrentProcess().Kill();
            }
        }