Created
May 25, 2021 22:06
-
-
Save monoxgas/552468ef3e90142f270f4b0ca6ce869b to your computer and use it in GitHub Desktop.
MacOS Shared DYLD Cache Extraction (Big Sur)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: https://opensource.apple.com/source/dyld/[VERSION]/launch-cache/dsc_extractor.cpp.auto.html | |
// > SDKROOT=`xcrun --sdk macosx --show-sdk-path` | |
// > clang++ -o extract extract.cpp | |
// > mkdir libraries | |
// > ./extract /System/Library/dyld/dyld_shared_cache_x86_64 `pwd`/libraries/ | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <dlfcn.h> | |
typedef int (*extractor_proc)(const char* shared_cache_file_path, const char* extraction_root_path, | |
void (^progress)(unsigned current, unsigned total)); | |
int main(int argc, const char* argv[]) | |
{ | |
if ( argc != 3 ) { | |
fprintf(stderr, "usage: dsc_extractor <path-to-cache-file> <path-to-device-dir>\n"); | |
return 1; | |
} | |
void* handle = dlopen("/usr/lib/dsc_extractor.bundle", RTLD_LAZY); | |
if ( handle == NULL ) { | |
fprintf(stderr, "dsc_extractor.bundle could not be loaded\n"); | |
return 1; | |
} | |
extractor_proc proc = (extractor_proc)dlsym(handle, "dyld_shared_cache_extract_dylibs_progress"); | |
if ( proc == NULL ) { | |
fprintf(stderr, "dsc_extractor.bundle did not have dyld_shared_cache_extract_dylibs_progress symbol\n"); | |
return 1; | |
} | |
int result = (*proc)(argv[1], argv[2], ^(unsigned c, unsigned total) { printf("%d/%d\n", c, total); } ); | |
fprintf(stderr, "dyld_shared_cache_extract_dylibs_progress() => %d\n", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment