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

superobject not loaded in hook at codeigniter

When I load the hook in codeigniter, hook successfully load but superobject not. public function __construct() { $this->CI =& get_instance(); // This gives me nothing print_r($this->CI); // This works fine echo "Hello!"; }…
Masoud Tavakkoli
  • 950
  • 13
  • 34
2
votes
0 answers

how to automatically compile class files after push to git

I want to be automatically compiled class files after push a git server. Is there a possible way? Static files are synchronized to checkout that was using hooks post-receive, I would like to also sync class files. Ultimately, I would like to…
Suby Lee
  • 415
  • 1
  • 4
  • 6
2
votes
3 answers

LowLevelMouseProc in background thread

I'm trying to setup mouse hook on background thread. delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam); LowLevelMouseProc _proc = HookCallback; SetWindowsHookEx(PInvoke.WH_MOUSE_LL, _proc, IntPtr.Zero, 0); and IntPtr…
Mafin
  • 21
  • 2
2
votes
2 answers

Adding hook without changing source code

Is it possible to add a hook to a meothd without changing the method? For example: public class class1{ public void method1(){} } public class class2{ public void method2(){} } Now how can I execute method2() everytime when method1() is…
RandomGuy
  • 75
  • 8
2
votes
2 answers

woocommerce_order_status_processing hook is not firing on backend

When the admin manually changes an order status from pending to processing payment, I would like to redirect this admin to an external website for completing an additional step. The customer should not be redirected at any stage, just the admin. I…
user2929830
2
votes
0 answers

How do I use EasyHook to change a System.Management method's result?

I've been working on making a C# DLL which to be injected into a specific target application which is also written in C#. The goal is to manipulate the output of several functions of the .NET framework. I was successful in changing the value of…
HoLLy
  • 31
  • 1
  • 7
2
votes
1 answer

What happens to a global hook when an executable process that hosts it crashes?

Say, if I set up a global hook procedure in my executable process: //Set global hook hHook = ::SetWindowsHookEx(WH_KEYBOARD_LL, HookWndProc_WH_KEYBOARD_LL, ::GetModuleHandle(NULL), NULL); and this process crashes. What happens to this…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
2
votes
2 answers

libMobileGestalt.dylib crashed when Hooking MGCopyAnswer for ARM64

When I try to hook MGCopyAnswer, I get a crash. I'm trying this on a jailbroken iPhone 5s in iOS 8.3, arm64…
zhouquan xia
  • 49
  • 1
  • 5
2
votes
1 answer

Mercurial changegroup hooks not triggered; Linux

I have a server which serves a "central" Mercurial repository; the team clones it and pushes their changes up to it via ssh. Hudson is installed on the same server (RHEL 5.5). I wish to trigger a Hudson build whenever anyone pushes to the central…
jasper77
  • 1,553
  • 5
  • 19
  • 31
2
votes
1 answer

Prestashop Two actions for two conditions for the same cart rule

I'm using Prestashop 1.6.1 A customer is asking to create a single voucher that makes a discount of 5€ if the cart is having 2 items and 7€ if it has 3 items(or more). I'm newbie to prestashop development and i've been trying for 2 days with no…
2
votes
2 answers

how do I get MSTest to run as Administrator, when called from a console app?

This console app code calls MSTest and starts to run the unit test but fails with "Access Denied" to some assemblies required for unit testing (see errors below code). Any way to smoothly make MSTest to run as Admin from here? I tried a manifest,…
Blackcoil
  • 175
  • 3
  • 18
2
votes
1 answer

Hook for pthread_create

Is there (in glibc-2.5 and newer) a way to define a hook for pthread_create? There is a lot of binary applications and I want to write a dynamic lib to be loaded via LD_PRELOAD I can add hook on entry to main (''attributte constructor''), but how…
osgx
  • 90,338
  • 53
  • 357
  • 513
2
votes
1 answer

Crash after returning from Windows keyboard hook procedure

There is a keyboard hook installed like this: s_hKeyboardHook = ::SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProc, nullptr, ::GetCurrentThreadId()); (This is a plug-in that wants to intercept keyboard events that get sent to its host (64-bit), even…
user38329
  • 719
  • 4
  • 17
2
votes
1 answer

PR_Write after hooking

So i recently hooked PR_Write in Mozilla and was able to log results( all of the connection literally ) to a log file, there's however one problem, i was assuming that after hooking PR_Write, i would be able to capture HTTPS data but when i log in…
demogorgon
  • 49
  • 1
  • 9
2
votes
2 answers

Save data from an Angular 2 component before navigate to another component

I would like to save some Angular 2 component related data to the database just before navigating from that particular component to another component so that database saved data will be able to display on the second component. In order to do that I…
chenk
  • 392
  • 7
  • 27