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

How to use SetWindowsHookEx in Vista and hook Admin apps with UAC?

I'm trying to figure out if there's a way to use SetWindowsHookEx and be able to affect apps that are run with Admin rights on Vista, with UAC enabled. This is an app that will need to add a small button to the caption bar of other windows to…
Warner Young
  • 111
  • 1
  • 5
2
votes
0 answers

What is the best way to hook to existing mongoose.model

I have a project with multiple self contained mongoose model files. I have another modelprovider which uses the model name and the request to perform an operation. I want to hook the operation to the pre of 'find' model file 'use strict'; // load…
Uma Maheshwaraa
  • 563
  • 2
  • 9
  • 17
2
votes
1 answer

pre commit hook to check versions in git

I am planning to write a pre commit hook. It should check whether the master branch have any versions after branching out of a file. Example. A file abc.txt has branched out from master, on 1st Jan. Say, the branch name is BR1.X. On BR1.x branch,…
2
votes
1 answer

How are process hooks used

I've seen the concept out there, but how are they implemented? are they related only to operating system messages and system calls? i was thinking about event handling in GUI applications, detecting and handling the event itself and doing something…
jgemedina
  • 516
  • 1
  • 4
  • 11
2
votes
1 answer

bp_core_signup_user hook not working (PHP, BuddyPress, Wordpress, & Parse.com)

I have been trying to hook into the WordPress registration action so that I can store the new user's account info on my Parse.com User database. However, since I am using BuddyPress, the WP hook user_register does not seem to work. After doing…
Koolstr
  • 464
  • 1
  • 10
  • 20
2
votes
0 answers

Global Keyboard hook in windows does not work on firefox browser

My global keyboard hook on windows does not work on the Firefox browser. If I press a key on other system its working but on certain application like Firefox browser, task manager it does not work. Is there any security privilege are required?
2
votes
0 answers

C++ Making form clickable when game

I want to make an app to see some values on game, I wrote some codes, but I need to click the form when the game is open. When I click to form, the game minimized, and returns me to desktop. How can I do that, I am new on this site, and I'm Turkish…
2
votes
0 answers

Global Mouse Hook: Modify mouse position before input hits hooked application

I created a global mouse hook where I tried to change the x and y cursor position that the hooked application receives without actually moving the cursor. For some reason it did not work. So I tried to change the cursor position to see if it would…
Lfod
  • 581
  • 5
  • 14
2
votes
1 answer

Banned IPs check before anything else in CodeIgniter

I have a table with IP/DNS data for banned visitors. I want this check to be done before anything else, but after the model for banned IPs is loaded. What is the best place to add this code and make it run every time a page is accessed, taking into…
ali
  • 10,927
  • 20
  • 89
  • 138
2
votes
0 answers

Taking Screeshot of extern Window which have an OpenGL ES Window inside

Im trying to capture a screenshot of a Genymotion instance which has an opengl es window inside. The problem is that injecting a dll (hooking) to capture the framebuffer didnt work as excepted (genymotion crash, cant hook the framebuffer because i…
Emanuel
  • 8,027
  • 2
  • 37
  • 56
2
votes
1 answer

how override sails.js view hook for res.view.js file?

How can I override sails.js view hook for res.view.js file? How is it possible to customize this file in our project and overwrite it? In which folder, and with what name? I cannot find any standard documentation for folder path converting names and…
2
votes
2 answers

Why does using a function pointer to call a function bypass the hook?

Using the Microsoft Detours library, I've written the following simple code: #include #include #include void RealFunc(int num) { printf("RealFunc %d\n", num); } void(*RealFuncPtr)(int) = &RealFunc; void…
2
votes
1 answer

pyinstaller hooks never called

I am trying to create an EXE of a python program. The program is quite complex and cannot be listed here. I have some user defined modules, halfwave, halfwave.utils and halfwave.db. I need to create a hook for these modules, so I have made files…
thorsan
  • 1,034
  • 8
  • 19
2
votes
1 answer

Need assistance with creating a Git client-side 'commit-msg' hook

I have installed the 'ticket_status.rb' server-side hook on Assembla. Although this is exactly what I'm looking for (in theory), it does not flag until the developer attempts to push to the server. If they have made several commits before pushing,…
2
votes
0 answers

Geting only alert Output from JS file but not run functionality with available hook "wp_footer" and any other

Working Code Status: I was testing my js files, what these files were adding and running correctly or not. So I write a alert code in my-custom.js with my theme functionality, and now I hook my jquery file path with in a function. and I hook it by…
Abdul Rehman
  • 628
  • 7
  • 11