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
0 answers

windows file copy internals (on the fly encryption)

I have to write an on-the-fly encryptor for Windows to encrypt all copied files, To implement this I need some detail about how windows FileCopy works. So I need a description such as the following: the CreateFile is called, creates a destination…
Kamran
  • 387
  • 1
  • 3
  • 19
2
votes
1 answer

Disable task switching keys with c++

I've done a lot of searching around with no real solution (to my own problem) so I thought I'd ask here. I'm designing a kiosk-like program that prevents the user from using task keys (alt+tab, alt+esc, ctrl+esc, etc) while the program is running.…
Sophia
  • 155
  • 2
  • 13
2
votes
3 answers

SVN post-update hook?

Does it exist? Basically I'm developing a Django app on my local machine, when I've finished adding my feature and get it working locally, I want to commit it, and then update the production server. Then I want to automatically restart apache. Is…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
2
votes
1 answer

iOS: NSProxy can't hook method called inside of Class itself

I use NSProxy to mock a class, and want to hook all invocation of the class. But only methods called outside the class are hooked, without methods called inside the class. Below is something like my code: In my AppDelegate.m, TBClassMock is…
keywind
  • 1,135
  • 14
  • 24
2
votes
1 answer

how to use use-git hooks?

i need to do like this post: Git commit hook - How to use the commit-msg hook to check for string in message? But i need to check if the commit message has an issue number or not. My goal is to only allow commits associated with issues on my github…
2
votes
0 answers

Overriding code in memory securely

I have a DLL that I am loading into a process. The purpose of the DLL is to hook some Windows APIs by placing a jmp on top of the function to my handler. I'm just wondering can I just patch the function like this: *pFunction = 0xE9 //jmp…
user2276094
  • 399
  • 1
  • 4
  • 11
2
votes
1 answer

How to emulate registry in Windows for program testing?

My application extensively reads and changes the windows registry. Because of the nature of the application there is possibility to destroy the system. To avoid system destruction I want to create a temporary copy of my registry and use the copy…
Gizmo
  • 1,990
  • 1
  • 24
  • 50
2
votes
1 answer

Repair wrong translation

There are a lot of places in liferay portal where translation to my language (sk_SK) is wrong. Is it possible to rewrite those bad translations with hook? (Any other idea is welcomed...) Thanks a lot.
BigT
  • 269
  • 1
  • 4
  • 21
2
votes
1 answer

remove_action fails on woocommerce_template_loop_product_thumbnail

I wrote a simple plugin that performs some logic on thumbnails in WooCommerce. This plugin worked great for about a year, until the client switched to a new theme. Now the plugin is no longer working and I've narrowed the problem to remove_action()…
rwkiii
  • 5,716
  • 18
  • 65
  • 114
2
votes
2 answers

Wordpress filter get_the_content()

I'm writing a plugin that requires adding to the content; adding a filter to the_content() is straightforward enough, but the theme I'm testing in uses get_the_content() to build the page. There's an indication that it should be possible in the…
DavidRobins
  • 31
  • 1
  • 4
2
votes
0 answers

SetWindowSubclass + SetWindowsHookEx = not full cleanup and crash?

My dll uses SetWindowsHookEx to get into the main window's thread ( 3rd party application ) to subclass it with SetWindowSubclass. Subclassed window procedure is used just to control additional child window added to the main window.…
psu
  • 111
  • 1
  • 10
2
votes
0 answers

Woocommerce free shipping based on payment gateway selected

I'm trying to get free shipping available when a certain Payment gateway is selected. So I've got 2 payment gateways: if Payment gateway 1 selected --> With shipping costs if Payment gateway 2 selected --> No shipping costs (free shipping) I can't…
Trekdrop
  • 475
  • 7
  • 27
2
votes
0 answers

Why does Qt not work with dll injection?

I am currently working on a program that extract text messages from a third party program, so I dont have to enter tooltip text manually in my excel sheets. I am using dll injection for this and have already successfully hooked the microsoft's…
JonathanSchmied
  • 137
  • 1
  • 7
2
votes
1 answer

Liferay hook CDI

I am developing a service hook for Liferay, and I want to use an external EJB to do the business logic for me. Is there any way to inject a bean to a service class? Here is my code: public class MyUserService extends UserServiceWrapper { //I…
Abel
  • 21
  • 2
2
votes
3 answers

Redirect std::function() callable to custom handler in pre C++11?

I have something like this: typedef std::function TheCallback; void callTheCallback(TheCallback& theCallback) { theCallback(1, 2); } int main(int argc, char *argv[]) { TheCallback cb = [](int a, int b) { …