From 09cd59b7285d5f5933f8557929b58265a07b5e92 Mon Sep 17 00:00:00 2001 From: Alisson Comerlatto Date: Thu, 3 Jul 2025 10:14:24 -0300 Subject: [PATCH] feat(native-connect-hook): enhance support for system connection hooks - Declare system module as a constant. - Add `conn` variable for cleaner `Interceptor.attach` initialization. - Improve error handling. --- native-connect-hook.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/native-connect-hook.js b/native-connect-hook.js index 523c481..bad1049 100644 --- a/native-connect-hook.js +++ b/native-connect-hook.js @@ -29,9 +29,9 @@ ? 4 : 2048; // Linux/Android - let systemModule, fcntl, send, recv; + let fcntl, send, recv, conn; try { - systemModule = Process.findModuleByName('libc.so') ?? // Android + const systemModule = Process.findModuleByName('libc.so') ?? // Android Process.findModuleByName('libc.so.6') ?? // Linux Process.findModuleByName('libsystem_kernel.dylib'); // iOS @@ -40,13 +40,15 @@ fcntl = new NativeFunction(systemModule.getExportByName('fcntl'), 'int', ['int', 'int', 'int']); send = new NativeFunction(systemModule.getExportByName('send'), 'ssize_t', ['int', 'pointer', 'size_t', 'int']); recv = new NativeFunction(systemModule.getExportByName('recv'), 'ssize_t', ['int', 'pointer', 'size_t', 'int']); + + conn = systemModule.getExportByName('connect') } catch (e) { console.error("Failed to set up native hooks:", e.message); console.warn('Could not initialize system functions to to hook raw traffic'); return; } - Interceptor.attach(systemModule.getExportByName('connect'), { + Interceptor.attach(conn, { onEnter(args) { const fd = this.sockFd = args[0].toInt32(); const sockType = Socket.type(fd);