void ChannelFaulted(object sender, EventArgs e) { InjecteeProxy = null; try { ConnectToInjectee(); } catch { if (AutoTerminate) { // BeginInvokeShutdown doesn't care OnExit() and the others. Application.Current.Dispatcher.BeginInvoke(new Action(() => { Application.Current.Shutdown(); })); } _IsHooking = false; _IsInstalled = false; OnPropertyChanged("IsInstalled"); OnPropertyChanged("IsHooking"); } }
private void ConnectToInjectee() { var pipeFactory = new DuplexChannelFactory <IOsuInjectee>( this, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/osuBeatmapHooker")); InjecteeProxy = pipeFactory.CreateChannel(); InjecteeProxy.Subscribe(); (InjecteeProxy as ICommunicationObject).Faulted += ChannelFaulted; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Toggle beatmap download hook state. If not installed yet, it will try injection. /// </summary> /// /// <returns> true if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// private bool ToggleHook() { try { if (IsHooking) { InjecteeProxy.SetDownloadHook(false); return(true); } else if (IsInstalled) { InjecteeProxy.SetDownloadHook(true); return(true); } } catch (Exception) { // Case of host terminated. var proxy = InjecteeProxy as ICommunicationObject; if (proxy != null) { proxy.Close(); InjecteeProxy = null; } } try { string thisFile = new Uri(System.Reflection.Assembly.GetExecutingAssembly().Location).LocalPath; var osuCandidates = from proc in Process.GetProcesses() where proc.ProcessName == "osu!" select proc; if (osuCandidates.Count() == 1) { TargetPid = osuCandidates.First().Id; } else { string osuPath = OsuHelper.GetOsuPath(); if (osuPath == null) { new Thread(new ThreadStart(() => { MessageBox.Show("osu!를 찾지 못했습니다. osu!를 한 번 실행해주세요."); })).Start(); return(false); } // CreateAndInject doesn't work. I don't know reason. Process osu = Process.Start(osuPath); TargetPid = osu.Id; osu.WaitForInputIdle(); } RemoteHooking.Inject(TargetPid, InjectionOptions.DoNotRequireStrongName, thisFile, thisFile); } catch (Exception extInfo) { LogException(extInfo); } try { ThreadPool.QueueUserWorkItem(new WaitCallback(obj => { try { ConnectToInjectee(); } catch (Exception e) { MessageBox.Show("DLL파일이 있는지, 관리자 권한이 있는지 확인해주세요.", "후킹 실패"); LogException(e); } })); } catch (Exception e) { LogException(e); return(false); } return(true); }