Skip to content

Instantly share code, notes, and snippets.

@theiostream
Last active December 10, 2015 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theiostream/4366719 to your computer and use it in GitHub Desktop.
Save theiostream/4366719 to your computer and use it in GitHub Desktop.
cachecopier
// cachecopier.m
// Copy the dyld_shared_cache into /var/tmp.
// Credits to planetbeing for the ASLR trick and theiostream for implementation.
// COMPILATION:
// arm-apple-darwin10-llvm-gcc-4.2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -framework Foundation -mdynamic-no-pic -o cachecopier cachecopier.m
#import <Foundation/Foundation.h>
int main() {
NSString *const cache_path = @"/System/Library/Caches/com.apple.dyld/";
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *caches[3] = {@"dyld_shared_cache_armv6", @"dyld_shared_cache_armv7", @"dyld_shared_cache_armv7s"};
int i;
for (i=0; i<3; i++) {
if ([fm fileExistsAtPath:[cache_path stringByAppendingString:caches[i]]]) {
NSString *cache = caches[i];
printf("Copying cache %s\n", [cache UTF8String]);
BOOL ret = [fm copyItemAtPath:[cache_path stringByAppendingString:cache] toPath:[@"/var/tmp/" stringByAppendingString:cache] error:nil];
if (!ret) {
fprintf(stderr, "Failed to copy cache %s to /var/tmp.\n", [cache UTF8String]);
return 1;
}
}
goto success;
}
fprintf(stderr, "Found no caches.\n");
return 2;
success:
[pool drain];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment