/// <summary> /// Reads a windows-specific PE header from the given binary /// data stream. /// </summary> /// <param name="reader">The reader to use.</param> /// <param name="isPE32Plus">Whether the file format is PE32+.</param> public WindowsHeader(BinaryReader reader, bool isPE32Plus) { this.ImageBase = isPE32Plus ? reader.ReadUInt64() : reader.ReadUInt32(); this.SectionAlignment = reader.ReadUInt32(); this.FileAlignment = reader.ReadUInt32(); this.TargetOSVersion = new Version(reader.ReadUInt16(), reader.ReadUInt16()); this.ImageVersion = new Version(reader.ReadUInt16(), reader.ReadUInt16()); this.SubsystemVersion = new Version(reader.ReadUInt16(), reader.ReadUInt16()); reader.ReadUInt32(); // Skip reserved field this.ImageSize = reader.ReadUInt32(); this.HeaderSize = reader.ReadUInt32(); this.Checksum = reader.ReadUInt32(); this.Subsystem = (Subsystem)reader.ReadUInt16(); this.DLLFlags = (DLLCharacteristics)reader.ReadUInt16(); this.StackReserveSize = isPE32Plus ? reader.ReadUInt64() : reader.ReadUInt32(); this.StackCommitSize = isPE32Plus ? reader.ReadUInt64() : reader.ReadUInt32(); this.HeapReserveSize = isPE32Plus ? reader.ReadUInt64() : reader.ReadUInt32(); this.HeapCommitSize = isPE32Plus ? reader.ReadUInt64() : reader.ReadUInt32(); reader.ReadUInt32(); // Skip reserved field this.DataDirectoryCount = reader.ReadUInt32(); }
public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback) { ThingList TL = new ThingList(); if (ProgressCallback != null) ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0); if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0) return TL; FFXIEncoding E = new FFXIEncoding(); if (E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) return TL; ushort Flag1 = BR.ReadUInt16(); if (Flag1 != 0 && Flag1 != 1) return TL; ushort Flag2 = BR.ReadUInt16(); if (Flag2 != 0 && Flag2 != 1) return TL; if (BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3) return TL; uint FileSize = BR.ReadUInt32(); if (FileSize != BR.BaseStream.Length) return TL; uint HeaderBytes = BR.ReadUInt32(); if (HeaderBytes != 0x40) return TL; if (BR.ReadUInt32() != 0) return TL; int BytesPerEntry = BR.ReadInt32(); if (BytesPerEntry < 0) return TL; uint DataBytes = BR.ReadUInt32(); if (FileSize != (HeaderBytes + DataBytes) || (DataBytes % BytesPerEntry) != 0) return TL; uint EntryCount = BR.ReadUInt32(); if (EntryCount * BytesPerEntry != DataBytes) return TL; if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0) return TL; if (ProgressCallback != null) ProgressCallback(I18N.GetText("FTM:LoadingData"), 0); for (uint i = 0; i < EntryCount; ++i) { BinaryReader EntryBR = new BinaryReader(new MemoryStream(BR.ReadBytes(BytesPerEntry))); EntryBR.BaseStream.Position = 0; bool ItemAdded = false; { Things.DMSGStringBlock SB = new Things.DMSGStringBlock(); if (SB.Read(EntryBR, E, i)) { TL.Add(SB); ItemAdded = true; } } EntryBR.Close(); if (!ItemAdded) { TL.Clear(); break; } if (ProgressCallback != null) ProgressCallback(null, (double) (i + 1) / EntryCount); } return TL; }
public ProgramHeader(BinaryReader reader, bool Is64Bit) { this.Type = (HeaderType)reader.ReadUInt32(); // 64-bit reads flags here if (Is64Bit) { this.SegmentFlags = (SegmentFlags)reader.ReadUInt32(); } this.SegmentOffset = Is64Bit ? reader.ReadInt64() : reader.ReadUInt32(); this.VirtualAddress = Is64Bit ? reader.ReadUInt64() : reader.ReadUInt32(); // Skip physical address - reserved if (Is64Bit) reader.ReadUInt64(); else reader.ReadUInt32(); this.SegmentFileSize = Is64Bit ? reader.ReadInt64() : reader.ReadUInt32(); this.SegmentLoadedSize = Is64Bit ? reader.ReadInt64() : reader.ReadUInt32(); // 32-bit reads flags here if (!Is64Bit) { this.SegmentFlags = (SegmentFlags)reader.ReadUInt32(); } this.Alignment = Is64Bit ? reader.ReadInt64() : reader.ReadUInt32(); if (this.SegmentOffset < 0 || this.SegmentFileSize < 0 || this.SegmentLoadedSize < 0 || this.Alignment < 0) { throw new BadImageFormatException("Program header values are too large to be " + "supported by this implementation"); } }
/// <summary>Reads a 128-bit binary value from the specified binary reader.</summary> public static Bin128 Read(BinaryReader br) { var result = new Bin128(); result._a = br.ReadUInt64(); result._b = br.ReadUInt64(); return result; }
protected override void Parse(Stream s) { BinaryReader r = new BinaryReader(s); base.Parse(s); this.unknown1 = new DataBlobHandler(RecommendedApiVersion, OnResourceChanged, r.ReadBytes(7 * 4)); this.unknownFlags1 = r.ReadUInt32(); this.unknownFlags2 = r.ReadUInt32(); this.unknownFlags3 = r.ReadUInt32(); this.unknownFlags4 = r.ReadUInt32(); this.unknownFlags5 = r.ReadUInt32(); this.unknownInstance1 = r.ReadUInt64(); this.unknown2 = r.ReadByte(); this.unknownInstance2 = r.ReadUInt64(); this.unknown3 = r.ReadByte(); this.colorList = new SwatchColorList(OnResourceChanged, s); this.unknownFlags = new DataBlobHandler(RecommendedApiVersion, OnResourceChanged, r.ReadBytes(5)); this.buildBuyMode = r.ReadBoolean(); if (base.Version >= 0x19) { this.unknown4 = r.ReadUInt32(); this.unknown5 = r.ReadUInt32(); this.unknown6 = r.ReadUInt32(); this.unknown7 = r.ReadUInt32(); } }
public Binding(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); byte StrLength = Reader.ReadByte(); string m_BoneName = Encoding.ASCII.GetString(Reader.ReadBytes(StrLength)); //Should be 8. uint MeshAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32()); //AssetID prefix, typical useless Maxis value... Reader.ReadUInt32(); m_MeshAssetID = Endian.SwapUInt64(Reader.ReadUInt64()); //Should be 8. uint TextureAssetIDSize = Endian.SwapUInt32(Reader.ReadUInt32()); //AssetID prefix, typical useless Maxis value... Reader.ReadUInt32(); m_TextureAssetID = Endian.SwapUInt64(Reader.ReadUInt64()); }
internal ELFProgramHeader(BinaryReader reader, ELFSizeFormat sizeFormat) { p_type = reader.ReadUInt32(); if (sizeFormat == ELFSizeFormat.ELF32) { p_offset = reader.ReadUInt32(); p_vaddr = reader.ReadUInt32(); p_paddr = reader.ReadUInt32(); } else if (sizeFormat == ELFSizeFormat.ELF64) { p_offset = reader.ReadUInt64(); p_vaddr = reader.ReadUInt64(); p_paddr = reader.ReadUInt64(); } else { throw new InvalidDataException("Unknown ELF size format value"); } p_filesz = reader.ReadUInt32(); p_memsz = reader.ReadUInt32(); p_flags = reader.ReadUInt32(); p_align = reader.ReadUInt32(); }
public SdkMeshVertexBuffer(BinaryReader reader) { NumVertices = reader.ReadUInt64(); SizeBytes = reader.ReadUInt64(); StrideBytes = reader.ReadUInt64(); Decl = new List<VertexElement>(); var processElem = true; for (int j = 0; j < MaxVertexElements; j++) { var stream = reader.ReadUInt16(); var offset = reader.ReadUInt16(); var type = reader.ReadByte(); var method = reader.ReadByte(); var usage = reader.ReadByte(); var usageIndex = reader.ReadByte(); if (stream < 16 && processElem) { var element = new VertexElement((short)stream, (short)offset, (DeclarationType)type, (DeclarationMethod)method, (DeclarationUsage)usage, usageIndex); Decl.Add(element); } else { processElem = false; } } DataOffset = reader.ReadUInt64(); Vertices = new List<VertPosNormTexTan>(); if (SizeBytes > 0) { ReadVertices(reader); } }
public bool Load(string path) { using (FileStream fs = new FileStream(path, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(fs)) { for (int i = 0; i < 8; ++i) { reader.ReadBytes(4); } uint count = reader.ReadUInt32(); uint offset = reader.ReadUInt32(); fs.Position = (long)offset; try { for (int i = 0; i < count; ++i) { ulong ext = reader.ReadUInt64(); ulong fpath = reader.ReadUInt64(); uint language = reader.ReadUInt32(); reader.ReadBytes(4); uint id = reader.ReadUInt32(); reader.ReadBytes(4); this.Add(ext, fpath, language, id); } } catch (Exception) { return false; } } } return true; }
/* private ushort _padding; */ /// <summary> /// Stream constructor. /// </summary> /// <param name="stream">The stream that contains the DirectorySectorEntry data.</param> public DirectorySectorEntry(Stream stream) { Debug.Assert(stream.Length >= Constants.DIR_ENTRY_SIZE); BinaryReader reader = new BinaryReader(stream); _name = Reader.ReadSimpleUnicodeString(reader, 64); _nameLength = reader.ReadUInt16(); if(_nameLength > 0) { _nameLength /= 2; --_nameLength; _name = _name.Substring(0, _nameLength); } else _name = ""; _type = (Stgty)reader.ReadByte(); _color = (DeColor)reader.ReadByte(); _leftSibling = new Sid(reader.ReadUInt32()); _rightSibling = new Sid(reader.ReadUInt32()); _child = new Sid(reader.ReadUInt32()); _clsId = new Guid(reader.ReadBytes(16)); _userFlags = reader.ReadUInt32(); _createTimeStamp = reader.ReadUInt64(); _modifyTimeStamp = reader.ReadUInt64(); _sectStart = new Sect(reader.ReadUInt32()); _size = reader.ReadUInt32(); _propType = reader.ReadUInt16(); /* _padding = */ reader.ReadUInt16(); }
public IEnumerable<Entry> Import() { using (var reader = new BinaryReader(File.OpenRead(filename))) { // 4 Version = reader.ReadInt32(); // 4 Positions = reader.ReadInt32(); foreach (var i in Enumerable.Range(0, Positions)) { // 16 var board = new Board(reader.ReadUInt64(), reader.ReadUInt64(), Color.Black); // 20 var height = reader.ReadInt32(); // 24 var prune = reader.ReadInt32(); // 25 var wld = reader.ReadBoolean(); // 26 var knownSolve = reader.ReadBoolean(); // 28 var fillOut = reader.ReadInt16(); // 30 var cutoff = reader.ReadInt16(); // 32 var heuristic = reader.ReadInt16(); // 34 var black = reader.ReadInt16(); // 36 var white = reader.ReadInt16(); // 37 var set = reader.ReadBoolean(); // 38 var assigned = reader.ReadBoolean(); // 39 var wldSolved = reader.ReadBoolean(); // 40 var fill2 = reader.ReadByte(); // 48 var games = new int[] { reader.ReadInt32(), reader.ReadInt32() }; // 49 var root = reader.ReadBoolean(); // 52 var fill3 = reader.ReadBytes(3); yield return new Entry(board, height, heuristic, 72/*new BookData() { Height = height, Prune = prune, WLD = wld, KnownSolve = knownSolve, Cutoff = cutoff, HeuristicValue = heuristic, BlackValue = black, WhiteValue = white, Games = games }*/); } } }
// extracts ZIP 64 extra field element from a given byte array internal override void ParseDataField(BinaryReader reader, UInt16 size) { Debug.Assert(reader != null); if ((_zip64ExtraFieldUsage & ZipIOZip64ExtraFieldUsage.UncompressedSize) != 0) { _uncompressedSize = reader.ReadUInt64(); if (size < sizeof(UInt64)) { throw new FileFormatException(SR.Get(SRID.CorruptedData)); } size -= sizeof(UInt64); } if ((_zip64ExtraFieldUsage & ZipIOZip64ExtraFieldUsage.CompressedSize) != 0) { _compressedSize = reader.ReadUInt64(); if (size < sizeof(UInt64)) { throw new FileFormatException(SR.Get(SRID.CorruptedData)); } size -= sizeof(UInt64); } if ((_zip64ExtraFieldUsage & ZipIOZip64ExtraFieldUsage.OffsetOfLocalHeader) != 0) { _offsetOfLocalHeader = reader.ReadUInt64(); if (size < sizeof(UInt64)) { throw new FileFormatException(SR.Get(SRID.CorruptedData)); } size -= sizeof(UInt64); } if ((_zip64ExtraFieldUsage & ZipIOZip64ExtraFieldUsage.DiskNumber) != 0) { _diskNumber = reader.ReadUInt32(); if (size < sizeof(UInt32)) { throw new FileFormatException(SR.Get(SRID.CorruptedData)); } size -= sizeof(UInt32); } if (size != 0) { throw new FileFormatException(SR.Get(SRID.CorruptedData)); } Validate(); }
public override ThingList Load(BinaryReader BR, ProgressCallback ProgressCallback) { ThingList TL = new ThingList(); if (ProgressCallback != null) ProgressCallback(I18N.GetText("FTM:CheckingFile"), 0); if (BR.BaseStream.Length < 0x40 || BR.BaseStream.Position != 0) return TL; FFXIEncoding E = new FFXIEncoding(); // Skip (presumably) fixed portion of the header if ((E.GetString(BR.ReadBytes(8)) != "d_msg".PadRight(8, '\0')) || BR.ReadUInt16() != 1 || BR.ReadUInt16() != 1 || BR.ReadUInt32() != 3 || BR.ReadUInt32() != 3) return TL; // Read the useful header fields uint FileSize = BR.ReadUInt32(); if (FileSize != BR.BaseStream.Length) return TL; uint HeaderBytes = BR.ReadUInt32(); if (HeaderBytes != 0x40) return TL; uint EntryBytes = BR.ReadUInt32(); if (BR.ReadUInt32() != 0) return TL; uint DataBytes = BR.ReadUInt32(); if (FileSize != HeaderBytes + EntryBytes + DataBytes) return TL; uint EntryCount = BR.ReadUInt32(); if (EntryBytes != EntryCount * 8) return TL; if (BR.ReadUInt32() != 1 || BR.ReadUInt64() != 0 || BR.ReadUInt64() != 0) return TL; if (ProgressCallback != null) ProgressCallback(I18N.GetText("FTM:LoadingData"), 0); for (uint i = 0; i < EntryCount; ++i) { BR.BaseStream.Position = HeaderBytes + i * 8; int Offset = ~BR.ReadInt32(); int Length = ~BR.ReadInt32(); if (Length < 0 || Offset < 0 || Offset + Length > DataBytes) { TL.Clear(); break; } BR.BaseStream.Position = HeaderBytes + EntryBytes + Offset; BinaryReader EntryBR = new BinaryReader(new MemoryStream(BR.ReadBytes(Length))); bool ItemAdded = false; { Things.DMSGStringBlock SB = new Things.DMSGStringBlock(); if (SB.Read(EntryBR, E, i)) { TL.Add(SB); ItemAdded = true; } } EntryBR.Close(); if (!ItemAdded) { TL.Clear(); break; } if (ProgressCallback != null) ProgressCallback(null, (double) (i + 1) / EntryCount); } return TL; }
public Reference(BinaryReader byteFile) { this.Station = new Id(byteFile); this.East = byteFile.ReadUInt64(); this.North = byteFile.ReadUInt64(); this.Altitude = byteFile.ReadUInt32(); this.Comment = byteFile.ReadString(); }
private void InternalRead(BinaryReader reader) { _gifTag0 = new GIFTag(reader); _trxPos = new TRXPOSRegister(reader); ulong trxPosAddress = reader.ReadUInt64(); _trxReg = new TRXREGRegister(reader); ulong trxRegisterAddress = reader.ReadUInt64(); _trxDir = new TRXDIRRegister(reader); ulong trxDirAddress = reader.ReadUInt64(); _gifTag1 = new GIFTag(reader); }
public override void Deserialize(BinaryReader reader) { SimID = reader.ReadUInt32(); Version = reader.ReadUInt16(); HeadID = reader.ReadUInt64(); BodyID = reader.ReadUInt64(); SkinTone = reader.ReadByte(); Gender = reader.ReadBoolean(); Name = reader.ReadString(); }
public bool Load() { var FolderPath = string.Format(FOLDER_PATH, DriveInfo.VolumeSerialNumber); var FilePath = string.Format(FILE_PATH, DriveInfo.VolumeSerialNumber); var LogPath = string.Format(UPDATELOG_PATH, DriveInfo.VolumeSerialNumber); if (File.Exists(FolderPath) && File.Exists(FilePath) && File.Exists(LogPath)) { using (FileStream stream = new FileStream(FolderPath, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { ulong frn = reader.ReadUInt64(); string name = reader.ReadString(); ulong parent_frn = reader.ReadUInt64(); FolderEntries[frn] = new FileNameAndFrn(name, parent_frn); } } } using (FileStream stream = new FileStream(FilePath, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { ulong frn = reader.ReadUInt64(); string name = reader.ReadString(); ulong parent_frn = reader.ReadUInt64(); FileEntries[frn] = new FileNameAndFrn(name, parent_frn); } } } using (FileStream stream = new FileStream(LogPath, FileMode.Open)) { using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { long ticks = reader.ReadInt64(); Int64 usn = reader.ReadInt64(); UpdateLogs[new DateTime(ticks)] = usn; } } } return true; } return false; }
public void Read(Stream s) { BinaryReader br = new BinaryReader(s); version = br.ReadInt32(); services = (Services)br.ReadUInt64(); timestamp = br.ReadInt64(); addr_recv = NetAddr.FromStream(s); addr_from = NetAddr.FromStream(s); nonce = br.ReadUInt64(); user_agent = VarStr.FromStream(s); start_height = br.ReadInt32(); }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); Version = reader.ReadUInt16(); RequesterID = reader.ReadUInt32(); HeadID = reader.ReadUInt64(); BodyID = reader.ReadUInt64(); SkinTone = reader.ReadByte(); Gender = reader.ReadBoolean(); Name = reader.ReadString(); Permissions = (VMTSOAvatarPermissions)reader.ReadByte(); }
public AuthKey(BigInteger gab) { key = gab.ToByteArrayUnsigned(); using(SHA1 hash = new SHA1Managed()) { using(MemoryStream hashStream = new MemoryStream(hash.ComputeHash(key), false)) { using(BinaryReader hashReader = new BinaryReader(hashStream)) { auxHash = hashReader.ReadUInt64(); hashReader.ReadBytes(4); keyId = hashReader.ReadUInt64(); } } } }
public AuthKey(byte[] data) { key = data; using (SHA1 hash = new SHA1Managed()) { using (MemoryStream hashStream = new MemoryStream(hash.ComputeHash(key), false)) { using (BinaryReader hashReader = new BinaryReader(hashStream)) { auxHash = hashReader.ReadUInt64(); hashReader.ReadBytes(4); keyId = hashReader.ReadUInt64(); } } } }
public Appearance(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); m_ThumbnailID = Endian.SwapUInt64(Reader.ReadUInt64()); uint Count = Endian.SwapUInt32(Reader.ReadUInt32()); for (int i = 0; i < Count; i++) BindingIDs.Add(Endian.SwapUInt64(Reader.ReadUInt64())); }
public SdkMeshIndexBuffer(BinaryReader reader) { NumIndices = reader.ReadUInt64(); SizeBytes = reader.ReadUInt64(); IndexType = reader.ReadUInt32(); reader.ReadUInt32(); // padding DataOffset = reader.ReadUInt64(); Indices = new List<int>(); if (SizeBytes > 0) { ReadIndices(reader); } }
public SdkMeshSubset(BinaryReader reader) { Name = Encoding.Default.GetString(reader.ReadBytes(MaxSubsetName)); if (Name[0] == '\0') { Name = string.Empty; } MaterialID = reader.ReadUInt32(); PrimitiveType = reader.ReadUInt32(); reader.ReadUInt32(); IndexStart = reader.ReadUInt64(); IndexCount = reader.ReadUInt64(); VertexStart = reader.ReadUInt64(); VertexCount = reader.ReadUInt64(); }
void ISteamSerializable.Deserialize(Stream stream) { try { BinaryReader br = new BinaryReader(stream); Invitee = br.ReadUInt64(); GroupID = br.ReadUInt64(); UnknownInfo = br.ReadBoolean(); }//try catch { throw new IOException(); }//catch }
/// <summary> /// Creates a new outfit. /// </summary> /// <param name="FileData">The data to create the outfit from.</param> public Outfit(byte[] FileData) { MemoryStream MemStream = new MemoryStream(FileData); BinaryReader Reader = new BinaryReader(MemStream); m_Version = Endian.SwapUInt32(Reader.ReadUInt32()); Reader.ReadUInt32(); //Unknown. m_LightAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); m_MediumAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); m_DarkAppearanceID = Endian.SwapUInt64(Reader.ReadUInt64()); Reader.Close(); }
public void TestMethod() { MemoryStream stream = new MemoryStream(100000); BinaryWriter writer = new BinaryWriter(stream); writer.Write(UInt16.MinValue, true); writer.Write(UInt16.MaxValue, true); writer.Write(UInt32.MinValue, true); writer.Write(UInt32.MaxValue, true); writer.Write(UInt64.MinValue, true); writer.Write(UInt64.MaxValue, true); writer.Write(Int16.MinValue, true); writer.Write(Int16.MaxValue, true); writer.Write(Int32.MinValue, true); writer.Write(Int32.MaxValue, true); writer.Write(Int64.MinValue, true); writer.Write(Int64.MaxValue, true); writer.Write(Single.MinValue, true); writer.Write(Single.MaxValue, true); writer.Write(Double.MinValue, true); writer.Write(Double.MaxValue, true); writer.Flush(); BinaryReader reader = new BinaryReader(stream); stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(UInt16.MinValue, reader.ReadUInt16(true)); Assert.AreEqual(UInt16.MaxValue, reader.ReadUInt16(true)); Assert.AreEqual(reader.ReadUInt32(true), UInt32.MinValue); Assert.AreEqual(reader.ReadUInt32(true), UInt32.MaxValue); Assert.AreEqual(reader.ReadUInt64(true), UInt64.MinValue); Assert.AreEqual(reader.ReadUInt64(true), UInt64.MaxValue); Assert.AreEqual(reader.ReadInt16(true), Int16.MinValue); Assert.AreEqual(reader.ReadInt16(true), Int16.MaxValue); Assert.AreEqual(reader.ReadInt32(true), Int32.MinValue); Assert.AreEqual(reader.ReadInt32(true), Int32.MaxValue); Assert.AreEqual(reader.ReadInt64(true), Int64.MinValue); Assert.AreEqual(reader.ReadInt64(true), Int64.MaxValue); Assert.AreEqual(reader.ReadSingle(true), Single.MinValue); Assert.AreEqual(reader.ReadSingle(true), Single.MaxValue); Assert.AreEqual(reader.ReadDouble(true), Double.MinValue); Assert.AreEqual(reader.ReadDouble(true), Double.MaxValue); }
/// <summary> /// Stream constructor. /// </summary> /// <param name="stream">The stream that contains the HeaderSector data.</param> /// <exception cref="Exception">Throws an exception if it encounters any invalid data in the stream.</exception> public HeaderSector(Stream stream) { Debug.Assert(stream.Length >= Constants.SECTOR_SIZE); BinaryReader reader = new BinaryReader(stream); ulong magicNumber = reader.ReadUInt64(); if(magicNumber != MAGIC_NUMBER) throw new Exception("Invalid header magic number."); _clsId = new Guid(reader.ReadBytes(16)); _minorVer = reader.ReadUInt16(); _dllVer = reader.ReadUInt16(); _byteOrder = reader.ReadUInt16(); _sectShift = reader.ReadUInt16(); _miniSectShift = reader.ReadUInt16(); _reserved = reader.ReadUInt16(); _reserved1 = reader.ReadUInt32(); _reserved2 = reader.ReadUInt32(); _sectFatCount = reader.ReadUInt32(); _sectDirStart = new Sect(reader.ReadUInt32()); _signature = reader.ReadUInt32(); _miniSectorCutoff = reader.ReadUInt32(); _sectMiniFatStart = new Sect(reader.ReadUInt32()); _sectMiniFatCount = reader.ReadUInt32(); _sectDifStart = new Sect(reader.ReadUInt32()); _sectDifCount = reader.ReadUInt32(); for(int i = 0; i < _sectFat.Length; ++i) _sectFat[i] = new Sect(reader.ReadUInt32()); }
public async Task<ImageInfo[]> LoadFromDbAsync(string dbFileName) { var file = await FileSystem.Current.GetFileFromPathAsync(dbFileName).ConfigureAwait(false); if (file == null) throw new FileNotFoundException(); using (var fs = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) using (var gz = new GZipStream(fs, CompressionMode.Decompress)) using (var br = new BinaryReader(gz)) { long count = br.ReadInt32(); _info = new ImageInfo[count]; for (var i = 0; i < count; i++) { var hash = br.ReadUInt64(); var titleId = br.ReadUInt16(); var episodeId = br.ReadUInt16(); var frame = br.ReadUInt32(); _info[i] = new ImageInfo { Hash = hash, TitleId = titleId, EpisodeId = episodeId, Frame = frame }; } } return _info; }
public Resource Read() { using (this.reader = new BinaryReader(stream)) { LSBHeader header; header.signature = reader.ReadUInt32(); if (header.signature != LSBHeader.Signature) throw new InvalidFormatException(String.Format("Illegal signature in header; expected {0}, got {1}", LSBHeader.Signature, header.signature)); header.totalSize = reader.ReadUInt32(); if (stream.Length != header.totalSize) throw new InvalidFormatException(String.Format("Invalid LSB file size; expected {0}, got {1}", header.totalSize, stream.Length)); header.bigEndian = reader.ReadUInt32(); // The game only uses little-endian files on all platforms currently and big-endian support isn't worth the hassle if (header.bigEndian != 0) throw new InvalidFormatException("Big-endian LSB files are not supported"); header.unknown = reader.ReadUInt32(); header.metadata.timestamp = reader.ReadUInt64(); header.metadata.majorVersion = reader.ReadUInt32(); header.metadata.minorVersion = reader.ReadUInt32(); header.metadata.revision = reader.ReadUInt32(); header.metadata.buildNumber = reader.ReadUInt32(); ReadStaticStrings(); Resource rsrc = new Resource(); rsrc.Metadata = header.metadata; ReadRegions(rsrc); return rsrc; } }