예제 #1
0
        private static int?LaunchWowProcess()
        {
            var doc     = XDocument.Load(GuiCore.SettingsFilePath);
            var element = doc.Element("Settings");
            var tmpPath = element.Element("WowExePath").Value;

            var si = new WinImports.STARTUPINFO();

            WinImports.PROCESS_INFORMATION pi;
            WinImports.CreateProcess(tmpPath, null,
                                     IntPtr.Zero, IntPtr.Zero, false,
                                     WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                     IntPtr.Zero, null, ref si, out pi);

            return((int)pi.dwProcessId);
        }
예제 #2
0
        internal static void Run()
        {
            string tmpPath = "";

            try
            {
                XDocument doc  = XDocument.Load(".\\Settings.xml");
                XElement  path = doc.Element("Settings").Element("Path");
                XElement  loot = doc.Element("Settings").Element("AutoLoot");
                tmpPath = path.Value;
                LuaFunctions.CustomFuncs.AutoLoot.enabled = Convert.ToBoolean(loot.Value);
            }
            catch
            {
                MessageBox.Show("Settings.xml is corrupted! Please delete it and rerun the framework");
                return;
            }

            WinImports.STARTUPINFO         si = new WinImports.STARTUPINFO();
            WinImports.PROCESS_INFORMATION pi = new WinImports.PROCESS_INFORMATION();
            bool success = WinImports.CreateProcess(tmpPath, null,
                                                    IntPtr.Zero, IntPtr.Zero, false,
                                                    WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                                    IntPtr.Zero, null, ref si, out pi);
            var proc = Process.GetProcessById((int)pi.dwProcessId);

            while (!proc.WaitForInputIdle(1000))
            {
                proc.Refresh();
            }
            while (string.IsNullOrWhiteSpace(proc.MainWindowTitle))
            {
                Thread.Sleep(200);
                proc.Refresh();
            }
            Thread.Sleep(2000);
            WinImports.SuspendThread(pi.hThread);
            DllInjectionResult res = DllInjector.GetInstance.Inject((int)pi.dwProcessId);

            WinImports.ResumeThread(pi.hThread);
        }
예제 #3
0
        internal static void Run(int?pId = null)
        {
            try
            {
                IntPtr?procHandle = null;
                if (pId == null)
                {
                    var doc     = XDocument.Load("..\\Settings\\Settings.xml");
                    var element = doc.Element("Settings");
                    var tmpPath = element.Element("Path").Value;

                    var si = new WinImports.STARTUPINFO();
                    WinImports.PROCESS_INFORMATION pi;
                    WinImports.CreateProcess(tmpPath, null,
                                             IntPtr.Zero, IntPtr.Zero, false,
                                             WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                             IntPtr.Zero, null, ref si, out pi);
                    pId = (int)pi.dwProcessId;
                    //MessageBox.Show("1");
                }
                else
                {
                    procHandle = WinImports.OpenProcess(0x001F0FFF, false, pId.Value);
                }
                var proc = Process.GetProcessById(pId.Value);
                //MessageBox.Show("ID:" + proc.Id);


                if (procHandle == null)
                {
                    procHandle = proc.Handle;
                }
                //MessageBox.Show("Handle:" + proc.Handle);

                if (proc.Id == 0)
                {
                    MessageBox.Show(
                        "Couldnt get the WoW process. Is the path in Settings.xml right? If no delete it and rerun ZzukBot");
                    return;
                }
                proc.WaitForInputIdle();
                //MessageBox.Show("Wait for input handle");
                var reader = new ExternalProcessReader(proc);

                var loadDllPtr = WinImports.GetProcAddress(WinImports.GetModuleHandle("kernel32.dll"), "LoadLibraryW");
                //MessageBox.Show("loadDllPtr: " + loadDllPtr.ToString("X"));
                if (loadDllPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt get address of LoadLibraryW");
                    return;
                }

                var LoaderStrPtr = reader.AllocateMemory(500);
                if (LoaderStrPtr == IntPtr.Zero)
                {
                    MessageBox.Show("Couldnt allocate memory 2");
                    return;
                }

                var LoaderStr =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
                    + "\\Loader.dll";
                //MessageBox.Show(LoaderStr);

                var res = reader.WriteString(LoaderStrPtr, LoaderStr, Encoding.Unicode);
                if (!res)
                {
                    MessageBox.Show("Couldnt write dll path to WoW's memory");
                    return;
                }

                var test = WinImports.CreateRemoteThread(procHandle.Value, (IntPtr)null, (IntPtr)0, loadDllPtr,
                                                         LoaderStrPtr, 0,
                                                         (IntPtr)null);
                if (test
                    == (IntPtr)0)
                {
                    MessageBox.Show("Couldnt inject the dll");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Injects the bot into the game client
        /// </summary>
        async Task Inject()
        {
            await Task.Run(() =>
            {
                try
                {
                    $"Loading path of WoW.exe from the settings".Log(Logs.PreInject);

                    $"Starting up the WoW process".Log(Logs.PreInject);

                    var si = new WinImports.STARTUPINFO();

                    WinImports.CreateProcess(Default.PathToWoW, null,
                                             IntPtr.Zero, IntPtr.Zero, false,
                                             WinImports.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE,
                                             IntPtr.Zero, null, ref si, out WinImports.PROCESS_INFORMATION pi);

                    var proc = Process.GetProcessById((int)pi.dwProcessId);

                    if (proc.Id == 0)
                    {
                        MessageBox.Show(
                            "Couldnt get the WoW process. Is the path in Settings.xml right? If no delete it and rerun ZzukBot");

                        return;
                    }

                    $"Waiting for WoW process to initialise".Log(Logs.PreInject);

                    while (!proc.WaitForInputIdle(1000))
                    {
                        $"WaitForInputIdle returned false. Trying again".Log(Logs.PreInject);
                        proc.Refresh();
                    }

                    while (string.IsNullOrWhiteSpace(proc.MainWindowTitle))
                    {
                        Thread.Sleep(200);
                        proc.Refresh();
                    }

                    Thread.Sleep(2000);

                    $"Initialising new ProcessReader".Log(Logs.PreInject);

                    using (var reader = new ExternalProcessReader(proc))
                    {
                        $"Retrieving function addresses for injection".Log(Logs.PreInject);

                        var loadDllPtr = WinImports.GetProcAddress(WinImports.GetModuleHandle("kernel32.dll"), "LoadLibraryW");

                        if (loadDllPtr == IntPtr.Zero)
                        {
                            MessageBox.Show("Couldnt get address of LoadLibraryW");

                            return;
                        }

                        $"Allocating memory for injection".Log(Logs.PreInject);

                        var LoaderStrPtr = reader.AllocateMemory(1000);

                        if (LoaderStrPtr == IntPtr.Zero)
                        {
                            MessageBox.Show("Couldnt allocate memory 2");

                            return;
                        }

                        var LoaderStr = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Loader.dll";

                        $"Preparing Loader.dll for injection".Log(Logs.PreInject);

                        var res = reader.WriteString(LoaderStrPtr, LoaderStr, Encoding.Unicode);

                        if (!res)
                        {
                            MessageBox.Show("Couldnt write dll path to WoW's memory");

                            return;
                        }

                        Thread.Sleep(1000);

                        $"Starting injection".Log(Logs.PreInject);

                        if (WinImports.CreateRemoteThread(proc.Handle, (IntPtr)null, (IntPtr)0, loadDllPtr, LoaderStrPtr, 0, (IntPtr)null) == (IntPtr)0)
                        {
                            MessageBox.Show("Couldnt inject the dll");
                        }

                        Thread.Sleep(1);

                        "Freeing allocated memory for injection".Log(Logs.PreInject);

                        reader.FreeMemory(LoaderStrPtr);
                    }
                }
                catch (Exception e)
                {
                    $"Exception occured while injecting: {e.Message}".Log(Logs.PreInject);
                    MessageBox.Show(e.Message);
                }
            });
        }