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

Hooking dll loaded to memory

I'm trying to write a program, which will catch the event of a dll load into memory. For that purpose I put a hook on LdrLoadDll API. That works very fine, but the problem is that this API doesn't catch dlls which loaded as dependencies. For…
macro_controller
  • 1,469
  • 1
  • 14
  • 32
2
votes
1 answer

Set hook on LoadLibrary which was called from DllMain of hooked delayed-dll

My goal is hook all LoadLibrary calls from particular dll and its dependencies (which may be delayed importable). Here is how I'm trying to solve this task: Load this dll using DONT_RESOLVE_DLL_REFERENCES flag. 1.1. Apply this algorithm to dll's…
Dmitry Katkevich
  • 883
  • 7
  • 26
2
votes
3 answers

How to conditionally use static library only when linked

I'm doing an iPhone plugin project where I build a static library, let's call it lib1.a, which I provide to other programmers. When they link lib1.a into their project, they may also link lib2.a, which they build themselves based on a header file I…
Simplex
  • 930
  • 1
  • 9
  • 20
2
votes
1 answer

Trying to make a lua proxy with metatables

I've read about metatables (here and here) and I asked myself if I could create a function call proxy by just adding a function with the same name to the __index table, so that it calls the index function (mine), and then I can call the normal…
K0IN
  • 79
  • 1
  • 7
2
votes
1 answer

why we must place a global hook procedure in a separate DLL

i read some article and msdn and blog but have some question why we must place a global hook procedure in a DLL separate from the application installing the hook procedure and what is different from global hook and keyloger( i write key loge…
maysam
  • 509
  • 10
  • 23
2
votes
1 answer

XPosed: IXposedHookZygoteInit vs IXposedHookLoadPackage

I'm using XPosed for hooking some methods on Android device. As I know, IXposedHookZygoteInit will run first when zygote process first starts. After that IXposedHookLoadPackage will be called when normal packages load. So IXposedHookLoadPackage…
Trần Kim Dự
  • 5,872
  • 12
  • 55
  • 107
2
votes
1 answer

Post Commit SVN hook on MediaTemple (gs) - svn update

I have created a SSH/FTP/email user and when I connect to my MTServer using SSH and that user I can't access /home/XXXX/domains/mydomain.com/. I am using subversion and it's working fine, but I want it to be able to auto update my webpage ( on the…
Bonfocchi
  • 523
  • 3
  • 10
  • 19
2
votes
0 answers

How to use lua_yield and lua_sethook to step into code line by line?

I'll want to implement a debugger to navigate through a lua script step by step. The script is embedded in a win32 c++ enviroment, created with the main gui thread and called by gui interaction like buttons, timers. A second thread also calls the…
Reine Elemente
  • 131
  • 1
  • 11
2
votes
0 answers

use wp_insert_post action hook to post to website2 while new post is created in website1, but the post is inserted 4,5 times in website 1

I require to insert a post in different website (website 2) while insert a post in website 1. I am using the xmlrcp api. The xmlrcp is working. But while i try to insert the post in remote server using the wp_insert_post action hook, the post is…
Rocky Prajapati
  • 187
  • 1
  • 15
2
votes
1 answer

authentication in liferay without login hook

I have a problem, I get the user and password of a view and I check if this data is correct in the data of liferay, when it's correct my method return 1 if the validation is true, but I don't know how to make the successful login in liferay, this is…
2
votes
1 answer

Drupal 8 hook_views_pre_build no effect

I'm trying to override some view by using the hook_views_pre_build hook. Following the documentation: https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php/function/hook_views_pre_build/8.1.x My module is named "mymodule", I've…
Metal3d
  • 2,905
  • 1
  • 23
  • 29
2
votes
1 answer

Pagedown markdown script inserts image url once

I have a modified pagedown markdown markup script for inserting image url to the editor but it works only the first time. I have explained my code with comments