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

Cucumber jvm - specify multiple tags to ignore in After hook

I'm writing some tests using the cucumber jvm that require a few different tear down behaviours for some features, with the majority of scenarios requiring a common tear down. So far I have been able to successfully tell cucumber to run a common…
Jeremy
  • 3,418
  • 2
  • 32
  • 42
2
votes
0 answers

new thread in IOS tweak?

I want to invoke IOS system delegate(jailbreaked) in tweak(dylib) for all app, for example - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations I try to do this in tweak.xm: void* Run(void *arg) { …
scvyao
  • 143
  • 1
  • 12
2
votes
0 answers

Hook minimize event of third party application

I have following hook class: public sealed class Hook : IDisposable { public delegate void Win32Event(IntPtr hWnd); #region Windows API private const uint WINEVENT_OUTOFCONTEXT = 0x0000; [DllImport("User32.dll", SetLastError =…
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
2
votes
1 answer

Issue in automatic executing post-commit in git hook to sync local and remote directory

I have a server that has bare git repository, and I'd like to use hook to sync the contents with a working so that I can sync my local directory to the working directory in the server. Googling here and there; this is what I have done so far. ssh…
prosseek
  • 182,215
  • 215
  • 566
  • 871
2
votes
3 answers

How to hook into a method with int[] using xposed?

I am trying to hook into this method in NotificationManagerService using Xposed: void enqueueNotificationInternal(final String pkg, final String opPkg, final int callingUid, final int callingPid, final String tag, final int id, final…
Wilco
  • 53
  • 1
  • 6
2
votes
0 answers

Create WP user from custom post type with action hook

I have a custom post type that I would like to use to create a WP user with an action hook. Once a user has completed the form the hook should enter the basic information to begin registering a wp user i.e. username, password email. This is the…
Douro
  • 21
  • 2
2
votes
2 answers

How to Correctly Translate WH_MOUSE lparam in Managed Code

I've set up a WH_MOUSE hook, everything is working fine except that I can't get the lparam (pointer to a MOUSEHOOKSTRUCT structure) passed to my HOOKPROC function correctly translated in C#. My project consists of two parts, an unmanaged part in C++…
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
2
votes
0 answers

detours hook memcpy dont work program stop working

when i inject this dll to program, the program crash when meet function memcpy. I want to hook function memcpy with detours. Please Help. #include #include #include "detours\detours.h" #pragma comment( lib, "msvcrt.lib"…
lukas kiss
  • 381
  • 2
  • 15
2
votes
1 answer

SetWindowsHookEx is injecting 32-bit DLL into 64-bit process and vice versa

I've been working on an application that requires monitoring thread specific mouse activity (WH_MOUSE) on another process and encountered something very curious. After finding out that this is not possible via exclusively managed code if I don't…
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
2
votes
0 answers

how to intercept dlopen in Linux kernel mode

I don't want use LD_PRELOAD mechanism in user mode to hook dlopen, because Malicious Code can bypass user mode hooking. I want to do this in kernel mode. Hooking 'open' has great side effects. Is there any other better way?
siyuan
  • 113
  • 7
2
votes
0 answers

where can I see the echo result when use git hooks?

I just want to know whether the post-receive git hook scripts have been executed, so I added an echo command to the bash script like this: #!/bin/sh echo "just test" When I run git push on local repo, nothing happened on the remote server. Where…
Lynnic
  • 21
  • 2
2
votes
1 answer

Which user-mode functions to hook to monitor/intercept file access?

Which user-mode functions in Windows 7 can I hook to monitor/intercept file access? I've tried ntdll.dll's NtOpenFile(), NtCreateFile(), but some of these aren't files - they're also pipes and mutexes. Same goes for kernel32.dll's CreateFile(). Is…
Rudi
  • 29
  • 3
2
votes
0 answers

Git post-receive hook fails to run worktree

I have set up bare git repository on server and I want to add post-receive hook which will add directory as a worktree and checkout master branch there. The problem is that each time I push my changes and hook is being executed I get an…
senx
  • 630
  • 9
  • 18
2
votes
1 answer

SetWindowsHookEx succeed but callback function is never called

dll code: LRESULT CALLBACK CBTNewProc(int nCode, WPARAM wParam, LPARAM lParam) { std::ofstream file; file.open("E:\\enter.txt", std::ios::out); file << nCode; file.close(); return CallNextHookEx(g_hHook, nCode, wParam,…
Wood
  • 945
  • 1
  • 9
  • 18
2
votes
0 answers

Git Push To Staging Server - Error message

I want to push from my local machine to a staging server via post-receive hook. I did the following steps: Remote Machine mkdir /var/www/mfserver.git git init --bare mkdir /var/www/mfserver sudo chmod -R ug+w /var/www/mfserver/.git sudo chown -R…
sesc360
  • 3,155
  • 10
  • 44
  • 86