Ejemplo n.º 1
0
    def _rebasePage(self, ctx: MachOContext, pageOffset: int,
                    delta: int) -> None:
        locOff = pageOffset

        while True:
            locOff += delta
            locInfo = dyld_cache_slide_pointer3(self.dyldCtx.file, locOff)

            # It appears the delta encoded in the pointers are 64bit jumps...
            delta = locInfo.plain.offsetToNextPointer * 8

            if locInfo.auth.authenticated:
                newValue = locInfo.auth.offsetFromSharedCacheBase
                newValue += self.slideInfo.auth_value_add
            else:
                value51 = locInfo.plain.pointerValue
                top8Bits = value51 & 0x0007F80000000000
                bottom43Bits = value51 & 0x000007FFFFFFFFFF
                newValue = (top8Bits << 13) | bottom43Bits

            ctx.writeBytes(locOff, struct.pack("<Q", newValue))

            if delta == 0:
                break
            pass
        pass
Ejemplo n.º 2
0
    def _rebasePage(self, ctx: MachOContext, pageStart: int,
                    pageOffset: int) -> None:
        """Process the slide info for a page.

		Args:
			pageStart: the file offset to the page.
			pageOffset: the offset from the pageStart to the first rebase location.
		"""

        deltaMask = self.slideInfo.delta_mask
        valueMask = ~deltaMask
        valueAdd = self.slideInfo.value_add

        # basically __builtin_ctzll(deltaMask) - 2;
        deltaShift = "{0:b}".format(deltaMask)
        deltaShift = len(deltaShift) - len(deltaShift.rstrip("0"))
        deltaShift = deltaShift - 2

        delta = 1
        while delta != 0:
            loc = pageStart + pageOffset

            rawValue = self.dyldCtx.readFormat("<Q", loc)[0]
            delta = (rawValue & deltaMask) >> deltaShift

            newValue = rawValue & valueMask
            if valueMask != 0:
                newValue += valueAdd

            ctx.writeBytes(loc, struct.pack("<Q", newValue))
            pageOffset += delta
        pass