Ejemplo n.º 1
0
        // 4/4a  (connect, bind) - Supports domains & ipaddress
        function negotiateSocks4(options, socket, callback) {
            buff.writeUInt8(0x04);
            buff.writeUInt8(options.proxy.command);
            buff.writeUInt16BE(options.target.port);

            // ipv4 or domain?
            if (net.isIPv4(options.target.host)) {
                buff.writeBuffer(ip.toBuffer(options.target.host));
                buff.writeStringNT(options.proxy.userid);
            } else {
                buff.writeUInt8(0x00);
                buff.writeUInt8(0x00);
                buff.writeUInt8(0x00);
                buff.writeUInt8(0x01);
                buff.writeStringNT(options.proxy.userid);
                buff.writeStringNT(options.target.host);
            }

            socket.once('data', receivedResponse);
            socket.write(buff.toBuffer());

            function receivedResponse(data) {
                socket.pause();
                if (data.length === 8 && data[1] === SOCKS4_RESPONSE.Granted) {

                    if (options.proxy.command === COMMAND.Bind) {
                        buff.clear();
                        buff.writeBuffer(data);
                        buff.skip(2);

                        var info = {
                            port: buff.readUInt16BE(),
                            host: buff.readUInt32BE()
                        };

                        if (info.host === 0) {
                            info.host = options.proxy.ipaddress;
                        } else {
                            info.host = ip.fromLong(info.host);
                        }

                        finish(null, socket, info, callback);
                    } else {
                        finish(null, socket, null, callback);
                    }

                } else {
                    finish(new Error("Rejected (" + data[1] + ")"), socket, null, callback);
                }
            }
        }
Ejemplo n.º 2
0
function patch(file, bin, from, to, callback) {
	if(from === 1 && to === 2) {
		// Set Version to 2
		// Add 1 Byte
	} else if(from === 2 && to === 1) {
		// Set version to 1
		// Remove 1 Byte
	} else {
		callback('Unsupported Patch - from Version: ' + from + ' to Version: ' + to)
	}

	var newFile = new SmartBuffer()

	bin.data._readOffset = 0
	bin.data._writeOffset = 0 // Reset read offset

	newFile.writeUInt32LE(bin.readUInt32LE()) // SCN Version
	newFile.writeUInt32LE(bin.readUInt32LE()) // Object ID
	newFile.writeStringNT(bin.readStringNT()) // Object Name
	newFile.writeStringNT(bin.readStringNT()) // Parent Name
	newFile.writeBuffer(bin.readBuffer(68)) // or 16 x readFloatLE() ... But not needed ;o

	if(from === 1 && to === 2) {
		bin.skip(4)
		newFile.writeUInt32LE(EScnVersion.Version2)
		newFile.writeUInt32LE(bin.readUInt32LE()) // Object Count

		newFile.writeUInt8(0) // Add missing 1 Byte

		newFile.writeBuffer(bin.readRemaining()) // Read and add remaining data
	} else if(from === 2 && to === 1) {
		bin.skip(4)
		newFile.writeUInt32LE(EScnVersion.Version1)
		newFile.writeUInt32LE(bin.readUInt32LE()) // Object Count

		bin.skip(1) // Remove 1 Byte

		newFile.writeBuffer(bin.readRemaining()) // Read and add remaining data
	}

	// And save to target folder
	fs.writeFile(Config.targetFolder + '/' + file, newFile.toBuffer(), { encoding: 'binary' }, function (err) {
		if (err) throw err

		callback()
	})
}
Ejemplo n.º 3
0
function buildAuthChallenge(challenge, serverCaps, protocolVersion, licenseAgreement) {
  assert(challenge.length === 8);

  var hasLicense = !!licenseAgreement;

  // Set the low bit for has-license flag.
  serverCaps = (hasLicense) ? (serverCaps | 1)
                            : (serverCaps & ~1);

  var buffer = new SmartBuffer();
  buffer.writeBuffer(challenge, /* offset: */ 0);
  buffer.writeUInt32LE(serverCaps);
  buffer.writeUInt32LE(protocolVersion);
  if (hasLicense) {
    buffer.writeStringNT(licenseAgreement);
  }

  return buffer.toBuffer();
};