示例#1
0
        public Stream getExtInputStream()
        {
            PipedMemoryStream In = new PipedMemoryStream(
                32 * 1024                       // this value should be customizable.
                );

            io.setExtOutputStream(In, false);
            return(In);
        }
        public override void run()
        {
            try
            {
                if (lport == -1)
                {
                    Type c = Type.GetType(target);
                    daemon = (ForwardedTCPIPDaemon)c.newInstance();

                    PipedMemoryStream Out = new PipedMemoryStream(32 * 1024);
                    /*
                    PipedOutputStream Out = new PipedOutputStream();
                    io.setInputStream(new PassiveInputStream(Out
                                                             , 32 * 1024
                                                             ), false);
                    */
                    io.setInputStream(Out);
                    daemon.setChannel(this, getInputStream(), Out);
                    object[] foo = getPort(getSession(), rport);
                    daemon.setArg((object[])foo[3]);

                    new Thread(new ThreadStart(daemon.run)).Start();
                }
                else
                {
                    socket = (factory == null) ?
                       Util.createSocket(target, lport, TIMEOUT) :
                      factory.createSocket(target, lport);
                    socket.NoDelay=true;
                    io.setInputStream(socket.GetStream());
                    io.setOutputStream(socket.GetStream());
                }
                sendOpenConfirmation();
            }
            catch //(Exception e)
            {
                sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
                close = true;
                disconnect();
                return;
            }

            thread = Thread.CurrentThread;
            Buffer buf = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int i = 0;
            try
            {
                while (thread != null &&
                      io != null &&
                      io.In != null)
                {
                    i = io.In.Read(buf.buffer,
                                 14,
                                 buf.buffer.Length - 14
                                 - 32 - 20 // padding and mac
                                 );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    packet.reset();
                    if (close) break;
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    getSession().write(packet, this, i);
                }
            }
            catch //(Exception e)
            {
                //Console.Error.WriteLine(e);
            }
            //thread=null;
            //eof();
            disconnect();
        }
示例#3
0
 public Stream getInputStream()
 {
     PipedMemoryStream In = new PipedMemoryStream(
                              32 * 1024  // this value should be customizable.
                              );
     io.setOutputStream(In, false);
     return In;
 }
        public override void run()
        {
            try
            {
                if (lport == -1)
                {
                    Type c = Type.GetType(target);
                    daemon = (ForwardedTCPIPDaemon)c.newInstance();

                    PipedMemoryStream Out = new PipedMemoryStream(32 * 1024);

                    /*
                     * PipedOutputStream Out = new PipedOutputStream();
                     * io.setInputStream(new PassiveInputStream(Out
                     *                                       , 32 * 1024
                     *                                       ), false);
                     */
                    io.setInputStream(Out);
                    daemon.setChannel(this, getInputStream(), Out);
                    object[] foo = getPort(getSession(), rport);
                    daemon.setArg((object[])foo[3]);

                    new Thread(new ThreadStart(daemon.run)).Start();
                }
                else
                {
                    socket = (factory == null) ?
                             Util.createSocket(target, lport, TIMEOUT) :
                             factory.createSocket(target, lport);
                    socket.NoDelay = true;
                    io.setInputStream(socket.GetStream());
                    io.setOutputStream(socket.GetStream());
                }
                sendOpenConfirmation();
            }
            catch //(Exception e)
            {
                sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
                close = true;
                disconnect();
                return;
            }

            thread = Thread.CurrentThread;
            Buffer buf    = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int    i      = 0;

            try
            {
                while (thread != null &&
                       io != null &&
                       io.In != null)
                {
                    i = io.In.Read(buf.buffer,
                                   14,
                                   buf.buffer.Length - 14
                                   - 32 - 20 // padding and mac
                                   );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    packet.reset();
                    if (close)
                    {
                        break;
                    }
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    getSession().write(packet, this, i);
                }
            }
            catch //(Exception e)
            {
                //Console.Error.WriteLine(e);
            }
            //thread=null;
            //eof();
            disconnect();
        }