0.1.7 • Public • Published

DeflectJS API - Hooking

Make it easier to hook APIs and functions into javascript using DeflectJS API Hooking. If you want install it in node, please check our npm package deflectjs-engine.

Get started into DeflectJS Hooking Engine

Our example will show how to change the behavior of the console.log function using a replacement hook.

The console.log by default display a text parameter specified in log(str), thus let's change the real output to "Hooked: " + str. When an user call console.log(str) the string displayed should be "Hooked: " + str. After attach our hook, console.log("Test!") will give "Hooked: Test!" instead of "Test!".

Original output when calling console.log

Hooked: Test!

Hooking the function console.log using DeflectJS Hooking Engine

var hookStruct; //Struct that contains our hook data.
var hookQueue = []; //Queue where our hook will be added.
//Function that will replace the current console.log
function hookedLog(text){
    return hookStruct.OriginalFunction("Hooked: " + text); 
//Creating the stub that will intercept calls for console.log
hookStruct = deflect_create_native_hook(console.log, hookedLog, DEFLECT_NATIVE_OVERWRITTEN_HOOK, console);
//Adding the hooks in the queue to be attached.
if (deflect_enqueue_hook(hookStruct, hookQueue) != DEFLECT_STATE_ENQUEUED){
//Attaching all hooks in queue.
if (deflect_attach_hook(hookQueue) != DEFLECT_STATE_HOOKED){

After hooking the console.log api, let's see what happens when you call it.

//Now, let's see what happens when call console.log

And our result will be:

Hooked: Test!

Unhooking the function console.log using DeflectJS Hooking Engine

if (deflect_detach_hook(hookQueue) == DEFLECT_STATE_UNHOOKED){
    alert('Successful unhooked!');

Compatibility of modern browsers

Browser Verified version Supported features
Google Chrome v79.0.3945.88 All features
Mozilla Firefox v71.0 All features
Opera v65.0.3467.78 All features
Microsoft Edge v20.10240.16384.0 All features

Malicious use of DeflectJS Hooking Engine

When a function is hooked its behavior changes and leads to different results than the application intended. Malicious use of hooks to exploit systems is discouraged and isn't our responsibility.

Wiki of DeflectJS Engine Hooking

Visit our wiki page and read our api sample.

Package Sidebar


npm i deflectjs-engine

Weekly Downloads






Unpacked Size

22.8 kB

Total Files


Last publish


  • muryllo.pimenta