Beispiel #1
0
        public void CanResolveSectionNames()
        {
            var reader       = new ArrayStructReaderWriter(_packaged.RawData);
            var sections     = reader.ReadArray <SectionHeader>(3);
            var sectionNames = sections.Select(sec => sec.NameString).ToArray();

            Assert.Contains(".text\0\0\0", sectionNames);
            Assert.Contains(".idata\0\0", sectionNames);
            Assert.Contains(".reloc\0\0", sectionNames);
        }
Beispiel #2
0
        public void CanResolveCodeBytes()
        {
            var reader      = new ArrayStructReaderWriter(_packaged.RawData);
            var sections    = reader.ReadArray <SectionHeader>(3);
            var codeSection = sections.First(sec => sec.NameString.StartsWith(".text"));
            var codeRaw     = _packaged.RawData.AsSpan()
                              .Slice((int)(codeSection.PointerToRawData - FileOffsetAtSectionsHeader), (int)codeSection.VirtualSize)
                              .ToArray();

            Assert.AreEqual(CodeSectionSize, codeSection.VirtualSize, "Bad size of code section (header corrupted?)");
            Assert.That(codeRaw, Is.All.EqualTo(CodeSectionContentByte));
        }
Beispiel #3
0
        public void SectionsDoNotOverlap()
        {
            var reader               = new ArrayStructReaderWriter(_packaged.RawData);
            var sections             = reader.ReadArray <SectionHeader>(2);
            var sectionVirtualRanges = sections.Select(sec => (start: sec.VirtualAddress, end: sec.VirtualAddress + sec.VirtualSize)).ToArray();
            var sectionOffsetRanges  = sections.Select(sec => (start: sec.PointerToRawData, end: sec.PointerToRawData + sec.SizeOfRawData)).ToArray();

            foreach (var section1 in sectionVirtualRanges)
            {
                foreach (var section2 in sectionVirtualRanges)
                {
                    if (section1 == section2)
                    {
                        continue;
                    }

                    Assert.False(
                        section1.start <section2.end && section1.end> section2.start,
                        $"Overlap: {section1.start}-{section1.end} overlaps with {section2.start}-{section2.end}"
                        );
                }
            }

            foreach (var section1 in sectionOffsetRanges)
            {
                foreach (var section2 in sectionOffsetRanges)
                {
                    if (section1 == section2)
                    {
                        continue;
                    }

                    Assert.False(
                        section1.start <section2.end && section1.end> section2.start,
                        $"Overlap (Offsets): {section1.start}-{section1.end} overlaps with {section2.start}-{section2.end}"
                        );
                }
            }
        }