示例#1
0
        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);
        }
示例#3
0
 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 });
 }
示例#4
0
 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));
         }
 }
示例#5
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);
            }
        }
示例#6
0
 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 });
     }
 }
示例#7
0
 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);
        }
示例#9
0
文件: Hooker.cs 项目: rayel/Injecter
 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!");
         }
     }
 }
示例#10
0
文件: Hooker.cs 项目: rayel/Injecter
 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!");
         }
     }
 }
示例#11
0
		/// <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);
        }
示例#13
0
        /// <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);
            }
        }
示例#14
0
 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);
            }
        }
示例#16
0
        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);
        }
示例#17
0
 private static extern bool InitializeHook(HookTypes hookType, UInt32 threadID);
示例#18
0
        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);
            }
        }
示例#19
0
 protected HookBase(HookTypes type)
 {
     Type = type;
 }
示例#20
0
 private static extern IntPtr SetWindowsHookEx(HookTypes code, HookProc func, IntPtr hInstance, int threadID);
示例#21
0
 private static extern void DisposeCppLayer(HookTypes hookType);
示例#22
0
 private static extern int InitializeHook(HookTypes hookType, int threadID);
示例#23
0
		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);
		}
示例#24
0
 public virtual HookBase this[HookTypes type]
 {
     get { return _hooks[(int)type + 1]; }
 }
示例#25
0
 private static extern IntPtr SetWindowsHookEx(HookTypes hookType, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
示例#26
0
		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);
		}
示例#27
0
 private static extern IntPtr SetWindowsHookEx(HookTypes hookType, LowLevelKeyboardProc lowLevelKeyboardProc, IntPtr hMod, uint dwThreadId);
示例#28
0
 public void FilterMessageWrapper(HookTypes type, int message)
 {
     base.FilterMessage(type, message);
 }
示例#29
0
 public HookBase(HookTypes type, HookProc proc)
     : this(type)
 {
     Procedure = new HookProc(proc);
 }
示例#30
0
 private static extern bool InitializeHook(HookTypes hookType, int threadID, IntPtr hwnd);
示例#31
0
		private static extern SetCallBackResults SetUserHookCallback(HookProcessedHandler hookCallback, HookTypes hookType);
示例#32
0
 public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc lpfn, IntPtr hMod, int dwThreadId);
示例#33
0
		private static extern bool InitializeHook(HookTypes hookType, int threadID);
示例#34
0
 private static extern SetCallBackResults SetUserHookCallback(HookProcessedHandler hookCallback, HookTypes hookType);
示例#35
0
		private static extern void UninitializeHook(HookTypes hookType);
示例#36
0
 private static extern void UninitializeHook(HookTypes hookType);
示例#37
0
		private static extern void DisposeCppLayer(HookTypes hookType);
示例#38
0
 private static extern FilterMessageResults InternalFilterMessage(HookTypes hookType, int message);
示例#39
0
		private static extern FilterMessageResults InternalFilterMessage(HookTypes hookType, int message);
示例#40
0
 public static extern int SetWindowsHookEx(HookTypes hookType, HookProc lpfn, IntPtr hInstance, int threadId);
示例#41
0
        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());
        }
示例#42
0
 /// <summary>
 /// Creates a new Hook of the specified type
 /// </summary>
 /// <param name="hookType"></param>
 public GlobalHook(HookTypes hookType)
 {
     _hookType = hookType;
     InstallHook();
 }
示例#43
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);
			}
		}
示例#44
0
 public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId);
示例#45
0
 /// <summary>
 /// Creates a new Hook of the specified type
 /// </summary>
 /// <param name="hookType"></param>
 public GlobalHook(HookTypes hookType)
 {
     _hookType = hookType;
     InstallHook();
 }
示例#46
0
文件: Win32.cs 项目: code-mtnit/WPFSM
 public static extern IntPtr SetWindowsHookEx(HookTypes hookType, HookProc hookProc, IntPtr hInstance, int nThreadId);
示例#47
-1
 protected GlobalHook(HookTypes hookType)
 {
     this.mHookType = HookTypes.NONE;
     this.mHandle = IntPtr.Zero;
     this.mProc = new HookProc(this.OnProc);
     this.mHookType = hookType;
 }