Exemple #1
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);
                }
            });
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        internal static void Run(int?pId = null)
        {
            int?tmpPiD = pId;

            try
            {
                IntPtr?procHandle = null;
                if (tmpPiD == null)
                {
                    tmpPiD = LaunchWowProcess();
                }
                else
                {
                    procHandle = WinImports.OpenProcess(0x001F0FFF, false, tmpPiD.Value);
                }

                var proc = Process.GetProcessById(tmpPiD.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);
            }
        }