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

Can't get a scenario's filename from scenario.file in Cucumber 2.3.2

I have this code in Rails app /features/support/hooks.rb: After do |scenario| if scenario.failed? filename = "#{FAILED_DIR_PATH}/failed--#{scenario.file.gsub("features/","").gsub("/","-")}--#{scenario.line}.html" Capybara.save_page…
Foton
  • 1,197
  • 13
  • 24
2
votes
1 answer

Logging in Liferay user without password

I need to login the user in Liferay by authenticating against an external system. However, I still need to have a valid Liferay session. So, I need to login to Liferay by Asking the username/password from the user Use them to authenticate against…
user1592521
  • 61
  • 1
  • 9
2
votes
2 answers

if statement grouped products reference woocommerce

In my functions.php file I have some remove_actions and add_filters that run for woocommerce but the problem is these functions run for all woocommerce product types. I'd like to wrap a simple if statement around the hooks/filters I have to only run…
mitchelangelo
  • 851
  • 4
  • 16
  • 42
2
votes
1 answer

How to use sails-auth in sails project?

How can I use sails-auth hook in my sails project? I installed sails-auth using npm install sails-auth --save. and when running project terminal logs says sails-auth controllers, services, models are loaded using marlinspike. But I don't have any…
2
votes
1 answer

IDA Python - Why My code return incorrect ESP Value?

I made a ida python code which for checking code coverage. But when I used this script, I got a runtime error and I could not get correct ESP value. -My code- from idaapi import * class DbgHook(DBG_Hooks): def dbg_process_exit(self, pid, tid,…
2
votes
0 answers

Making hooks on OSX system events

There are a lot of system' events in OSX. I would like to start my [python] script on some of them e.g. on power supply on. How can I do such hook?
2
votes
1 answer

How can I modify a CCK fields display via a module?

I'm working on a drupal module, and one thing that it needs to do is modify the display of cck file fields automatically (using template files is not an option). For example, this array: $node->field_images[0]['view']; That is what I would like to…
pulsedemon
  • 421
  • 3
  • 8
2
votes
0 answers

Python PEP 302 and __name__ attribute

Currently i am creating a custom import hook, which seems to work pretty well (still under development). When i read the PEP 302 i came accross the __name__ attribute, which is descriped like this: The __name__ attribute must be set. If one uses…
BendEg
  • 20,098
  • 17
  • 57
  • 131
2
votes
3 answers

Removing action added by a plugin in Wordpress

I am using Popup Maker plugin for Wordpress and I am trying to prevent it to load on a particular page using the functions.php file of a child theme. I've located in the plugin's directory the file popup-maker.php which contains the following line…
BMM
  • 690
  • 1
  • 13
  • 26
2
votes
1 answer

C# Change Global Mouse Cursor

I have a form with a Transparency-key color, where I'm doing a global mouse hook for the right click. Until there everything is okay, but since the form is transparent, the mouse cursor is changing according to what is behind the form. Is there any…
Rias
  • 217
  • 1
  • 6
  • 14
2
votes
2 answers

Add id of new document to array in existing document using collection-hooks

I've used matb33:collection-hooks to insert a document after inserting into another, is it possible to update an existing document following an insert? I'm trying to do the following: within a template Box, whose data context has an _id of boxId,…
Bren
  • 273
  • 1
  • 18
2
votes
0 answers

C++ - Change vertical pitch of your mouse

The Idea I was wondering if it's possible to change the pitch of your mouse over the entire screen. To give an example: If you draw a perfect circle with your physical mouse on your table, your screen would draw an oval (with: width > height). This…
Im2be
  • 53
  • 2
  • 4
2
votes
0 answers

Global keyboard hook fires twice

I have the following method which is attempting to intercept a global press of ALT + Z: private int KbHookProc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { var hookStruct =…
James Hogle
  • 3,010
  • 3
  • 22
  • 46
2
votes
1 answer

Wordpress 4.4: Change max_srcset_image_width in media.php from functions.php

Wordpress defines the maximum resolution included in the new srcset attribute in the media.php with the following line: $max_srcset_image_width = apply_filters( 'max_srcset_image_width', 1600, $size_array ); Is there any way to change that value…
Fabian Sebastian
  • 329
  • 5
  • 17
2
votes
1 answer

Android RIL socket and phone calls encryption?

Now I'm testing something in Android phone calls encryption. I have Hook some method in RIL.java by using Xposed framework if ( lpparam.packageName.contains("com.android.phone")){ XposedBridge.log("damowang Loaded app: " +…
Keith.L
  • 21
  • 4