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

GetProcAddress fails for a function exported with dllexport

First of all, I am new to hooking methods and dll manipulation. I have an assignment to first create a simple program that opens a message box using MessageBoxA. The Code: #include #include #include using namespace…
2
votes
3 answers

Getting top-level window by widget

I'm hooking the QPainter::drawText() function of a Qt5 application on Windows. My goal is to identify the native handle of the top-level-window to which the text is painted. First, I'm getting the associated widget. QWidget *widget =…
m1st4x
  • 31
  • 1
  • 8
2
votes
1 answer

How to pre-hook the gitflow hotfix finish?

I think I am using the "https://github.com/nvie/gitflow", if that is the one which comes within the Smartgit GUI program. Every time I to commit something, I update the 'build' number. Example: 2.6.0-77 to 2.6.0-78 This is already implemented to…
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
2
votes
2 answers

Global test hook or global test teardown for each test in robot framework

I want to some sort of hook mechanism running before/after each test. For instance, I want to run keyword if I passed ARGUMENT=1 to pybot or python for each test, not modifying whole bunch of tests in my project. Is it possible? Similar way, you…
Alexander.Iljushkin
  • 4,519
  • 7
  • 29
  • 46
2
votes
1 answer

WordPress - Trigger after save new post including meta data and taxonomy

I have a situation in which I am bit confused with WordPress filters and action hooks. I have custom form at front-end (BuddyForms) which is creating wooCommerce product on submit. I have to process some data on such products added from front-end so…
Nikhil
  • 267
  • 1
  • 4
  • 10
2
votes
3 answers

SailsJs - problems with lifting (orm hook failed to load)

I am having problems with running my app under windows. Normally, I am developing on Macbook but temporarly I had to switch. The thing is, that the app was already working on windows without problems. Here is an error message: error: A hook (orm)…
DeJoT
  • 73
  • 2
  • 6
2
votes
1 answer

Hooking into Forms redrawing

I'm looking for a way to overlay the graphical output of a third-party application with some lines, arcs etc. The applications accepts a handle of a window in which it will then display its output. Using VC++ I put together a Windows Forms app in…
Ada
  • 21
  • 1
2
votes
2 answers

Buddypress hook after xprofile field is updated

i want to update a custom user_meta field when a User changed/edit the xProfile field (width the ID 1542). this does hook not work function action_xprofile_data_after_save( $x ) { print_r($x); // if($field == 1542) // …
Peter
  • 11,413
  • 31
  • 100
  • 152
2
votes
1 answer

Application crashes when using hooked function with cout

I'm trying to hook a function using its address, and so far it is overall working great! The only problem is when using std::cout in combination with having MessageBoxA from the WinAPI hooked, then it crashes! The weird thing is, it only crashes in…
vallentin
  • 23,478
  • 6
  • 59
  • 81
2
votes
1 answer

How can I get autocomplete arguments before ENTER?

There is a file argComp.py in Ubuntu 14.04 LTS. I install argcomplete 1.0.0 module successfully. chmod +x argComp.py and then data = [ name1 : { address1 : [Korea, Seoul ] }, name2 : { address2 : [ USA, LA ] } ] ./argComp.py --name…
2
votes
1 answer

Prestashop 1.6 custom module : addJS/addCSS don't work properly

I created my prestashop module, with a hook to display my specific search form. public function hookDisplayTopColumn($params) { $this->context->controller->addCSS($this->_path.'css/modelfilter.css', 'all'); …
Nathanael
  • 23
  • 1
  • 4
2
votes
1 answer

keyboard hook- different languages - c++

I'm trying to write a key-logger, but I have a problem when I switch a language. I have Hebrew and English in my keyboard. It recognizes well Hebrew and English separately, the problem is if I change language(alt+shift) so it remains in the first…
1337
  • 317
  • 1
  • 9
2
votes
2 answers

Rails 2 hook to modify data before it is read/written to MySQL DB

I have a rails 2 application that I am trying to modify so that before an attribute is written to my MySql DB, it is encoded, and on read, it is decoded (not all attributes, just pre-determined ones). I have looked at some gems, specifically…
Hawkeye001
  • 791
  • 2
  • 11
  • 25
2
votes
0 answers

Problems hooking olesetclipboard

Goal: While running inside another process (... Say a plugin inside an Office application like Word), intercept the calls to OleSetClipboard/OleGetClipboard and proxy the iDataObject interface by replacing the object originally set/get by the…
David
  • 21
  • 2
2
votes
5 answers

Loopback get IP address from operation hook

Well, that XD, how do I get the IP Address of the querier (if that's even the word xD) from within an operation hook? or a remote hook? (I can save it with loopback.getCurrentContext() to use on the operation hook). Say: Model.observe('loaded',…
Alons Oh
  • 195
  • 1
  • 14