public void EmptyStreamCoreFiles() { var emptyReader = new BinaryReader(new MemoryStream()); var sections = NoteSection.ReadModuleSections(emptyReader, 1).ToArray(); Assert.AreEqual(0, sections.Length); }
public void SeveralNtFiles() { var StartAddresss = new ulong[] { expectedStartAddress, anotherExpectedStartAddress }; var offsets = new ulong[] { expectedOffset, expectedOffset }; var EndAddresss = new ulong[] { expectedEndAddress, anotherExpectedEndAddress }; var names = new string[] { expectedName, anotherExpectedName }; var ntFiles = TestData.GetNtFileSectionsBytes(StartAddresss, EndAddresss, offsets, names); var noteBytes = TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFiles); var fileReader = new BinaryReader(new MemoryStream(noteBytes)); var sections = NoteSection.ReadModuleSections(fileReader, ntFiles.Length).ToArray(); Assert.AreEqual(2, sections.Length); var first = sections.First(); Assert.AreEqual(expectedEndAddress, first.EndAddress); Assert.AreEqual(expectedStartAddress, first.StartAddress); Assert.AreEqual(expectedName, first.Path); var last = sections.Last(); Assert.AreEqual(anotherExpectedEndAddress, last.EndAddress); Assert.AreEqual(anotherExpectedStartAddress, last.StartAddress); Assert.AreEqual(anotherExpectedName, last.Path); }
public void ShortNoteStream() { var minNote = TestData.GetNoteSectionBytes("", 0, new byte[0]); var notEnoughBytes = minNote.Skip(1).ToArray(); var emptyReader = new BinaryReader(new MemoryStream(notEnoughBytes)); var sections = NoteSection.ReadModuleSections(emptyReader, minNote.Length).ToArray(); Assert.AreEqual(0, sections.Length); }
public void WrongNtFileType() { var ntFile = GetExpectedNtFileBytes(); var noteBytes = TestData.GetNoteSectionBytes(NoteSection.CoreName, 0, ntFile); var fileReader = new BinaryReader(new MemoryStream(noteBytes)); var sections = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray(); Assert.AreEqual(0, sections.Length); }
public void CorrectNtFileNote() { var ntFile = GetExpectedNtFileBytes(); var noteBytes = TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFile); var fileReader = new BinaryReader(new MemoryStream(noteBytes)); var sections = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray(); Assert.AreEqual(1, sections.Length); var section = sections.First(); Assert.AreEqual(expectedEndAddress, section.EndAddress); Assert.AreEqual(expectedStartAddress, section.StartAddress); Assert.AreEqual(expectedName, section.Path); }
public void NtFileWithSeveralLocations() { var StartAddresss = new ulong[] { expectedStartAddress + 1, expectedStartAddress }; var offsets = new ulong[] { expectedOffset + 1, expectedOffset }; var EndAddresss = new ulong[] { expectedEndAddress + 1, expectedEndAddress }; var names = new string[] { expectedName, expectedName }; var ntFile = TestData.GetNtFileSectionsBytes(StartAddresss, EndAddresss, offsets, names); var noteBytes = TestData.GetNoteSectionBytes(NoteSection.CoreName, NoteSection.NtFileType, ntFile); var fileReader = new BinaryReader(new MemoryStream(noteBytes)); var sections = NoteSection.ReadModuleSections(fileReader, ntFile.Length).ToArray(); Assert.AreEqual(1, sections.Length); var section = sections.First(); Assert.AreEqual(expectedEndAddress, section.EndAddress); Assert.AreEqual(expectedStartAddress, section.StartAddress); Assert.AreEqual(expectedName, section.Path); }
public void SeveralNtFilesNotes() { var firstNtFilesSection = GetExpectedNtFileBytes(); var firstNoteBytes = TestData.GetNoteSectionBytes( NoteSection.CoreName, NoteSection.NtFileType, firstNtFilesSection); var wrongNtFilesSection = GetExpectedNtFileBytes(); var wrongNoteBytes = TestData.GetNoteSectionBytes( NoteSection.GnuName, NoteSection.NtFileType, wrongNtFilesSection); var secondNtFileSection = TestData.GetNtFileSectionBytes( anotherExpectedStartAddress, anotherExpectedEndAddress, expectedOffset, anotherExpectedName); var secondNoteBytes = TestData.GetNoteSectionBytes( NoteSection.CoreName, NoteSection.NtFileType, secondNtFileSection); var fullNoteBytes = firstNoteBytes.Concat(wrongNoteBytes).Concat(secondNoteBytes) .ToArray(); var fileReader = new BinaryReader(new MemoryStream(fullNoteBytes)); var sections = NoteSection.ReadModuleSections(fileReader, fullNoteBytes.Length).ToArray(); Assert.AreEqual(2, sections.Length); var first = sections.First(); Assert.AreEqual(expectedEndAddress, first.EndAddress); Assert.AreEqual(expectedStartAddress, first.StartAddress); Assert.AreEqual(expectedName, first.Path); var last = sections.Last(); Assert.AreEqual(anotherExpectedEndAddress, last.EndAddress); Assert.AreEqual(anotherExpectedStartAddress, last.StartAddress); Assert.AreEqual(anotherExpectedName, last.Path); }