public void ReadUInt32LE_WithValidUInt32_ReadsData() { using MemoryStream ms = new MemoryStream(new byte[] { 0x01, 0xEE, 0xA0, 0x0 }); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); var result = EndianUtility.ReadUInt32LE(br); Assert.Equal(10546689u, result); }
public void WriteUInt32LE_WithUInt32_WritesData() { using MemoryStream ms = new MemoryStream(new byte[4]); using BinaryWriter bw = new BinaryWriter(ms); EndianUtility.WriteUInt32LE(bw, 12345678u); ms.Seek(0, SeekOrigin.Begin); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); Assert.Equal(12345678u, EndianUtility.ReadUInt32LE(br)); }
private List <uint> ReadChunkTableValues(MemoryStream ms) { List <uint> valueList = new List <uint>(); using (BinaryReader br = new BinaryReader(ms, new ASCIIEncoding(), true)) { // get the offset information byte type = br.ReadByte(); // Get the size of each object in bytes int countByteSize = type - 12; uint count = 0; if (countByteSize == 1) { count = br.ReadByte(); } else if (countByteSize == 2) { count = EndianUtility.ReadUInt16LE(br); } else if (countByteSize == 4) { count = EndianUtility.ReadUInt32LE(br); } byte entrySizeType = br.ReadByte(); int entryByteSize = entrySizeType - 12; uint value = 0; // Read in the values for (int i = 0; i < count; i++) { if (countByteSize == 1) { value = br.ReadByte(); } if (entryByteSize == 2) { value = EndianUtility.ReadUInt16LE(br); } else if (entryByteSize == 4) { value = EndianUtility.ReadUInt32LE(br); } valueList.Add(value); } } return(valueList); }
/// <summary> /// Initializes a new instance of the <see cref="MdfHeader"/> class. /// </summary> /// <param name="psbPath">path to the PSB file to read.</param> public MdfHeader(string psbPath) { this.signature = new byte[MDFSignatureLength]; using FileStream fs = new FileStream(psbPath, FileMode.Open, FileAccess.Read); using BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()); // Read in the header this.signature = br.ReadBytes(MDFSignatureLength); this.length = EndianUtility.ReadUInt32LE(br); }
public MdfHeader(string psbPath) { signature = new byte[MDF_SIGNATURE_LENGTH]; using (FileStream fs = new FileStream(psbPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding())) { // Read in the header signature = br.ReadBytes(MDF_SIGNATURE_LENGTH); length = EndianUtility.ReadUInt32LE(br); } } }
/// <summary> /// Initializes a new instance of the <see cref="PsbHeader"/> class. /// </summary> /// <param name="psbPath">path to the PSB file.</param> public PsbHeader(string psbPath) { this.signature = new byte[PsbSignatureLength]; using FileStream fs = new FileStream(psbPath, FileMode.Open, FileAccess.Read); using BinaryReader br = new BinaryReader(fs, new ASCIIEncoding()); // Read in the header this.signature = br.ReadBytes(PsbSignatureLength); this.type = EndianUtility.ReadUInt32LE(br); this.unknown = EndianUtility.ReadUInt32LE(br); this.namesOffset = EndianUtility.ReadUInt32LE(br); this.stringsOffset = EndianUtility.ReadUInt32LE(br); this.stringsDataOffset = EndianUtility.ReadUInt32LE(br); this.chunkOffsetsOffset = EndianUtility.ReadUInt32LE(br); this.chunkLengthsOffset = EndianUtility.ReadUInt32LE(br); this.chunkDataOffset = EndianUtility.ReadUInt32LE(br); this.entriesOffset = EndianUtility.ReadUInt32LE(br); }
public PsbHeader(string psbPath) { signature = new byte[PSB_SIGNATURE_LENGTH]; using (FileStream fs = new FileStream(psbPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding())) { // Read in the header signature = br.ReadBytes(PSB_SIGNATURE_LENGTH); type = EndianUtility.ReadUInt32LE(br); unknown = EndianUtility.ReadUInt32LE(br); namesOffset = EndianUtility.ReadUInt32LE(br); stringsOffset = EndianUtility.ReadUInt32LE(br); stringsDataOffset = EndianUtility.ReadUInt32LE(br); chunkOffsetsOffset = EndianUtility.ReadUInt32LE(br); chunkLengthsOffset = EndianUtility.ReadUInt32LE(br); chunkDataOffset = EndianUtility.ReadUInt32LE(br); entriesOffset = EndianUtility.ReadUInt32LE(br); } } }
public void ReadUInt32LE_WithInvalidUInt32_ThrowsException() { using MemoryStream ms = new MemoryStream(new byte[] { 0x10, 0x00, 0xBB }); using BinaryReader br = new BinaryReader(ms, new ASCIIEncoding()); Assert.Throws <System.IO.EndOfStreamException>(() => EndianUtility.ReadUInt32LE(br)); }