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

ProcessInputData() public method

public ProcessInputData ( byte buffer, int offset, int count ) : byte[]
buffer byte
offset int
count int
return byte[]
        public byte[] ProcessInputData(byte[] buffer, int offset, int count)
        {
            //realign buffer.
            try
            {
                byte[] buff = new byte[count];
                Buffer.BlockCopy(buffer, offset, buff, 0, count);
                switch (this.auth)
                {
                    case AuthTypes.SocksBoth:
                        //decrypt, then decompress.
                        byte[] data = this.dcc.DecryptBytes(buff);
                        return dcc.DecompressBytes(data);
                    case AuthTypes.SocksCompress:
                        //compress data.
                        return dcc.DecompressBytes(buff);
                    case AuthTypes.SocksEncrypt:
                        return dcc.DecryptBytes(buff);
                    default:
                        return buffer;
                }
            }
            catch {
                return null;
            }
        }

Usage Example

コード例 #1
0
ファイル: Socks.cs プロジェクト: hymersm/Socks5
        public static SocksRequest RequestTunnel(SocksClient client, SocksEncryption ph)
        {
            byte[] data;
            int recv = Receive(client.Client, out data);
            byte[] buff = ph.ProcessInputData(data, 0, recv);
            if (buff == null || (HeaderTypes)buff[0] != HeaderTypes.Socks5) return null;
            switch ((StreamTypes)buff[1])
            {
                case StreamTypes.Stream:
                    {
                        int fwd = 4;
                        StringBuilder address = new StringBuilder();
                        switch ((AddressType)buff[3])
                        {
                            case AddressType.IP:
                                {
                                    for (int i = 4; i < 8; i++)
                                    {
                                        //grab IP.
                                        address.Append(Convert.ToInt32(buff[i]).ToString() + (i != 7 ? "." : ""));
                                    }
                                    fwd += 4;
                                }
                                break;
                            case AddressType.Domain:
                                {
                                    int domainlen = Convert.ToInt32(buff[4]);
                                    address.Append(Encoding.ASCII.GetString(buff, 5, domainlen));
                                    fwd += domainlen + 1;
                                }
                                break;
                            case AddressType.IPv6:
                                //can't handle IPV6 traffic just yet.
                                return null;
                        }
                        byte[] po = new byte[2];
                        Array.Copy(buff, fwd, po, 0, 2);
                        Int16 x = BitConverter.ToInt16(po, 0);
                        int port = Convert.ToInt32(IPAddress.NetworkToHostOrder(x));
                        port = (port < 1 ? port + 65536 : port);
                        return new SocksRequest(StreamTypes.Stream, (AddressType)buff[3], address.ToString(), port);
                    }
                default:
                    //not supported.
                    return null;

            }
        }
All Usage Examples Of socks5.Encryption.SocksEncryption::ProcessInputData