Beispiel #1
0
        public void CorrectModules()
        {
            ushort programHeadersCount = 4;
            var    elfHeaderBytes      = TestData.GetElfBytes(ElfHeader.Size, ProgramHeader.Size,
                                                              programHeadersCount, false);

            ulong firstFileOffset = ElfHeader.Size +
                                    (ulong)programHeadersCount * ProgramHeader.Size;

            var firstFileBytes  = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var secondFileBytes = TestData.GetElfFileBytesFromBuildId(TestData.anotherExpectedId);

            var firstFileHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.LoadableSegment, firstFileOffset, firstFileOffset,
                (ulong)firstFileBytes.Length);

            var firstFileIndexOffset = firstFileOffset + (ulong)firstFileBytes.Length;
            var fileIndexBytes       = TestData.GetNtFileSectionBytes(
                firstFileOffset, firstFileIndexOffset, 0ul, expectedFileName);

            var firstFileIndexNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, fileIndexBytes);

            var firstFileIndexHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, firstFileIndexOffset, firstFileIndexOffset,
                (ulong)firstFileBytes.Length);

            ulong secondFileIndexOffset = firstFileIndexOffset +
                                          (ulong)firstFileIndexNoteBytes.Length;
            ulong secondFileOffset  = secondFileIndexOffset + (ulong)firstFileIndexNoteBytes.Length;
            ulong secondFileDataEnd = secondFileOffset + (ulong)secondFileBytes.Length;

            var secondIndexBytes = TestData.GetNtFileSectionBytes(
                secondFileOffset, secondFileDataEnd, 0ul, anotherExpectedFileName);

            var secondFileIndexHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.NoteSegment, secondFileIndexOffset, secondFileIndexOffset,
                (ulong)secondIndexBytes.Length);

            var secondFileIndexNoteBytes = TestData.GetNoteSectionBytes(
                NoteSection.CoreName, NoteSection.NtFileType, secondIndexBytes);

            var secondFileHeaderBytes = TestData.GetProgramHeaderBytes(
                ProgramHeader.Type.LoadableSegment, secondFileOffset, secondFileOffset,
                (ulong)secondFileBytes.Length);

            var dumpBytes = elfHeaderBytes.Concat(firstFileHeaderBytes)
                            .Concat(firstFileIndexHeaderBytes).Concat(secondFileIndexHeaderBytes)
                            .Concat(secondFileHeaderBytes).Concat(firstFileBytes)
                            .Concat(firstFileIndexNoteBytes).Concat(secondFileIndexNoteBytes)
                            .Concat(secondFileBytes).ToArray();

            _fileSystem.AddFile(dumpPath, new MockFileData(dumpBytes));

            DumpReadResult dump = _provider.GetModules(dumpPath);

            Assert.AreEqual(2, dump.Modules.Count());

            var firstModule = dump.Modules.First();

            Assert.AreEqual(expectedFileName, firstModule.Path);
            Assert.AreEqual(TestData.expectedId, firstModule.Id);

            var lastModule = dump.Modules.Last();

            Assert.AreEqual(anotherExpectedFileName, lastModule.Path);
            Assert.AreEqual(TestData.anotherExpectedId, lastModule.Id);
        }