Created
June 29, 2025 12:33
-
-
Save eddieh/775631da5c757ae650b269d3daf4a5e5 to your computer and use it in GitHub Desktop.
Extracts (uncaches) a dyld shared cache file on macOS
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
#include <dlfcn.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* | |
Extracts (uncaches) a dyld shared cache file on macOS | |
Compile: | |
cc uncache_dylds.c -o uncache_dylds | |
Example: | |
uncache_dylds /…/Cryptexes/…/dyld/dyld_shared_cache_arm64e outdir | |
*/ | |
#define EXTACTOR_BUNDLE "/usr/lib/dsc_extractor.bundle" | |
#define EXTRACT_FN "dyld_shared_cache_extract_dylibs_progress" | |
/* | |
uncache | |
Parameters: | |
cache: path to the dyld cache file | |
out: path to output directory | |
progress: block with two int arguments: current & total | |
Returns: | |
0 on success // I, um, think? | |
*/ | |
int | |
(*uncache)(const char *cache, const char *out, void (^progress)(int, int)); | |
int | |
main(int argc, char **argv) | |
{ | |
if (argc < 3) { | |
fprintf(stderr, "usage: %s <dyld-shared-cache> <outdir>\n", argv[0]); | |
exit(1); | |
} | |
void *bundle = dlopen(EXTACTOR_BUNDLE, RTLD_LAZY); | |
if (!bundle) { | |
fprintf(stderr, "load error: " EXTACTOR_BUNDLE " did not open\n"); | |
fprintf(stderr, "dlerror: %s\n", dlerror()); | |
exit(1); | |
} | |
uncache = dlsym(bundle, EXTRACT_FN); | |
if (!uncache) { | |
fprintf(stderr, "not found: " EXTRACT_FN "\n"); | |
fprintf(stderr, "dlerror: %s\n", dlerror()); | |
exit(1); | |
} | |
int result = uncache(argv[1], argv[2], ^(int i, int n) { | |
fprintf(stderr, "."); | |
}); | |
fprintf(stderr, "\nresult=%d\n", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment