/* 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 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); } }
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(); } }
/// <summary> /// Read the end of the Zip64 central directory /// </summary> /// <returns>Status of the given stream</returns> private ZipReturn ReadZip64EndOfCentralDir() { // Set the type of the archive to Zip64 _zip64 = true; // Open the stream for reading BinaryReader br = new BinaryReader(_zipstream); // If the signature doesn't match, then return uint thisSignature = br.ReadUInt32(); if (thisSignature != Constants.Zip64EndOfCentralDirSignature) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If the size of the central dir record isn't right, return ulong tulong = br.ReadUInt64(); // Size of zip64 end of central directory record if (tulong != 44) { return(ZipReturn.Zip64EndOfCentralDirError); } br.ReadUInt16(); // version made by // If the version needed to extract isn't correct, return ushort tushort = br.ReadUInt16(); // version needed to extract if (tushort != (ushort)ArchiveVersion.TorrentZip64) { return(ZipReturn.Zip64EndOfCentralDirError); } // If this is part of a spanned archive, return uint tuint = br.ReadUInt32(); // number of this disk if (tuint != 0) { return(ZipReturn.Zip64EndOfCentralDirError); } tuint = br.ReadUInt32(); // number of the disk with the start of the central directory if (tuint != 0) { return(ZipReturn.Zip64EndOfCentralDirError); } // If the number of entries in the current disk doesn't match up with the total entries, return _entriesCount = (uint)br.ReadUInt64(); // total number of entries in the central directory on this disk tulong = br.ReadUInt64(); // total number of entries in the central directory if (tulong != _entriesCount) { return(ZipReturn.Zip64EndOfCentralDirError); } _centerDirSize = br.ReadUInt64(); // size of central directory _centerDirStart = br.ReadUInt64(); // offset of start of central directory with respect to the starting disk number return(ZipReturn.ZipGood); }
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 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()); }
/// <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; }
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 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 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; }
// 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 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 }*/); } } }
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 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 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 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 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); }
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; }
/// <summary> /// Read the end of the Zip64 central directory locator /// </summary> /// <returns></returns> private ZipReturn ReadZip64EndOfCentralDirectoryLocator() { // Set the current archive type to Zip64 _zip64 = true; // Open the stream for reading BinaryReader br = new BinaryReader(_zipstream); // If the signature doesn't match, return uint thisSignature = br.ReadUInt32(); if (thisSignature != Constants.Zip64EndOfCentralDirectoryLocator) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If the disk isn't the first and only, then return uint tuint = br.ReadUInt32(); // number of the disk with the start of the zip64 end of centeral directory if (tuint != 0) { return(ZipReturn.Zip64EndOfCentralDirectoryLocatorError); } _endOfCenterDir64 = br.ReadUInt64(); // relative offset of the zip64 end of central directory record tuint = br.ReadUInt32(); // total number of disks if (tuint != 1) { return(ZipReturn.Zip64EndOfCentralDirectoryLocatorError); } return(ZipReturn.ZipGood); }
internal HTTPCacheFileInfo(Uri uri, System.IO.BinaryReader reader, int version) { this.Uri = uri; this.LastAccess = DateTime.FromBinary(reader.ReadInt64()); this.BodyLength = reader.ReadInt32(); switch (version) { case 2: this.MappedNameIDX = reader.ReadUInt64(); goto case 1; case 1: { this.ETag = reader.ReadString(); this.LastModified = reader.ReadString(); this.Expires = DateTime.FromBinary(reader.ReadInt64()); this.Age = reader.ReadInt64(); this.MaxAge = reader.ReadInt64(); this.Date = DateTime.FromBinary(reader.ReadInt64()); this.MustRevalidate = reader.ReadBoolean(); this.Received = DateTime.FromBinary(reader.ReadInt64()); break; } } }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } name = reader.ReadString(); type = reader.ReadString(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); influence = reader.ReadInt32(); score = reader.ReadInt32(); guid = reader.ReadUInt32(); folder = reader.ReadString(); int size = reader.ReadInt32(); if (size == 0) { thumb = null; } else { byte[] data = reader.ReadBytes(size); MemoryStream ms = new MemoryStream(data); thumb = Image.FromStream(ms); } }
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; } }
/// <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()); }
/// <summary> /// 分析网络数据包并进行转换为信息对象 /// </summary> /// <param name="packs">接收到的封包对象</param> /// <returns></returns> /// <remarks> /// 对于分包消息,如果收到的只是片段并且尚未接收完全,则不会进行解析 /// </remarks> public static IPMessager.Entity.Message ParseToMessage(params Entity.PackedNetworkMessage[] packs) { if (packs.Length == 0 || (packs[0].PackageCount > 1 && packs.Length != packs[0].PackageCount)) { return(null); } var ms = DecompressMessagePacks(packs); if (ms == null) { OnDecompressFailed(new DecomprssFailedEventArgs(packs)); return(null); } //构造读取流 var br = new System.IO.BinaryReader(ms, System.Text.Encoding.Unicode); //开始读出数据 var m = new FSLib.IPMessager.Entity.Message(packs[0].RemoteIP); m.PackageNo = br.ReadUInt64(); //包编号 var tl = br.ReadUInt64(); m.Command = (Define.Consts.Commands)(tl & 0xFF); //命令编码 m.Options = tl & 0xFFFFFF00; //命令参数 m.UserName = br.ReadString(); //用户名 m.HostName = br.ReadString(); //主机名 var length = br.ReadInt32(); m.NormalMsgBytes = new byte[length]; br.Read(m.NormalMsgBytes, 0, length); length = br.ReadInt32(); m.ExtendMessageBytes = new byte[length]; br.Read(m.ExtendMessageBytes, 0, length); if (!Consts.Check(m.Options, Consts.Cmd_All_Option.BinaryMessage)) { m.NormalMsg = System.Text.Encoding.Unicode.GetString(m.NormalMsgBytes, 0, length); //正文 m.ExtendMessage = System.Text.Encoding.Unicode.GetString(m.ExtendMessageBytes, 0, length); //扩展消息 } return(m); }
static int ReadUInt64(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); System.IO.BinaryReader obj = (System.IO.BinaryReader)LuaScriptMgr.GetNetObjectSelf(L, 1, "System.IO.BinaryReader"); ulong o = obj.ReadUInt64(); LuaScriptMgr.Push(L, o); return(1); }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } name = reader.ReadString(); if (version >= 2) { objdname = reader.ReadString(); } else { objdname = null; } if (version >= 3) { int ct = reader.ReadUInt16(); valuenames = new string[ct]; for (int i = 0; i < ct; i++) { valuenames[i] = reader.ReadString(); } } else { valuenames = new string[0]; } type = (SimPe.Data.ObjectTypes)reader.ReadUInt16(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); guid = reader.ReadUInt32(); int size = reader.ReadInt32(); if (size == 0) { thumb = null; } else { byte[] data = reader.ReadBytes(size); MemoryStream ms = new MemoryStream(data); thumb = Image.FromStream(ms); } }
static public int ReadUInt64(IntPtr l) { try { System.IO.BinaryReader self = (System.IO.BinaryReader)checkSelf(l); var ret = self.ReadUInt64(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public static ulong ReadUInt64(System.IO.BinaryReader reader) { ulong value = reader.ReadUInt64(); value = unchecked ((value & 0xFF00000000000000) >> 56 | (value & 0x00FF000000000000) >> 40 | (value & 0x0000FF0000000000) >> 24 | (value & 0x000000FF00000000) >> 8 | (value & 0x00000000FF000000) << 8 | (value & 0x0000000000FF0000) << 24 | (value & 0x000000000000FF00) << 40 | (value & 0x00000000000000FF) << 56); return(value); }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } resourcename = reader.ReadString(); rtp = (RcolCacheItemType)reader.ReadByte(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); }
public void LoadStateBinary(System.IO.BinaryReader reader) { int length = reader.ReadInt32(); byte[] data = reader.ReadBytes(length); //LoadCoreBinary(data); NewLoadCoreBinary(data); // other variables IsLagFrame = reader.ReadBoolean(); LagCount = reader.ReadInt32(); Frame = reader.ReadInt32(); frameOverflow = reader.ReadUInt32(); _cycleCount = reader.ReadUInt64(); }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } modelname = reader.ReadString(); family = reader.ReadString(); def = reader.ReadBoolean(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); }
public void LoadAccountData() { byte[] data = RuntimeInfo.GetLocalFile(RuntimeInfo.GetAccountFileName()); if (data == null) { Init(); return; } System.IO.MemoryStream ms = new System.IO.MemoryStream(data); System.IO.BinaryReader br = new System.IO.BinaryReader(ms); this.KEY = br.ReadUInt32(); if (this.KEY == ConstValue.FILE_END_MAGIC) { this.VER = br.ReadByte(); this.TAG = br.ReadByte(); this.AccountInfo.UID = br.ReadString(); this.bIsSavePassword = true; this.AccountInfo.CRC1 = br.ReadUInt32(); this.AccountInfo.CRC2 = br.ReadUInt32(); this.AccountInfo.CRC3 = br.ReadUInt32(); this.PhoneInfo.PhoneNumber = 0; this.bIsSavePhonePassword = true; this.PhoneInfo.phoneCRC1 = 0; this.PhoneInfo.phoneCRC2 = 0; this.PhoneInfo.phoneCRC3 = 0; } else if (this.KEY == ConstValue.FILE_END_MAGIC + 1) { this.VER = br.ReadByte(); this.TAG = br.ReadByte(); this.AccountInfo.UID = br.ReadString(); this.bIsSavePassword = br.ReadBoolean(); this.AccountInfo.CRC1 = br.ReadUInt32(); this.AccountInfo.CRC2 = br.ReadUInt32(); this.AccountInfo.CRC3 = br.ReadUInt32(); this.PhoneInfo.PhoneNumber = br.ReadUInt64(); this.bIsSavePhonePassword = br.ReadBoolean(); this.PhoneInfo.phoneCRC1 = br.ReadUInt32(); this.PhoneInfo.phoneCRC2 = br.ReadUInt32(); this.PhoneInfo.phoneCRC3 = br.ReadUInt32(); } ms.Close(); br.Close(); }
public PostingArray(string path) { if (!File.Exists(path)) { list = new Posting[0]; return; } using (System.IO.BinaryReader br = new System.IO.BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { int byteCount = br.ReadInt32(); this.list = new Posting[byteCount / sizeof(ulong)]; for (int i = 0; i < list.Length; i++) { var hash = br.ReadUInt64(); list[i] = new Posting(hash); } } }
public override void Read(System.IO.BinaryReader br) { Decimal d; br.ReadInt16(); // wReserved byte scale = br.ReadByte(); byte sign = br.ReadByte(); uint u = br.ReadUInt32(); d = Convert.ToDecimal(Math.Pow(2, 64)) * u; d += br.ReadUInt64(); if (sign != 0) { d = -d; } d /= (10 << scale); this.propertyValue = d; }
public void LoadStateBinary(System.IO.BinaryReader reader) { int length = reader.ReadInt32(); if (length != savebuff.Length) { throw new InvalidOperationException("Savestate buffer size mismatch!"); } reader.Read(savebuff, 0, savebuff.Length); if (!LibGambatte.gambatte_newstateload(GambatteState, savebuff, savebuff.Length)) { throw new Exception("gambatte_newstateload() returned false"); } // other variables IsLagFrame = reader.ReadBoolean(); LagCount = reader.ReadInt32(); Frame = reader.ReadInt32(); frameOverflow = reader.ReadUInt32(); _cycleCount = reader.ReadUInt64(); }
public override ulong ReadScalarValue(System.IO.BinaryReader br) { var r = br.ReadUInt64(); return(r); }
/// <summary> /// Retrieve file information for a single torrent GZ file /// </summary> /// <returns>Populated DatItem object if success, empty one on error</returns> public BaseFile GetTorrentGZFileInfo() { // Check for the file existing first if (!File.Exists(_filename)) { return(null); } string datum = Path.GetFileName(_filename).ToLowerInvariant(); long filesize = new FileInfo(_filename).Length; // If we have the romba depot files, just skip them gracefully if (datum == ".romba_size" || datum == ".romba_size.backup") { Globals.Logger.Verbose("Romba depot file found, skipping: {0}", _filename); return(null); } // Check if the name is the right length if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length { Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(_filename)); return(null); } // Check if the file is at least the minimum length if (filesize < 40 /* bytes */) { Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(_filename), Utilities.GetBytesReadable(filesize)); return(null); } // Get the Romba-specific header data byte[] header; // Get preamble header for checking byte[] headermd5; // MD5 byte[] headercrc; // CRC ulong headersz; // Int64 size BinaryReader br = new BinaryReader(Utilities.TryOpenRead(_filename)); header = br.ReadBytes(12); headermd5 = br.ReadBytes(16); headercrc = br.ReadBytes(4); headersz = br.ReadUInt64(); br.Dispose(); // If the header is not correct, return a blank rom bool correct = true; for (int i = 0; i < header.Length; i++) { // This is a temp fix to ignore the modification time and OS until romba can be fixed if (i == 4 || i == 5 || i == 6 || i == 7 || i == 9) { continue; } correct &= (header[i] == Constants.TorrentGZHeader[i]); } if (!correct) { return(null); } // Now convert the data and get the right position long extractedsize = (long)headersz; BaseFile baseFile = new BaseFile { Filename = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), Size = extractedsize, CRC = headercrc, MD5 = headermd5, SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(_filename)), // TODO: When updating to SHA-256, this needs to update to SHA256 Parent = Path.GetFileNameWithoutExtension(_filename).ToLowerInvariant(), }; return(baseFile); }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } name = reader.ReadString(); modelname = reader.ReadString(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); localgroup = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); int size = reader.ReadInt32(); if (size == 0) { thumb = null; } else { byte[] data = reader.ReadBytes(size); MemoryStream ms = new MemoryStream(data); thumb = Image.FromStream(ms); } objtype = (Data.ObjectTypes)reader.ReadUInt16(); if (version >= 4) { objfuncsort = reader.ReadUInt32(); } else { objfuncsort = (uint)reader.ReadInt16(); } if (version >= 2) { objname = reader.ReadString(); use = reader.ReadBoolean(); } else { objname = modelname; use = true; } if (version >= 3) { oclass = (ObjectClass)reader.ReadByte(); } else { oclass = ObjectClass.Object; } }
public void readFromFile(string path, bool withOutChunks) { this.relatedFileName = path; try { System.IO.FileStream fileStream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream); this.ThisLPRVersion = binaryReader.ReadInt32(); if (this.ThisLPRVersion >= 0) { int count = binaryReader.ReadInt32(); this.spectatorClientVersion = binaryReader.ReadChars(count); if (this.ThisLPRVersion < 2) { this.gameId = (ulong)((long)binaryReader.ReadInt32()); } else { this.gameId = binaryReader.ReadUInt64(); } this.gameEndStartupChunkId = binaryReader.ReadInt32(); this.gameStartChunkId = binaryReader.ReadInt32(); this.gameEndChunkId = binaryReader.ReadInt32(); this.gameEndKeyFrameId = binaryReader.ReadInt32(); this.gameLength = binaryReader.ReadInt32(); this.gameDelayTime = binaryReader.ReadInt32(); this.gameClientAddLag = binaryReader.ReadInt32(); this.gameChunkTimeInterval = binaryReader.ReadInt32(); this.gameKeyFrameTimeInterval = binaryReader.ReadInt32(); //this.gameELOLevel = binaryReader.ReadInt32(); this.gameLastChunkTime = binaryReader.ReadInt32(); this.gameLastChunkDuration = binaryReader.ReadInt32(); count = binaryReader.ReadInt32(); this.gamePlatform = binaryReader.ReadChars(count); count = binaryReader.ReadInt32(); this.observerEncryptionKey = binaryReader.ReadChars(count); //count = binaryReader.ReadInt32(); //this.gameCreateTime = binaryReader.ReadChars(count); //count = binaryReader.ReadInt32(); //this.gameStartTime = binaryReader.ReadChars(count); //count = binaryReader.ReadInt32(); //this.gameEndTime = binaryReader.ReadChars(count); if (this.ThisLPRVersion >= 3) { count = binaryReader.ReadInt32(); this.lolVersion = binaryReader.ReadChars(count); } else { this.lolVersion = string.Empty.ToCharArray(); } if (this.ThisLPRVersion >= 2) { this.hasResult = binaryReader.ReadBoolean(); if (this.ThisLPRVersion >= 4) { if (this.hasResult) { count = binaryReader.ReadInt32(); this.endOfGameStatsBytes = binaryReader.ReadBytes(count); this.gameStats = new EndOfGameStats(this.endOfGameStatsBytes); } if (binaryReader.ReadBoolean()) { this.readPlayerOldFormat(binaryReader); } } else { if (this.hasResult) { count = binaryReader.ReadInt32(); this.endOfGameStatsBytes = binaryReader.ReadBytes(count); this.gameStats = new EndOfGameStats(this.endOfGameStatsBytes); } else { this.readPlayerOldFormat(binaryReader); } } } else { this.readPlayerOldFormat(binaryReader); } if (!withOutChunks) { this.readChunks(binaryReader); } binaryReader.Close(); fileStream.Close(); } } catch { this.IsBroken = true; } }
/// <summary> /// Loads a database schema /// </summary> /// <param name="reader">binary reader</param> /// <returns></returns> public static DbSchemaConfig Load(io.BinaryReader reader) { var schema = new DbSchemaConfig() { Flags = (DbSchemaConfigType)reader.ReadUInt32(), Version = reader.BinaryRead(), Description = reader.BinaryRead(), Name = reader.BinaryRead(), PageSize = reader.ReadInt32(), _tables = new Dictionary <string, DbTable>() //Tables = new List<DbTable>() }; //tables var pageCount = reader.ReadInt32(); for (var t = 0; t < pageCount; t++) { var table = new DbTable() { Name = reader.BinaryRead(), FileName = reader.BinaryRead(), Generate = reader.ReadBoolean(), Multikey = reader.ReadBoolean(), Rows = reader.ReadInt32(), RowMask = reader.ReadUInt64(), RowMaskLength = reader.ReadInt32(), Pager = DbTablePager.Load(reader), Count = reader.ReadInt32(), _columns = new Dictionary <string, DbColumn>() }; //read columns var columnNameList = new List <string>(); for (var c = 0; c < table.Count; c++) { var col = new DbColumn() { Indexer = reader.BinaryRead(), Unique = reader.ReadBoolean(), Name = reader.BinaryRead(), Index = reader.ReadInt32(), Type = reader.BinaryRead(), Key = reader.ReadBoolean(), Indexed = reader.ReadBoolean(), // NodePages = reader.ReadInt32(), ItemPages = reader.ReadInt32() }; if (!table.Add(col)) { throw new ArgumentException($"duplicated column: {col.Name} on table {table.Name}"); } columnNameList.Add(col.Name); } //check count if (table.Count != table.Columns.Count()) { throw new ArgumentException($"invalid table count on: {table.Name}"); } table._columnNameList = columnNameList.ToArray(); //get key table.Keys = table.Columns.Where(c => c.Key).ToArray(); var keyCount = table.Keys.Length; if (table.Multikey) { //must have more than one key table.Key = null; if (keyCount < 2) { throw new ArgumentException($"table: {table} is multi-key and has less than 2 keys"); } } else { //must have just one key if (keyCount != 1) { throw new ArgumentException($"table: {table} must have one key"); } table.Key = table.Keys[0]; } //schema.Tables.Add(table); schema._tables.Add(table.Name, table); } return(schema); }
/// <summary> /// (INCOMPLETE) Retrieve file information for a RAR file /// </summary> /// TODO: Write the rest of this RAR file handling public void GetRarFileInfo() { if (!File.Exists(this.Filename)) { return; } BinaryReader br = new BinaryReader(Utilities.TryOpenRead(this.Filename)); // Check for the signature first (Skipping the SFX Module) byte[] signature = br.ReadBytes(8); int startpos = 0; while (startpos < Constants.MibiByte && !signature.StartsWith(Constants.RarSignature, exact: true) && !signature.StartsWith(Constants.RarFiveSignature, exact: true)) { startpos++; br.BaseStream.Position = startpos; signature = br.ReadBytes(8); } if (!signature.StartsWith(Constants.RarSignature, exact: true) && !signature.StartsWith(Constants.RarFiveSignature, exact: true)) { return; } CoreRarArchive cra = new CoreRarArchive(); if (startpos > 0) { br.BaseStream.Position = 0; cra.SFX = br.ReadBytes(startpos); } // Get all archive header information cra.HeaderCRC32 = br.ReadUInt32(); cra.HeaderSize = br.ReadUInt32(); uint headerType = br.ReadUInt32(); // Special encryption information bool hasEncryptionHeader = false; // If it's encrypted if (headerType == (uint)RarHeaderType.ArchiveEncryption) { hasEncryptionHeader = true; cra.EncryptionHeaderCRC32 = cra.HeaderCRC32; cra.EncryptionHeaderSize = cra.HeaderSize; cra.EncryptionHeaderFlags = (RarHeaderFlags)br.ReadUInt32(); cra.EncryptionVersion = br.ReadUInt32(); cra.EncryptionFlags = br.ReadUInt32(); cra.KDFCount = br.ReadByte(); cra.Salt = br.ReadBytes(16); cra.CheckValue = br.ReadBytes(12); cra.HeaderCRC32 = br.ReadUInt32(); cra.HeaderSize = br.ReadUInt32(); headerType = br.ReadUInt32(); } cra.HeaderFlags = (RarHeaderFlags)br.ReadUInt32(); if ((cra.HeaderFlags & RarHeaderFlags.ExtraAreaPresent) != 0) { cra.ExtraAreaSize = br.ReadUInt32(); } cra.ArchiveFlags = (RarArchiveFlags)br.ReadUInt32(); if ((cra.ArchiveFlags & RarArchiveFlags.VolumeNumberField) != 0) { cra.VolumeNumber = br.ReadUInt32(); } if (((cra.HeaderFlags & RarHeaderFlags.ExtraAreaPresent) != 0) && cra.ExtraAreaSize != 0) { cra.ExtraArea = br.ReadBytes((int)cra.ExtraAreaSize); } // Archive Comment Service Header // Now for file headers for (; ;) { CoreRarArchiveEntry crae = new CoreRarArchiveEntry(); crae.HeaderCRC32 = br.ReadUInt32(); crae.HeaderSize = br.ReadUInt32(); crae.HeaderType = (RarHeaderType)br.ReadUInt32(); if (crae.HeaderType == RarHeaderType.EndOfArchive) { break; } crae.HeaderFlags = (RarHeaderFlags)br.ReadUInt32(); if ((crae.HeaderFlags & RarHeaderFlags.ExtraAreaPresent) != 0) { crae.ExtraAreaSize = br.ReadUInt32(); } if ((crae.HeaderFlags & RarHeaderFlags.DataAreaPresent) != 0) { crae.DataAreaSize = br.ReadUInt32(); } crae.FileFlags = (RarFileFlags)br.ReadUInt32(); crae.UnpackedSize = br.ReadUInt32(); if ((crae.FileFlags & RarFileFlags.UnpackedSizeUnknown) != 0) { crae.UnpackedSize = 0; } crae.Attributes = br.ReadUInt32(); crae.mtime = br.ReadUInt32(); crae.DataCRC32 = br.ReadUInt32(); crae.CompressionInformation = br.ReadUInt32(); crae.HostOS = br.ReadUInt32(); crae.NameLength = br.ReadUInt32(); crae.Name = br.ReadBytes((int)crae.NameLength); if ((crae.HeaderFlags & RarHeaderFlags.ExtraAreaPresent) != 0) { uint extraSize = br.ReadUInt32(); switch (br.ReadUInt32()) // Extra Area Type { case 0x01: // File encryption information crae.EncryptionSize = extraSize; crae.EncryptionFlags = (RarEncryptionFlags)br.ReadUInt32(); crae.KDFCount = br.ReadByte(); crae.Salt = br.ReadBytes(16); crae.IV = br.ReadBytes(16); crae.CheckValue = br.ReadBytes(12); break; case 0x02: // File data hash crae.HashSize = extraSize; crae.HashType = br.ReadUInt32(); crae.HashData = br.ReadBytes(32); break; case 0x03: // High precision file time crae.TimeSize = extraSize; crae.TimeFlags = (RarTimeFlags)br.ReadUInt32(); if ((crae.TimeFlags & RarTimeFlags.TimeInUnixFormat) != 0) { if ((crae.TimeFlags & RarTimeFlags.ModificationTimePresent) != 0) { crae.TimeMtime64 = br.ReadUInt64(); } if ((crae.TimeFlags & RarTimeFlags.CreationTimePresent) != 0) { crae.TimeCtime64 = br.ReadUInt64(); } if ((crae.TimeFlags & RarTimeFlags.LastAccessTimePresent) != 0) { crae.TimeLtime64 = br.ReadUInt64(); } } else { if ((crae.TimeFlags & RarTimeFlags.ModificationTimePresent) != 0) { crae.TimeMtime = br.ReadUInt32(); } if ((crae.TimeFlags & RarTimeFlags.CreationTimePresent) != 0) { crae.TimeCtime = br.ReadUInt32(); } if ((crae.TimeFlags & RarTimeFlags.LastAccessTimePresent) != 0) { crae.TimeLtime = br.ReadUInt32(); } } break; case 0x04: // File version number crae.VersionSize = extraSize; /* crae.VersionFlags = */ br.ReadUInt32(); crae.VersionNumber = br.ReadUInt32(); break; case 0x05: // File system redirection crae.RedirectionSize = extraSize; crae.RedirectionType = (RarRedirectionType)br.ReadUInt32(); crae.RedirectionFlags = br.ReadUInt32(); crae.RedirectionNameLength = br.ReadUInt32(); crae.RedirectionName = br.ReadBytes((int)crae.RedirectionNameLength); break; case 0x06: // Unix owner and group information crae.UnixOwnerSize = extraSize; crae.UnixOwnerFlags = (RarUnixOwnerRecordFlags)br.ReadUInt32(); if ((crae.UnixOwnerFlags & RarUnixOwnerRecordFlags.UserNameStringIsPresent) != 0) { crae.UnixOwnerUserNameLength = br.ReadUInt32(); crae.UnixOwnerUserName = br.ReadBytes((int)crae.UnixOwnerUserNameLength); } if ((crae.UnixOwnerFlags & RarUnixOwnerRecordFlags.GroupNameStringIsPresent) != 0) { crae.UnixOwnerGroupNameLength = br.ReadUInt32(); crae.UnixOwnerGroupName = br.ReadBytes((int)crae.UnixOwnerGroupNameLength); } if ((crae.UnixOwnerFlags & RarUnixOwnerRecordFlags.NumericUserIdIsPresent) != 0) { crae.UnixOwnerUserId = br.ReadUInt32(); } if ((crae.UnixOwnerFlags & RarUnixOwnerRecordFlags.NumericGroupIdIsPresent) != 0) { crae.UnixOwnerGroupId = br.ReadUInt32(); } break; case 0x07: // Service header data array break; } } if ((crae.HeaderFlags & RarHeaderFlags.DataAreaPresent) != 0) { crae.DataArea = br.ReadBytes((int)crae.DataAreaSize); } } }