// redirect_connect.js - Redirect game server connections to local proxy // Hooks ws2_32!connect and changes destination IP to 127.0.0.1 for port 11001 (function() { 'use strict'; var REDIRECT_PORT = 11001; var REDIRECT_TO_IP = [127, 0, 0, 1]; var ws2 = Process.getModuleByName('ws2_32.dll'); var connectAddr = null; ws2.enumerateExports().forEach(function(e) { if (e.name === 'connect') connectAddr = e.address; }); if (!connectAddr) { send({t: 'error', msg: 'connect not found'}); return; } Interceptor.attach(connectAddr, { onEnter: function(args) { var addr = args[1]; var family = addr.readU16(); if (family !== 2) return; // AF_INET only var port = (addr.add(2).readU8() << 8) | addr.add(3).readU8(); if (port !== REDIRECT_PORT) return; var origIp = addr.add(4).readU8() + '.' + addr.add(5).readU8() + '.' + addr.add(6).readU8() + '.' + addr.add(7).readU8(); // Rewrite IP to 127.0.0.1 addr.add(4).writeU8(REDIRECT_TO_IP[0]); addr.add(5).writeU8(REDIRECT_TO_IP[1]); addr.add(6).writeU8(REDIRECT_TO_IP[2]); addr.add(7).writeU8(REDIRECT_TO_IP[3]); send({t: 'redirect', from: origIp, port: port, to: '127.0.0.1'}); } }); send({t: 'ready', msg: 'connect() hook installed. Port ' + REDIRECT_PORT + ' will be redirected to 127.0.0.1'}); })();