How 0xsdeo/hook_js works
Project Type and Purpose
• This is an open-source collection of JavaScript “hook” userscripts (for Tampermonkey/Greasemonkey) that override or wrap built-in Web APIs (console, fetch, XHR, DOM properties, storage, debugger functions, CryptoJS, cookie, etc.).
• Its goal is to help reverse-engineers and front-end security analysts intercept calls, log parameters and stacks, or bypass anti-debugging tricks by injecting these scripts at document-start.
File Structure Analysis
• Top-level script files (Hook_fetch.js, Hook_xhr.js, hook_JSON.js) each target a single API.
• Folders group related scripts:
• hook_console/ (hook_log, hook_clear, hook_table, Forbidden_log)
• hook_window/ (hook_localStorage, hook_sessionStorage, hook_history, hook_close)
• Hook_xss/ (Hook_innerHTML, Hook_outerHTML)
• Hook_CryptoJS/ (unfinished CryptoJS hooks)
• Hook_cookie/ (v0.1, v0.2 cookie hooks)
• hook_debugger/ (Bypass_Debugger, Hook_Function, Hook_eval, plus tutorial-series scripts)
• “实用小脚本” (Fixed_window_size, 格式化检测 bypass)
• README describes each script’s purpose, usage notes, and sample outputs (in /image/README).
Key Architectural Components
a. Browser environment
b. Userscript engine (Tampermonkey/Greasemonkey)
c. HookJS script loader/manifest (each script’s @include, @run-at document-start)
d. Hook modules:
• Console hooks
• Window/storage hooks
• Network hooks (fetch, XHR)
• DOM hooks (innerHTML, outerHTML)
• CryptoJS hook
• Cookie hook
• Debugger bypass hooks
• Utility scripts
e. Underlying Web APIs / JS built-ins being overridden
f. Logging/output channel (console.log, stack traces, screenshots)
g. Consumer (developer observing console, using stack info)
Relationships and Data Flows
• At document-start, the userscript engine injects each HookJS module into the page context.
• Modules override or wrap target methods/properties on global objects (window, Document.prototype, XMLHttpRequest.prototype, etc.).
• When the page’s own code invokes those APIs, control flows into the HookJS wrapper, which:
• Captures parameters and stack traces
• Optionally bypasses anti-debugger traps (skips debugger statements)
• Logs details back via console or other means
• Passes control through to the original implementation (except in some blocking hooks)
• The developer views the output in the browser console to analyze behavior.
Architectural Patterns and Design Principles
• Modular grouping by concern (single-responsibility per hook script)
• Method overriding and proxy patterns (Function.prototype, Proxy usage in some bypass scripts)
• Central injection point (userscript manifest) with consistent run-at=document-start
• Non-invasive fall-through: after logging, original behavior continues unless explicitly blocked