def extractImage(dyld: Dyld.DyldFile, image: Dyld.dyld_cache_image_info, outputPath: str) -> None: """Extract and image Args: dyld: The DyldFile to extract from. image: The target image to extract. outputPath: The path to extract to. """ imageOff = dyld.convertAddr(image.address) machoFile = MachO.MachoFile.parse(dyld.file, imageOff) # rebuild the linkedit segment, which includes symbols logging.info("Starting LinkeditConverter") Converter.LinkeditConverter(machoFile, dyld).convert() # remove extra data in pointers and generate rebase data logging.info("Starting RebaseConverter") Converter.RebaseConverter(machoFile, dyld).convert() # fix references to selectors logging.info("Starting SelectorConverter") Converter.SelectorConverter(machoFile, dyld).convert() # fix stubs and references to stubs logging.info("Starting StubConverter") Converter.StubConverter(machoFile, dyld).convert() # fix and decache ObjC info logging.info("Starting ObjCConverter") Converter.ObjCConverter(machoFile, dyld).convert() # changes file offsets so that the final MachO file is not GBs big logging.info("Starting OffsetConverter") Converter.OffsetConverter(machoFile).convert() # save the converted image to a file logging.info("Starting Writer") MachO.Writer(machoFile).writeToPath(outputPath) pass
def runOnce(imageIndex: int, path: str) -> None: """ Decache an image at the imageIndex, and save it to the path. """ with open(DYLD_PATH, "rb") as dyldFile: dyld = Dyld.DyldFile(dyldFile) image = dyld.images[imageIndex] imageOff = dyld.convertAddr(image.address) macho = MachO.MachoFile.parse(dyldFile, imageOff) # comment or uncomment lines below to enable or disable modules. Though some do rely on each other. # rebuild the linkedit segment, which includes symbols print("LinkeditConverter") LinkeditConverter(macho, dyld).convert() # remove extra data in pointers and generate rebase data print("RebaseConverter") RebaseConverter(macho, dyld).convert() # fix references to selectors print("SelectorConverter") SelectorConverter(macho, dyld).convert() # fix stubs and references to stubs print("StubConverter") StubConverter(macho, dyld).convert() # fix and decache ObjC info print("ObjCConverter") ObjCConverter(macho, dyld).convert() # changes file offsets so that the final MachO file is not GBs big print("OffsetConverter") OffsetConverter(macho).convert() # save the converted image to a file print("Writer") MachO.Writer(macho).writeToPath(path)