Skip to content

Commit

Permalink
managed codesigning time to avoid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iMokhles authored and iMokhles committed Jun 3, 2016
1 parent fbf8857 commit a01d8e2
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
Binary file modified precompiled/IMSign.app/Contents/MacOS/IMSign
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 12 additions & 12 deletions precompiled/IMSign.app/Contents/_CodeSignature/CodeResources
Expand Up @@ -12,7 +12,7 @@
<dict>
<key>hash</key>
<data>
MymdADPnr5e1gXAU7caTlgST9VU=
84cYezSWEM4pFffPS/nLOAQ7Nxw=
</data>
<key>optional</key>
<true/>
Expand All @@ -21,7 +21,7 @@
<dict>
<key>hash</key>
<data>
JbaUCCJ/Q7/EJruGS4P0OsA/yrU=
7J8K/d7pey96heik80JpyUHXohI=
</data>
<key>optional</key>
<true/>
Expand All @@ -30,7 +30,7 @@
<dict>
<key>hash</key>
<data>
gRIvvSMd2PwXfp1LyB6lCMZ0Zuw=
p+FIhoxut/c6SHaRioYL9SAU+5Y=
</data>
<key>optional</key>
<true/>
Expand All @@ -39,7 +39,7 @@
<dict>
<key>hash</key>
<data>
UcYuPII8BgWxCuDhcvEXOA7pIlg=
wPZW8TrHVTAwRFvYBmuAKhYv16Y=
</data>
<key>optional</key>
<true/>
Expand All @@ -66,11 +66,11 @@
<dict>
<key>hash</key>
<data>
MymdADPnr5e1gXAU7caTlgST9VU=
84cYezSWEM4pFffPS/nLOAQ7Nxw=
</data>
<key>hash2</key>
<data>
+/eoBLJkFKWi8oo07SbTLWC1IpBJEuRdGNxyQ1zVQog=
kdQpZpx97FyCFeZUmgQxOras4MDrhxgfiBl0g/dzYgc=
</data>
<key>optional</key>
<true/>
Expand All @@ -79,11 +79,11 @@
<dict>
<key>hash</key>
<data>
JbaUCCJ/Q7/EJruGS4P0OsA/yrU=
7J8K/d7pey96heik80JpyUHXohI=
</data>
<key>hash2</key>
<data>
fpqeOlN9QP7v1Qq529kkBWtIZkyLJ5N4H9vnY1e2fxc=
Fz4uDm+/aqvsMldUmVrB5mTrRt+oPx0cHObIJPRk6MY=
</data>
<key>optional</key>
<true/>
Expand All @@ -92,11 +92,11 @@
<dict>
<key>hash</key>
<data>
gRIvvSMd2PwXfp1LyB6lCMZ0Zuw=
p+FIhoxut/c6SHaRioYL9SAU+5Y=
</data>
<key>hash2</key>
<data>
Z86V5ljx7AzICiVdcRo6baNlTl27Uzg6H0RxU7fmpSg=
TiDIfTefAv8yJcGUqJnZdfmWgZj97FiMOt3tALILhrY=
</data>
<key>optional</key>
<true/>
Expand All @@ -105,11 +105,11 @@
<dict>
<key>hash</key>
<data>
UcYuPII8BgWxCuDhcvEXOA7pIlg=
wPZW8TrHVTAwRFvYBmuAKhYv16Y=
</data>
<key>hash2</key>
<data>
BY4lvdjxlXwzPMY7vaiA36NgRW2cp+pEppdSnYtibWM=
Y/xBYp/TQd2lJAO4wFzssQpJ477JRSG8JL/nU4DMgIM=
</data>
<key>optional</key>
<true/>
Expand Down
87 changes: 73 additions & 14 deletions source code/IMSign/ViewController.m
Expand Up @@ -133,8 +133,14 @@ - (void)startProcesses {

[self excuteCommandWithLaunchPath:@"/usr/bin/unzip" andArguments:@[@"-oqq", _ipaFileField.stringValue, @"-d", [self extractedPath]] andCompleteBlock:^(BOOL exited) {
if (exited) {
[self deleteFileAtPath:[self appCodeSignaturePath]];
[self checkIfTheAppAlreadyTweakedWithBlock:^(BOOL isTweaked, NSArray *allDylibs) {
if (isTweaked && allDylibs.count > 0) {
// if (isTweak) {
// [self startAlreadyTweakedProcess];
// } else {
// [self startNotTweakedProcess];
// }
[self startAlreadyTweakedProcess];
} else if (!isTweaked && allDylibs.count == 0) {
[self startNotTweakedProcess];
Expand All @@ -154,7 +160,12 @@ - (void)startProcesses {
#pragma mark - App Tweaked Already
- (void)startAlreadyTweakedProcess {
isAppAlreadyTweaked = YES;
[self showAlertWithMessage:@"We don't support tweaking already tweaked app ( for now )"];
if (isTweak) {
[self showAlertWithMessage:@"We don't support tweaking already tweaked app ( for now )"];
} else {
[self startJustResignProcess];
}

}

/************
Expand Down Expand Up @@ -274,6 +285,21 @@ - (void)configureAppInfoPlistFile {
}];
}
}];
} else {
[self excuteCommandWithLaunchPath:@"/usr/libexec/PlistBuddy" andArguments:@[@"-c", [NSString stringWithFormat:@"Set :CFBundleDisplayName %@", _appNameField.stringValue], [[self extractedAppBundlePath] stringByAppendingPathComponent:@"Info.plist"]] andCompleteBlock:^(BOOL exited) {
if (exited) {
[self excuteCommandWithLaunchPath:@"/usr/libexec/PlistBuddy" andArguments:@[@"-c", [NSString stringWithFormat:@"Set :CFBundleIdentifier %@", _appIDField.stringValue], [[self extractedAppBundlePath] stringByAppendingPathComponent:@"Info.plist"]] andCompleteBlock:^(BOOL exited) {
if (exited) {
if (isTweak) {
[self checkTweakAndLoadThemCorrectly];
} else {
[self startEntitlementsProcess];
}

}
}];
}
}];
}
}

Expand Down Expand Up @@ -414,12 +440,8 @@ - (void)startEntitlementsProcess {
NSString *entitlementsCommand = [NSString stringWithFormat:@"/usr/libexec/PlistBuddy -c \"Print Entitlements\" \"%@\" -x > \"%@\"", [self entitlementsTempPlist], [self appEntitlementsFile]];
system([entitlementsCommand UTF8String]);
[self updateProgress:47];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// start siging all dylibs process
[self startSignAllDylibProcess];
});
// start siging all dylibs process
[self startSignAllDylibProcess];

});
}
Expand All @@ -434,7 +456,12 @@ - (void)startSignAllDylibProcess {
if (index == [allDylibs count]-1) {
[self updateProgress:53];
// sign all plugins
[self signAllAppPlugins];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signAllAppPlugins];
});
}
NSString *dylibFullPath = [[self extractedAppBundlePath] stringByAppendingPathComponent:[allDylibs objectAtIndex:index]];
[self excuteCommandWithLaunchPath:@"/usr/bin/codesign" andArguments:@[@"-fs", certificateName, dylibFullPath] andCompleteBlock:^(BOOL exited) {
Expand All @@ -445,7 +472,13 @@ - (void)startSignAllDylibProcess {
} else if (!isTweaked && allDylibs.count == 0) {
[self updateProgress:53];
// sign all plugins
[self signAllAppPlugins];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signAllAppPlugins];
});

}
}];
}
Expand All @@ -455,10 +488,21 @@ - (void)signAllAppPlugins {
[self updateProgress:57];
// remove it for now
[self deleteFileAtPath:[self appPluginPath]];
[self signAllAppFrameworks];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signAllAppFrameworks];
});
} else {
[self updateProgress:57];
[self signAllAppFrameworks];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signAllAppFrameworks];
});

}
}

Expand All @@ -470,7 +514,12 @@ - (void)signAllAppFrameworks {
if (index == [frameworksContents count]-1) {
[self updateProgress:60];
// sign all plugins
[self signTheMainAppNow];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signTheMainAppNow];
});
}
NSString *frameworkFullPath = [[self extractedAppBundlePath] stringByAppendingPathComponent:[frameworksContents objectAtIndex:index]];
[self excuteCommandWithLaunchPath:@"/usr/bin/codesign" andArguments:@[@"-fs", certificateName, frameworkFullPath] andCompleteBlock:^(BOOL exited) {
Expand All @@ -480,7 +529,13 @@ - (void)signAllAppFrameworks {
} else {
[self updateProgress:60];
// sign all plugins
[self signTheMainAppNow];
double delayInSeconds = 1.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// exited
[self signTheMainAppNow];
});

}
}

Expand All @@ -491,7 +546,7 @@ - (void)signTheMainAppNow {
NSString *appBinary = [[self extractedAppBundlePath] stringByAppendingPathComponent:[self appInfoPlistDictionary][@"CFBundleExecutable"]];
[self excuteCommandWithLaunchPath:@"/bin/cp" andArguments:@[[NSString stringWithFormat:@"%@", _appProfileField.stringValue], [NSString stringWithFormat:@"%@/embedded.mobileprovision", [self extractedAppBundlePath]]] andCompleteBlock:^(BOOL exited) {
if (exited) {
[self excuteCommandWithLaunchPath:@"/usr/bin/codesign" andArguments:@[@"-fs", certificateName, @"--entitlements", [self appEntitlementsFile], @"--timestamp=none", appBinary] andCompleteBlock:^(BOOL exited) {
[self excuteCommandWithLaunchPath:@"/usr/bin/codesign" andArguments:@[@"-fs", certificateName, @"--entitlements", [self appEntitlementsFile], @"--timestamp=none", [self extractedAppBundlePath]] andCompleteBlock:^(BOOL exited) {
if (exited) {
// create ipa
[self updateProgress:97];
Expand Down Expand Up @@ -733,6 +788,10 @@ - (NSString *)appFrameworksPath {
return [[self extractedAppBundlePath] stringByAppendingPathComponent:@"Frameworks"];
}

- (NSString *)appCodeSignaturePath {
return [[self extractedAppBundlePath] stringByAppendingPathComponent:@"_CodeSignature"];
}

- (NSDictionary *)appInfoPlistDictionary {
NSDictionary *appInfoDict = [NSDictionary dictionaryWithContentsOfFile:[[self extractedAppBundlePath] stringByAppendingPathComponent:@"Info.plist"]];
return appInfoDict;
Expand Down

0 comments on commit a01d8e2

Please sign in to comment.