Exemplo n.º 1
0
        protected void WriteCommonFields(byte[] data, ref int offset)
        {
            BigEndianWriter.WriteUInt16(data, ref offset, (ushort)UpdateStatus);
            ByteWriter.WriteByte(data, ref offset, Flags);
            byte temp = (byte)(((RecordRevision & 0xF) << 4) | ((byte)RecordType & 0xF));

            ByteWriter.WriteByte(data, ref offset, temp);
            BigEndianWriter.WriteUInt32(data, ref offset, (uint)data.Length - RecordHeaderLength); // record data length does not include the record header (first 8 bytes)
            WriteVarULong(data, ref offset, Id);
            WriteVarString(data, ref offset, Name);
        }
Exemplo n.º 2
0
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[Length];
            ByteWriter.WriteAnsiString(buffer, 0, Signature, 8);
            ByteWriter.WriteByte(buffer, 8, RecordRevision);
            BigEndianWriter.WriteUInt16(buffer, 9, (ushort)Operation);

            WriteOperationParameters(buffer, 16);

            return(buffer);
        }
 public byte[] GetBytes(int blockSize)
 {
     byte[] buffer = new byte[blockSize];
     ByteWriter.WriteAnsiString(buffer, 0, Signature, 4);
     BigEndianWriter.WriteUInt32(buffer, 0x04, SequenceNumber);
     BigEndianWriter.WriteUInt32(buffer, 0x08, GroupNumber);
     BigEndianWriter.WriteUInt16(buffer, 0x0C, NumberInGroup);
     BigEndianWriter.WriteUInt16(buffer, 0x0E, FragmentCount);
     ByteWriter.WriteBytes(buffer, 0x10, Data, Math.Min(Data.Length, blockSize - HeaderLength));
     return(buffer);
 }
 public byte[] GetBytes()
 {
     byte[] buffer = new byte[4 + PageLength];
     buffer[0] |= (byte)(PeripheralQualifier << 5);
     buffer[0] |= (byte)(PeripheralQualifier & 0x1F);
     buffer[1]  = (byte)PageCode;
     buffer[3]  = PageLength;
     BigEndianWriter.WriteUInt16(buffer, 4, MediumRotationRate);
     BigEndianWriter.WriteUInt16(buffer, 6, Reserved);
     return(buffer);
 }
Exemplo n.º 5
0
 public byte[] GetBytes()
 {
     byte[] buffer = new byte[4 + PageLength];
     buffer[0] |= (byte)(PeripheralQualifier << 5);
     buffer[0] |= (byte)(PeripheralQualifier & 0x1F);
     buffer[1]  = (byte)PageCode;
     buffer[3]  = PageLength;
     BigEndianWriter.WriteUInt16(buffer, 6, OptimalTransferLengthGranularity);
     BigEndianWriter.WriteUInt32(buffer, 8, MaximumTransferLength);
     BigEndianWriter.WriteUInt32(buffer, 12, OptimalTransferLength);
     return(buffer);
 }
Exemplo n.º 6
0
        public override byte[] GetBytes()
        {
            OpCodeSpecificHeader[1] = (byte)Response;

            BigEndianWriter.WriteUInt32(OpCodeSpecific, 4, StatSN);
            BigEndianWriter.WriteUInt32(OpCodeSpecific, 8, ExpCmdSN);
            BigEndianWriter.WriteUInt32(OpCodeSpecific, 12, MaxCmdSN);
            BigEndianWriter.WriteUInt16(OpCodeSpecific, 20, TimeToWait);
            BigEndianWriter.WriteUInt16(OpCodeSpecific, 22, TimeToRetain);

            return(base.GetBytes());
        }
        private byte[] GetData()
        {
            byte[] data   = new byte[EntryLength * Addresses.Count];
            int    offset = 0;

            foreach (KeyValuePair <byte[], NameFlags> entry in Addresses)
            {
                BigEndianWriter.WriteUInt16(data, ref offset, (ushort)entry.Value);
                ByteWriter.WriteBytes(data, ref offset, entry.Key, 4);
            }
            return(data);
        }
 public override byte[] GetBytes()
 {
     byte[] buffer = new byte[10];
     buffer[0]  = (byte)OpCode;
     buffer[1] |= (byte)(MiscellaneousCDBInformationHeader << 5);
     buffer[1] |= (byte)((byte)ServiceAction & 0x1F);
     BigEndianWriter.WriteUInt32(buffer, 2, LogicalBlockAddress);
     buffer[6] = MiscellaneousCDBinformation;
     BigEndianWriter.WriteUInt16(buffer, 7, (ushort)TransferLength);
     buffer[9] = Control;
     return(buffer);
 }
Exemplo n.º 9
0
        public override byte[] GetBytes()
        {
            byte[] buffer = base.GetBytes();
            buffer[2] = (byte)(TST << 5 | Convert.ToByte(TmfOnly) << 4 | Convert.ToByte(Reserved1) << 3 | Convert.ToByte(DSense) << 2 | Convert.ToByte(GLTSD) << 1 | Convert.ToByte(RLEC));
            buffer[3] = (byte)(QueueAlgorithmModifier << 4 | Convert.ToByte(Reserved2) << 3 | (Convert.ToByte(QErr) & 0x3) << 1 | Convert.ToByte(DQUE));
            buffer[4] = (byte)(Convert.ToByte(VS) << 7 | Convert.ToByte(RAC) << 6 | (Convert.ToByte(UA_INTLCK_CTRL) & 0x3) << 4 | Convert.ToByte(SWP) << 3 | Convert.ToByte(RAERP) << 2 | Convert.ToByte(UAAERP) << 1 | Convert.ToByte(EAERP));
            buffer[5] = (byte)(Convert.ToByte(ATO) << 7 | Convert.ToByte(TAS) << 6 | (Convert.ToByte(Reserved3) & 0x7) << 3 | (Convert.ToByte(AutoLoadMode) & 0x7));
            BigEndianWriter.WriteUInt16(buffer, 6, Obsolete1);
            BigEndianWriter.WriteUInt16(buffer, 8, Obsolete2);
            BigEndianWriter.WriteUInt16(buffer, 10, Obsolete3);

            return(buffer);
        }
 public override byte[] GetBytes()
 {
     byte[] buffer = new byte[6];
     buffer[0] = (byte)OpCode;
     if (EVPD)
     {
         buffer[1] |= 0x01;
     }
     buffer[2] = (byte)PageCode;
     BigEndianWriter.WriteUInt16(buffer, 3, AllocationLength);
     buffer[5] = Control;
     return(buffer);
 }
Exemplo n.º 11
0
        public void WriteBytes(Stream stream)
        {
            BigEndianWriter.WriteUInt16(stream, TransactionID);
            ushort temp = (ushort)(ResultCode & (0xF));

            temp |= (ushort)((byte)Flags << 4);
            temp |= (ushort)((byte)OpCode << 11);
            BigEndianWriter.WriteUInt16(stream, temp);
            BigEndianWriter.WriteUInt16(stream, QDCount);
            BigEndianWriter.WriteUInt16(stream, ANCount);
            BigEndianWriter.WriteUInt16(stream, NSCount);
            BigEndianWriter.WriteUInt16(stream, ARCount);
        }
Exemplo n.º 12
0
        private byte[] GetData()
        {
            using MemoryStream stream = new MemoryStream();
            stream.WriteByte((byte)Names.Count);
            foreach (KeyValuePair <string, NameFlags> entry in Names)
            {
                ByteWriter.WriteAnsiString(stream, entry.Key);
                BigEndianWriter.WriteUInt16(stream, (ushort)entry.Value);
            }

            ByteWriter.WriteBytes(stream, Statistics.GetBytes());

            return(stream.ToArray());
        }
Exemplo n.º 13
0
 public void Write(BigEndianWriter Writer)
 {
     Writer.WriteUInt16(NameOffset);
     Writer.WriteUInt16(Alpha);
     Writer.WriteUInt16(Animation);
     Writer.WriteUInt16(Padding);
     Writer.WriteSingle(Delay);
     Writer.WriteSingles(TranslationWS);
     Writer.WriteSingles(ScaleWS);
     Writer.WriteSingles(Translation);
     Writer.WriteSingles(Scale);
     Writer.WriteUInt16(Section4ID);
     Writer.WriteUInt16(NrSection4);
     Writer.WriteUInt16(Section5ID);
     Writer.WriteUInt16(NrSection5);
 }
Exemplo n.º 14
0
        public virtual byte[] GetBytes()
        {
            TrailerLength = Trailer.Length;

            byte flags = Convert.ToByte(TrailerLength >> 16);

            byte[] buffer = new byte[HeaderLength + Trailer.Length];
            ByteWriter.WriteByte(buffer, 0, (byte)Type);
            ByteWriter.WriteByte(buffer, 1, flags);
            BigEndianWriter.WriteUInt16(buffer, 2, (ushort)(TrailerLength & 0xFFFF));
            ByteWriter.WriteBytes(buffer, 4, Trailer);

            return(buffer);
        }
Exemplo n.º 15
0
 public void Write(BigEndianWriter Writer)
 {
     Writer.WriteUInt16(Section3Offset);
     Writer.WriteUInt16(NrSection3);
     Writer.WriteUInt16(Section4Offset);
     Writer.WriteUInt16(NrSection4);
     Writer.WriteUInt16(Section5Offset);
     Writer.WriteUInt16(NrSection5);
 }
Exemplo n.º 16
0
        public void WriteBBLM(string FilePath)
        {
            FileName = FilePath;
            BigEndianWriter Writer = new BigEndianWriter(File.Open(FilePath, FileMode.Create));
            BBLM            b      = bblmComponent1.ReturnData();

            Writer.WriteChars("PBLM".ToCharArray(), 0, 4);
            Writer.WriteUInt32(0xA4);
            Writer.WriteUInt64(b.Unknown1);
            Writer.WriteSingle(b.ScaleFactor);
            Writer.WriteUInt32(b.RGB);
            Writer.WriteUInt32(b.blurrRGB);
            Writer.WriteUInt16(b.Unknown2);
            Writer.WriteUInt16(b.Unknown3);
            for (int i = 0; i < b.Entries.Count; i++)
            {
                Writer.WriteSingle(b.Entries[i].Unknown1);
                Writer.WriteSingle(b.Entries[i].Unknown2);
                Writer.WriteUInt32(b.Entries[i].Unknown3);
                Writer.WriteUInt32(b.Entries[i].Unknown4);
                Writer.WriteUInt32(b.Entries[i].Unknown5);
                Writer.WriteUInt32(b.Entries[i].Unknown6);
                Writer.WriteUInt32(b.Entries[i].Unknown7);
                Writer.WriteUInt32(b.Entries[i].Unknown8);
            }
            Writer.WriteUInt32(b.Unknown4);
            Writer.WriteUInt32(b.Unknown5);
            Writer.WriteUInt32(b.Unknown6);
            Writer.WriteUInt32(b.Unknown7);
            Writer.WriteUInt32(b.Unknown8);
            Writer.WriteSingle(b.Unknown9);
            Writer.WriteSingle(b.float1);
            Writer.WriteSingle(b.float2);
            Writer.WriteSingle(b.float3);
            Writer.Close();
        }
Exemplo n.º 17
0
        private void ExportLTEX_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();

            s.Filter = "Binary Light Texture (*bltex)|*.bltex";
            if (s.ShowDialog() == DialogResult.OK)
            {
                BLMAPLTEX LTEX = ltexComponent1.ReturnData();
                LTEX.Entries           = ReturnLTEX();
                listLTEX[SelectedNode] = LTEX;

                BigEndianWriter Writer = new BigEndianWriter(File.Open(s.FileName, FileMode.Create));
                Writer.WriteChars("LTEX".ToCharArray(), 0, 4);
                Writer.WriteInt32(0x3C + LTEX.Entries.Count * 8);
                Writer.WriteUInt32(LTEX.Padding);
                Writer.WriteUInt32(LTEX.Unknown);
                Writer.WriteUInt16(Convert.ToUInt16(LTEX.Entries.Count));
                Writer.WriteUInt16(LTEX.Unknown1);
                Writer.WriteChars(LTEX.Texture.ToCharArray(), 0, 4);
                Writer.WriteUInt32(LTEX.Unknown2);
                Writer.WriteUInt32(LTEX.Unknown3);
                Writer.WriteUInt32(LTEX.Unknown4);
                Writer.WriteUInt32(LTEX.Unknown5);
                Writer.WriteUInt32(LTEX.Unknown6);
                Writer.WriteUInt32(LTEX.Unknown7);
                Writer.WriteUInt32(LTEX.Unknown8);
                Writer.WriteUInt32(LTEX.Unknown9);
                Writer.WriteInt32(LTEX.Entries.Count * 8);
                for (int j = 0; j < LTEX.Entries.Count; j++)
                {
                    Writer.WriteSingle(LTEX.Entries[j].Unknown1);
                    Writer.WriteUInt32(LTEX.Entries[j].Unknown2);
                }
                Writer.Close();
            }
        }
        public void UInt16ReadWrite()
        {
            UInt16 value;
            UInt16 result;

            value = 20;

            ResetPosition();
            _writer.WriteUInt16(value);
            ResetPosition();
            result = _reader.ReadUInt16();


            Assert.AreEqual(value, result);

            //Multiple bytes

            value = 30000;

            ResetPosition();
            _writer.WriteUInt16(value);
            ResetPosition();
            result = _reader.ReadUInt16();

            Assert.AreEqual(value, result);


            value = 65535;

            ResetPosition();
            _writer.WriteUInt16(value);
            ResetPosition();
            result = _reader.ReadUInt16();

            Assert.AreEqual(value, result);
        }
Exemplo n.º 19
0
        public byte[] GetData()
        {
            MemoryStream stream = new MemoryStream();

            stream.WriteByte((byte)Names.Count);
            foreach (KeyValuePair <string, NameFlags> entry in Names)
            {
                ByteWriter.WriteAnsiString(stream, entry.Key);
                //byte[] encodedName = NetBiosUtils.EncodeName(entry.Key, String.Empty);
                //ByteWriter.WriteBytes(stream, encodedName);
                BigEndianWriter.WriteUInt16(stream, entry.Value.Value);
            }

            ByteWriter.WriteBytes(stream, Statistics.GetBytes());

            return(stream.ToArray());
        }
Exemplo n.º 20
0
 public void WriteBytes(Stream stream, int? nameOffset)
 {
     if (nameOffset.HasValue)
     {
         NetBiosUtils.WriteNamePointer(stream, nameOffset.Value);
     }
     else
     {
         byte[] encodedName = NetBiosUtils.EncodeName(Name, String.Empty);
         ByteWriter.WriteBytes(stream, encodedName);
     }
     BigEndianWriter.WriteUInt16(stream, (ushort)Type);
     BigEndianWriter.WriteUInt16(stream, (ushort)Class);
     BigEndianWriter.WriteUInt32(stream, TTL);
     BigEndianWriter.WriteUInt16(stream, (ushort)Data.Length);
     ByteWriter.WriteBytes(stream, Data);
 }
Exemplo n.º 21
0
        override public byte[] GetBytes()
        {
            byte[] buffer = new byte[4 + PageLength];
            if (PS)
            {
                buffer[0] |= 0x80;
            }
            if (SPF)
            {
                buffer[0] |= 0x40;
            }
            buffer[0] |= (byte)((byte)PageCode & 0x3F);
            buffer[1]  = SubPageCode;
            BigEndianWriter.WriteUInt16(buffer, 2, PageLength);

            return(buffer);
        }
Exemplo n.º 22
0
        public virtual byte[] GetBytes()
        {
            TrailerLength = this.Trailer.Length;
            if (TrailerLength > 0x1FFFF)
            {
                throw new ArgumentException("Invalid NBT packet length");
            }

            Flags = Convert.ToByte(TrailerLength > 0xFFFF);

            byte[] buffer = new byte[HeaderLength + Trailer.Length];
            ByteWriter.WriteByte(buffer, 0, (byte)Type);
            ByteWriter.WriteByte(buffer, 1, Flags);
            BigEndianWriter.WriteUInt16(buffer, 2, (ushort)(TrailerLength & 0xFFFF));
            ByteWriter.WriteBytes(buffer, 4, Trailer);

            return(buffer);
        }
Exemplo n.º 23
0
        public byte[] GetBytes()
        {
            byte[] buffer = new byte[Length];
            ByteWriter.WriteAnsiString(buffer, 0x00, Signature, 8);
            // we'll write the checksum later
            BigEndianWriter.WriteUInt16(buffer, 0x0C, MajorVersion);
            BigEndianWriter.WriteUInt16(buffer, 0x0E, MinorVersion);
            BigEndianWriter.WriteInt64(buffer, 0x10, LastUpdateDT.ToFileTimeUtc());
            BigEndianWriter.WriteUInt64(buffer, 0x18, UpdateSequenceNumber);
            BigEndianWriter.WriteUInt64(buffer, 0x20, PrimaryPrivateHeaderLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x28, SecondaryPrivateHeaderLBA);
            ByteWriter.WriteAnsiString(buffer, 0x30, DiskGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0x70, HostGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0xB0, DiskGroupGuidString, 0x40);
            ByteWriter.WriteAnsiString(buffer, 0xF0, DiskGroupName, 31);
            BigEndianWriter.WriteUInt32(buffer, 0x10F, BytesPerSector);
            BigEndianWriter.WriteUInt32(buffer, 0x113, (uint)Flags);

            BigEndianWriter.WriteUInt16(buffer, 0x117, PublicRegionSliceNumber);
            BigEndianWriter.WriteUInt16(buffer, 0x119, PrivateRegionSliceNumber);
            BigEndianWriter.WriteUInt64(buffer, 0x11B, PublicRegionStartLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x123, PublicRegionSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x12B, PrivateRegionStartLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x133, PrivateRegionSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x13B, PrimaryTocLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x143, SecondaryTocLBA);

            BigEndianWriter.WriteUInt32(buffer, 0x14B, NumberOfConfigs);
            BigEndianWriter.WriteUInt32(buffer, 0x14F, NumberOfLogs);
            BigEndianWriter.WriteUInt64(buffer, 0x153, ConfigSizeLBA);
            BigEndianWriter.WriteUInt64(buffer, 0x15B, LogSizeLBA);

            BigEndianWriter.WriteUInt32(buffer, 0x163, DiskSignature);
            BigEndianWriter.WriteGuidBytes(buffer, 0x167, DiskSetGuid);
            BigEndianWriter.WriteGuidBytes(buffer, 0x177, DiskSetGuidRepeat);

            uint checksum = CalculateChecksum(buffer);

            BigEndianWriter.WriteUInt32(buffer, 0x08, checksum);

            return(buffer);
        }
Exemplo n.º 24
0
 public byte[] GetBytes()
 {
     byte[] buffer = new byte[Length];
     BigEndianWriter.WriteUInt16(buffer, 0, ModeDataLength);
     ByteWriter.WriteByte(buffer, 2, MediumType);
     if (WP)
     {
         buffer[3] |= 0x80;
     }
     if (DPOFUA)
     {
         buffer[3] |= 0x10;
     }
     if (LongLBA)
     {
         buffer[4] |= 0x01;
     }
     BigEndianWriter.WriteUInt16(buffer, 6, BlockDescriptorLength);
     return(buffer);
 }
Exemplo n.º 25
0
 public void WriteBytes(byte[] buffer, int offset)
 {
     ByteWriter.WriteBytes(buffer, ref offset, UnitID, 6);
     ByteWriter.WriteByte(buffer, ref offset, Jumpers);
     ByteWriter.WriteByte(buffer, ref offset, TestResult);
     BigEndianWriter.WriteUInt16(buffer, ref offset, VersionNumber);
     BigEndianWriter.WriteUInt16(buffer, ref offset, PeriodOfStatistics);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfCRCs);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfAlignmentErrors);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfCollisions);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfSendAborts);
     BigEndianWriter.WriteUInt32(buffer, ref offset, NumberOfGoodSends);
     BigEndianWriter.WriteUInt32(buffer, ref offset, NumberOfGoodReceives);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfRetransmits);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfNoResourceConditions);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfFreeCommandBlocks);
     BigEndianWriter.WriteUInt16(buffer, ref offset, TotalNumberOfCommandBlocks);
     BigEndianWriter.WriteUInt16(buffer, ref offset, MaxTotalNumberOfCommandBlocks);
     BigEndianWriter.WriteUInt16(buffer, ref offset, NumberOfPendingSessions);
     BigEndianWriter.WriteUInt16(buffer, ref offset, MaxNumberOfPendingSessions);
     BigEndianWriter.WriteUInt16(buffer, ref offset, MaxTotalsSessionsPossible);
     BigEndianWriter.WriteUInt16(buffer, ref offset, SessionDataPacketSize);
 }
        public byte[] GetBytes()
        {
            PageLength = 0;
            foreach (IdentificationDescriptor descriptor in IdentificationDescriptorList)
            {
                PageLength += (ushort)descriptor.Length;
            }

            byte[] buffer = new byte[4 + PageLength];
            buffer[0] |= (byte)(PeripheralQualifier << 5);
            buffer[0] |= (byte)(PeripheralQualifier & 0x1F);
            buffer[1]  = (byte)PageCode;
            BigEndianWriter.WriteUInt16(buffer, 2, PageLength);

            int offset = 4;

            foreach (IdentificationDescriptor descriptor in IdentificationDescriptorList)
            {
                Array.Copy(descriptor.GetBytes(), 0, buffer, offset, descriptor.Length);
                offset += descriptor.Length;
            }
            return(buffer);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Will write a 2 bytes pointer to a name
        /// Note: NetBIOS implementations can only use label string pointers in Name Service packets
        /// </summary>
        public static void WriteNamePointer(byte[] buffer, int offset, int nameOffset)
        {
            ushort pointer = (ushort)(0xC000 | (nameOffset & 0x3FFF));

            BigEndianWriter.WriteUInt16(buffer, offset, pointer);
        }
Exemplo n.º 28
0
        public static void WriteNamePointer(Stream stream, int nameOffset)
        {
            ushort pointer = (ushort)(0xC000 | (nameOffset & 0x3FFF));

            BigEndianWriter.WriteUInt16(stream, pointer);
        }
Exemplo n.º 29
0
 public void Write(BigEndianWriter Writer)
 {
     Writer.WriteUInt16(Unknown1);
     Writer.WriteUInt16(Unknown2);
     Writer.WriteUInt32(MessageID);
 }
Exemplo n.º 30
0
 public void Write(BigEndianWriter Writer)
 {
     Writer.WriteUInt16s(NameOffsets);
     Writer.WriteUInt16(Section2ID);
     Writer.WriteUInt16(NrSection2);
 }