public static new WriteStructuredFieldOrder Factory(InputByteArray InputArray) { WriteStructuredFieldOrder fieldOrder = null; var buf = InputArray.PeekBytes(10); var wtdOrder = buf[0].ToWtdOrder(); var majorLength = buf.BigEndianBytesToShort(1); var fieldBytes = InputArray.PeekBytes(majorLength + 1); var classByte = buf[3]; var typeByte = buf[4]; if (classByte == 0xd9) { if (typeByte == 0x51) { fieldOrder = new CreateWindowStructuredField(InputArray); } else if (typeByte == 0x60) { fieldOrder = new DrawGridLinesStructuredField(InputArray); } else { throw new Exception("unexpected typeByte"); } } return(fieldOrder); }
public TransparentDataOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.TransparentData) { if (InputArray.RemainingLength < 3) { this.Errmsg = "Transparent data order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.LLBytes = buf.SubArray(1, 2); // this is all wrong. was a bug workaround. should instead process the // LLBytes as a big endian length value. // throw new Exception("TransparentDataOrder order does not handle LL length correctly"); // advance past order code and LL bytes. this.BytesLength += 2; InputArray.AdvanceIndex(3); // bytes after the LL byte pair are bytes to show on the display ?? var rv = Common5250.ScanNonTextDataByte(InputArray); int textLx = rv.Item2; this.BytesLength += textLx; this.TransparentData = InputArray.GetEbcdicBytes(textLx); } }
public StartFieldOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.StartField) { if (InputArray.RemainingLength < 8) { this.Errmsg = "Start field order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(8); var wtdOrder = buf[0].ToWtdOrder(); this.FFW_Bytes = buf.SubArray(1, 2); this.FCW_Bytes = null; // fcw may or may not be present. if (buf[3] >= 0x80) { this.FCW_Bytes = buf.SubArray(3, 2); this.AttrByte = buf[5]; this.LL_Length = buf.BigEndianBytesToShort(6); this.BytesLength += 7; InputArray.AdvanceIndex(8); } else { this.AttrByte = buf[3]; this.LL_Length = buf.BigEndianBytesToShort(4); this.BytesLength += 5; InputArray.AdvanceIndex(6); } } }
public static DataStreamHeader Factory(InputByteArray InputArray) { DataStreamHeader dsHeader = null; if (InputArray.RemainingLength >= 10) { var buf = InputArray.PeekBytes(10); var rcdLgth = buf.BigEndianBytesToShort(0); byte[] rcdType = new byte[2]; Array.Copy(buf, 2, rcdType, 0, 2); byte[] reserved = new byte[2]; Array.Copy(buf, 4, reserved, 0, 2); if ((rcdType[0] == 0x12) && (rcdType[1] == 0xa0) && (rcdLgth >= 10)) { byte varHdrLgth = buf[6]; byte[] flags = new byte[2]; Array.Copy(buf, 7, flags, 0, 2); var dsOpcode = buf[9].ToDataStreamOpcode(); if ((varHdrLgth == 4) && (dsOpcode != null)) { dsHeader = new DataStreamHeader( rcdLgth, rcdType, reserved, varHdrLgth, flags, dsOpcode.Value); InputArray.AdvanceIndex(10); } } } return(dsHeader); }
ParseByteArray(byte[] ByteArray, int ArrayLx = -1, string DataStreamName = "") { if (ArrayLx == -1) { ArrayLx = ByteArray.Length; } var inputArray = new InputByteArray(ByteArray, ArrayLx); var sessionSettings = new SessionSettings(); var rv = ServerDataStream.ParseDataStream(inputArray, sessionSettings, DataStreamName); var wrkstnCmdList = rv.Item1; var responseItemList = rv.Item2; var dsh = rv.Item3; var telList = rv.Item4; var funcList = rv.Item5; byte[] remainingBytes = null; if (inputArray.RemainingLength > 0) { remainingBytes = inputArray.PeekBytes(); var report = remainingBytes.ToHexReport(16); } return(new Tuple <WorkstationCommandList, ResponseItemList, DataStreamHeader, TelnetCommandList, ControlFunctionList, byte[]>( wrkstnCmdList, responseItemList, dsh, telList, funcList, remainingBytes)); }
public static IBM5250DataStreamCommand Factory(InputByteArray InputArray) { IBM5250DataStreamCommand dsCmd = null; if (InputArray.RemainingLength >= 2) { var buf = InputArray.PeekBytes(2); if (buf[0] == 0x04) { var cmdCode = buf[1].ToCommandCode(); if (cmdCode != null) { if (cmdCode.Value == CommandCode.ClearUnit) { dsCmd = new ClearUnitCommand(); } else if (cmdCode.Value == CommandCode.WTD) { dsCmd = WriteToDisplayCommand.Factory(InputArray); } if (dsCmd != null) { InputArray.AdvanceIndex(dsCmd.GetDataStreamLength()); } } } } return(dsCmd); }
public Query5250Response(InputByteArray InputArray) { InputByteArray buf = null; if (InputArray.RemainingLength < 58) { this.Errmsg = "Insufficient bytes in byte stream for 5250 query response."; } if (this.Errmsg == null) { this.Length = InputArray.PeekBigEndianShort(0); if (InputArray.RemainingLength < this.Length) { this.Errmsg = "response length exceeds byte stream."; } } if (this.Errmsg == null) { this.RawBytes = InputArray.PeekBytes(this.Length); buf = new InputByteArray(this.RawBytes); buf.AdvanceIndex(2); // the length this.cField = buf.GetByte(); var tField = buf.GetByte(); this.RequestCode = tField.ToRequestCode(); this.ResponseByte = buf.GetByte(); // 0x80 fixed code if ((cField != 0xd9) || (this.RequestCode == null) || (this.ResponseByte != 0x80)) { this.Errmsg = "invalid c Field, t Field or response byte in 5250 " + "query response."; } } // isolate other 5250 query response fields. if (this.Errmsg == null) { this.ControlUnitCode = buf.GetBytes(2); this.CodeLevel = buf.GetBytes(3); this.Reserve1 = buf.GetBytes(16); this.WorkstationByte = buf.GetByte(); this.MachineType = buf.GetEbcdicBytes(7); this.KeyboardId = buf.GetByte(); buf.AdvanceIndex(2); this.SerialNumber = buf.GetBytes(4); this.MaxInputFields = buf.GetBigEndianShort(); this.Reserve2 = buf.GetBytes(3); this.Capabilities = buf.GetBytes(5); } // is a valid query 5250 response byte stream. Advance index of input bytes. if (this.Errmsg == null) { InputArray.AdvanceIndex(this.Length); } }
public static WorkstationCommandBase ParseFactory(InputByteArray InputArray) { WorkstationCommandBase dsCmd = null; if (InputArray.RemainingLength >= 2) { // command codes as documented on 15.2 - 1 of 5494 function ref manual var buf = InputArray.PeekBytes(2); if (buf[0] == 0x04) { var wrkstnCode = buf[1].ToWorkstationCode(); if (wrkstnCode != null) { var code = wrkstnCode.Value; if (code == WorkstationCode.ClearUnit) { dsCmd = new ClearUnitCommand(InputArray); } else if (code == WorkstationCode.WTD) { dsCmd = new WriteToDisplayCommand(InputArray); } else if (code == WorkstationCode.ReadMdtFields) { dsCmd = new ReadMdtFieldsCommand(InputArray); } // 04 F3. write structure field. Used as vehicle for the D9 70 5250 query // command. else if (code == WorkstationCode.WriteStructuredField) { dsCmd = new WriteStructuredFieldCommand(InputArray); } else if (code == WorkstationCode.SaveScreen) { dsCmd = new SaveScreenCommand(InputArray); } else if (code == WorkstationCode.RestoreScreen) { dsCmd = new RestoreScreenCommand(InputArray); } else { throw new Exception( "workstation data stream command code not supported. " + code.ToString()); } } } } return(dsCmd); }
public WriteToDisplayCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WTD) { this.OrderList = new List <WtdOrderBase>(); if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); InputArray.AdvanceIndex(4); this.BytesLength = 4; // gather WTD orders and display characters. while (true) { WtdOrderBase orderBase = null; if (InputArray.RemainingLength == 0) { break; } orderBase = WtdOrderBase.Factory(InputArray); // not an explicit WTD order. Check that is a text data order. if (orderBase == null) { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == true) { orderBase = new TextDataOrder(InputArray); } } // current input stream bytes are not WTD order. End of WTD command. if (orderBase == null) { break; } // got an order but some sort of form error. if (orderBase.Errmsg != null) { throw new Exception("invalid WTD order"); } // Append to list of orders of the WTD command. this.OrderList.Add(orderBase); this.BytesLength += orderBase.GetDataStreamLength(); } } }
public TextDataOrder(InputByteArray InputArray) : base(InputArray, "TextData") { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == false) { this.Errmsg = "Invalid text data order. Order must begin with data character."; } if (this.Errmsg == null) { // scan forward in the input array for a non text character. var rv = Common5250.ScanNonTextDataByte(InputArray); this.DataStreamLength = rv.Item2; // the actual data stream bytes. var rawBytes = InputArray.PeekBytes(this.DataStreamLength); int rawLx = rawBytes.Length; // first byte is the attribute byte. if (Common5250.IsAttributeByte(b1)) { this.AttrByte = b1; } // last text byte is an attribute byte. if ((rawLx > 1) && (rawBytes[rawLx - 1].IsAttributeByte( ) == true)) { this.TailAttrByte = rawBytes[rawLx - 1]; } // bytes the attrByte and tailAttrByte are textBytes. { int fx = 0; int lx = rawLx; if (this.AttrByte != null) { fx += 1; lx -= 1; } if (this.TailAttrByte != null) { lx -= 1; } if (lx > 0) { this.TextBytes = rawBytes.SubArray(fx, lx); } } this.RawBytes = rawBytes; this.BytesLength = rawLx; InputArray.AdvanceIndex(rawLx); } }
public Query5250Response(InputByteArray InputArray) { InputByteArray buf = null; if (InputArray.RemainingLength < 58) { this.Errmsg = "insufficient remaining length."; } // isolate length and raw bytes. if (this.Errmsg == null) { this.Length = InputArray.PeekBigEndianShort(0); if (this.Length > InputArray.RemainingLength) { this.Errmsg = "query 5250 response length exceeds byte stream length"; } else { this.RawBytes = InputArray.PeekBytes(this.Length); buf = new InputByteArray(this.RawBytes); } } // isolate components of the response stream. if (this.Errmsg == null) { buf.GetBigEndianShort(); this.ResponseCode = buf.SubArray(2, 3); } // isolate components of the response stream. if (this.Errmsg == null) { this.ResponseCode = buf.SubArray(2, 3); } ra.Append(new byte[] { 0xd9, 0x70, 0x80 }); // 5250 query response ra.Append(new byte[] { 0x06, 0x00 }); // control unit code. ra.Append(new byte[] { 0x01, 0x03, 0x00 }); // code release level. ra.Append(byteZero.Repeat(16)); // 16 bytes of null ra.Append(0x01); // 01 - display station ra.Append("3180002".ToEbcdicBytes()); // machine type and model. ra.Append(0x02); // keyboard id ra.Append(0x00); // extended keyboard id ra.Append(0x00); // reserve ra.Append(new byte[] { 0x00, 0x61, 0x50, 0x00 }); // device serial number. ra.AppendBigEndianShort(256); // max number input fields. ra.Append(0x00); // control unit customization ra.Append(new byte[] { 0x00, 0x00 }); // reserved ra.Append(new byte[] { 0x18, 0x11, 0x00, 0x00, 0x00 }); // ra.Append(byteZero.Repeat(7)); // 7 bytes of null. }
/// <summary> /// peek at the next 2 bytes of input array. Return CommandCode if they bytes /// contain IAC escape followed by IAC command code. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static CommandCode?PeekTelnetCommandCode( this InputByteArray InputArray) { CommandCode?code = null; if (InputArray.RemainingLength >= 2) { var buf = InputArray.PeekBytes(2); code = buf.ParseTelnetCommandCode(); } return(code); }
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); } } }
public WriteErrorCodeCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WriteErrorCode) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.BytesLength += 2; InputArray.AdvanceIndex(this.BytesLength); } }
public ReadMdtFieldsCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.ReadMdtFields) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); this.BytesLength += 2; InputArray.AdvanceIndex(this.BytesLength); } }
public SetBufferAddressOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.SetBufferAddress) { if (InputArray.RemainingLength < 3) { this.Errmsg = "SBA order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowNum = buf[1]; this.ColNum = buf[2]; this.BytesLength += 2; InputArray.AdvanceIndex(3); } }
public InsertCursorOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.InsertCursor) { if (InputArray.RemainingLength < 3) { this.Errmsg = "Insert cursor order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowAddress = buf[1]; this.ColumnAddress = buf[2]; this.BytesLength += 2; InputArray.AdvanceIndex(3); } }
public static WriteToDisplayCommand Factory(InputByteArray InputArray) { WriteToDisplayCommand wtdCmd = null; if (InputArray.RemainingLength >= 4) { var buf = InputArray.PeekBytes(4); if ((buf[0] == 0x04) && (buf[1] == 0x11)) { byte[] controlChars = new byte[2]; Array.Copy(buf, 3, controlChars, 0, 2); wtdCmd = new WriteToDisplayCommand(InputArray, controlChars); InputArray.AdvanceIndex(4); // gather WTD orders and display characters. while (true) { if (InputArray.RemainingLength == 0) { break; } var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder != null) { } else if (TextDataOrder.IsTextDataChar(b1)) { var tdOrder = TextDataOrder.Factory(InputArray); wtdCmd.OrderList.Add(tdOrder); } else { break; } } } } return(wtdCmd); }
/// <summary> /// peek at the bytes in the InputArray. return true if bytes 2 - 3 contain /// GDS identifier. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static bool IsDataStreamHeader(this InputByteArray InputArray) { if (InputArray.RemainingLength < 6) { return(false); } var buf = InputArray.PeekBytes(6); var lgth = buf.BigEndianBytesToShort(0); if ((buf[2] == 0x12) && (buf[3] == 0xa0)) { if (lgth >= 10) { return(true); } } return(false); }
public ResponseHeader(InputByteArray InputArray) : base(InputArray, "ResponseHeader") { if (InputArray.RemainingLength < 3) { this.Errmsg = "input array shortage"; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(3); this.RowNum = buf[0]; this.ColNum = buf[1]; this.AidByte = buf[2]; this.AidKey = buf[2].ToAidKey(); this.BytesLength = 3; InputArray.AdvanceIndex(3); } }
public RepeatToAddressOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.RepeatToAddress) { if (InputArray.RemainingLength < 4) { this.Errmsg = "Repeat to address order. end of stream."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.RowAddress = buf[1]; this.ColumnAddress = buf[2]; // the repeat character. this.RepeatTextByte = buf[3]; this.BytesLength += 3; InputArray.AdvanceIndex(this.BytesLength); } }
/// <summary> /// check that the current bytes in the input stream contain an SBA order. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static string CheckOrder(InputByteArray InputArray) { string errmsg = null; byte[] buf = null; if (InputArray.RemainingLength < 3) { errmsg = "not enough bytes for SBA order"; } if (errmsg == null) { buf = InputArray.PeekBytes(3); if (buf[0] != (byte)WtdOrder.SetBufferAddress) { errmsg = "first byte does not contain SBA order code."; } } return(errmsg); }
public StartHeaderOrder(InputByteArray InputArray) : base(InputArray, WtdOrder.StartHeader) { // at least 3 bytes remaining. ( command code, length byte and length must be from // 1 to 7. if (InputArray.RemainingLength < 3) { this.Errmsg = "SOH not long enough"; } if (this.Errmsg == null) { var buf2 = InputArray.PeekBytes(2); this.LengthByte = buf2[1]; // invalid start of header order length. if ((this.LengthByte < 1) || (this.LengthByte > 7)) { this.Errmsg = "SOH length not valid"; } } if (this.Errmsg == null) { int actualOrderLength = CalcActualOrderLength(this.LengthByte); var buf = InputArray.PeekBytesPad(this.BytesLength, 9, 0x00); this.FlagByte = buf[2]; this.ReservedByte = buf[3]; this.FirstResponseFieldNumber = buf[4]; this.ErrRow = buf[5]; this.CmdKeySwitches = buf.SubArray(6, 3); // advance current pos in input array by the actual length of the order. InputArray.AdvanceIndex(this.BytesLength); } }
public static Tuple <bool, string> IsResponseHeader(InputByteArray InputArray) { bool isHeader = true; string errmsg = null; if (InputArray.RemainingLength < 3) { errmsg = "input array shortage"; isHeader = false; } if (errmsg == null) { var buf = InputArray.PeekBytes(3); byte rowNum = buf[0]; byte colNum = buf[1]; var aidKey = buf[2].ToAidKey();; if (rowNum > 27) { isHeader = false; errmsg = "invalid row number"; } else if (colNum > 132) { isHeader = false; errmsg = "invalid column number"; } else if (aidKey == null) { isHeader = false; errmsg = "invalid aid key byte"; } } return(new Tuple <bool, string>(isHeader, errmsg)); }
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); } }
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); } }
public PresentationPositionControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.PresentationPosition) { if (InputArray.RemainingLength < 3) { this.Errmsg = "need 3 bytes"; } else { var buf = InputArray.PeekBytes(3); if (buf[0] == 0x34) { var dir = buf[1].ToPresentationPositionDirection(); if (dir != null) { this.Direction = dir.Value; this.PositionValue = buf[2]; } else { this.Errmsg = "invalid direction code"; } } else { this.Errmsg = "invalid function code"; } } // valid control function. advance in input stream. if (this.Errmsg == null) { InputArray.AdvanceIndex(3); } }