private static void Install() { lock (ThreadSafe) { // Ensure we create a new one if the existing // channel cannot be pinged try { if (m_Interface != null) { m_Interface.Ping(); } } catch { m_Interface = null; } if (m_Interface == null) { String ChannelName = RemoteHooking.GenerateName(); String SvcExecutablePath = (Config.DependencyPath.Length > 0 ? Config.DependencyPath : Config.GetProcessPath()) + Config.GetWOW64BypassExecutableName(); Process Proc = new Process(); ProcessStartInfo StartInfo = new ProcessStartInfo( SvcExecutablePath, "\"" + ChannelName + "\""); // create sync objects EventWaitHandle Listening = new EventWaitHandle( false, EventResetMode.ManualReset, "Global\\Event_" + ChannelName); m_TermMutex = new Mutex(true, "Global\\Mutex_" + ChannelName); // start and connect program StartInfo.CreateNoWindow = true; StartInfo.WindowStyle = ProcessWindowStyle.Hidden; Proc.StartInfo = StartInfo; Proc.Start(); if (!Listening.WaitOne(5000, true)) { throw new ApplicationException("Unable to wait for service application due to timeout."); } HelperServiceInterface Interface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(ChannelName); Interface.Ping(); m_Interface = Interface; } } }
private static void Install() { lock (ThreadSafe) { // Ensure we create a new one if the existing // channel cannot be pinged try { if (m_Interface != null) { m_Interface.Ping(); } } catch { m_Interface = null; } if (m_Interface == null) { // create sync objects String ChannelName = RemoteHooking.GenerateName(); EventWaitHandle Listening = new EventWaitHandle( false, EventResetMode.ManualReset, "Global\\Event_" + ChannelName); Mutex TermMutex = new Mutex(true, "Global\\Mutex_" + ChannelName); using (TermMutex) { // install and start service NativeAPI.RtlInstallService( "EasyHook" + (NativeAPI.Is64Bit?"64":"32") + "Svc", Path.GetFullPath(Config.GetDependantSvcExecutableName()), ChannelName); if (!Listening.WaitOne(5000, true)) { throw new ApplicationException("Unable to wait for service startup."); } HelperServiceInterface Interface = RemoteHooking.IpcConnectClient <HelperServiceInterface>(ChannelName); Interface.Ping(); // now we can be sure that all things are fine... m_Interface = Interface; m_TermMutex = TermMutex; } } } }