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

IW31 searching for a user exit or enh. point to get gsber

I am working with transaction IW31, the task is to rewrite the field of gsber with another value during the save process (when I clicked the save button this function should be activated at this time). I had seen all the relevant user exit and…
Freddiboy
  • 133
  • 10
2
votes
2 answers

SetWindowsHookEx global keyboard hook not catching all keypresses

I'm writing code that is part of an automation system. I wanted to add a keyboard hook to end the test prematurely, and I did this by using SetWindowHookEx. My code looks pretty much like this: http://support.microsoft.com/kb/318804 Here's my…
Jonathan Yee
  • 1,957
  • 2
  • 19
  • 21
2
votes
2 answers

Get current process Id from DLL

I have trying to hook WinApi using AppInitHook. So it works perfectly but I need to hook only some processes not all. The question is how to get process id where dll is loaded? For example dll was loaded for MyApp.exe, how can I get this process…
Alexey Kulikov
  • 1,097
  • 1
  • 14
  • 38
2
votes
1 answer

Getting full module name in Import hook

I am implementing an import hook that automatically installs missing modules using pip. So far it is working OK with simple modules (that have only one level), for instance unipath. However if I try to use it with multilevel imports, such as…
chaos.ct
  • 1,001
  • 1
  • 7
  • 18
2
votes
2 answers

Modifying global system menus

Is there a way in C# to globally add a menu item to all the system menus on all active windows? Perhaps under the "Maximize" command?
Icemanind
  • 47,519
  • 50
  • 171
  • 296
2
votes
2 answers

Writing a class to pass add_action arguments in wordpress

I'm using the hook user_register that writes to the variable $user_id. I want to call this hook inside a function and pass the variable $pass from the parent function to the function register_pass. Once there, $pass and user_id will be sent to…
neanderslob
  • 2,633
  • 6
  • 40
  • 82
2
votes
1 answer

Run cucumber test from hooks file

Is there a way to start a scenario from inside of the hooks file. In the After hook I am grabbing the line of the scenario that failed and the file or feature that the scenario is in and formatted it so that I can run that line in the cmd and it…
Josh Lesch
  • 395
  • 1
  • 5
  • 23
2
votes
3 answers

EventEmitter implementation that allows you to get the listeners' results?

I realise that nodejs has a powerful EventEmitter constructor which allows you to emit events. However, what EventEmitter is missing is a way for the event emitter to see what the listeners returned. This is the functionality I am after: e = new…
Merc
  • 16,277
  • 18
  • 79
  • 122
2
votes
0 answers

Windows API hooking python to msvbvm60.dll (rtcMsgBox)

I want to intercept the API calls of a process to know when a process call to the API rtcMsgBox of the msvbvm60 dll. I have tried it with this code but it seems not to work: from winappdbg import Debug, EventHandler import sys import os class…
Alberto
  • 701
  • 4
  • 9
  • 25
2
votes
1 answer

Wordpress Base Path Hook?

What's the wordpress / php hook to link to the base path of the wordpress installation? I want to be able to link to the home page of the wordpress blog, regardless of which directory the theme is installed in.
Matrym
  • 16,643
  • 33
  • 95
  • 140
2
votes
2 answers

Git post-receive hook acts differently to shell

I'm trying to setup a git repo on my live server to automatically update a subdomain on receive. Using this guide http://toroid.org/ams/git-website-howto. hooks/post-receive #!/bin/sh pwd git checkout -f config [core] …
Jake
  • 21
  • 3
2
votes
1 answer

How to solve post_controller_constructor Hooks redirection issues in CodeIgniter

I am trying to set-up a 'post_controller_constructor' hook in CodeIgniter. The purpose is to check if a user is not logged in then redirect him back to login page. Here is my hook configuration array : $hook['post_controller_constructor'] = array( …
Rivnat
  • 1,497
  • 1
  • 20
  • 34
2
votes
0 answers

How to display WPF overlay on top of DirectX?

I learned how to hook into the game EndScene function, but how to host WPF content is something I am trying a very long time to understand. I am trying to do something like Overwolf, for a specific game (starcraft), I asked their team how they do…
BBLN
  • 495
  • 6
  • 19
2
votes
1 answer

TortoiseHg hook with GUI

We are trying to write a mercurial pre-commit hook which should work with both commandline and TortoiseHg. The idea of the hook is to connect to JIRA and get the list of activities assigned to the developer, and show the activities in a list from…
2
votes
1 answer

View commits on a new branch in the update hook

I wrote an update hook (server-side) which checks all commit messages (To check if there is an Issue Id) There is an extract of my python code (update.py): [...] if newrev == "0000000000000000000000000000000000000000": newrev_type = "delete" elif…
1 2 3
99
100