Last active
December 10, 2015 02:19
-
-
Save theiostream/4366719 to your computer and use it in GitHub Desktop.
cachecopier
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
// 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