Skip to content

Instantly share code, notes, and snippets.

@freehuntx
Created November 1, 2023 18:24
Show Gist options
  • Save freehuntx/ce3b9902f9c84fbb8dfd3417ac71e94f to your computer and use it in GitHub Desktop.
Save freehuntx/ce3b9902f9c84fbb8dfd3417ac71e94f to your computer and use it in GitHub Desktop.
Javascript function hook logger
function logHookFunction(obj, key, hookTime = 5000) {
if (typeof obj[key] !== "function") {
console.log("[-] Hook failed! Not a function!")
return
}
obj[`o${key}`] = obj[`o${key}`] || obj[key]
obj[key] = function(...args) {
console.log(`[HOOKR] ${key}(${args.join(',')})`)
return this[`o${key}`](...args)
}
console.log(`[+] Hooked "${key}"`)
setTimeout(() => {
obj[key] = obj[`o${key}`]
delete obj[`o${key}`]
console.log(`[+] UnHooked "${key}"`)
}, hookTime)
}
// Example: logHookFunction(document.head, "addChild")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment