public static int GetHook(HookTypes hookType, HookProc hookProc) { int hHook = WinApiMethods.SetWindowsHookEx((int)hookType, hookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0); return(hHook); }
private void GenerateCallBackException(HookTypes type, SetCallBackResults result) { if (result == SetCallBackResults.Success) { return; } string msg; switch (result) { case SetCallBackResults.AlreadySet: msg = "A hook of type " + type + " is already registered. You can only register "; msg += "a single instance of each type of hook class. This can also occur when you forget "; msg += "to unregister or dispose a previous instance of the class."; throw new ManagedHooksException(msg); case SetCallBackResults.ArgumentError: msg = "Failed to set hook callback due to an error in the arguments."; throw new ArgumentException(msg); case SetCallBackResults.NotImplemented: msg = "The hook type of type " + type + " is not implemented in the C++ layer. "; msg += "You must implement this hook type before you can use it. See the C++ function "; msg += "SetUserHookCallback."; throw new HookTypeNotImplementedException(msg); } msg = "Unrecognized exception during hook callback setup. Error code " + result + "."; throw new ManagedHooksException(msg); }
public static void Disable(HookTypes type) { GlobalHook hook = Create(type); hook.Proc = (HookInvoke) Delegate.Combine(hook.Proc, new HookInvoke(GlobalHook.IgnoreGlobalHook)); DisabledHooks[type] = hook; EventLog.WriteLine("Global hooks of type: {0} have been disabled.", new object[] { type }); }
internal IntPtr SetHook(HookTypes typeOfHook, HookProc callBack) { using (Process currentProcess = Process.GetCurrentProcess()) using (ProcessModule currentModule = currentProcess.MainModule) { return(SetWindowsHookEx((int)typeOfHook, callBack, GetModuleHandle(currentModule.ModuleName), 0)); } }
/// <include file='ManagedHooks.xml' path='Docs/SystemHook/FilterMessage/*'/> protected void FilterMessage(HookTypes hookType, int message) { FilterMessageResults result = InternalFilterMessage(hookType, message); if (result != FilterMessageResults.Success) { GenerateFilterMessageException(hookType, result); } }
public static void Enable(HookTypes type) { if (DisabledHooks.ContainsKey(type)) { DisabledHooks[type].Uninstall(); DisabledHooks.Remove(type); EventLog.WriteLine("Global hooks of type: {0} have been enabled.", new object[] { type }); } }
public static GlobalHook Create(HookTypes type) { GlobalHook hook = new GlobalHook { mHookType = type }; hook.Install(); EventLog.WriteLine("Created global hook of type: {0}", new object[] { type }); return hook; }
public static string HookTypeToString(HookTypes hookType) { if (!s_stringByHookTypes.TryGetValue(hookType, out string result)) { throw new ArgumentException($"Unknown hook type: {hookType}"); } return(result); }
public void SetWindowsHook(HookTypes idHook) { if (hHook == 0) { hHook = NativeMethods.SetWindowsHookEx((int)idHook, hProc, IntPtr.Zero, NativeMethods.GetCurrentThreadId()); if (hHook == 0) { throw new Exception("Set Hook Failed!"); } } }
public void SetGlobalHook(HookTypes idHook) { if (hHook == 0 && hmod != IntPtr.Zero) { hHook = NativeMethods.SetWindowsHookEx((int)idHook, hProc, hmod, 0); if (hHook == 0) { throw new Exception("Set Hook Failed!"); } } }
/// <include file='ManagedHooks.xml' path='Docs/SystemHook/ctor/*'/> public SystemHook(HookTypes type) { _type = type; _processHandler = new HookProcessedHandler(InternalHookCallback); SetCallBackResults result = SetUserHookCallback(_processHandler, _type); if (result != SetCallBackResults.Success) { this.Dispose(); GenerateCallBackException(type, result); } }
public void ConstructionUnsupportedTypeTests(TestMethodRecord tmr) { HookTypes type = HookTypes.Hardware; tmr.WriteLine("If you implement the hook type HookTypes." + type + ", change the type parameter to continue testing this senario."); tmr.RegisterException("An unimplemented hook type will cause an exception.", typeof(HookTypeNotImplementedException)); SystemHookTestWrapper hook = new SystemHookTestWrapper(type); }
/// <include file='Internal.xml' path='Docs/SystemHook/ctor/*'/> public SystemHook(HookTypes type) { this.type = type; processHandler = new HookProcessedHandler(InternalHookCallback); SetCallBackResults result = SetUserHookCallback(processHandler, type); if (result != SetCallBackResults.Success) { this.Dispose(); GenerateCallBackException(type, result); } }
public virtual void InstallHooks(params HookTypes[] types) { if (types == null) types = new HookTypes[0]; var selectedHookTypes = types.Select(t => (int)t + 1).ToArray(); foreach (var i in selectedHookTypes.Where(i => _hooks[i] != null)) { _hooks[i].Enabled = true; } foreach (var i in _hooks.Select((h, i) => i).Where(i => _hooks[i] != null).Except(selectedHookTypes)) { _hooks[i].Enabled = false; } }
public void UnsupportedFilterTypesTest1(TestMethodRecord tmr) { HookTypes type = HookTypes.Hardware; tmr.WriteLine("If you implement the hook type HookTypes." + type + ", change the type parameter to continue testing this senario."); using (SystemHookTestWrapper hook = new SystemHookTestWrapper(HookTypes.MouseLL)) { tmr.RegisterException("An unimplemented hook type will cause an exception (filter message).", typeof(ManagedHooksException)); hook.FilterMessageWrapper(type, 12345); } }
private void GenerateFilterMessageException(HookTypes type, FilterMessageResults result) { if (result == FilterMessageResults.Success) { return; } string msg; if (result == FilterMessageResults.NotImplemented) { msg = "The hook type of type " + type + " is not implemented in the C++ layer. "; msg += "You must implement this hook type before you can use it. See the C++ function "; msg += "FilterMessage."; throw new HookTypeNotImplementedException(msg); } // // All other errors are general errors. // msg = "Unrecognized exception during hook FilterMessage call. Error code " + result + "."; throw new ManagedHooksException(msg); }
private static extern bool InitializeHook(HookTypes hookType, UInt32 threadID);
public void RegisterLuaFunctions() { _lua["HookTypes"] = new HookTypes(); _lua["Hooks"] = _hooks; _lua["Game"] = _game; _lua["Color"] = new Color(); _lua["Bans"] = TShock.Bans; _lua["Backups"] = TShock.Backups; _lua["Groups"] = TShock.Groups; _lua["Players"] = TShock.Players; _lua["Regions"] = TShock.Regions; _lua["Users"] = TShock.Users; _lua["Utils"] = TShock.Utils; _lua["Warps"] = TShock.Warps; _lua["ConfigType"] = new ConfigType(); //More Lua Functions var luaFuncs = new LuaFunctions(this); var luaFuncMethods = luaFuncs.GetType().GetMethods(); foreach (var method in luaFuncMethods) { _lua.RegisterFunction(method.Name, luaFuncs, method); } }
protected HookBase(HookTypes type) { Type = type; }
private static extern IntPtr SetWindowsHookEx(HookTypes code, HookProc func, IntPtr hInstance, int threadID);
private static extern void DisposeCppLayer(HookTypes hookType);
private static extern int InitializeHook(HookTypes hookType, int threadID);
public virtual HookBase this[HookTypes type] { get { return _hooks[(int)type + 1]; } }
private static extern IntPtr SetWindowsHookEx(HookTypes hookType, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
private static extern IntPtr SetWindowsHookEx(HookTypes hookType, LowLevelKeyboardProc lowLevelKeyboardProc, IntPtr hMod, uint dwThreadId);
public void FilterMessageWrapper(HookTypes type, int message) { base.FilterMessage(type, message); }
public HookBase(HookTypes type, HookProc proc) : this(type) { Procedure = new HookProc(proc); }
private static extern bool InitializeHook(HookTypes hookType, int threadID, IntPtr hwnd);
private static extern SetCallBackResults SetUserHookCallback(HookProcessedHandler hookCallback, HookTypes hookType);
public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc lpfn, IntPtr hMod, int dwThreadId);
private static extern bool InitializeHook(HookTypes hookType, int threadID);
private static extern void UninitializeHook(HookTypes hookType);
private static extern FilterMessageResults InternalFilterMessage(HookTypes hookType, int message);
public static extern int SetWindowsHookEx(HookTypes hookType, HookProc lpfn, IntPtr hInstance, int threadId);
private static void SetHook(ref IntPtr hookHandle, HookTypes type, HookProc proc, bool local) { if (hookHandle != IntPtr.Zero) return; hookHandle = Hook.SetWindowsHookEx(type, proc, IntPtr.Zero, local ? ProcessThread.GetCurrentThreadId() : 0); if (hookHandle == IntPtr.Zero) throw new Win32Exception(Marshal.GetLastWin32Error()); }
/// <summary> /// Creates a new Hook of the specified type /// </summary> /// <param name="hookType"></param> public GlobalHook(HookTypes hookType) { _hookType = hookType; InstallHook(); }
public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId);
protected GlobalHook(HookTypes hookType) { this.mHookType = HookTypes.NONE; this.mHandle = IntPtr.Zero; this.mProc = new HookProc(this.OnProc); this.mHookType = hookType; }