/// <summary> /// You can't register a method like <see cref="YouSavedScience"/> in static methods. /// </summary> public void WakingUpToScience() { int pid = 0; Console.WriteLine("Input process name:"); string processName = Console.ReadLine(); //Get a process by name var ps = Process.GetProcessesByName(processName); bool getted = false; foreach (var process in ps) { //if (string.IsNullOrEmpty(process.MainWindowTitle)) // continue; pid = process.Id; getted = true; break; } if (!getted) { Console.WriteLine("Can not find that process!"); Console.ReadLine(); return; } //pass through target PID InjectableProcess ip = new InjectableProcess(pid); //Good morning. You have been in suspension for nine nine nine... nine nine ni- ip.SleepInterval = 9999999; //Don't worry, since when we call Eject, the dll thread will be woke up immediately. //Register a method to handle DLL's response //Always register methods BEFORE DLL injection ip.OnClientResponse += YouSavedScience; //If a method would not associate with any local vars (like below), it is safe and can be registered even in static methods ip.OnClientExit += (s,e) => { MessageBox.Show("[Host]Got client offline message.\nNow I only Want You Gone-"); }; //Inject method would return 0 If inject failed (same as VInjDn do) if (ip.Inject(@"TestDLL.dll",@"TestDLL.dll") == 0) { Console.WriteLine("Failed to inject!"); Console.ReadLine(); return; } //Commands To Test By ip.Command("This was a triumph."); Console.ReadLine(); //Reconstructing More Science ip.Command(1); //Tell me something about your process! Console.ReadLine(); //Use this to release DLL //ip.Eject(); Console.WriteLine("Total Response:" + TestChamber); Console.ReadLine(); }
/// <summary> /// [For Compatibility] Create a <see cref="InjectableProcess"/>. /// </summary> /// <param name="pid"></param> /// <returns></returns> public static InjectableProcess Create(int pid) { InjectableProcess ip = new InjectableProcess(pid); return ip; }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (!Program.Direct) { Settings.Default.QQNum = txt_qq.Text; Settings.Default.AppName = txt_process.Text; Settings.Default.Encoding = GetSolution(cbo_solution.Text).ToString(); Settings.Default.QQPath = _qqPath; Settings.Default.Save(); } //以下代码已复活 if (_ip != null && !Program.Direct) { if (!SyncEnabled) { _ip?.Eject(); _ip = null; return; } DialogResult r = MessageBox.Show("退出后要保持同步吗?", "退出提示", MessageBoxButtons.YesNoCancel); if (r == DialogResult.Yes) //要同步,直接退出 { return; } if (r == DialogResult.Cancel) //取消退出 { e.Cancel = true; //撤销关闭 return; } if (r == DialogResult.No) //不要同步,结束注入 { SendCommand(Command.Close); Helper.Send2QQ(txt_qq.Text, ""); _ip?.Eject(); _ip = null; } } //if (_ip != null && !Program.Direct) //{ // //DialogResult r = MessageBox.Show("要退出吗?", "退出提示", MessageBoxButtons.OKCancel); // //if (r == DialogResult.Cancel) // //{ // // e.Cancel = true; //撤销关闭 // // return; // //} // SendCommand(Command.Close); // Helper.Send2QQ(txt_qq.Text, ""); // _ip?.Eject(); // _ip = null; //} }
//public static void Test() //{ // string targetProcess = "cloudmusic"; // if (Process.GetProcessesByName(targetProcess).Length <= 0) // { // //rtxt_display.Text = ("找不到 " + targetProcess); // return; // } // var processes = Process.GetProcessesByName(targetProcess); // int handle = 0; // foreach (var process in processes) // { // if (!String.IsNullOrEmpty(process.MainWindowTitle) && process.MainWindowTitle != "." && !process.MainWindowTitle.Contains("网易云音乐B")) // { // handle = process.Id; // var t = process.Modules[0]; // break; // } // } //} /// <summary> /// 注入进程 /// </summary> public void Injection() { string targetProcess = txt_process.Text; if (Process.GetProcessesByName(targetProcess).Length <= 0) { rtxt_display.Text = ("找不到 " + targetProcess); return; } //FIXED:Find main process var processes = Process.GetProcessesByName(targetProcess); int handle = 0; foreach (var process in processes) { if (!String.IsNullOrEmpty(process.MainWindowTitle) && process.MainWindowTitle != ".") //TODO: Support CloudMusic UWP { try { if (process.MainModule.FileVersionInfo.FileDescription == "CloudMusic") { continue; } } catch (Exception) { //throw; continue; } handle = process.Id; break; } } if (handle == 0) { handle = Process.GetProcessesByName(targetProcess)[0].Id; } _ip = InjectableProcess.Create(handle); _ip.SleepInterval = 10000; Thread.Sleep(200);//FIXED:Wait for injection complete if (Program.Direct) { //_ip.IsBackgroundThread = false; _ip.OnClientExit += (sender, args) => Application.Exit(); } //_injectResult = _ip.Inject(Path.Combine(Application.StartupPath, SYNC_DLL), Path.Combine(Application.StartupPath, SYNC_DLL)); _injectResult = _ip.Inject(Path.Combine(Application.StartupPath, SYNC_DLL), null); if (_injectResult == 0) { rtxt_display.Text = "程序注入失败。"; return; } rtxt_display.Text = "程序注入成功!"; SyncEnabled = true; SendCommand(Command.SetQQPath, _qqPath); SendCommand(Command.SetAppType, txt_process.Text); SendEncoding(Settings.Default.Encoding.ParseEnum<QQSolution>()); }
/// <summary> /// [For Compatibility] Create a <see cref="InjectableProcess"/>. /// </summary> /// <param name="pid"></param> /// <returns></returns> public static InjectableProcess Create(int pid) { InjectableProcess ip = new InjectableProcess(pid); return(ip); }