# This file is part of Mach-O Loader for CLE.# Contributed December 2016 by Fraunhofer SIT (https://www.sit.fraunhofer.de/en/).fromcle.backends.regionimportSectionfrom.segmentimportMachOSegmentTYPE_MASK=0x000000FFATTRIBUTES_MASK=0xFFFFFF00
[docs]classMachOSection(Section):""" Mach-O Section, only defined within the context of a Mach-O Segment. - offset is the offset into the file the region starts - vaddr (or just addr) is the virtual address - filesize (or just size) is the size of the region in the file - memsize (or vsize) is the size of the region when loaded into memory - segname is the corresponding segment's name without padding - sectname is the section's name without padding - align is the sections alignment as a power of 2 - reloff is the file offset to the section's relocation entries - nreloc is the number of relocation entries for this section - flags is a bit vector containing per-section flags - r1 and r2 are values for the reserved1 and reserved2 fields respectively """
@propertydeftype(self):returnself.flags&TYPE_MASK@propertydefattributes(self):returnself.flags&ATTRIBUTES_MASK@propertydefis_readable(self):""" Always true, because sections should always be readable :return: """returnTrue@propertydefis_writable(self):""" Returns the permission of the parent segment, because MachO sections simply inherit that :return: """returnself.parent_segment.is_writable@propertydefis_executable(self):""" Returns the permission of the parent segment, because MachO sections simply inherit that :return: """returnself.parent_segment.is_executable@propertydefonly_contains_uninitialized_data(self):""" I actually don't know if this is true, but it seems like a saner assumption than true :return: """returnFalsedef__repr__(self):return"<Section: {} (part of Segment: {})| offset {:#x}, vaddr {:#x}, size {:#x}>".format(self.sectnameifself.sectnameelse"Unnamed",self.segname,self.offset,self.vaddr,self.memsize)