/// <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(); }
//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>()); }