Last active
May 25, 2022 17:53
-
-
Save mstange/7a642437b67ab7d8b0c68979ccd23a36 to your computer and use it in GitHub Desktop.
Save and then compile with `clang dsc_extractor.c -o dsc_extractor` and run with `./dsc_extractor /System/Library/dyld/dyld_shared_cache_arm64e ~/extracted-libs/`
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
// from https://github.com/apple-opensource/dyld/blob/master/dyld3/shared-cache/dsc_extractor.cpp#L817-L849 | |
#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