Skip to content

Commit

Permalink
Clutch 2.0 RC
Browse files Browse the repository at this point in the history
  • Loading branch information
iT0ny committed Apr 17, 2015
1 parent 665921e commit 5c5600e
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 86 deletions.
26 changes: 13 additions & 13 deletions Clutch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
324EA63E1A89260A00844540 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 324EA63D1A89260A00844540 /* MobileCoreServices.framework */; };
324EA6421A8926DC00844540 /* Application.m in Sources */ = {isa = PBXBuildFile; fileRef = 324EA6411A8926DC00844540 /* Application.m */; };
3258FD641A90AAED007C2E66 /* Device.m in Sources */ = {isa = PBXBuildFile; fileRef = 3258FD631A90AAED007C2E66 /* Device.m */; };
326ABC8A1AD2B94000B21FCC /* Framework32Dumper.m in Sources */ = {isa = PBXBuildFile; fileRef = 326ABC891AD2B94000B21FCC /* Framework32Dumper.m */; };
326ABC8A1AD2B94000B21FCC /* FrameworkLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 326ABC891AD2B94000B21FCC /* FrameworkLoader.m */; };
3274B9581ABEA6E100964049 /* ARMDumper.m in Sources */ = {isa = PBXBuildFile; fileRef = 3274B9571ABEA6E100964049 /* ARMDumper.m */; };
3274B9601ABEB00400964049 /* ARM64Dumper.m in Sources */ = {isa = PBXBuildFile; fileRef = 3274B95F1ABEB00400964049 /* ARM64Dumper.m */; };
3277BF991ACD50BD0060935A /* FrameworkDumper.m in Sources */ = {isa = PBXBuildFile; fileRef = 3277BF981ACD50BD0060935A /* FrameworkDumper.m */; };
Expand Down Expand Up @@ -64,8 +64,8 @@
324EA6471A892AAD00844540 /* FBApplicationInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBApplicationInfo.h; sourceTree = "<group>"; };
3258FD621A90AAED007C2E66 /* Device.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Device.h; sourceTree = "<group>"; };
3258FD631A90AAED007C2E66 /* Device.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Device.m; sourceTree = "<group>"; };
326ABC881AD2B94000B21FCC /* Framework32Dumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Framework32Dumper.h; sourceTree = "<group>"; };
326ABC891AD2B94000B21FCC /* Framework32Dumper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Framework32Dumper.m; sourceTree = "<group>"; };
326ABC881AD2B94000B21FCC /* FrameworkLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FrameworkLoader.h; sourceTree = "<group>"; };
326ABC891AD2B94000B21FCC /* FrameworkLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FrameworkLoader.m; sourceTree = "<group>"; };
3274B9551ABEA60500964049 /* BinaryDumpProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BinaryDumpProtocol.h; sourceTree = "<group>"; };
3274B9561ABEA6E100964049 /* ARMDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARMDumper.h; sourceTree = "<group>"; };
3274B9571ABEA6E100964049 /* ARMDumper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARMDumper.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -198,26 +198,26 @@
324EA62D1A89258000844540 /* Supporting Files */ = {
isa = PBXGroup;
children = (
ADE1ED301AD1636D00398728 /* ProgressBar.h */,
ADE1ED311AD1636D00398728 /* ProgressBar.m */,
328CCB711AD004FF00B21225 /* NSTask.h */,
328CCB3D1ACED00600B21225 /* SCInfoBuilder.h */,
328CCB3E1ACED00600B21225 /* SCInfoBuilder.m */,
328CCB3B1ACECF5800B21225 /* README.md */,
324EA6431A89270D00844540 /* Clutch.entitlements */,
32BC93F11A8F3C0B00805D14 /* mach_vm.h */,
328CCB711AD004FF00B21225 /* NSTask.h */,
ADE1ED301AD1636D00398728 /* ProgressBar.h */,
ADE1ED311AD1636D00398728 /* ProgressBar.m */,
328CCB351ACECEB500B21225 /* scinfo.h */,
328CCB361ACECEB500B21225 /* scinfo.m */,
32BC93E41A8E0E8B00805D14 /* sha1.c */,
32BC93E51A8E0E8B00805D14 /* sha1.h */,
323C86AB1AC03E3F008949F2 /* .gitignore */,
32BC93F11A8F3C0B00805D14 /* mach_vm.h */,
3282BE041A8D9A9100E5068A /* optool */,
32EFB6CD1A8A4F06005BB56C /* Zip */,
32FB77B11A89DC6600BB5ABC /* GBCLI */,
324EA6471A892AAD00844540 /* FBApplicationInfo.h */,
324EA6341A89258000844540 /* Clutch-Prefix.pch */,
324EA6431A89270D00844540 /* Clutch.entitlements */,
328359DC1ACC118D003587F3 /* NSFileHandle+Private.h */,
328359DD1ACC118D003587F3 /* NSFileHandle+Private.m */,
328CCB3B1ACECF5800B21225 /* README.md */,
323C86AB1AC03E3F008949F2 /* .gitignore */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -310,10 +310,10 @@
3274B95F1ABEB00400964049 /* ARM64Dumper.m */,
3277BF971ACD50BD0060935A /* FrameworkDumper.h */,
3277BF981ACD50BD0060935A /* FrameworkDumper.m */,
326ABC881AD2B94000B21FCC /* Framework32Dumper.h */,
326ABC891AD2B94000B21FCC /* Framework32Dumper.m */,
328CCB381ACECF4100B21225 /* Framework64Dumper.h */,
328CCB391ACECF4100B21225 /* Framework64Dumper.m */,
326ABC881AD2B94000B21FCC /* FrameworkLoader.h */,
326ABC891AD2B94000B21FCC /* FrameworkLoader.m */,
);
name = Dumpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -429,7 +429,7 @@
3282BB7C1A8C920D00E5068A /* FinalizeDumpOperation.m in Sources */,
32FB77C11A89F09300BB5ABC /* ClutchBundle.m in Sources */,
324EA6331A89258000844540 /* main.m in Sources */,
326ABC8A1AD2B94000B21FCC /* Framework32Dumper.m in Sources */,
326ABC8A1AD2B94000B21FCC /* FrameworkLoader.m in Sources */,
32FB77C41A89F13000BB5ABC /* Binary.m in Sources */,
323C86B11AC05AE4008949F2 /* Dumper.m in Sources */,
328359DE1ACC118D003587F3 /* NSFileHandle+Private.m in Sources */,
Expand Down
10 changes: 0 additions & 10 deletions Clutch/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
#import "Extension.h"
#import "Framework.h"

@class Application;

@protocol ApplicationDelegate <NSObject>

- (void)crackingProcessStarted:(Application*)app;
- (void)application:(Application *)app crackingProcessStatusChanged:(NSString *)status progress:(float)progress;
- (void)crackingProcessFinished:(Application *)app;

@end

@interface Application : ClutchBundle

@property (readonly) BOOL hasAppleWatchApp;
Expand Down
2 changes: 1 addition & 1 deletion Clutch/Application.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ - (void)dumpToDirectoryURL:(NSURL *)directoryURL onlyBinaries:(BOOL)yrn

[self prepareForDump];

// NSLog(@"SCInfo SINF for %@:\n %@",self,[SCInfoBuilder parseOriginaleSinfForBundle:self]);
NSLog(@"SCInfo SINF for %@:\n %@",self,[SCInfoBuilder parseOriginaleSinfForBundle:self]);

[[NSFileManager defaultManager]createDirectoryAtPath:_workingPath withIntermediateDirectories:YES attributes:nil error:nil];

Expand Down
8 changes: 4 additions & 4 deletions Clutch/ApplicationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#define applistCachePath @"/etc/applist-cache.clutch"
#define crackedAppPath @"/etc/cracked.clutch"
#define dumpedAppPath @"/etc/dumped.clutch"

#import <dlfcn.h>
#import "ApplicationsManager.h"
Expand Down Expand Up @@ -128,10 +128,10 @@ - (NSDictionary *)installedApps
return [self _allApplications];
}

- (NSArray *)crackedApps
- (NSArray *)dumpedApps
{
NSString *crackedPath = @""; //[NSString stringWithFormat:@"%@/", [[Preferences sharedInstance] ipaDirectory]];
NSArray *array=[[NSArray alloc]initWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:crackedPath error:nil]];
NSString *dumpedPath = @""; //[NSString stringWithFormat:@"%@/", [[Preferences sharedInstance] ipaDirectory]];
NSArray *array=[[NSArray alloc]initWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:dumpedPath error:nil]];

NSMutableArray *paths=[NSMutableArray new];

Expand Down
2 changes: 1 addition & 1 deletion Clutch/Clutch-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import <Foundation/Foundation.h>
#endif

#define CLUTCH_VERSION @"2.0 PB4"
#define CLUTCH_VERSION @"2.0 RC"

#ifdef DEBUG
# define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // shortened path of __FILE__ is there is one
Expand Down
2 changes: 1 addition & 1 deletion Clutch/Device.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Device.h
// CrackAddict
// Clutch
//
// Created by Zorro on 14/11/13.
// Copyright (c) 2013 AppAddict. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Clutch/Device.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Device.m
// CrackAddict
// Clutch
//
// Created by Zorro on 14/11/13.
// Copyright (c) 2013 AppAddict. All rights reserved.
Expand Down
6 changes: 3 additions & 3 deletions Clutch/FinalizeDumpOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ - (void)main {
// remove .ipa if failed
[[NSFileManager defaultManager]removeItemAtPath:[_application.workingPath stringByAppendingPathComponent:_zipFilename] error:nil];
}else {
[[NSFileManager defaultManager] createDirectoryAtPath:@"/private/var/mobile/Documents/Cracked" withIntermediateDirectories:YES attributes:nil error:nil];
[[NSFileManager defaultManager]moveItemAtPath:[_application.workingPath stringByAppendingPathComponent:_zipFilename] toPath:[@"/private/var/mobile/Documents/Cracked" stringByAppendingPathComponent:_zipFilename] error:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:@"/private/var/mobile/Documents/Dumped" withIntermediateDirectories:YES attributes:nil error:nil];
[[NSFileManager defaultManager]moveItemAtPath:[_application.workingPath stringByAppendingPathComponent:_zipFilename] toPath:[@"/private/var/mobile/Documents/Dumped" stringByAppendingPathComponent:_zipFilename] error:nil];
}

gbprintln(@"%@: %@",status?@"DONE":@"FAILED",status?[@"/private/var/mobile/Documents/Cracked" stringByAppendingPathComponent:_zipFilename]:_application);
gbprintln(@"%@: %@",status?@"DONE":@"FAILED",status?[@"/private/var/mobile/Documents/Dumped" stringByAppendingPathComponent:_zipFilename]:_application);

// Do the main work of the operation here.
[self completeOperation];
Expand Down
67 changes: 37 additions & 30 deletions Clutch/Framework64Dumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@

#import "Framework64Dumper.h"
#import "Device.h"
#import <dlfcn.h>
#import <mach-o/fat.h>
#import <mach-o/loader.h>
#import <mach-o/dyld.h>
#import <mach/mach.h>
#import <mach/mach_traps.h>
#import <mach/mach_init.h>
#import <mach-o/dyld_images.h>
#import <spawn.h>

@implementation Framework64Dumper

Expand Down Expand Up @@ -134,34 +127,45 @@ - (BOOL)dumpBinary
DumperLog(@"pages == 0");
return NO;
}

[newFileHandle closeFile];

[newFileHandle seekToFileOffset:_thinHeader.offset];
[self.originalFileHandle closeFile];

void * handle = dlopen(swappedBinaryPath.UTF8String, RTLD_LAZY);
extern char **environ;
posix_spawnattr_t attr;

uint32_t imageCount = _dyld_image_count();
uint32_t dyldIndex = -1;
for (uint32_t idx = 0; idx < imageCount; idx++) {
NSString *dyldPath = [NSString stringWithUTF8String:_dyld_get_image_name(idx)];

if ([swappedBinaryPath.lastPathComponent isEqualToString:dyldPath.lastPathComponent]) {
dyldIndex = idx;
break;
}
}
pid_t pid;

if (dyldIndex == -1) {
DumperLog(@"dlopen error: %s",dlerror());
dlclose(handle);
return NO;
}
char *argv[] = {[[NSProcessInfo processInfo].arguments[0] UTF8String],
"-f",
swappedBinaryPath.UTF8String,
binaryDumpPath.UTF8String,
[NSString stringWithFormat:@"%u",(crypt.cryptsize + crypt.cryptoff)].UTF8String,
[NSString stringWithFormat:@"%u",pages].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.header.ncmds].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.offset].UTF8String,
NULL};

posix_spawnattr_init (&attr);

size_t ocount = 0;

intptr_t dyldPointer = _dyld_get_image_vmaddr_slide(dyldIndex);
cpu_type_t cpu_type = CPU_TYPE_ARM64;

BOOL dumpResult = [self _dumpToFileHandle:newFileHandle withEncryptionInfoCommand:(crypt.cryptsize + crypt.cryptoff) pages:pages fromPort:mach_task_self() pid:[NSProcessInfo processInfo].processIdentifier aslrSlide:dyldPointer];
posix_spawnattr_setbinpref_np (&attr, 1, &cpu_type, &ocount);

if (dlclose(handle)) {
DumperLog(@"dlclose error: %s",dlerror());
int dumpResult = posix_spawnp(&pid, argv[0], NULL, &attr, argv, environ);

if (dumpResult == 0) {
DumperDebugLog(@"Child pid: %i", pid);
if (waitpid(pid, &dumpResult, 0) != -1) {
DumperDebugLog(@"Child exited with status %i", dumpResult);
} else {
perror("waitpid");
}
} else {
DumperDebugLog(@"posix_spawn: %s", strerror(dumpResult));
}

if (![swappedBinaryPath isEqualToString:_originalBinary.binaryPath])
Expand All @@ -173,7 +177,10 @@ - (BOOL)dumpBinary
if (![newSupf isEqualToString:_originalBinary.supfPath])
[[NSFileManager defaultManager]removeItemAtPath:newSupf error:nil];

return dumpResult;
if (dumpResult == 0)
return YES;

return NO;
}

@end
8 changes: 0 additions & 8 deletions Clutch/FrameworkDumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

#import "FrameworkDumper.h"
#import "Device.h"
#import <dlfcn.h>
#import <mach-o/fat.h>
#import <mach-o/loader.h>
#import <mach-o/dyld.h>
#import <mach/mach.h>
#import <mach/mach_traps.h>
#import <mach/mach_init.h>
#import <mach-o/dyld_images.h>
#import <spawn.h>

@implementation FrameworkDumper
Expand Down
4 changes: 2 additions & 2 deletions Clutch/Framework32Dumper.h → Clutch/FrameworkLoader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Framework32Dumper.h
// FrameworkLoader.h
// Clutch
//
// Created by Anton Titkov on 06.04.15.
Expand All @@ -8,7 +8,7 @@

#import "Dumper.h"

@interface Framework32Dumper : Dumper
@interface FrameworkLoader : Dumper

@property (assign) uint32_t ncmds;
@property (assign) uint32_t offset;
Expand Down
19 changes: 14 additions & 5 deletions Clutch/Framework32Dumper.m → Clutch/FrameworkLoader.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// Framework32Dumper.m
// FrameworkLoader.m
// Clutch
//
// Created by Anton Titkov on 06.04.15.
//
//

#import "Framework32Dumper.h"
#import "FrameworkLoader.h"
#import "Device.h"
#import <dlfcn.h>
#import <mach-o/fat.h>
Expand All @@ -17,11 +17,17 @@
#import <mach/mach_init.h>
#import <mach-o/dyld_images.h>

@implementation Framework32Dumper
@interface FrameworkLoader ()
{
uint32_t _dyldImageIndex;
}
@end

@implementation FrameworkLoader

- (cpu_type_t)supportedCPUType
{
return CPU_TYPE_ARM;
return CPU_TYPE_ARM | CPU_TYPE_ARM64;
}

- (BOOL)dumpBinary {
Expand Down Expand Up @@ -53,6 +59,8 @@ - (BOOL)dumpBinary {
return NO;
}

_dyldImageIndex = dyldIndex;

intptr_t dyldPointer = _dyld_get_image_vmaddr_slide(dyldIndex);

BOOL dumpResult = [self _dumpToFileHandle:newFileHandle withEncryptionInfoCommand:self.encryptionInfoCommand pages:self.pages fromPort:mach_task_self() pid:[NSProcessInfo processInfo].processIdentifier aslrSlide:dyldPointer];
Expand All @@ -66,8 +74,9 @@ - (BOOL)_dumpToFileHandle:(NSFileHandle *)fileHandle withEncryptionInfoCommand:(
{
void *checksum = malloc(pages * 20); // 160 bits for each hash (SHA1)

const struct mach_header *image_header = _dyld_get_image_header(_dyldImageIndex);

uint32_t headerProgress = sizeof(struct mach_header);
uint32_t headerProgress = sizeof(image_header);

uint32_t i_lcmd = 0;
kern_return_t err;
Expand Down
4 changes: 3 additions & 1 deletion Clutch/ZipOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ - (void)main {
}

if (!_application.parentBundle && [[NSFileManager defaultManager]fileExistsAtPath:[_application.bundleContainerURL URLByAppendingPathComponent:@"iTunesMetadata.plist" isDirectory:NO].path]) {
[_archive addFileToZip:[_application.bundleContainerURL URLByAppendingPathComponent:@"iTunesMetadata.plist" isDirectory:NO].path newname:@"iTunesMetadata.plist"];

// skip iTunesMetadata
// [_archive addFileToZip:[_application.bundleContainerURL URLByAppendingPathComponent:@"iTunesMetadata.plist" isDirectory:NO].path newname:@"iTunesMetadata.plist"];
}

NSDirectoryEnumerator *dirEnumerator = [NSFileManager.defaultManager enumeratorAtURL:_application.bundleURL includingPropertiesForKeys:@[NSURLNameKey,NSURLIsDirectoryKey] options:nil errorHandler:^BOOL(NSURL *url, NSError *error) {
Expand Down
4 changes: 2 additions & 2 deletions Clutch/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "GBCli.h"
#import "ApplicationsManager.h"
#import "sha1.h"
#import "Framework32Dumper.h"
#import "FrameworkLoader.h"

int main (int argc, const char * argv[])
{
Expand Down Expand Up @@ -83,7 +83,7 @@ int main (int argc, const char * argv[])

if (([arguments[1]isEqualToString:@"--fmwk-dump"]||[arguments[1]isEqualToString:@"-f"]) && (arguments.count == 8)) {

Framework32Dumper *fmwk = [Framework32Dumper new];
FrameworkLoader *fmwk = [FrameworkLoader new];

fmwk.binPath = arguments[2];
fmwk.dumpPath = arguments[3];
Expand Down
2 changes: 1 addition & 1 deletion Clutch/scinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
void *create_atom(char *name, int len, void *content);
void *coalesced_atom(int amount, uint32_t name, ...);
void *combine_atoms(char *name, int amount, ...);
void *generate_sinf(int appid, char *cracker_name, int vendorID);
void *generate_sinf(int appid, char *person_name, int vendorID);
void *generate_supp(uint32_t *suppsize);
Loading

0 comments on commit 5c5600e

Please sign in to comment.