Example #1
0
//		internal void padding()
//		{
//			uint len=(uint)buffer.index;
//			int pad=(int) ((-len)&7);
//			if(pad<8)
//			{
//				pad+=8;
//			}
//			len=(uint)(len+pad-4);
//			tmp[0]=(byte)(len>>24);
//			tmp[1]=(byte)(len>>16);
//			tmp[2]=(byte)(len>>8);
//			tmp[3]=(byte)(len);
//			Array.Copy(tmp, 0, buffer.buffer, 0, 4);
//			buffer.buffer[4]=(byte)pad;
//			lock(random)
//			{
//									random.fill(buffer.buffer, buffer.index, pad);
//								}
//			buffer.skip(pad);
//			//buffer.putPad(pad);
//			/*
//			for(int i=0; i<buffer.index; i++){
//			  System.out.print(Integer.toHexString(buffer.buffer[i]&0xff)+":");
//			}
//			System.out.println("");
//			*/
//		}

        internal void padding(int bsize)
        {
            uint len = (uint)buffer.index;
            int  pad = (int)((-len) & (bsize - 1));

            if (pad < bsize)
            {
                pad += bsize;
            }
            len    = (uint)(len + pad - 4);
            tmp[0] = (byte)(len >> 24);
            tmp[1] = (byte)(len >> 16);
            tmp[2] = (byte)(len >> 8);
            tmp[3] = (byte)(len);
            Array.Copy(tmp, 0, buffer.buffer, 0, 4);
            buffer.buffer[4] = (byte)pad;
            lock (random)
            {
                random.fill(buffer.buffer, buffer.index, pad);
            }
            buffer.skip(pad);
            //buffer.putPad(pad);

            /*
             * for(int i=0; i<buffer.index; i++){
             * System.out.print(Integer.toHexString(buffer.buffer[i]&0xff)+":");
             * }
             * System.out.println("");
             */
        }
Example #2
0
        public override void run()
        {
            //System.out.println(this+":run >");

            /*
             *      if(thread!=null){ return; }
             *      thread=Thread.currentThread();
             */

            //    Buffer buf=new Buffer();
            Buffer buf    = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int    i      = -1;

            try
            {
                while (isConnected() &&
                       thread != null &&
                       io != null &&
                       io.ins != null)
                {
                    i = io.ins.Read(buf.buffer,
                                    14,
                                    buf.buffer.Length - 14
                                    - 32 - 20           // padding and mac
                                    );
                    if (i == 0)
                    {
                        continue;
                    }
                    if (i == -1)
                    {
                        eof();
                        break;
                    }
                    if (_close)
                    {
                        break;
                    }
                    packet.reset();
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    session.write(packet, this, i);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("# ChannelExec.run");
                Console.WriteLine(e);
            }
            if (thread != null)
            {
                //lock(thread){ System.Threading.Monitor.PulseAll(this);/*thread.notifyAll();*/ }
            }
            thread = null;
            //System.out.println(this+":run <");
        }
Example #3
0
        public override void run()
        {
            //    thread=Thread.currentThread();
            //System.out.println("rmpsize: "+rmpsize+", lmpsize: "+lmpsize);
            Buffer buf = new Buffer(rmpsize);
            //    Buffer buf=new Buffer(lmpsize);
            Packet packet = new Packet(buf);
            int    i      = 0;

            try
            {
                while (isConnected() &&
                       thread != null &&
                       io != null &&
                       io.ins != null)
                {
                    i = io.ins.Read(buf.buffer,
                                    14,
                                    buf.buffer.Length - 14
                                    - 32 - 20           // padding and mac
                                    );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    if (_close)
                    {
                        break;
                    }
                    packet.reset();
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    session.write(packet, this, i);
                }
            }
            catch
            {
            }
            disconnect();
            //System.out.println("connect end");

            /*
             *      try{
             *        packet.reset();
             *        buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
             *        buf.putInt(recipient);
             *        session.write(packet);
             *      }
             *      catch(Exception e){
             *      }
             */
            //    close();
        }
Example #4
0
        public override void run()
        {
            thread = Thread.currentThread();
            Buffer buf    = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int    i      = 0;

            try
            {
                while (thread != null && io != null && io.ins != null)
                {
                    i = io.ins.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);
                    session.write(packet, this, i);
                }
            }
            catch (Exception e)
            {
                //System.out.println(e);
            }

            //thread=null;
            //eof();
            disconnect();
        }
Example #5
0
		public override void run()
		{
			//System.out.println(this+":run >");
			/*
				if(thread!=null){ return; }
				thread=Thread.currentThread();
			*/

			//    Buffer buf=new Buffer();
			Buffer buf=new Buffer(rmpsize);
			Packet packet=new Packet(buf);
			int i=-1;
			try
			{
				while(isConnected() &&
					thread!=null && 
					io!=null && 
					io.ins!=null)
				{
					i=io.ins.Read(buf.buffer, 
						14,    
						buf.buffer.Length-14
						-32 -20 // padding and mac
						);
					if(i==0)continue;
					if(i==-1)
					{
						eof();
						break;
					}
					if(_close)break;
					packet.reset();
					buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
					buf.putInt(recipient);
					buf.putInt(i);
					buf.skip(i);
					session.write(packet, this, i);
				}
			}
			catch(Exception e)
			{
				Console.WriteLine("# ChannelExec.run");
				Console.WriteLine(e);
			}
			if(thread!=null)
			{
				//lock(thread){ System.Threading.Monitor.PulseAll(this);/*thread.notifyAll();*/ }
			}
			thread=null;
			//System.out.println(this+":run <");
		}
Example #6
0
        public override void run()
        {
            //    thread=Thread.currentThread();
            //System.out.println("rmpsize: "+rmpsize+", lmpsize: "+lmpsize);
            Buffer buf=new Buffer(rmpsize);
            //    Buffer buf=new Buffer(lmpsize);
            Packet packet=new Packet(buf);
            int i=0;
            try
            {
                while(isConnected() &&
                    thread!=null &&
                    io!=null &&
                    io.ins!=null)
                {
                    i=io.ins.Read(buf.buffer,
                        14,
                        buf.buffer.Length-14
                        -32 -20 // padding and mac
                        );
                    if(i<=0)
                    {
                        eof();
                        break;
                    }
                    if(_close)break;
                    packet.reset();
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    session.write(packet, this, i);
                }
            }
            catch
            {
            }
            disconnect();
            //System.out.println("connect end");

            /*
                try{
                  packet.reset();
                  buf.putByte((byte)Session.SSH_MSG_CHANNEL_EOF);
                  buf.putInt(recipient);
                  session.write(packet);
                }
                catch(Exception e){
                }
            */
            //    close();
        }
Example #7
0
 public override void run()
 {
     thread=Thread.currentThread();
     Buffer buf=new Buffer(rmpsize);
     Packet packet=new Packet(buf);
     int i=0;
     try
     {
         while(thread!=null)
         {
             i=io.ins.Read(buf.buffer,
                 14,
                 buf.buffer.Length-14
                 -16 -20 // padding and mac
                 );
             if(i<=0)
             {
                 eof();
                 break;
             }
             if(_close)break;
             packet.reset();
             buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
             buf.putInt(recipient);
             buf.putInt(i);
             buf.skip(i);
             session.write(packet, this, i);
         }
     }
     catch
     {
         //System.out.println(e);
     }
     thread=null;
 }