socks5.Encryption.SocksEncryption.ProcessOutputData C# (CSharp) Method

ProcessOutputData() public method

public ProcessOutputData ( byte buffer, int offset, int count ) : byte[]
buffer byte
offset int
count int
return byte[]
        public byte[] ProcessOutputData(byte[] buffer, int offset, int count)
        {
            //realign buffer.
            try
            {
                byte[] buff = new byte[count - offset];
                Buffer.BlockCopy(buffer, offset, buff, 0, count);
                switch (this.auth)
                {
                    case AuthTypes.SocksBoth:
                        //compress, then encrypt.
                        byte[] data = dc.CompressBytes(buff, 0, count);
                        return this.dc.EncryptBytes(data);
                    case AuthTypes.SocksCompress:
                        //compress data.
                        return dc.CompressBytes(buff, 0, count);
                    case AuthTypes.SocksEncrypt:
                        return dc.EncryptBytes(buff);
                    default:
                        return buffer;
                }
            }
            catch
            {
                return null;
            }
        }

Usage Example

Esempio n. 1
0
        public static socks5.Socks.SocksError SendRequest(Client cli, SocksEncryption enc, string ipOrDomain, int port)
        {
            AddressType type;
            IPAddress ipAddress;
            if (!IPAddress.TryParse(ipOrDomain, out ipAddress))
                //it's a domain. :D (hopefully).
                type = AddressType.Domain;
            else
                type = AddressType.IP;
            SocksRequest sr = new SocksRequest(StreamTypes.Stream, type, ipOrDomain, port);
            //send data.
            byte[] p = sr.GetData(false);
            p[1] = 0x01;
            //process data.
            cli.Send(enc.ProcessOutputData(p, 0, p.Length));
            byte[] buffer = new byte[512];
            //process input data.
            int recv = cli.Receive(buffer, 0, buffer.Length);
            if(recv == -1)
            {
                return SocksError.Failure;
            }
            byte[] buff = enc.ProcessInputData(buffer, 0, recv);

            return (SocksError)buff[1];
        }