Esempio n. 1
0
 /// <summary>
 /// erzeugt einen StringBuilder mit den Hex-Werten des <see cref="BinaryReaderWriter"/>
 /// </summary>
 /// <param name="br"></param>
 /// <param name="start">Index des 1. Bytes</param>
 /// <param name="length">Länge des Bereiches</param>
 /// <param name="bytesperline">wenn größer 0 wird für die entsprechende Anzahl Bytes jeweils eine neue Zeile verwendet</param>
 /// <returns></returns>
 static public StringBuilder DumpMemory(BinaryReaderWriter br, int start = -1, int length = -1, int bytesperline = -1)
 {
     if (start >= 0)
     {
         br.Seek(start);
     }
     byte[] buff = br.ReadBytes(length > 0 ? length : (int)(br.Length - br.Position));
     return(DumpMemory(buff, 0, buff.Length, bytesperline));
 }
Esempio n. 2
0
        /// <summary>
        /// liefert 3 Byte als signed Wert
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        static public int Read3Int(BinaryReaderWriter br)
        {
            int v = ReadByte(br) + (ReadByte(br) << 8) + (ReadByte(br) << 16);

            if (v >= 0x800000)
            {
                v -= 0x1000000;
            }
            return(v);
        }
Esempio n. 3
0
        /// <summary>
        /// Basisfkt. zum Lesen eines Bytes (ev. auch XORt; IOException am Streamende)
        /// </summary>
        /// <returns></returns>
        static public byte ReadByte(BinaryReaderWriter br)
        {
            int b = br.BaseStream.ReadByte() ^ br.XOR;

            if (b == -1)
            {
                throw new IOException("End of file");
            }
            return((byte)b);
        }
Esempio n. 4
0
        /// <summary>
        /// liefert 4 Byte als signed Wert
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        static public int Read4Int(BinaryReaderWriter br)
        {
            long v = ReadByte(br) + (ReadByte(br) << 8) + (ReadByte(br) << 16) + (ReadByte(br) << 24);

            if (v >= 0x80000000)
            {
                v -= 0x100000000;
            }
            return((int)v);
        }
Esempio n. 5
0
        /// <summary>
        /// liefert 1 Byte als signed Wert
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        static public int Read1Int(BinaryReaderWriter br)
        {
            int v = br.ReadByte();

            if (v >= 0x80) // Bit 7 = 1 -> negativ
            {
                v -= 0x100;
            }
            return(v);
        }
Esempio n. 6
0
 /// <summary>
 /// ab der der Position des Start-Bits im <see cref="BinaryReaderWriter"/> wird die benötigte Anzahl Bits (als komplette Bytes) eingelesen
 /// und als Text aufbereitet
 /// </summary>
 /// <param name="br"></param>
 /// <param name="start">Anzahl der zu ignorierenden Bits ab der akt. Byteposition</param>
 /// <param name="length">wenn größer 0 die Anzahl der Bits</param>
 /// <param name="bitsperline">wenn größer 0 die Anzahl der Bits je Textzeile</param>
 /// <param name="low2high">je Byte beginnend mit Bit 0 oder 7</param>
 /// <returns></returns>
 static public StringBuilder Dumpstream(BinaryReaderWriter br, int start = -1, int length = -1, int bitsperline = 8, bool low2high = false)
 {
     if (start >= 0)
     {
         br.Seek(start);
     }
     byte[] buff = br.ReadBytes(length > 0 ?
                                1 + length / 8 :
                                (int)(br.Length - br.Position));
     return(Dumpstream(br, 0, length, bitsperline, low2high));
 }
Esempio n. 7
0
 /// <summary>
 /// Basisfkt zum Füllen des Byte-Puffer
 /// </summary>
 /// <param name="buff"></param>
 /// <returns></returns>
 static public byte[] ReadBytes(BinaryReaderWriter br, byte[] buff)
 {
     br.BaseStream.Read(buff, 0, buff.Length);
     if (br.XOR != 0)
     {
         for (int i = 0; i < buff.Length; i++)
         {
             buff[i] ^= br.XOR;
         }
     }
     return(buff);
 }
Esempio n. 8
0
 /// <summary>
 /// liest die Blockdaten
 /// </summary>
 /// <param name="br"></param>
 public void Read(BinaryReaderWriter br)
 {
     Offset = br.Read4UInt();
     Length = br.Read2AsUShort();
 }
Esempio n. 9
0
 public ShortDataBlock(BinaryReaderWriter br)
     : this()
 {
     Read(br);
 }
Esempio n. 10
0
 /// <summary>
 /// erzeugt einen StringBuilder mit den Hex-Werten des <see cref="BinaryReaderWriter"/>
 /// </summary>
 /// <param name="br"></param>
 /// <param name="block">Index des 1. Bytes und Länge des Bereichs</param>
 /// <param name="bytesperline">wenn größer 0 wird für die entsprechende Anzahl Bytes jeweils eine neue Zeile verwendet</param>
 /// <returns></returns>
 static public StringBuilder DumpMemory(BinaryReaderWriter br, DataBlock block, int bytesperline = -1)
 {
     return(DumpMemory(br, (int)block.Offset, (int)block.Length, bytesperline));
 }
Esempio n. 11
0
        //public long ReadInt64() {
        //   basestream.Read(m_buffer, 0, 8);
        //   if (XOR != 0)
        //      for (int i = 0; i < 8; i++)
        //         m_buffer[i] ^= XOR;
        //   uint lo = (uint)(m_buffer[0] | m_buffer[1] << 8 |
        //                    m_buffer[2] << 16 | m_buffer[3] << 24);
        //   uint hi = (uint)(m_buffer[4] | m_buffer[5] << 8 |
        //                    m_buffer[6] << 16 | m_buffer[7] << 24);
        //   return (long)((ulong)hi) << 32 | lo;
        //}

        //public ulong ReadUInt64() {
        //   basestream.Read(m_buffer, 0, 8);
        //   if (XOR != 0)
        //      for (int i = 0; i < 8; i++)
        //         m_buffer[i] ^= XOR;
        //   uint lo = (uint)(m_buffer[0] | m_buffer[1] << 8 |
        //                    m_buffer[2] << 16 | m_buffer[3] << 24);
        //   uint hi = (uint)(m_buffer[4] | m_buffer[5] << 8 |
        //                    m_buffer[6] << 16 | m_buffer[7] << 24);
        //   return ((ulong)hi) << 32 | lo;
        //}

        #endregion

        #region spez. static-Lesefkt. für den bequemeren Zugriff auf Daten (greifen auf die Kernfkt. zurück)

        /// <summary>
        /// liefert 1 Byte als unsigned Wert
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        static public int Read1UInt(BinaryReaderWriter br)
        {
            return(ReadByte(br));
        }
Esempio n. 12
0
 /// <summary>
 /// liest die Blockdaten
 /// </summary>
 /// <param name="br"></param>
 public new void Read(BinaryReaderWriter br)
 {
     base.Read(br);
     Recordsize = br.Read2AsUShort();
 }
Esempio n. 13
0
 /// <summary>
 /// liefert 4 Byte als unsigned Wert
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 static public uint Read4UInt(BinaryReaderWriter br)
 {
     return((uint)(ReadByte(br) + ((long)ReadByte(br) << 8) + ((long)ReadByte(br) << 16) + ((long)ReadByte(br) << 24)));
 }
Esempio n. 14
0
 /// <summary>
 /// liefert 3 Byte als unsigned Wert
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 static public int Read3UInt(BinaryReaderWriter br)
 {
     return(ReadByte(br) + (ReadByte(br) << 8) + (ReadByte(br) << 16));
 }
Esempio n. 15
0
 /// <summary>
 /// schreibt die Blockdaten
 /// </summary>
 /// <param name="bw"></param>
 public void Write(BinaryReaderWriter bw)
 {
     bw.Write(Offset);
     bw.Write(Length);
 }
Esempio n. 16
0
 public abstract void Read(BinaryReaderWriter br, object data);
Esempio n. 17
0
 public DataBlockWithRecordsize(BinaryReaderWriter br)
     : this()
 {
     Read(br);
 }
Esempio n. 18
0
 public abstract void Write(BinaryReaderWriter bw, object data);
Esempio n. 19
0
 /// <summary>
 /// schreibt die Blockdaten
 /// </summary>
 /// <param name="bw"></param>
 public new void Write(BinaryReaderWriter bw)
 {
     base.Write(bw);
     bw.Write(Recordsize);
 }
Esempio n. 20
0
 /// <summary>
 /// kopiert die restlichen Bytes des Streams
 /// </summary>
 /// <param name="brw"></param>
 public void CopyTo(BinaryReaderWriter brw)
 {
     CopyTo(brw.BaseStream);
 }