Overview
TheNapi2NativeLoader enables bypassing NTQQ’s security restrictions that prevent Node.js addons from accessing native APIs. This is required for advanced features like packet hooking and native module integration.
Architecture
Implemented inpackages/napcat-core/packet/handler/napi2nativeLoader.ts:22, the loader manages platform-specific native modules that patch NTQQ’s security checks.
Supported Platforms
win32.x64- Windows 64-bitlinux.x64- Linux 64-bitlinux.arm64- Linux ARM64darwin.x64- macOS Inteldarwin.arm64- macOS Apple Silicon
Initialization
Basic Setup
Loading Process
The loader automatically attempts to load the native module on construction:Bypass Options
TheenableAllBypasses function accepts granular control over which security features to bypass:
Enable All Bypasses
Selective Bypass Configuration
Common Configurations
Minimal Configuration (Packet Handling Only)
For basic packet monitoring:Full Access Configuration
For development or debugging:Production Configuration
For production bots with minimal risk:Verbose Logging
Enable detailed logging from the native module:Verbose mode is disabled by default for performance. Only enable during debugging.
Hook Initialization
After enabling bypasses, initialize hooks with memory offsets:Complete Integration Example
Security Implications
Hook Bypass (hook: true)
- Allows: Function hooking, detours, memory patching
- Risk: Code injection vulnerabilities
- Required for: Packet monitoring, protocol analysis
Module Bypass (module: true)
- Allows: Loading additional native modules
- Risk: Malicious module loading
- Required for: Plugin system, dynamic features
Process Bypass (process: true)
- Allows: System API access, process manipulation
- Risk: System-wide impact, privilege escalation
- Required for: Advanced system integration
Window Bypass (window: true)
- Allows: GUI access, window manipulation
- Risk: UI hijacking
- Required for: Custom UI features
Container Bypass (container: true)
- Allows: Escape sandbox restrictions
- Risk: Sandbox escape
- Required for: Full system access
JavaScript Bypass (js: true)
- Allows: Bypass JS engine restrictions
- Risk: Arbitrary code execution
- Required for: Advanced scripting
Error Handling
Platform-Specific Considerations
Windows
- Requires administrator privileges for some bypasses
- Antivirus may flag native modules
- Windows Defender may block hook operations
Linux
- SELinux/AppArmor may interfere with bypasses
- Permissions may need adjustment
- Works best with relaxed security policies
macOS
- System Integrity Protection (SIP) may block operations
- Gatekeeper may prevent module loading
- Requires appropriate entitlements
Debugging
Check Loader Status
Verify Bypass Status
Best Practices
- Minimal bypasses: Only enable what you need
- Error handling: Always check return values
- Platform detection: Verify platform support before loading
- Graceful degradation: Fall back to restricted mode if bypasses fail
- Security audit: Document which bypasses are enabled and why
- Testing: Test on all target platforms
- Monitoring: Log bypass operations for security audit
Troubleshooting
Module Not Loading
Bypass Fails to Enable
Hook Initialization Fails
Related APIs
- Native Packet Handler - Uses bypasses for packet hooking
- Custom Adapters - May require module bypass
