How to use the smart-buffer.SmartBuffer.fromBuffer function in smart-buffer

To help you get started, we’ve selected a few smart-buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JoshGlazebrook / socks / src / client / socksclient.ts View on Github external
);

        remoteHost = {
          host: buff.readString(hostLength),
          port: buff.readUInt16BE()
        };
        // IPv6
      } else if (addressType === Socks5HostType.IPv6) {
        // Check if data is available.
        const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
        if (this._receiveBuffer.length < dataNeeded) {
          this._nextRequiredPacketBufferSize = dataNeeded;
          return;
        }

        buff = SmartBuffer.fromBuffer(
          this._receiveBuffer.get(dataNeeded).slice(4)
        );

        remoteHost = {
          host: ip.toString(buff.readBuffer(16)),
          port: buff.readUInt16BE()
        };
      }

      this.state = SocksClientState.Established;
      this.removeInternalSocketHandlers();
      this.emit('established', { socket: this._socket, remoteHost });
    }
  }
github JoshGlazebrook / socks / src / client / socksclient.ts View on Github external
private handleSocks4FinalHandshakeResponse() {
    const data = this._receiveBuffer.get(8);

    if (data[1] !== Socks4Response.Granted) {
      this._closeSocket(
        `${ERRORS.Socks4ProxyRejectedConnection} - (${Socks4Response[data[1]]})`
      );
    } else {
      // Bind response
      if (SocksCommand[this._options.command] === SocksCommand.bind) {
        const buff = SmartBuffer.fromBuffer(data);
        buff.readOffset = 2;

        const remoteHost: SocksRemoteHost = {
          port: buff.readUInt16BE(),
          host: ip.fromLong(buff.readUInt32BE())
        };

        // If host is 0.0.0.0, set to proxy host.
        if (remoteHost.host === '0.0.0.0') {
          remoteHost.host = this._options.proxy.ipaddress;
        }
        this.state = SocksClientState.BoundWaitingForConnection;
        this.emit('bound', { socket: this._socket, remoteHost });

        // Connect response
      } else {
github JoshGlazebrook / socks / src / client / socksclient.ts View on Github external
// Read address type
      const addressType = header[3];

      let remoteHost: SocksRemoteHost;
      let buff: SmartBuffer;

      // IPv4
      if (addressType === Socks5HostType.IPv4) {
        // Check if data is available.
        const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;
        if (this._receiveBuffer.length < dataNeeded) {
          this._nextRequiredPacketBufferSize = dataNeeded;
          return;
        }

        buff = SmartBuffer.fromBuffer(
          this._receiveBuffer.get(dataNeeded).slice(4)
        );

        remoteHost = {
          host: ip.fromLong(buff.readUInt32BE()),
          port: buff.readUInt16BE()
        };

        // If given host is 0.0.0.0, assume remote proxy ip instead.
        if (remoteHost.host === '0.0.0.0') {
          remoteHost.host = this._options.proxy.ipaddress;
        }

        // Hostname
      } else if (addressType === Socks5HostType.Hostname) {
        const hostLength = header[4];
github JoshGlazebrook / socks / src / client / socksclient.ts View on Github external
}

        // Hostname
      } else if (addressType === Socks5HostType.Hostname) {
        const hostLength = header[4];
        const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(
          hostLength
        ); // header + host length + host + port

        // Check if data is available.
        if (this._receiveBuffer.length < dataNeeded) {
          this._nextRequiredPacketBufferSize = dataNeeded;
          return;
        }

        buff = SmartBuffer.fromBuffer(
          this._receiveBuffer.get(dataNeeded).slice(5) // Slice at 5 to skip host length
        );

        remoteHost = {
          host: buff.readString(hostLength),
          port: buff.readUInt16BE()
        };
        // IPv6
      } else if (addressType === Socks5HostType.IPv6) {
        // Check if data is available.
        const dataNeeded = SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
        if (this._receiveBuffer.length < dataNeeded) {
          this._nextRequiredPacketBufferSize = dataNeeded;
          return;
        }
github JoshGlazebrook / socks / src / client / socksclient.ts View on Github external
private handleSocks4IncomingConnectionResponse() {
    const data = this._receiveBuffer.get(8);

    if (data[1] !== Socks4Response.Granted) {
      this._closeSocket(
        `${ERRORS.Socks4ProxyRejectedIncomingBoundConnection} - (${
          Socks4Response[data[1]]
        })`
      );
    } else {
      const buff = SmartBuffer.fromBuffer(data);
      buff.readOffset = 2;

      const remoteHost: SocksRemoteHost = {
        port: buff.readUInt16BE(),
        host: ip.fromLong(buff.readUInt32BE())
      };

      this.state = SocksClientState.Established;
      this.removeInternalSocketHandlers();
      this.emit('established', { socket: this._socket, remoteHost });
    }
  }
github germanrcuriel / conan-exiles-admin-map / src / controllers / api / pets.js View on Github external
function getPetOwnerId (pet) {
  const petOwner = SmartBuffer.fromBuffer(pet.owner)
  const ownerId = petOwner.readUInt16LE(petOwner.length - 8)

  return ownerId
}
github germanrcuriel / conan-exiles-admin-map / src / controllers / api / pets.js View on Github external
function getPetInfo (pet) {
  const petInfo = SmartBuffer.fromBuffer(pet.info).readString('utf8')
  const position = petInfo.indexOf('_Name')

  let info = petInfo.substr(position + 5, petInfo.indexOf('ThrallIcon') - position - 5).trim()
  info = JSON.stringify(info)
    .replace(/\\u[0-9a-f]{4}/gi, '')
    .replace(/\\[bfnr]/gi, '')
    .replace(/\"/gi, '')

  return info
}
github germanrcuriel / conan-exiles-admin-map / src / controllers / api / pets.js View on Github external
function getPetName (pet) {
  const petName = SmartBuffer.fromBuffer(pet.name)

  if (petName.length > 21) {
    petName.readOffset = 21
    let name = JSON.stringify(petName.readString())
      .replace(/\\u[0-9a-f]{4}/gi, '')
      .replace(/\\[bfnr]/gi, '')
      .replace(/\"/gi, '')
      .replace('.Imo', '')
      .trim()

    return name
  }

  return "Unknown"
}
github germanrcuriel / conan-exiles-admin-map / src / controllers / api / pippi / thespians.js View on Github external
function getPippiMobName (pippi) {
  const pippiName = SmartBuffer.fromBuffer(pippi.buffer).readString('ascii')
  const position = pippiName.indexOf('StrProperty')

  let name = pippiName.substr(position + 25, pippiName.indexOf('profession') - position - 26).trim()
  name = JSON.stringify(name)
    .replace(/\\u[0-9a-f]{4}/gi, '')
    .replace(/\\[bfnrt]/gi, '')
    .replace(/\"/gi, '')
    .slice(0, -1)

  return name
}

smart-buffer

smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis