Skip to content
Browse files

redid everything, added --armv7 flag

  • Loading branch information...
1 parent 5bf71ce commit 6fed755f7b879d1feeeb267b53d154e360bb4cc9 @ttwj committed Jun 18, 2012
Showing with 101 additions and 117 deletions.
  1. +0 −1 Classes/Configuration.h
  2. +1 −7 Clutch.xcodeproj/project.pbxproj
  3. +2 −7 crack.h
  4. +80 −92 crack.m
  5. +1 −2 dump.m
  6. +16 −3 main.m
  7. +1 −1 out.h
  8. +0 −1 out.m
  9. +0 −3 scinfo.m
View
1 Classes/Configuration.h
@@ -1,4 +1,3 @@
-#import <Foundation/Foundation.h>
@interface ClutchConfiguration : NSObject {
}
View
8 Clutch.xcodeproj/project.pbxproj
@@ -17,7 +17,6 @@
41E0DF0B123752D30068268F /* Configuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 41E0DF0A123752D30068268F /* Configuration.m */; };
41E0DFD3123823030068268F /* applist.m in Sources */ = {isa = PBXBuildFile; fileRef = 41E0DFD2123823030068268F /* applist.m */; };
AD2ABA53158088E000146E30 /* Property List.plist in Resources */ = {isa = PBXBuildFile; fileRef = AD2ABA52158088E000146E30 /* Property List.plist */; };
- AD2ABA571580BB7B00146E30 /* bash.m in Sources */ = {isa = PBXBuildFile; fileRef = AD2ABA561580BB7B00146E30 /* bash.m */; };
AD2ABA5A1580FA9800146E30 /* CrackApp.m in Sources */ = {isa = PBXBuildFile; fileRef = AD2ABA591580FA9700146E30 /* CrackApp.m */; };
/* End PBXBuildFile section */
@@ -43,8 +42,6 @@
8D1107310486CEB800E47090 /* Clutch-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Clutch-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
AD2ABA52158088E000146E30 /* Property List.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Property List.plist"; sourceTree = "<group>"; };
AD2ABA541580A71D00146E30 /* Clutch.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Clutch.entitlements; sourceTree = "<group>"; };
- AD2ABA551580BB7B00146E30 /* bash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bash.h; path = Classes/bash.h; sourceTree = "<group>"; };
- AD2ABA561580BB7B00146E30 /* bash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = bash.m; path = Classes/bash.m; sourceTree = "<group>"; };
AD2ABA581580FA9700146E30 /* CrackApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrackApp.h; sourceTree = "<group>"; };
AD2ABA591580FA9700146E30 /* CrackApp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CrackApp.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -92,8 +89,6 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
- AD2ABA551580BB7B00146E30 /* bash.h */,
- AD2ABA561580BB7B00146E30 /* bash.m */,
4155391A1238256D008EE206 /* crack.h */,
4155391B1238256D008EE206 /* crack.m */,
AD2ABA591580FA9700146E30 /* CrackApp.m */,
@@ -215,7 +210,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate\nif [ \"${PLATFORM_NAME}\" == \"iphoneos\" ]; then\n/Users/ttwj/entitlements/gen_entitlements.py \"us.hackulo.${PROJECT_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent\";\ncodesign -f -s \"iPhone Developer\" --entitlements \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\nfi";
+ shellScript = "export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate\nif [ \"${PLATFORM_NAME}\" == \"iphoneos\" ]; then\n/Users/ttwj/entitlements/gen_entitlements.py \"us.hackulo.${PROJECT_NAME}\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent\";\ncodesign -f -s \"iPhone Developer\" --entitlements \"/Users/ttwj/Clutch/Clutch.entitlements\" \"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/\"\nfi";
};
/* End PBXShellScriptBuildPhase section */
@@ -232,7 +227,6 @@
4155396A12387DF8008EE206 /* dump.m in Sources */,
41261396141B5CFA006DBF89 /* scinfo.m in Sources */,
41C30A2914311408008C17DB /* out.m in Sources */,
- AD2ABA571580BB7B00146E30 /* bash.m in Sources */,
AD2ABA5A1580FA9800146E30 /* CrackApp.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
View
9 crack.h
@@ -8,11 +8,8 @@
#import "out.h"
int overdrive_enabled;
-NSString *workingDir;
-NSString *binary_name;
-NSString *ipapath;
-NSString *crackerName;
-
+int only_armv7;
+int only_armv6;
#define FAT_CIGAM 0xbebafeca
#define MH_MAGIC 0xfeedface
@@ -22,12 +19,10 @@ NSString *crackerName;
#define ARMV6 6
#define ARMV7 9
-NSString * get_ipapath();
NSString * crack_application(NSString *application_basedir, NSString *basename);
NSString * init_crack_binary(NSString *application_basedir, NSString *bdir, NSString *workingDir, NSDictionary *infoplist);
NSString * crack_binary(NSString *binaryPath, NSString *finalPath, NSString **error);
NSString * genRandStringLength(int len);
-void zip(NSString *dir, NSString *zip);
int get_local_arch();
struct fat_arch {
View
172 crack.m
@@ -1,62 +1,12 @@
#import "crack.h"
-#import <Foundation/Foundation.h>
-
-#include <pthread.h>
int overdrive_enabled = 0;
-NSString *workingDir = @"";
-NSString *binary_name = @"";
-NSString *ipapath = @"";
-NSString *crackerName = @"";
-NSString *application_base = @"";
-
-NSMutableDictionary *infoplist;
-
+int only_armv7 = 0;
+int only_armv6 = 0;
-void *zip_resources() {
- NSString *zip = get_ipapath();
- NOTIFY("Compressing original app...");
- NSString *compressionArguments = [[ClutchConfiguration getValue:@"CompressionArguments"] stringByAppendingString:@" "];
- if (compressionArguments == nil)
- compressionArguments = @"-0 ";
- NSLog(@"working dir: %@\n app dir: %@", [workingDir stringByAppendingString:@"Payload"], [application_base stringByAppendingString:@"/../"]);
- NSError* error = nil;
- [[NSFileManager defaultManager] createSymbolicLinkAtPath:[workingDir stringByAppendingString:@"Payload"] withDestinationPath:[application_base stringByAppendingString:@"/../"] error:&error];
- NSLog(@"%@", [error localizedDescription]);
- NSLog(@"no segfault here bro");
- NSLog(@"working %@ zip %@ binary %@", workingDir, zip, binary_name);
- system([[NSString stringWithFormat:@"cd %@; zip %@-u -y -r -n .jpg:.JPG:.jpeg:.png:.PNG:.gif:.GIF:.Z:.gz:.zip:.zoo:.arc:.lzh:.rar:.arj:.mp3:.mp4:.m4a:.m4v:.ogg:.ogv:.avi:.flac:.aac \"%@\" Payload/* -x Payload/iTunesArtwork Payload/iTunesMetadata.plist \"Payload/Documents/*\" \"Payload/Library/*\" \"Payload/tmp/*\" \"Payload/*/%@\" \"Payload/*/SC_Info/*\" 2>&1> /dev/null", compressionArguments workingDir, zip, binary_name] UTF8String]);
- //I love you dissident
- [[NSFileManager defaultManager] removeItemAtPath:[workingDir stringByAppendingString:@"Payload"] error: NULL]; //I hope this doesn't remove the entire folder...
- NSLog(@"Zip path: %@", zip);
- return 0;
-}
-NSString * get_ipapath() {
- if (ipapath.length > 1) {
- return ipapath;
- }
- // filename addendum
- NSString *addendum = @"";
-
- if (overdrive_enabled)
- addendum = @"-OD";
-
- if ([[ClutchConfiguration getValue:@"FilenameCredit"] isEqualToString:@"YES"]) {
- ipapath = [NSString stringWithFormat:@"/var/root/Documents/Cracked/%@-v%@-%@%@.ipa", [[infoplist objectForKey:@"CFBundleDisplayName"] stringByReplacingOccurrencesOfString:@"/" withString:@"_"], [infoplist objectForKey:@"CFBundleVersion"], crackerName, addendum];
- } else {
- ipapath = [NSString stringWithFormat:@"/var/root/Documents/Cracked/%@-v%@%@.ipa", [[infoplist objectForKey:@"CFBundleDisplayName"] stringByReplacingOccurrencesOfString:@"/" withString:@"_"], [infoplist objectForKey:@"CFBundleVersion"], addendum];
- }
- [[NSFileManager defaultManager] createDirectoryAtPath:@"/var/root/Documents/Cracked/" withIntermediateDirectories:TRUE attributes:nil error:NULL];
- [[NSFileManager defaultManager] removeItemAtPath:ipapath error:NULL];
- NSLog(@"IPA Path %@", ipapath);
- return ipapath;
-
-}
NSString * crack_application(NSString *application_basedir, NSString *basename) {
- application_base = application_basedir;
- crackerName = [ClutchConfiguration getValue:@"CrackerName"];
VERBOSE("Creating working directory...");
- workingDir = [NSString stringWithFormat:@"%@%@/", @"/tmp/clutch_", genRandStringLength(8)];
+ NSString *workingDir = [NSString stringWithFormat:@"%@%@/", @"/tmp/clutch_", genRandStringLength(8)];
if (![[NSFileManager defaultManager] createDirectoryAtPath:[workingDir stringByAppendingFormat:@"Payload/%@", basename] withIntermediateDirectories:YES attributes:[NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"mobile", @"mobile", nil]
forKeys:[NSArray arrayWithObjects:@"NSFileOwnerAccountName", @"NSFileGroupOwnerAccountName", nil]
@@ -65,7 +15,6 @@
return nil;
}
-
VERBOSE("Performing initial analysis...");
struct stat statbuf_info;
stat([[application_basedir stringByAppendingString:@"Info.plist"] UTF8String], &statbuf_info);
@@ -75,7 +24,7 @@
oldtimes_info.actime = ist_atime;
oldtimes_info.modtime = ist_mtime;
- infoplist = [NSMutableDictionary dictionaryWithContentsOfFile:[application_basedir stringByAppendingString:@"Info.plist"]];
+ NSMutableDictionary *infoplist = [NSMutableDictionary dictionaryWithContentsOfFile:[application_basedir stringByAppendingString:@"Info.plist"]];
if (infoplist == nil) {
printf("error: Could not open Info.plist\n");
goto fatalc;
@@ -94,23 +43,8 @@
utime([[application_basedir stringByAppendingString:@"Info.plist"] UTF8String], &oldtimes_info);
- binary_name = [infoplist objectForKey:@"CFBundleExecutable"];
-
- //zip thread
- /*pthread_t zip_thread;
- if (pthread_create(&zip_thread, NULL, &zip_resources, NULL)) {
- printf("error: Could not prepare zip thread\n");
- goto fatalc;
- }
- */
- zip_resources();
- if (ipapath.length < 1) {
- printf("error: Could not prepare IPA directory\n");
- goto fatalc;
- }
-
- NSLog(@"cracking binary %@ %@ %@ %@", application_basedir, basename, workingDir, infoplist);
-
+ NSString *binary_name = [infoplist objectForKey:@"CFBundleExecutable"];
+
NSString *fbinary_path = init_crack_binary(application_basedir, basename, workingDir, infoplist);
if (fbinary_path == nil) {
printf("error: Could not crack binary\n");
@@ -195,7 +129,7 @@
utime([[application_basedir stringByAppendingString:@"/../iTunesMetadata.plist"] UTF8String], &oldtimes_metadata);
}
-
+ NSString *crackerName = [ClutchConfiguration getValue:@"CrackerName"];
if ([[ClutchConfiguration getValue:@"CreditFile"] isEqualToString:@"YES"]) {
VERBOSE("Creating credit file...");
FILE *fh = fopen([[workingDir stringByAppendingFormat:@"_%@", crackerName] UTF8String], "w");
@@ -230,35 +164,44 @@
VERBOSE("Packaging IPA file...");
+ // filename addendum
+ NSString *addendum = @"";
+
+ if (overdrive_enabled)
+ addendum = @"-OD";
+
+ NSString *ipapath;
+ if ([[ClutchConfiguration getValue:@"FilenameCredit"] isEqualToString:@"YES"]) {
+ ipapath = [NSString stringWithFormat:@"/var/root/Documents/Cracked/%@-v%@-%@%@.ipa", [[infoplist objectForKey:@"CFBundleDisplayName"] stringByReplacingOccurrencesOfString:@"/" withString:@"_"], [infoplist objectForKey:@"CFBundleVersion"], crackerName, addendum];
+ } else {
+ ipapath = [NSString stringWithFormat:@"/var/root/Documents/Cracked/%@-v%@%@.ipa", [[infoplist objectForKey:@"CFBundleDisplayName"] stringByReplacingOccurrencesOfString:@"/" withString:@"_"], [infoplist objectForKey:@"CFBundleVersion"], addendum];
+ }
+ [[NSFileManager defaultManager] createDirectoryAtPath:@"/var/root/Documents/Cracked/" withIntermediateDirectories:TRUE attributes:nil error:NULL];
+ [[NSFileManager defaultManager] removeItemAtPath:ipapath error:NULL];
NSString *compressionArguments = [[ClutchConfiguration getValue:@"CompressionArguments"] stringByAppendingString:@" "];
if (compressionArguments == nil)
compressionArguments = @"";
- NOTIFY("Compressing payload...");
+ NOTIFY("Compressing first stage resources (1/2)...");
system([[NSString stringWithFormat:@"cd %@; zip %@-m -r \"%@\" * 2>&1> /dev/null", workingDir, compressionArguments, ipapath] UTF8String]);
[[NSFileManager defaultManager] moveItemAtPath:[workingDir stringByAppendingString:@"Payload"] toPath:[workingDir stringByAppendingString:@"Payload_1"] error:NULL];
-
-// NOTIFY("Compressing second stage payload (2/2)...");
-//
-// [[NSFileManager defaultManager] createSymbolicLinkAtPath:[workingDir stringByAppendingString:@"Payload"] withDestinationPath:[application_basedir stringByAppendingString:@"/../"] error:NULL];
-//
-// system([[NSString stringWithFormat:@"cd %@; zip %@-u -y -r -n .jpg:.JPG:.jpeg:.png:.PNG:.gif:.GIF:.Z:.gz:.zip:.zoo:.arc:.lzh:.rar:.arj:.mp3:.mp4:.m4a:.m4v:.ogg:.ogv:.avi:.flac:.aac \"%@\" Payload/* -x Payload/iTunesArtwork Payload/iTunesMetadata.plist \"Payload/Documents/*\" \"Payload/Library/*\" \"Payload/tmp/*\" \"Payload/*/%@\" \"Payload/*/SC_Info/*\" 2>&1> /dev/null", workingDir, compressionArguments, ipapath, binary_name] UTF8String]);
-//
+ NOTIFY("Compressing second stage payload (2/2)...");
+
+ [[NSFileManager defaultManager] createSymbolicLinkAtPath:[workingDir stringByAppendingString:@"Payload"] withDestinationPath:[application_basedir stringByAppendingString:@"/../"] error:NULL];
+
+ system([[NSString stringWithFormat:@"cd %@; zip %@-u -y -r -n .jpg:.JPG:.jpeg:.png:.PNG:.gif:.GIF:.Z:.gz:.zip:.zoo:.arc:.lzh:.rar:.arj:.mp3:.mp4:.m4a:.m4v:.ogg:.ogv:.avi:.flac:.aac \"%@\" Payload/* -x Payload/iTunesArtwork Payload/iTunesMetadata.plist \"Payload/Documents/*\" \"Payload/Library/*\" \"Payload/tmp/*\" \"Payload/*/%@\" \"Payload/*/SC_Info/*\" 2>&1> /dev/null", workingDir, compressionArguments, ipapath, binary_name] UTF8String]);
stop_bar();
- NSLog(@"hi %@", ipapath);
- //[[NSFileManager defaultManager] removeItemAtPath:workingDir error:NULL];
+
+ [[NSFileManager defaultManager] removeItemAtPath:workingDir error:NULL];
return ipapath;
fatalc:
- @autoreleasepool {
- [[NSFileManager defaultManager] removeItemAtPath:workingDir error:NULL];
- return nil;
- } //lazy
-
+ [[NSFileManager defaultManager] removeItemAtPath:workingDir error:NULL];
+ return nil;
}
NSString * init_crack_binary(NSString *application_basedir, NSString *bdir, NSString *workingDir, NSDictionary *infoplist) {
@@ -322,8 +265,54 @@
struct fat_arch armv6, armv7;
fread(&armv6, sizeof(struct fat_arch), 1, oldbinary);
fread(&armv7, sizeof(struct fat_arch), 1, oldbinary);
-
- if (local_arch != ARMV6) {
+ if (only_armv7 == 1) {
+ VERBOSE("Only dumping ARMV7 portion because you said so");
+ NOTIFY("Dumping ARMV7 portion...");
+ // we can only crack the armv7 portion
+ if (!dump_binary(oldbinary, newbinary, CFSwapInt32(armv7.offset), binaryPath)) {
+ stop_bar();
+ *error = @"Cannot crack ARMV7 portion.";
+ goto c_err;
+ }
+ stop_bar();
+
+ VERBOSE("Performing liposuction of ARMV7 mach object...");
+ // lipo out the data
+ NSString *lipoPath = [NSString stringWithFormat:@"%@_l", finalPath]; // assign a new lipo path
+ FILE *lipoOut = fopen([lipoPath UTF8String], "w+"); // prepare the file stream
+ fseek(newbinary, CFSwapInt32(armv7.offset), SEEK_SET); // go to the armv6 offset
+ void *tmp_b = malloc(0x1000); // allocate a temporary buffer
+
+ uint32_t remain = CFSwapInt32(armv7.size);
+
+ while (remain > 0) {
+ if (remain > 0x1000) {
+ // move over 0x1000
+ fread(tmp_b, 0x1000, 1, newbinary);
+ fwrite(tmp_b, 0x1000, 1, lipoOut);
+ remain -= 0x1000;
+ } else {
+ // move over remaining and break
+ fread(tmp_b, remain, 1, newbinary);
+ fwrite(tmp_b, remain, 1, lipoOut);
+ break;
+ }
+ }
+
+ free(tmp_b); // free temporary buffer
+ fclose(lipoOut); // close lipo output stream
+ fclose(newbinary); // close new binary stream
+ fclose(oldbinary); // close old binary stream
+
+ [[NSFileManager defaultManager] removeItemAtPath:finalPath error:NULL]; // remove old file
+ [[NSFileManager defaultManager] moveItemAtPath:lipoPath toPath:finalPath error:NULL]; // move the lipo'd binary to the final path
+ chown([finalPath UTF8String], 501, 501); // adjust permissions
+ chmod([finalPath UTF8String], 0777); // adjust permissions
+
+ return finalPath;
+
+ }
+ else if (local_arch != ARMV6) {
VERBOSE("Application is a fat binary, cracking both architectures...");
NOTIFY("Dumping ARMV7 portion...");
@@ -467,8 +456,7 @@
int get_local_arch() {
int i;
int len = sizeof(i);
- //TheSexyPenguin likes penises
+
sysctlbyname("hw.cpusubtype", &i, (size_t *) &len, NULL, 0);
return i;
-
}
View
3 dump.m
@@ -84,6 +84,7 @@ BOOL dump_binary(FILE *origin, FILE *target, uint32_t top, NSString *originPath)
execl([originPath UTF8String], "", (char *) 0); // import binary memory into executable space
exit(2); // exit with err code 2 in case we could not import (this should not happen)
} else if (pid < 0) {
+ printf("error: Couldn't fork, did you compile with proper entitlements?");
return FALSE; // couldn't fork
} else {
// wait until the binary stops
@@ -98,8 +99,6 @@ BOOL dump_binary(FILE *origin, FILE *target, uint32_t top, NSString *originPath)
// open mach port to the other process
if ((err = task_for_pid(mach_task_self(), pid, &port) != KERN_SUCCESS)) {
kill(pid, SIGKILL); // kill the fork
- VERBOSE("hello");
- printf("hi %d", err);
return FALSE;
}
View
19 main.m
@@ -9,7 +9,6 @@
#import "applist.h"
#import "crack.h"
#import <unistd.h>
-#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
int retVal = 0;
@@ -88,7 +87,11 @@ int main(int argc, char *argv[]) {
printf("Caches cleared.\n");
} else if (strncmp(argv[1], "-v", 2) == 0) {
printf("%s\n", CLUTCH_VERSION);
- } else {
+ } else if (strncmp(argv[1], "-update", 7) == 0) {
+
+ } else if (strncmp(argv[1], "-h", 2) == 0) {
+ goto help;
+ } else {
BOOL numberMenu = [(NSString *)[ClutchConfiguration getValue:@"NumberBasedMenu"] isEqualToString:@"YES"];
NSArray *applist;
if (numberMenu)
@@ -139,7 +142,11 @@ int main(int argc, char *argv[]) {
if (!strcmp(argv[i], "--overdrive")) {
printf("Overdrive is enabled.\n");
overdrive_enabled = 1;
- } else {
+ }
+ else if (!strcmp(argv[i], "--armv7")) {
+ only_armv7 = 1;
+ }
+ else {
printf("error: Unrecognized application \"%s\"\n", argv[i]);
}
}
@@ -150,4 +157,10 @@ int main(int argc, char *argv[]) {
endMain:
return retVal;
[pool release];
+help:
+ printf("ClutchMod help\n");
+ printf("-- Cracks all applications\n");
+ printf("-f Clears cache\n");
+ printf("-v Shows version\n");
+ [pool release];
}
View
2 out.h
@@ -7,7 +7,7 @@
#import "Configuration.h"
// print something verbose
-#define VERBOSE(x) { progress_event(x); };
+#define VERBOSE(x) if ([[ClutchConfiguration getValue:@"VerboseLogging"] isEqualToString:@"YES"]) { progress_event(x); };
// output some data
#define NOTIFY(x) progress_message(x);
// update percentage of currently running task
View
1 out.m
@@ -1,5 +1,4 @@
#import "out.h"
-#import <Foundation/Foundation.h>
int determine_screen_width (void) {
int fd;
View
3 scinfo.m
@@ -3,9 +3,6 @@ Generates SC_Info keys (.sinf and .supp)
see http://hackulo.us/wiki/SC_Info
*/
-#include <stdint.h>
-#import <Foundation/Foundation.h>
-
// create a SINF atom
void *create_atom(char *name, int len, void *content) {
uint32_t atomsize = len + 8;

0 comments on commit 6fed755

Please sign in to comment.
Something went wrong with that request. Please try again.