sectionHasValidSegmentAddresses method

bool sectionHasValidSegmentAddresses(
  1. Section section
)

Checks that the contents of a given section have valid addresses when the file contents for the corresponding segment is loaded into memory.

Returns false for sections that are not allocated or where the address does not correspond to file contents (i.e., NOBITS sections).

Implementation

bool sectionHasValidSegmentAddresses(Section section) {
  final headerEntry = section.headerEntry;
  if (!headerEntry.isAllocated || !headerEntry.hasBits) return false;
  final segment = _programHeader.loadSegmentFor(headerEntry.addr);
  if (segment == null) return false;
  return (headerEntry.addr < (segment.vaddr + segment.filesz)) &&
      (headerEntry.addr + headerEntry.size) <=
          (segment.vaddr + segment.filesz);
}