Questions tagged [hook]

A hook refers to replacing or extending a system or application's default behavior with a custom behavior for a specific event. For keyboard hooks prefer the tag [keyhook]. For git related hooking use the tag [githooks] alone. For hooking web services use the tag [webhooks] instead. For React hooks use tag[react-hooks].

What is it?

A hook refers to replacing or extending the default behavior with a custom behavior for specific events. The events may be operating system events, but also application events that are meant to be extended with hooks.

The hook may fully replace the default behavior. It may also just extend the default behavior for example by adding a listening or monitoring activity without changing the default behavior, or add an extra effect on the top of it.

Hooking and programming techniques

"Hook" is commonly used to describe replacing a function pointer in an existing data structure with a new function pointer that points to new code. This new code can extend the default behavior by calling the old function pointer before or after the new code executes, or the new code can replace / disable the existing behavior by not calling the old pointer.

Hooking is similar in concept to OOP inheritance, but is usually more dynamic (determined at runtime) than OOP inheritance.

Essentially it's a place in code that allows you to tap in to a module to either provide different behavior or to react when something happens. Hooks often (but not always) use callback functions. For example, you might hook an event system using hookEvent(Events.STARTUP, myCallbackFunction). You are passing a function pointer to the hookEvent function, so it knows what function to call when the event occurs.

How does it work?

Typically hooks are inserted while software is already running, but hooking is a tactic that can also be employed prior to the application being started. There are two techniques to achieve this:

  • Physical modification
  • Runtime modification

Related tags and disambiguation

  • For the hooks related to keyboard events, prefer the tag
  • For the hooking git events, you must use the tag preferably without the
  • For hooking web services with web service callbacks prefer the tag
  • For React hooks, prefer the tag

More Information

5710 questions
2
votes
1 answer

IAT hooking - unable to hook ExitProcess

I can hook any other function, but not ExitProcess. Here is the code to demonstrate this: #include #include #include #include void __stdcall NewSleep(DWORD milliseconds) { std::cout << "Sleep." <<…
NFRCR
  • 5,304
  • 6
  • 32
  • 37
2
votes
2 answers

SetWindowsHookEx WH_MOUSE_LL Hook only takes 1 mouse movement

I am setting a global hook with the following code: SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0) I have a breakpoint set so that when I first run the application I can see that the MouseProc method is called. This works but after the first…
Mark Achrin
  • 357
  • 2
  • 7
  • 15
2
votes
1 answer

Create a client side hook script to prevent user commit to external in TortoiseSVN

My trunk has structure: \trunk ----\data ----\src ----\tool with \tool is external to another place, not in my trunk. So i don't want user commit to \tool in SVN. They can only commit to \data or \src. Can anybody help me to create a hook script…
anticafe
  • 6,816
  • 9
  • 43
  • 74
2
votes
1 answer

Intercepting mouse events using a global hook. Stop an action from happening

I'm attempting to intercept and interrupt mouse events. Lets say I wanted to disable the right mouse button down event, or even the mouse move event. I haven't been able to figure out the interrupting part. I am using the (I assume pretty widely…
fMinkel
  • 179
  • 2
  • 5
  • 12
2
votes
2 answers

(iOS, TheOS) %hook into global app function

I am looking for a global function for apps in iOS 7. More specifically, I want to injected code into the app(s) upon launch, which will only effect the app, and not the SpringBoard. I have tried a couple of things but they only affect the…
Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87
2
votes
1 answer

Is it possible to achieve something like "global" Hooks?

I know how to enable Server side hooks in Tortoise SVN, but the problem is that I want to have hooks which are like "global", e.g. every repository on the server should use the global hooks. I have a hook which has to be included in every…
fen89
  • 539
  • 4
  • 10
2
votes
2 answers

How to tell if a Lua line number is a valid execution point (from C/C++)?

How Can I tell if line number x in a Lua script will respond to the Lua line hook? Example: 1 first = 1 2 3 function test ( data ) 4 if first == 0 then 5 print ("\r\n") 6 end 7 print(data) 8 --[[ 9 first = 0 10 ]] 11 end 12 13…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
2
votes
3 answers

Is there any hook provided to register a thread with garbage collection in java?

JVM provides you a hook to register a thread with the shutdown initiation sequence. Once a thread is registered, on every shutdown that thread is run. Now, is there any such a hook java provide to register a thread with JVM's Garbage collector?
Prashant Shilimkar
  • 8,402
  • 13
  • 54
  • 89
2
votes
0 answers

PHP global $post not working! Trying to get the post ID in WordPress

I'm running into an issue where i'm trying to get the Post ID while trying to hook into a plugin function(function is inside my functions.php file) For some reason global $post is not working! My objective is to store the current posts, post ID into…
iammikerodriguez
  • 379
  • 1
  • 5
  • 16
2
votes
2 answers

CBT Hook receiving only some events

I created a DLL to hook some events using a CBT hook. It seems to work only for the windows created by the process launching the hook... My system is Windows 7 x64, but the behaviour is the same also on the x32. This is the code (sorry but I'm no…
cyrusza
  • 113
  • 11
2
votes
1 answer

Customizing LifeRay portlet using jspf hook

i need to customize the create account portlet, i want to hide the filed "middle name" , but that field exists under the file /html/portlet/login/create_account_user_name.jspf, using the hook for customizing jsp pages didn't work because that file…
Mathis Hobden
  • 356
  • 2
  • 7
  • 19
2
votes
1 answer

WPF application crashes randomly reporting internal error with exit code 80131506

I have an issue with my WPF application crashing randomly (but at least twice per day) leaving the following message in windows Application log: Application: AppName.exe Framework Version: v4.0.30319 Description: The process was terminated due…
Netrunner
  • 43
  • 5
2
votes
2 answers

Global Mouse Hook + Simulate Mouse Inputs

I'm looking to create a global mouse hook that works in XP/Vista/7 which would allow me to access the X,Y values that the mouse is inputting, and modify those values before they hit Windows... I also want to be able to simulate mouse inputs in…
Drax
  • 53
  • 1
  • 7
2
votes
1 answer

Subversion post-commit hook will not run on commit, script works because I can run it on the command line

I have just made a new repository. My server is Ubuntu 12.04 32 bit. I want my commits to be live as soon as I have committed them. This is achieved by making a working copy in my public html directory, and having the post-commit hook update that…
chiliNUT
  • 18,989
  • 14
  • 66
  • 106
2
votes
1 answer

Simple hooking procedure

I'm trying to make a simple globalhook that prints some text into a .txt file whenever someone presses a key on the keyboard. The problem is that when I execute my program and press on a key in a certain program, the program gets stuck and doesn't…
1 2 3
99
100