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

Read Text From Windows Form

I would like, if for no other reason that an academic exercise, to be able to read text written to a form on a Windows Application. The program appears to be written in non-.NET, but in .NET terms, I think you would describe the program as having a…
omghai2u
  • 273
  • 3
  • 14
2
votes
1 answer

Using GetProcAddress and EasyHook to hook class methods and constructors

I've had plenty of success using EasyHook to hook system API routines (in C++) out of libraries. These libraries have always been flat and basically filled with globally callable routines. Here is a small sample using MessageBeep() out of the…
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48
2
votes
1 answer

Finding static function address in linux library

I need to find address of a static function in a linux library for hooking. I tried using dlopen() and dlsym() but it didn't work. Is there any way to find it? Or how to iterate through library's memory so I can do a pattern scanning?
Bien Pham
  • 47
  • 3
2
votes
2 answers

Hooking sycalls from userspace on Linux

Is there any way to catch all syscalls on Linux? The only solution I know of is using LD_PRELOAD à la fakeroot, but that only works for dynamically linked applications. Furthermore, this approach requires enumerating all syscalls which is something…
phihag
  • 278,196
  • 72
  • 453
  • 469
2
votes
1 answer

Hook crashing after trampoline

im trying to create a sort of overlay of a game i play in order to display my ping in realtime as there has been a lot of issues and people blaming the ping so i just wanted an easy solution and add a realtime ping display in game :) Anyways hooks…
Paze
  • 191
  • 1
  • 13
2
votes
2 answers

drupal module alter view or node

I have been using hook_alter to modify forms in a custom PHP module. I started to take the same approach modifying the result page of "node add" form. However this page is not a form so I don't have a form ID to hook on to. Actually it contains a…
bert
  • 287
  • 6
  • 14
2
votes
1 answer

Global CBT hook is never called

I'm trying to make an application that gets informed on creation and destruction of top-level windows, system-wide. I've made a code to exploit a CBT hook. The solution contains two projects, DLL and EXE. EXE project has a reference to the DLL…
polkovnikov.ph
  • 6,256
  • 6
  • 44
  • 79
2
votes
1 answer

cordova hook: stop node until promise finished

I'm writting a cordova hook which updates plugins on before_prepare. Three questions here: I'm getting the error: [TypeError: Cannot read property 'buffer' of undefined] I would like to stop the flow until the plugin has been updated Is it possible…
Miquel
  • 8,339
  • 11
  • 59
  • 82
2
votes
2 answers

Drupal - how to add add same page to two menus?

How can I add same callback to 2 different menus? function my_callback_menu(){ $items = array(); $items['my_callback'] = array( 'title' => t('My title'), 'menu_name' => 'menu-my-menu', 'page callback' …
bert
  • 287
  • 6
  • 14
2
votes
1 answer

When to use add-hook, eval-after-load in Emacs

I'v read eval-after-load vs add-hook. According to the page, code in eval-after-load is executed once. On the other hand, code inside add-hook will run every time a buffer of that mode in opened. Ok. But How can I figure out which code should be…
1ambda
  • 1,145
  • 8
  • 19
2
votes
1 answer

SetWindowsHookEx with WH_KEYBOARD stuck in a loop/queue

I am trying to hook a Notepad with dll-injection. After the exe is run and hooks the Notepad (form what I can tell successfully) and some keys are pressed, what seems to happan is that the key presses get stuck in a loop or a queue (Notepad not…
Binder
  • 63
  • 9
2
votes
1 answer

Wildfly deployment hook/event

Is there a way to create deployment hooks on Wildfly? I need to be mailed after all deployments made in my server. Doesn't matter if the deployment is OK or not.
Hernã Saldanha
  • 300
  • 2
  • 10
2
votes
1 answer

C# - Clipboard hooking check if the data being copied is really image or a text?

I have a small program that is listening to clipboard(hook) for images. If there is an image stored or copied through ctrl+c and the like, my program will paste the image automatically to an open word doc. Code: if (Clipboard.ContainsImage()) { …
luwanda
  • 21
  • 1
2
votes
1 answer

Waiting for a program to load DLLs and then suspend it

I want to hook an api as soon as a program loads. For that I use createprocess with the appropriate flag set so that the process is created suspended. I place the hook and then I resume it. But when I try to hook an api that's not from ntdll.DLL i…
Alex
  • 103
  • 1
  • 10
2
votes
3 answers

How to create a user without autologin after sign up on Meteor

I'm building a Meteor app and I need to remove the autologin of Meteor after a user create an account. I'm using accounts-password and accounts-entry for the UI (optional). Any idea? Thank you.
skozz
  • 2,662
  • 3
  • 26
  • 37