Skip to content

Commit

Permalink
Clutch 2.0 RC2
Browse files Browse the repository at this point in the history
  • Loading branch information
iT0ny committed Apr 20, 2015
1 parent 5c5600e commit 25755c3
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Clutch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
324EA6421A8926DC00844540 /* Application.m in Sources */ = {isa = PBXBuildFile; fileRef = 324EA6411A8926DC00844540 /* Application.m */; };
3258FD641A90AAED007C2E66 /* Device.m in Sources */ = {isa = PBXBuildFile; fileRef = 3258FD631A90AAED007C2E66 /* Device.m */; };
326ABC8A1AD2B94000B21FCC /* FrameworkLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 326ABC891AD2B94000B21FCC /* FrameworkLoader.m */; };
326E8D2E1AE53DED00DCDD64 /* NSBundle+Clutch.m in Sources */ = {isa = PBXBuildFile; fileRef = 326E8D2D1AE53DED00DCDD64 /* NSBundle+Clutch.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 @@ -66,6 +67,8 @@
3258FD631A90AAED007C2E66 /* Device.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Device.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>"; };
326E8D2C1AE53DED00DCDD64 /* NSBundle+Clutch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+Clutch.h"; sourceTree = "<group>"; };
326E8D2D1AE53DED00DCDD64 /* NSBundle+Clutch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+Clutch.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 @@ -216,6 +219,8 @@
324EA6341A89258000844540 /* Clutch-Prefix.pch */,
328359DC1ACC118D003587F3 /* NSFileHandle+Private.h */,
328359DD1ACC118D003587F3 /* NSFileHandle+Private.m */,
326E8D2C1AE53DED00DCDD64 /* NSBundle+Clutch.h */,
326E8D2D1AE53DED00DCDD64 /* NSBundle+Clutch.m */,
328CCB3B1ACECF5800B21225 /* README.md */,
323C86AB1AC03E3F008949F2 /* .gitignore */,
);
Expand Down Expand Up @@ -404,6 +409,7 @@
3282BE0E1A8D9ACD00E5068A /* optool-operations.m in Sources */,
32BC93F41A8F726800805D14 /* ASLRDisabler.m in Sources */,
32FB77BC1A89DC9200BB5ABC /* GBOptionsHelper.m in Sources */,
326E8D2E1AE53DED00DCDD64 /* NSBundle+Clutch.m in Sources */,
32EFB6F81A8AC2AF005BB56C /* BundleDumpOperation.m in Sources */,
32EFB6EF1A8A4FEF005BB56C /* ioapi.c in Sources */,
32FB77A51A89BEAD00BB5ABC /* Framework.m in Sources */,
Expand Down Expand Up @@ -504,6 +510,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = "${PROJECT_DIR}/Clutch/Clutch.entitlements";
CODE_SIGN_IDENTITY = "-";
CREATE_INFOPLIST_SECTION_IN_BINARY = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
Expand Down Expand Up @@ -536,6 +543,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_ENTITLEMENTS = "${PROJECT_DIR}/Clutch/Clutch.entitlements";
CODE_SIGN_IDENTITY = "-";
CREATE_INFOPLIST_SECTION_IN_BINARY = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(SDKROOT)$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
Expand Down
7 changes: 7 additions & 0 deletions Clutch/Binary.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ - (NSString *)workingPath
- (instancetype)initWithBundle:(ClutchBundle *)path
{
if (self = [super init]) {

_bundle = path;

// perm. fix

NSDictionary *ownershipInfo = @{NSFileOwnerAccountName:@"mobile", NSFileGroupOwnerAccountName:@"mobile"};

[[NSFileManager defaultManager] setAttributes:ownershipInfo ofItemAtPath:self.binaryPath error:nil];

_sinfPath = [_bundle pathForResource:_bundle.executablePath.lastPathComponent ofType:@"sinf" inDirectory:@"SC_Info"];
_supfPath = [_bundle pathForResource:_bundle.executablePath.lastPathComponent ofType:@"supf" inDirectory:@"SC_Info"];
_suppPath = [_bundle pathForResource:_bundle.executablePath.lastPathComponent ofType:@"supp" inDirectory:@"SC_Info"];
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 RC"
#define CLUTCH_VERSION @"2.0 RC2"

#ifdef DEBUG
# define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) // shortened path of __FILE__ is there is one
Expand Down
5 changes: 4 additions & 1 deletion Clutch/ClutchBundle.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ - (void)prepareForDump {
}

[data writeToFile:self.executable.binaryPath atomically:YES];


NSDictionary *ownershipInfo = @{NSFileOwnerAccountName:@"mobile", NSFileGroupOwnerAccountName:@"mobile"};

[[NSFileManager defaultManager] setAttributes:ownershipInfo ofItemAtPath:self.executable.binaryPath error:nil];

}

Expand Down
1 change: 1 addition & 0 deletions Clutch/Dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "Binary.h"
#import "ASLRDisabler.h"
#import "mach_vm.h"
#import "ClutchBundle.h"

@interface Dumper : NSObject
{
Expand Down
5 changes: 5 additions & 0 deletions Clutch/Framework64Dumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ - (cpu_type_t)supportedCPUType

- (BOOL)dumpBinary
{

ClutchBundle *bundle = [_originalBinary valueForKey:@"_bundle"];


NSString *binaryDumpPath = [_originalBinary.workingPath stringByAppendingPathComponent:_originalBinary.binaryPath.lastPathComponent];

NSString* swappedBinaryPath = _originalBinary.binaryPath, *newSinf = _originalBinary.sinfPath, *newSupp = _originalBinary.suppPath, *newSupf = _originalBinary.supfPath; // default values if we dont need to swap archs
Expand Down Expand Up @@ -145,6 +149,7 @@ - (BOOL)dumpBinary
[NSString stringWithFormat:@"%u",pages].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.header.ncmds].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.offset].UTF8String,
bundle.parentBundle.bundleIdentifier.UTF8String,
NULL};

posix_spawnattr_init (&attr);
Expand Down
3 changes: 3 additions & 0 deletions Clutch/FrameworkDumper.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ - (cpu_type_t)supportedCPUType
- (BOOL)dumpBinary
{

ClutchBundle *bundle = [_originalBinary valueForKey:@"_bundle"];

NSString *binaryDumpPath = [_originalBinary.workingPath stringByAppendingPathComponent:_originalBinary.binaryPath.lastPathComponent];

NSString* swappedBinaryPath = _originalBinary.binaryPath, *newSinf = _originalBinary.sinfPath, *newSupp = _originalBinary.suppPath; // default values if we dont need to swap archs
Expand Down Expand Up @@ -146,6 +148,7 @@ - (BOOL)dumpBinary
[NSString stringWithFormat:@"%u",pages].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.header.ncmds].UTF8String,
[NSString stringWithFormat:@"%u",_thinHeader.offset].UTF8String,
bundle.parentBundle.bundleIdentifier.UTF8String,
NULL};

posix_spawnattr_init (&attr);
Expand Down
1 change: 1 addition & 0 deletions Clutch/FrameworkLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (assign) uint32_t encryptionInfoCommand;
@property (nonatomic) NSString *binPath;
@property (nonatomic) NSString *dumpPath;
@property (nonatomic) NSString *bID;

- (cpu_type_t)supportedCPUType;

Expand Down
12 changes: 12 additions & 0 deletions Clutch/FrameworkLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//


#import "FrameworkLoader.h"
#import "Device.h"
#import <dlfcn.h>
Expand All @@ -16,6 +17,9 @@
#import <mach/mach_traps.h>
#import <mach/mach_init.h>
#import <mach-o/dyld_images.h>
#import "NSBundle+Clutch.h"

@import ObjectiveC.runtime;

@interface FrameworkLoader ()
{
Expand All @@ -36,6 +40,14 @@ - (BOOL)dumpBinary {

NSString* swappedBinaryPath = self.binPath; // default values if we dont need to swap archs

NSDictionary *_infoPlist = [NSDictionary dictionaryWithContentsOfFile:[self.binPath.stringByDeletingLastPathComponent stringByAppendingPathComponent:@"Info.plist"]];

[NSBundle mainBundle].clutchBID = self.bID;//_infoPlist[@"CFBundleIdentifier"];


NSLog(@"%@ %@",_infoPlist,[NSBundle mainBundle].bundleIdentifier);


NSFileHandle *newFileHandle = [[NSFileHandle alloc]initWithFileDescriptor:fileno(fopen(binaryDumpPath.UTF8String, "r+"))];

[newFileHandle seekToFileOffset:self.offset];
Expand Down
17 changes: 17 additions & 0 deletions Clutch/NSBundle+Clutch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// NSBundle+Clutch.h
// Clutch
//
// Created by Anton Titkov on 20.04.15.
//
//

#import <Foundation/Foundation.h>

@interface NSBundle (Clutch)

@property NSString *clutchBID;

- (NSString *)bundleIdentifier;

@end
40 changes: 40 additions & 0 deletions Clutch/NSBundle+Clutch.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// NSBundle+Clutch.m
// Clutch
//
// Created by Anton Titkov on 20.04.15.
//
//

#import "NSBundle+Clutch.h"

@import ObjectiveC.runtime;

@implementation NSBundle (Clutch)

static NSString* _bID;

- (NSString *)clutchBID
{
NSString *value = objc_getAssociatedObject(self, &_bID);
return value;
}

- (void)setClutchBID:(NSString *)clutchBID
{
[self willChangeValueForKey:@"clutchBID"];
objc_setAssociatedObject(self, &_bID, clutchBID, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self didChangeValueForKey:@"clutchBID"];
}

- (NSString *)bundleIdentifier {

if ([self.bundlePath isEqualToString:[NSBundle mainBundle].bundlePath]) {

return self.clutchBID;
}

return self.infoDictionary[@"CFBundleIdentifier"];
}

@end
8 changes: 5 additions & 3 deletions Clutch/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

int main (int argc, const char * argv[])
{


@autoreleasepool
{
// yo
if (SYSTEM_VERSION_LESS_THAN(NSFoundationVersionNumber_iOS_6_0)) {

gbprintln(@"You need iOS 6.0+ to use Clutch 2");
gbprintln(@"You need iOS 6.0+ to use Clutch %@",CLUTCH_VERSION);

return 0;
}
Expand Down Expand Up @@ -81,7 +82,7 @@ int main (int argc, const char * argv[])

NSArray *arguments = [NSProcessInfo processInfo].arguments;

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

FrameworkLoader *fmwk = [FrameworkLoader new];

Expand All @@ -91,7 +92,8 @@ int main (int argc, const char * argv[])
fmwk.pages = [arguments[5]intValue];
fmwk.ncmds = [arguments[6]intValue];
fmwk.offset = [arguments[7]intValue];

fmwk.bID = arguments[8];

BOOL result = [fmwk dumpBinary];

if (result) {
Expand Down

0 comments on commit 25755c3

Please sign in to comment.