/// <summary> /// Sets up the API hooks and maintains them. /// </summary> /// <param name="inContext">Hooking context information.</param> /// <param name="implentationDir">The base directory of the implementation containing this executable.</param> /// <param name="registryFilter">A set of filter rules to registry access.</param> /// <param name="relaunchControl">Stores information about how commands within an implementation can be relaunched. Used for Windows 7 taskbar pinning.</param> public void Run(RemoteHooking.IContext inContext, string implentationDir, RegistryFilter registryFilter, RelaunchControl relaunchControl) { try { SetupHooks(); } #region Error handling catch (Exception ex) { MessageBox.Show(ex.ToString()); string errorLogFile = Path.Combine(Path.GetTempPath(), "Zero Install Hooking Error Log.txt"); File.WriteAllText(errorLogFile, ex.ToString()); EventLog.WriteEntry("Zero Install", ex.ToString(), EventLogEntryType.Error); return; } #endregion finally { RemoteHooking.WakeUpProcess(); } while (true) { Thread.Sleep(500); } }
/// <summary> /// Creates a new entry point. /// </summary> /// <param name="inContext">Hooking context information.</param> /// <param name="implentationDir">The base directory of the implementation containing this executable.</param> /// <param name="registryFilter">A set of filter rules to registry access.</param> /// <param name="relaunchControl">Stores information about how commands within an implementation can be relaunched. Used for Windows 7 taskbar pinning.</param> public EntryPoint(RemoteHooking.IContext inContext, string implentationDir, RegistryFilter registryFilter, RelaunchControl relaunchControl) { #region Sanity checks if (string.IsNullOrEmpty(implentationDir)) throw new ArgumentNullException("implentationDir"); if (registryFilter == null) throw new ArgumentNullException("registryFilter"); if (relaunchControl == null) throw new ArgumentNullException("relaunchControl"); #endregion _implementationDir = implentationDir; _registryFilter = registryFilter; _relaunchControl = relaunchControl; _relaunchInformation = relaunchControl.GetCurrentEntry(); }
/// <summary> /// Hooks into the creation of new processes on the current thread to inject API hooks. /// </summary> /// <param name="selections">The implementations chosen for launch.</param> /// <param name="executor">The executor used to launch the new process.</param> /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param> /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param> /// <exception cref="ImplementationNotFoundException">The main implementation is not cached (possibly because it is installed natively).</exception> public RunHook(Selections selections, IExecutor executor, IFeedManager feedManager, ITaskHandler handler) { var feed = feedManager[selections.InterfaceUri]; _target = new FeedTarget(selections.InterfaceUri, feed); var mainImplementation = selections.MainImplementation; _implementationDir = executor.GetImplementationPath(mainImplementation); _mainImplementation = feed[mainImplementation.ID]; _handler = handler; _registryFilter = GetRegistryFilter(); _relaunchControl = GetRelaunchControl(); Log.Info("Activating API hooking"); _hookW = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateProcessW"), new UnsafeNativeMethods.DCreateProcessW(CreateProcessWCallback), null); _hookW.ThreadACL.SetInclusiveACL(new[] {Thread.CurrentThread.ManagedThreadId}); _hookA = LocalHook.Create(LocalHook.GetProcAddress("kernel32.dll", "CreateProcessA"), new UnsafeNativeMethods.DCreateProcessA(CreateProcessACallback), null); _hookA.ThreadACL.SetInclusiveACL(new[] {Thread.CurrentThread.ManagedThreadId}); }
/// <summary> /// Creates a new entry point. /// </summary> /// <param name="inContext">Hooking context information.</param> /// <param name="implentationDir">The base directory of the implementation containing this executable.</param> /// <param name="registryFilter">A set of filter rules to registry access.</param> /// <param name="relaunchControl">Stores information about how commands within an implementation can be relaunched. Used for Windows 7 taskbar pinning.</param> public EntryPoint(RemoteHooking.IContext inContext, string implentationDir, RegistryFilter registryFilter, RelaunchControl relaunchControl) { #region Sanity checks if (string.IsNullOrEmpty(implentationDir)) { throw new ArgumentNullException(nameof(implentationDir)); } if (registryFilter == null) { throw new ArgumentNullException(nameof(registryFilter)); } if (relaunchControl == null) { throw new ArgumentNullException(nameof(relaunchControl)); } #endregion _implementationDir = implentationDir; _registryFilter = registryFilter; _relaunchControl = relaunchControl; _relaunchInformation = relaunchControl.GetCurrentEntry(); }
/// <summary> /// Sets up the API hooks and maintains them. /// </summary> /// <param name="inContext">Hooking context information.</param> /// <param name="implentationDir">The base directory of the implementation containing this executable.</param> /// <param name="registryFilter">A set of filter rules to registry access.</param> /// <param name="relaunchControl">Stores information about how commands within an implementation can be relaunched. Used for Windows 7 taskbar pinning.</param> public void Run(RemoteHooking.IContext inContext, string implentationDir, RegistryFilter registryFilter, RelaunchControl relaunchControl) { try { SetupHooks(); } #region Error handling catch (Exception ex) { MessageBox.Show(ex.ToString()); string errorLogFile = Path.Combine(Path.GetTempPath(), "Zero Install Hooking Error Log.txt"); File.WriteAllText(errorLogFile, ex.ToString()); EventLog.WriteEntry("Zero Install", ex.ToString(), EventLogEntryType.Error); return; } #endregion finally { RemoteHooking.WakeUpProcess(); } while (true) Thread.Sleep(500); }