public DescriptorBlock(Stream stream) { bytes = new byte[DefaultBlockSize]; int bytesRead = stream.Read(bytes, 0, bytes.Length); stream.Seek(-bytesRead, SeekOrigin.Current); int bytePtr = 0; type = Encoding.ASCII.GetString(bytes, bytePtr, 4); bytePtr += 4; attributes = BitConverter.ToUInt32(bytes, bytePtr); bytePtr += 4; firstEventOffset = BitConverter.ToUInt16(bytes, bytePtr); bytePtr += 2; osId = bytes[bytePtr++]; osVersion = bytes[bytePtr++]; displayableSize = BitConverter.ToUInt64(bytes, bytePtr); bytePtr += 8; formatLogicalAddress = BitConverter.ToUInt64(bytes, bytePtr); bytePtr += 8; bytePtr += 8; // reserved controlBlockId = BitConverter.ToUInt32(bytes, bytePtr); bytePtr += 4; bytePtr += 4; // reserved osSpecificData = new TapeAddress(bytes, bytePtr); bytePtr += 4; stringType = bytes[bytePtr++]; bytePtr++; // reserved int checksum = BitConverter.ToUInt16(bytes, bytePtr); bytePtr += 2; // TODO: verify checksum? }
protected string GetString(TapeAddress addr) { if (addr.offset + addr.size >= bytes.Length) { Console.WriteLine("Warning: bad TapeAddress offset/size."); return(""); } if (addr.size == 0) { return(""); } if (stringType == 2) { return(Encoding.Unicode.GetString(bytes, addr.offset, addr.size)); } else { return(Encoding.ASCII.GetString(bytes, addr.offset, addr.size)); } }