private void FromStream(Stream stream) { // Read in the DLL or EXE and get the timestamp. Stream = new BufferedStreamReader(stream, 4096); StreamStart = stream.Position; Stream.Read <IMAGE_DOS_HEADER>(out _dosHeader); Stream.Seek(_dosHeader.e_lfanew, SeekOrigin.Begin); Stream.Seek(sizeof(uint), SeekOrigin.Current); // NT Header Signature Stream.Read <IMAGE_FILE_HEADER>(out _fileHeader); bool isPe32 = Stream.Peek <ushort>() == 0x10B; if (isPe32) { Stream.Read <IMAGE_OPTIONAL_HEADER32>(out _optionalHeader32); PopulateDataDirectories(Stream, _optionalHeader32.NumberOfRvaAndSizes); } else { Stream.Read <IMAGE_OPTIONAL_HEADER64>(out _optionalHeader64); PopulateDataDirectories(Stream, _optionalHeader64.NumberOfRvaAndSizes); } _imageSectionHeaders = new IMAGE_SECTION_HEADER[FileHeader.NumberOfSections]; for (int x = 0; x < ImageSectionHeaders.Length; ++x) { Stream.Read <IMAGE_SECTION_HEADER>(out ImageSectionHeaders[x], true); } PopulateImportDescriptors(Stream); }
public static void boxTest() { List <System.Numerics.Vector3> verts = new List <System.Numerics.Vector3>(); List <int> stripIndices = new List <int>(); using (Stream stream = (Stream) new FileStream(@"C:\boxVertData", FileMode.Open)) using (var streamReader = new BufferedStreamReader(stream, 8192)) { for (int i = 0; i < 8; i++) { var half0 = SystemHalf.HalfHelper.HalfToSingle(streamReader.Read <SystemHalf.Half>()); var half1 = SystemHalf.HalfHelper.HalfToSingle(streamReader.Read <SystemHalf.Half>()); var half2 = SystemHalf.HalfHelper.HalfToSingle(streamReader.Read <SystemHalf.Half>()); streamReader.Read <SystemHalf.Half>(); verts.Add(new System.Numerics.Vector3(half0, half1, half2)); } } int maxStep; using (Stream stream = (Stream) new FileStream(@"C:\boxFaces", FileMode.Open)) using (var streamReader = new BufferedStreamReader(stream, 8192)) { maxStep = streamReader.Read <ushort>(); for (int i = 0; i < 26; i++) { stripIndices.Add(streamReader.Read <ushort>()); } } List <int> indices = inverseWatermarkTransform(stripIndices, maxStep); List <int> indicesTest = unpackInds(indices); List <byte> indicesOut = new List <byte>(); List <byte> indicesOut2 = new List <byte>(); foreach (var id in indices) { indicesOut.AddRange(BitConverter.GetBytes((ushort)id)); } foreach (var id in indicesTest) { indicesOut2.AddRange(BitConverter.GetBytes((ushort)id)); } File.WriteAllBytes(@"C:\boxFacesDecrypted", indicesOut.ToArray()); File.WriteAllBytes(@"C:\boxFacesDecryptedTest", indicesOut2.ToArray()); StringBuilder outStr = new StringBuilder(); foreach (var vert in verts) { outStr.AppendLine($"v {vert.X} {vert.Y} {vert.Z}"); } outStr.AppendLine(); for (int i = 0; i < indicesTest.Count - 2; i += 3) { outStr.AppendLine($"f {indicesTest[i] + 1} {indicesTest[i + 1] + 1} {indicesTest[i + 2] + 1}"); } File.WriteAllText(@"C:\boxbad.obj", outStr.ToString()); }
static void Scan(ScanOptions options) { var files = Directory.GetFiles(options.Source, "*.*", SearchOption.AllDirectories); var entries = new List <JsonFileEntry>(); foreach (var file in files) { using var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read); using var streamReader = new BufferedStreamReader(fileStream, 8); // Check if compressed archive (magic header) var header = streamReader.Read <uint>(); if (header == 0x80000001) { Console.WriteLine($"Found: {Path.GetFileName(file)}, hashing and adding."); var wholeFile = File.ReadAllBytes(file); var checksum = XXHash.Hash32(wholeFile); entries.Add(new JsonFileEntry(Path.GetFileName(file), streamReader.Read <int>(), (int)fileStream.Length, checksum)); } } var jsonFile = new JsonFile(entries); File.WriteAllText(options.SavePath, jsonFile.ToFile()); }
public static List <stamData> ReadLM(this BufferedStreamReader streamReader) { var stamList = new List <stamData>(); var lmStart = streamReader.Position(); streamReader.Read <int>(); var lmEnd = streamReader.Read <int>() + lmStart; streamReader.Seek(0x8, SeekOrigin.Current); while (streamReader.Position() < lmEnd) { var tag = streamReader.Peek <int>(); switch (tag) { case stam: stamList.Add(streamReader.ReadStam()); break; default: streamReader.SkipBasicAXSStruct(); break; } //Make sure to stop the loop if needed if (stamList[stamList.Count - 1].lastStam == true) { break; } } streamReader.Seek(lmEnd, SeekOrigin.Begin); return(stamList); }
public static LobbyActionCommon ReadNIFLRebootLAC(BufferedStreamReader streamReader, int offset) { var lac = new LobbyActionCommon(); var nifl = streamReader.Read <AquaCommon.NIFL>(); var end = nifl.NOF0Offset + offset; var rel0 = streamReader.Read <AquaCommon.REL0>(); streamReader.Seek(rel0.REL0DataStart + offset, SeekOrigin.Begin); lac.header = streamReader.Read <LobbyActionCommon.lacHeader>(); streamReader.Seek(lac.header.dataInfoPointer + offset, SeekOrigin.Begin); lac.info = streamReader.Read <LobbyActionCommon.dataInfo>(); streamReader.Seek(lac.info.blockOffset + offset, SeekOrigin.Begin); for (int i = 0; i < lac.info.blockCount; i++) { var block = streamReader.Read <LobbyActionCommon.dataBlockReboot>(); long bookmark = streamReader.Position(); lac.rebootDataBlocks.Add(LobbyActionCommon.ReadDataBlockReboot(streamReader, offset, block)); streamReader.Seek(bookmark, SeekOrigin.Begin); } return(lac); }
//Returns DAEH's length for the section - its own length public static int ReadDAEH(this BufferedStreamReader streamReader) { streamReader.Seek(0x4, SeekOrigin.Current); var len = streamReader.Read <int>(); streamReader.Seek(len - 0x10, SeekOrigin.Current); var meshSettingLen = streamReader.Read <int>(); streamReader.Seek(0x4, SeekOrigin.Current); return(meshSettingLen - len); }
/// <summary> /// Creates a <see cref="HintFile"/> from a byte array. /// </summary> /// <param name="fileData">The hint file to parse.</param> public static unsafe HintFile FromArray(byte[] fileData) { using (MemoryStream fileDataStream = new MemoryStream(fileData)) { var reader = new BufferedStreamReader(fileDataStream, 4096); // Get all entries. var entries = new List <Entry>((fileData.Length / 2) / sizeof(Entry)); Entry entry; do { reader.Read(out entry); entries.Add(entry); }while (entry != Entry.Null); entries.RemoveAt(entries.Count - 1); // Convert all entries to managed. fixed(byte *stringDataPtr = &fileData[reader.Position()]) { var managedEntries = new ManagedEntry[entries.Count]; for (int i = 0; i < managedEntries.Length; i++) { var textPtr = &stringDataPtr[entries[i].Offset]; var text = _encoder.GetString(textPtr, Strlen(textPtr)); managedEntries[i] = new ManagedEntry(entries[i], text); } return(new HintFile(managedEntries)); } } }
/// <summary>Tries to read the DICOM file header from a stream</summary> public static bool TryReadHeader(BufferedStreamReader input, out DicomFileMetaInformation fileMetaInformation) { fileMetaInformation = null; Span <byte> header = stackalloc byte[128 + BeforeFileMetaInformationLength.Length + 4 + AfterFileMetaInformationLength.Length]; if (!TryReadAll(input, header)) { return(false); } var before = header.Slice(128, BeforeFileMetaInformationLength.Length); var after = header.Slice(128 + BeforeFileMetaInformationLength.Length + 4, AfterFileMetaInformationLength.Length); if (!before.SequenceEqual(BeforeFileMetaInformationLength) || !after.SequenceEqual(AfterFileMetaInformationLength)) { return(false); } var metaInformationLength = BitConverter.ToUInt32(header.Slice(128 + BeforeFileMetaInformationLength.Length, 4)); DicomFileMetaInformation tmp = null; input.Read((int)metaInformationLength - AfterFileMetaInformationLength.Length, () => { var metaInformationReader = DicomStreamReader.Create(input, DicomUID.TransferSyntax.ExplicitVRLittleEndian); tmp = FileMetaInformationSerializer.Deserialize(metaInformationReader); }); fileMetaInformation = tmp; return(true); }
private List <DatFileEntry>?GetEntriesForPointerPattern(string datFileName, BufferedStreamReader streamReader, int offset) { // Validate if first entry streamReader.Seek(offset, SeekOrigin.Begin); streamReader.Read(out DatFileEntry headerEntry); streamReader.Read(out DatFileEntry firstEntry); var savedPos = streamReader.Position(); if (!headerEntry.IsFirstEntry(streamReader, MemoryToRawAddress, firstEntry, datFileName)) { return(null); } streamReader.Seek(savedPos, SeekOrigin.Begin); // Populate other entries. var entries = new List <DatFileEntry>(new[] { firstEntry }); DatFileEntry entry; while (!(entry = streamReader.Read <DatFileEntry>()).IsLastEntry()) { entries.Add(entry); } return(entries); }
public Symbol[] Read(Stream input) { reader = new BufferedStreamReader(input); BeginRead(); Context.Execute(Steps.RootStep); List <Symbol> ret = Context.Output; if (!reader.EndOfStream) { StringBuilder sb = new StringBuilder(); string seg; while (reader.Read(out seg, 512) > 0) { sb.Append(seg); } ret.Add(new StringOverflowSymbol(sb.ToString())); } EndRead(); reader = null; return(ret.ToArray()); }
public void Read_CheckEOF2() { var streamMock = new Mock <Stream>(); int i = 1; streamMock.Setup(p => p.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Returns <byte[], int, int>((a, b, c) => i--); byte[] tmparr = new byte[2]; BufferedStreamReader s = new BufferedStreamReader(streamMock.Object, GetConfig(1)); var r1 = s.Read(tmparr, 0, 1); var r2 = s.Read(tmparr, 1, 1); Assert.AreEqual(1, r1); Assert.AreEqual(0, r2); }
public void Read_ReadByteNotCalledOnInnerStream(int shadowBufferSize) { var streamMock = new Mock <Stream>(); streamMock.Setup(p => p.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Returns <byte[], int, int>((a, b, c) => c); byte[] tmparr = new byte[3]; BufferedStreamReader s = new BufferedStreamReader(streamMock.Object, GetConfig(shadowBufferSize)); s.Read(tmparr, 0, 1); s.Read(tmparr, 1, 1); s.Read(tmparr, 2, 1); streamMock.Verify(f => f.ReadByte(), Times.Never()); }
private static LobbyActionCommon BeginReadRebootLAC(BufferedStreamReader streamReader) { string type = Encoding.UTF8.GetString(BitConverter.GetBytes(streamReader.Peek <int>())); int offset = 0x20; //Base offset due to NIFL header //Deal with deicer's extra header nonsense if (type.Equals("lac\0")) { streamReader.Seek(0xC, SeekOrigin.Begin); //Basically always 0x60, but some deicer files from the Alpha have 0x50... int headJunkSize = streamReader.Read <int>(); streamReader.Seek(headJunkSize - 0x10, SeekOrigin.Current); type = Encoding.UTF8.GetString(BitConverter.GetBytes(streamReader.Peek <int>())); offset += headJunkSize; } //Proceed based on file variant if (type.Equals("NIFL")) { //NIFL return(ReadNIFLRebootLAC(streamReader, offset)); } else if (type.Equals("VTBF")) { //Lacs should really never be VTBF... } else { MessageBox.Show("Improper File Format!"); } return(null); }
private static List <int> BeginReadMGX(BufferedStreamReader streamReader) { string type = Encoding.UTF8.GetString(BitConverter.GetBytes(streamReader.Peek <int>())); int offset = 0x20; //Base offset due to NIFL header //Deal with deicer's extra header nonsense if (type.Equals("mgx\0")) { streamReader.Seek(0xC, SeekOrigin.Begin); //Basically always 0x60, but some deicer files from the Alpha have 0x50... int headJunkSize = streamReader.Read <int>(); streamReader.Seek(headJunkSize - 0x10, SeekOrigin.Current); type = Encoding.UTF8.GetString(BitConverter.GetBytes(streamReader.Peek <int>())); offset += headJunkSize; } //Proceed based on file variant if (type.Equals("NIFL")) { //There shouldn't be a nifl variant of this for now. MessageBox.Show("Error, NIFL .mgx found"); return(null); } else if (type.Equals("VTBF")) { return(ReadVTBFMGX(streamReader)); } else { MessageBox.Show("Improper File Format!"); return(null); } }
/* Data Parsing */ private void PopulateDataDirectories(BufferedStreamReader reader, long numberOfEntries) { _dataDirectories = new IMAGE_DATA_DIRECTORY[numberOfEntries]; for (int x = 0; x < numberOfEntries; x++) { reader.Read <IMAGE_DATA_DIRECTORY>(out _dataDirectories[x]); } }
public static void AlignReader(BufferedStreamReader streamReader, int align) { //Align to int align while (streamReader.Position() % align > 0) { streamReader.Read <byte>(); } }
public static NOF0 readNOF0(BufferedStreamReader streamReader) { NOF0 nof0 = new NOF0(); nof0.magic = streamReader.Read <int>(); nof0.NOF0Size = streamReader.Read <int>(); nof0.NOF0EntryCount = streamReader.Read <int>(); nof0.NOF0DataSizeStart = streamReader.Read <int>(); nof0.relAddresses = new List <int>(); for (int nofEntry = 0; nofEntry < nof0.NOF0EntryCount; nofEntry++) { nof0.relAddresses.Add(streamReader.Read <int>()); } return(nof0); }
public static NGSSHAD ReadNGSSHAD(BufferedStreamReader streamReader, int offset) { NGSSHAD shad = new NGSSHAD(); shad.unk0 = streamReader.Read <int>(); shad.pixelShader = streamReader.Read <PSO2String>(); shad.vertexShader = streamReader.Read <PSO2String>(); shad.shadDetailOffset = streamReader.Read <int>(); shad.shadExtraOffset = streamReader.Read <int>(); long bookmark = streamReader.Position(); //Some shaders, like some player ones apparently, do not use the extra structs... if (shad.shadDetailOffset > 0) { streamReader.Seek(shad.shadDetailOffset + offset, System.IO.SeekOrigin.Begin); shad.shadDetail = streamReader.Read <SHADDetail>(); streamReader.Seek(shad.shadExtraOffset + offset, System.IO.SeekOrigin.Begin); for (int i = 0; i < shad.shadDetail.shadExtraCount; i++) { shad.shadExtra.Add(streamReader.Read <SHADExtraEntry>()); } } else if (shad.shadExtraOffset > 0) { Console.WriteLine("**Apparently shadExtraOffset is allowed to be used without shadDetailOffset???**"); } streamReader.Seek(bookmark, System.IO.SeekOrigin.Begin); return(shad); }
public static void SkipBasicAXSStruct(this BufferedStreamReader streamReader) { long bookmark = streamReader.Position(); streamReader.Read <int>(); var trueLen = streamReader.Read <int>(); //Doesn't include padding so shouldn't be used streamReader.Read <int>(); var len = streamReader.Read <int>(); streamReader.Seek(bookmark, SeekOrigin.Begin); if (len == 0) { len = trueLen; } streamReader.Seek(len, SeekOrigin.Current); }
public void Read_InnerStreamCountBufferedBytes(int shadowBufferSize, int expectedBytesRead) { int bytesRead = 0; var streamMock = new Mock <Stream>(); streamMock.Setup(p => p.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Callback <byte[], int, int>((a, b, c) => bytesRead += c) .Returns <byte[], int, int>((a, b, c) => c); byte[] tmparr = new byte[3]; BufferedStreamReader s = new BufferedStreamReader(streamMock.Object, GetConfig(shadowBufferSize)); s.Read(tmparr, 0, 1); s.Read(tmparr, 1, 1); s.Read(tmparr, 2, 1); Assert.AreEqual(expectedBytesRead, bytesRead); streamMock.Verify(f => f.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.Is <int>(f => f != shadowBufferSize)), Times.Never()); }
public static dataBlockData ReadDataBlock(BufferedStreamReader streamReader, int offset, dataBlock offsetBlock) { dataBlockData data = new dataBlockData(); data.rawBlock = offsetBlock; data.unkInt0 = offsetBlock.unkInt0; streamReader.Seek(offsetBlock.internalName0Offset + offset, System.IO.SeekOrigin.Begin); data.internalName0 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.chatCommandOffset + offset, System.IO.SeekOrigin.Begin); data.chatCommand = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.internalName1Offset + offset, System.IO.SeekOrigin.Begin); data.internalName1 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.lobbyActionIdOffset + offset, System.IO.SeekOrigin.Begin); data.lobbyActionId = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.commonReferenceOffset0 + offset, System.IO.SeekOrigin.Begin); data.commonReference0 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.commonReferenceOffset1 + offset, System.IO.SeekOrigin.Begin); data.commonReference1 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.unkIntOffset0 + offset, System.IO.SeekOrigin.Begin); data.unkOffsetInt0 = streamReader.Read <int>(); streamReader.Seek(offsetBlock.unkIntOffset1 + offset, System.IO.SeekOrigin.Begin); data.unkOffsetInt1 = streamReader.Read <int>(); streamReader.Seek(offsetBlock.unkIntOffset2 + offset, System.IO.SeekOrigin.Begin); data.unkOffsetInt2 = streamReader.Read <int>(); streamReader.Seek(offsetBlock.iceNameOffset + offset, System.IO.SeekOrigin.Begin); data.iceName = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.humanAqmOffset + offset, System.IO.SeekOrigin.Begin); data.humanAqm = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.castAqmOffset1 + offset, System.IO.SeekOrigin.Begin); data.castAqm1 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.castAqmOffset2 + offset, System.IO.SeekOrigin.Begin); data.castAqm2 = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.kmnAqmOffset + offset, System.IO.SeekOrigin.Begin); data.kmnAqm = AquaObjectMethods.ReadCString(streamReader); streamReader.Seek(offsetBlock.vfxOffset + offset, System.IO.SeekOrigin.Begin); data.vfxIce = AquaObjectMethods.ReadCString(streamReader); return(data); }
public static T ReadStructBE <T>(this BufferedStreamReader streamReader, bool active) where T : unmanaged, IEndianReversible { if (active) { return(streamReader.ReadBigEndianStruct <T>()); } else { return(streamReader.Read <T>()); } }
public static T ReadBE <T>(this BufferedStreamReader streamReader, bool active) where T : unmanaged { if (active) { return(streamReader.ReadBigEndianPrimitive <T>()); } else { return(streamReader.Read <T>()); } }
public static ipnbStruct ReadIpnb(this BufferedStreamReader streamReader) { long bookmark = streamReader.Position(); ipnbStruct ipbnStr = new ipnbStruct(); ipbnStr.magic = streamReader.Read <int>(); ipbnStr.len = streamReader.Read <int>(); ipbnStr.int_08 = streamReader.Read <int>(); ipbnStr.paddedLen = streamReader.Read <int>(); int count = (ipbnStr.len - 0x10) / 2; for (int i = 0; i < count; i++) { ipbnStr.shortList.Add(streamReader.Read <short>()); } streamReader.Seek(bookmark + ipbnStr.paddedLen, SeekOrigin.Begin); return(ipbnStr); }
/// <summary> /// Parses a given PE header file. /// </summary> /// <param name="exeStream">Stream which starts at the beginning of the file, the DOS header.</param> public BasicPeParser(Stream exeStream) { // Read in the DLL or EXE and get the timestamp. using (var reader = new BufferedStreamReader(exeStream, 4096)) { reader.Read<IMAGE_DOS_HEADER>(out _dosHeader); reader.Seek(_dosHeader.e_lfanew, SeekOrigin.Begin); reader.Seek(sizeof(uint), SeekOrigin.Current); // NT Header Signature reader.Read<IMAGE_FILE_HEADER>(out _fileHeader); if (Is32BitHeader) reader.Read<IMAGE_OPTIONAL_HEADER32>(out _optionalHeader32); else reader.Read<IMAGE_OPTIONAL_HEADER64>(out _optionalHeader64); _imageSectionHeaders = new IMAGE_SECTION_HEADER[FileHeader.NumberOfSections]; for (int x = 0; x < ImageSectionHeaders.Length; ++x) reader.Read<IMAGE_SECTION_HEADER>(out ImageSectionHeaders[x], true); } }
public static List <OffsetTimeSet> ReadOffsetTimeSets(this BufferedStreamReader streamReader, long position, int timeCount) { List <OffsetTimeSet> sets = new List <OffsetTimeSet>(); OffsetTimeSet set0 = new OffsetTimeSet() { offset = streamReader.Read <int>(), time = streamReader.Read <float>() }; for (int i = 0; i < timeCount; i++) { //Add i * 8 to the offset for the true offset since the offsets here are relatigve to the position of their defining int OffsetTimeSet set = new OffsetTimeSet() { offset = (int)position + streamReader.Read <int>() + i * 8, time = streamReader.Read <float>() }; sets.Add(set); } return(sets); }
public static stamData ReadStam(this BufferedStreamReader streamReader) { var stamDataObj = new stamData(); var stamStart = streamReader.Position(); streamReader.Read <int>(); streamReader.Seek(0x8, SeekOrigin.Current); var stamSize = streamReader.Read <int>(); streamReader.Seek(0x8, SeekOrigin.Current); var stamTexCount = streamReader.Read <ushort>(); streamReader.Seek(0x12, SeekOrigin.Current); int texOffset = streamReader.Read <int>(); if (texOffset == 0) { stamDataObj.lastStam = true; return(stamDataObj); } streamReader.Seek(stamStart + texOffset, SeekOrigin.Begin); for (int i = 0; i < stamTexCount; i++) { var key0 = BitConverter.GetBytes(streamReader.Read <int>()); int key1 = streamReader.Read <int>(); stamDataObj.texIds.Add(key0[0].ToString("X2") + key0[1].ToString("X2") + key0[2].ToString("X2") + key0[3].ToString("X2") + key1.ToString("X")); streamReader.Seek(0x18, SeekOrigin.Current); } //streamReader.Seek(stamEnd, SeekOrigin.Begin); return(stamDataObj); }
public static ydbmStruct ReadYdbm(this BufferedStreamReader streamReader) { ydbmStruct ydbmStr = new ydbmStruct(); ydbmStr.magic = streamReader.Read <int>(); ydbmStr.len = streamReader.Read <int>(); ydbmStr.int_08 = streamReader.Read <int>(); ydbmStr.paddedLen = streamReader.Read <int>(); ydbmStr.int_10 = streamReader.Read <int>(); ydbmStr.int_14 = streamReader.Read <int>(); ydbmStr.int_18 = streamReader.Read <int>(); ydbmStr.int_1C = streamReader.Read <int>(); return(ydbmStr); }
/// <summary> /// Reads a null terminated ASCII string, up to 1024 characters. /// </summary> public static string ReadString(this BufferedStreamReader reader) { Span <byte> data = stackalloc byte[1024]; int numCharactersRead = 0; byte currentByte = 0; while ((currentByte = reader.Read <byte>()) != 0) { data[numCharactersRead++] = currentByte; } return(Encoding.ASCII.GetString(data.Slice(0, numCharactersRead))); }
public void Dispose_InnerStreamDoesntDispose() { var streamMock = new Mock <Stream>(); streamMock.Setup(p => p.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Returns <byte[], int, int>((a, b, c) => c); byte[] finalBuffer = new byte[1]; using (BufferedStreamReader s = new BufferedStreamReader(streamMock.Object, GetConfig(1))) { s.Read(finalBuffer, 0, 1); } streamMock.Verify(f => f.Close(), Times.Never()); }