Permalink
Browse files

seperated into smaller functions

  • Loading branch information...
ttwj committed Jun 8, 2012
1 parent 0f3ef9a commit db232b128fbdfc785e33e8610d36a19fd6bd60ec
Showing with 65 additions and 44 deletions.
  1. +0 −1 Classes/bash.h
  2. +2 −2 Clutch.xcodeproj/project.pbxproj
  3. +6 −13 CrackApp.h
  4. +0 −8 CrackApp.m
  5. +2 −0 crack.h
  6. +55 −20 crack.m
View
@@ -12,7 +12,6 @@
@interface bash : NSObject {
NSString* script;
NSDictionary* env;
- NSTask* task;
}
- (void) run;
@end
@@ -95,9 +95,9 @@
AD2ABA551580BB7B00146E30 /* bash.h */,
AD2ABA561580BB7B00146E30 /* bash.m */,
4155391A1238256D008EE206 /* crack.h */,
- AD2ABA581580FA9700146E30 /* CrackApp.h */,
- AD2ABA591580FA9700146E30 /* CrackApp.m */,
4155391B1238256D008EE206 /* crack.m */,
+ AD2ABA591580FA9700146E30 /* CrackApp.m */,
+ AD2ABA581580FA9700146E30 /* CrackApp.h */,
41C30A2814311408008C17DB /* out.m */,
41C30A2A14311416008C17DB /* out.h */,
41261392141B5C8D006DBF89 /* scinfo.h */,
View
@@ -1,11 +1,3 @@
-//
-// CrackApp.h
-// Clutch
-//
-// Created by Terence Tan on 7/6/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
#import <Foundation/Foundation.h>
@@ -20,9 +12,10 @@
NSString *workingDir;
}
-
-- (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);
+/*
+ TODO: Move cracking to a class
+
+- (NSString*) crack_application;
+- (NSString*) init_crack_binary;
+ */
@end
View
@@ -1,11 +1,3 @@
-//
-// CrackApp.m
-// Clutch
-//
-// Created by Terence Tan on 7/6/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
#import "CrackApp.h"
@implementation CrackApp
View
@@ -8,6 +8,7 @@
#import "out.h"
int overdrive_enabled;
+NSString *workingDir;
#define FAT_CIGAM 0xbebafeca
#define MH_MAGIC 0xfeedface
@@ -21,6 +22,7 @@ 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
75 crack.m
@@ -1,11 +1,53 @@
#import "crack.h"
#import <Foundation/Foundation.h>
+#include <pthread.h>
+
int overdrive_enabled = 0;
+NSString *workingDir = @"";
+NSString *binary_name = @"";
+NSString *ipapath = @"";
+NSString *crackerName = @"";
+
+NSMutableDictionary *infoplist;
+NSThread *zipthread;
+void zip_resources(NSString *dir, NSString *zip) {
+ NOTIFY("Compressing original app...");
+ NSString *compressionArguments = [[ClutchConfiguration getValue:@"CompressionArguments"] stringByAppendingString:@" "];
+ if (compressionArguments == nil)
+ compressionArguments = @"-0 ";
+
+ [[NSFileManager defaultManager] createSymbolicLinkAtPath:[workingDir stringByAppendingString:@"Payload"] withDestinationPath:[dir 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, 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...
+}
+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];
+ return ipapath;
+
+}
NSString * crack_application(NSString *application_basedir, NSString *basename) {
+ crackerName = [ClutchConfiguration getValue:@"CrackerName"];
VERBOSE("Creating working directory...");
- NSString *workingDir = [NSString stringWithFormat:@"%@%@/", @"/tmp/clutch_", genRandStringLength(8)];
+ 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]
@@ -14,6 +56,7 @@
return nil;
}
+
VERBOSE("Performing initial analysis...");
struct stat statbuf_info;
stat([[application_basedir stringByAppendingString:@"Info.plist"] UTF8String], &statbuf_info);
@@ -23,7 +66,7 @@
oldtimes_info.actime = ist_atime;
oldtimes_info.modtime = ist_mtime;
- NSMutableDictionary *infoplist = [NSMutableDictionary dictionaryWithContentsOfFile:[application_basedir stringByAppendingString:@"Info.plist"]];
+ infoplist = [NSMutableDictionary dictionaryWithContentsOfFile:[application_basedir stringByAppendingString:@"Info.plist"]];
if (infoplist == nil) {
printf("error: Could not open Info.plist\n");
goto fatalc;
@@ -42,8 +85,13 @@
utime([[application_basedir stringByAppendingString:@"Info.plist"] UTF8String], &oldtimes_info);
- NSString *binary_name = [infoplist objectForKey:@"CFBundleExecutable"];
-
+ binary_name = [infoplist objectForKey:@"CFBundleExecutable"];
+
+ //zip thread
+
+ [NSThread detachNewThreadSelector:@selector(zip_resources) toTarget:zipthread withObject:nil];
+
+
NSString *fbinary_path = init_crack_binary(application_basedir, basename, workingDir, infoplist);
if (fbinary_path == nil) {
printf("error: Could not crack binary\n");
@@ -128,7 +176,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");
@@ -163,20 +211,6 @@
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)
@@ -409,7 +443,8 @@
int get_local_arch() {
int i;
int len = sizeof(i);
-
+ //TheSexyPenguin likes penises
sysctlbyname("hw.cpusubtype", &i, (size_t *) &len, NULL, 0);
return i;
+
}

0 comments on commit db232b1

Please sign in to comment.