public WriteStructuredFieldCommand(InputByteArray InputArray)
            : base(InputArray, WorkstationCode.WriteStructuredField)
        {
            byte[] buf = null;

            // advance past the 0x04 and  0xf3.
            InputArray.AdvanceIndex(2);

            // first 2 bytes are the LL length bytes.
            this.llLength = InputArray.PeekBigEndianShort(0);

            // make sure enough length remaining in the input array
            if (this.llLength > InputArray.RemainingLength)
            {
                this.Errmsg = "LL length " + this.llLength.ToString()
                              + " exceeds remaining length of input array.";
            }

            // setup c field and t field
            if (this.Errmsg == null)
            {
                buf         = InputArray.GetBytes(this.llLength);
                this.cField = buf[2];
                this.tField = buf[3];

                this.RequestCode = this.tField.ToRequestCode();
            }

            if (this.Errmsg == null)
            {
                this.BytesLength += this.llLength;
                this.FormatFlags  = null;
                this.FormatFlags  = buf.SubArray(4, 1);
            }
        }
 public TelnetCommand(InputByteArray InputArray, CommandCode CmdCode)
 {
     this.Start    = InputArray.Index;
     this.RawBytes = new ByteArrayBuilder();
     this.RawBytes.Append(InputArray.GetBytes(2));
     this.EscapeCode = CommandCode.IAC;
     this.CmdCode    = CmdCode;
 }
        /// <summary>
        /// expecting closing IAC SE command code. If exists at current position of the
        /// input array, process the IAC SE command.
        /// </summary>
        /// <param name="InputArray"></param>
        protected void ParseClosingSE(InputByteArray InputArray)
        {
            // parse the closing IAC SE
            var seCode = InputArray.PeekTelnetCommandCode(CommandCode.SE);

            if (seCode != null)
            {
                this.GotClosingSE = true;
                this.RawBytes.Append(InputArray.GetBytes(2));
            }
        }
        public UndocumentedControlFunction(
            InputByteArray InputArray, ControlFunctionCode FunctionCode, int ParmLength)
            : base(InputArray, FunctionCode)
        {
            InputArray.AdvanceIndex(1);

            // isolate the parm bytes.
            if (ParmLength > 0)
            {
                this.ParmBytes = InputArray.GetBytes(ParmLength);
            }
        }
        public EraseToAddressOrder(InputByteArray InputArray)
            : base(InputArray, WtdOrder.EraseToAddress)
        {
            if (InputArray.RemainingLength < 5)
            {
                this.Errmsg = "erase address order. end of stream.";
            }

            if (this.Errmsg == null)
            {
                var buf = InputArray.PeekBytes(4);
                this.RowAddress      = buf[1];
                this.ColumnAddress   = buf[2];
                this.AttrTypesLength = buf[3];

                this.BytesLength += 3;
                InputArray.AdvanceIndex(4);
            }

            // attr types length between 2 and 5.
            if ((this.Errmsg == null) &&
                ((this.AttrTypesLength < 2) || (this.AttrTypesLength > 5)))
            {
                this.Errmsg = "attribute types length not between 2 and 5.";
            }

            // isolate the list of attr type bytes.
            if (this.Errmsg == null)
            {
                // the count of attrType bytes.
                int lx = 0;
                if (this.AttrTypesLength == 0xff)
                {
                    lx = 1;
                }
                else
                {
                    lx = this.AttrTypesLength - 1;
                }

                if (InputArray.RemainingLength < lx)
                {
                    this.Errmsg = "attribute types length not valid";
                }
                else
                {
                    this.AttrTypesArray = InputArray.GetBytes(lx);
                }
            }
        }
        protected DataStreamHeader(InputByteArray InputArray, string ItemName)
            : base(InputArray, ItemName)
        {
            byte[] buf = null;

            // must be at least 7 bytes in the input stream.
            if (InputArray.RemainingLength < 7)
            {
                this.Errmsg = "Not enough bytes for data stream header";
            }

            // isolate the next 7 bytes.
            if (this.Errmsg == null)
            {
                buf = InputArray.PeekBytesLenient(7);

                // the first 6 bytes are logical record length, 2 byte marker and 2 bytes
                // DataStreamCode.
                this.DataStreamLength = buf.BigEndianBytesToShort(0);
                this.Marker           = buf.SubArray(2, 2);

                this.StreamCodeBytes = buf.SubArray(4, 2);
                this.StreamCode      = StreamCodeBytes.ToDataStreamCode();

                this.VariableLength = buf[6];

                if ((this.Marker[0] != 0x12) || (this.Marker[1] != 0xa0))
                {
                    this.Errmsg = "Invalid record type";
                }
                else if (this.DataStreamLength < 7)
                {
                    this.Errmsg = "Invalid record length";
                }
                else if (this.VariableLength == 0)
                {
                    this.Errmsg = "Invalid variable length";
                }
            }

            if (this.Errmsg == null)
            {
                this.RawBytes    = InputArray.GetBytes(this.HeaderLength);
                this.BytesLength = this.HeaderLength;
            }
        }
Esempio n. 7
0
        public WriteStructuredFieldCommand(InputByteArray InputArray)
            : base(InputArray, WorkstationCode.WriteStructuredField)
        {
            // advance past the 0x04 and  0xf3.
            InputArray.AdvanceIndex(2);

            // first 2 bytes are the LL length bytes.
            this.llLength = InputArray.PeekBigEndianShort(0);

            // make sure enough length remaining in the input array
            if (this.llLength > InputArray.RemainingLength)
            {
                this.Errmsg = "LL length " + this.llLength.ToString( )
                              + " exceeds remaining length of input array.";
            }

            if (this.Errmsg == null)
            {
                this.BytesLength += this.llLength;

                var buf = InputArray.GetBytes(this.llLength);
                this.FormatFlags = null;

                // isolate cField and tField
                this.cField = buf[2];
                this.tField = buf[3];

                // 5250 query. format flags are 1 byte.
                if (this.cField == 0xd9)
                {
                    if (this.tField == 0x30)
                    {
                        this.RequestCode = WSF_RequestCode.DefineAuditWindow;
                    }
                    else if (this.tField == 0x31)
                    {
                        this.RequestCode = WSF_RequestCode.DefineCmdKeyFunc;
                    }
                    else if (this.tField == 0x70)
                    {
                        this.FormatFlags = buf.SubArray(4, 1);
                        this.RequestCode = WSF_RequestCode.Query5250;
                    }
                }
            }
        }
        public WriteSingleStructuredFieldCommand(InputByteArray InputArray)
            : base(InputArray, WorkstationCode.WriteSingleStructuredField)
        {
            byte[] buf = null;

            // advance past the 0x04 and  0xf4.
            InputArray.AdvanceIndex(2);

            // first 2 bytes are the LL length bytes.
            this.llLength = InputArray.PeekBigEndianShort(0);

            // make sure enough length remaining in the input array
            if (this.llLength > InputArray.RemainingLength)
            {
                this.Errmsg = "LL length " + this.llLength.ToString()
                              + " exceeds remaining length of input array.";
            }

            // setup c field and t field
            if (this.Errmsg == null)
            {
                buf          = InputArray.GetBytes(this.llLength);
                this.cField  = buf[2];
                this.tField  = buf[3];
                this.f1Field = buf[4];
                this.f2Field = buf[5];

                // command contains minor structure.
                if (this.llLength > 8)
                {
                    this.minor_ll = buf[6];
                    this.minor_t  = buf[7];
                    this.minor_f  = buf[8];
                }
            }

            if (this.Errmsg == null)
            {
                this.BytesLength += this.llLength;
            }
        }
Esempio n. 9
0
        public NewEnvironCommand(InputByteArray InputArray, CommandCode CmdCode)
            : base(InputArray, CmdCode, TelnetSubject.NEW_ENVIRON)
        {
            this.SubOption  = null;
            this.OptionList = new List <OptionVariable>();
            this.EndFound   = false;

            // statement contains additional parameters.
            if (this.CmdCode == CommandCode.SB)
            {
                var b1 = InputArray.GetNextByte();
                this.RawBytes.Append(b1);
                this.SubOption = b1.ToTelnetOptionParm(); // IS, SEND, INFO

                // list of VARs and USERVARS follow until IAC SE.
                if ((this.SubOption.Value == TelnetOptionParm.SEND) ||
                    (this.SubOption.Value == TelnetOptionParm.IS))
                {
                    while (true)
                    {
                        var ov = OptionVariable.Construct(InputArray);
                        if (ov == null)
                        {
                            break;
                        }
                        this.OptionList.Add(ov);
                        this.RawBytes.Append(ov.ToBytes());
                    }

                    if (InputArray.PeekIacSe())
                    {
                        this.EndFound = true;
                        this.RawBytes.Append(InputArray.GetBytes(2));
                    }
                }

                // parse the closing IAC SE
                ParseClosingSE(InputArray);
            }
        }
Esempio n. 10
0
        public SomePrinterDataStreamHeader(InputByteArray InputArray)
            : base(InputArray, "SomePrinterDataStreamHeader")
        {
            // get the remaining bytes of the data stream.
            int remLx = this.DataStreamLength - this.HeaderLength;

            if (remLx <= 0)
            {
                this.Errmsg = "Not enough remaining bytes";
            }

            if (this.Errmsg == null)
            {
                if (InputArray.RemainingLength < remLx)
                {
                    this.ByteData = InputArray.GetBytesToEnd();
                }
                else
                {
                    this.ByteData = InputArray.GetBytes(remLx);
                }
            }
        }
Esempio n. 11
0
        public PrinterStartupDataStreamHeader(InputByteArray InputArray)
            : base(InputArray, "PrinterStartupDataStreamHeader")
        {
            byte[] buf = null;

            // a printer starup message.
            if ((this.Errmsg == null) && (this.DataStreamLength == 73) &&
                (this.RawBytes.SubArray(4, 7).CompareEqual(PrinterStartupFixedBytes) == true))
            {
                this.PrinterFixedValueBytes = this.RawBytes.SubArray(4, 7);

                buf = InputArray.GetBytes(this.PayloadLength);

                this.ResponseCode = buf.SubArray(5, 4).EbcdicBytesToString();
                this.SystemName   = buf.SubArray(9, 8).EbcdicBytesToString();
                this.PrinterName  = buf.SubArray(17, 10).EbcdicBytesToString();
            }

            else if (this.Errmsg == null)
            {
                this.Errmsg = "Bytes do not contain PrinterStartup data stream header";
            }
        }
Esempio n. 12
0
        public WriteStructuredFieldOrder(InputByteArray InputArray)
            : base(InputArray, WtdOrder.WriteStructuredField)
        {
            if (InputArray.RemainingLength < 10)
            {
                this.Errmsg = "Start field order. end of stream.";
            }

            if (this.Errmsg == null)
            {
                var buf = InputArray.PeekBytes(10);

                var wtdOrder = buf[0].ToWtdOrder();
                this.MajorLength = buf.BigEndianBytesToShort(1);

                this.FieldBytes = InputArray.GetBytes(this.MajorLength + 1);

                this.ClassByte = buf[3];
                this.TypeByte  = buf[4];

                this.BytesLength += this.MajorLength;
//          InputArray.AdvanceIndex(this.MajorLength + 1);
            }
        }
Esempio n. 13
0
        public VariableLengthControlFunction(
            InputByteArray InputArray, ControlFunctionCode ControlCode)
            : base(InputArray, ControlCode)
        {
            // first 3 bytes contain control code and then length byte.
            {
                var buf = InputArray.PeekBytes(3);
                this.ByteCount = buf[2];
            }

            // byte count from 1 to 50
            if ((this.ByteCount < 1) || (this.ByteCount > InputArray.RemainingLength) ||
                (this.ByteCount > 20))
            {
                this.Errmsg = "invalid byte count";
            }

            // isolate function parameter bytes.
            if (this.Errmsg == null)
            {
                InputArray.AdvanceIndex(3);
                this.ParmBytes = InputArray.GetBytes(this.ByteCount - 1);
            }
        }