forked from kpwn/uikittools-ng
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from absidue/master
Add options, help and ability to open bundle ids to uiopen
- Loading branch information
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,79 @@ | ||
#include <stdio.h> | ||
#import <getopt.h> | ||
#include <dlfcn.h> | ||
#include <Foundation/Foundation.h> | ||
|
||
@interface LSApplicationWorkspace : NSObject | ||
+ (id)defaultWorkspace; | ||
- (BOOL)openSensitiveURL:(NSURL *)url withOptions:(NSDictionary *)options; | ||
- (BOOL)openApplicationWithBundleID:(NSString *)bundleId; | ||
@end | ||
|
||
void help(char *name) { | ||
printf( | ||
"Usage: %s [OPTION...]\n" | ||
"Open URLs and open iOS applications by bundle ID\n\n" | ||
|
||
" <URL> Open the specified URL\n" | ||
" (replicates the old uiopen behavior)\n" | ||
" --url <URL> Open the specified URL\n" | ||
" --bundleid <id> Open iOS application with the\n" | ||
" specified bundle id.\n" | ||
" --help Give this help list.\n", name); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc < 2) { | ||
fprintf(stderr, "Usage: %s url\n", argv[0]); | ||
char *url = NULL; | ||
char *bundleId = NULL; | ||
int showhelp = 0; | ||
|
||
struct option longOptions[] = { | ||
{ "url" , required_argument, 0, 'u'}, | ||
{ "bundleid", required_argument, 0, 'b'}, | ||
{ "help", no_argument, 0, 'h' }, | ||
{ NULL, 0, NULL, 0 } | ||
}; | ||
|
||
int index = 0, code = 0; | ||
|
||
int opterr = 0; // silence getopt errors, allow us to replicate old behaviour | ||
|
||
while ((code = getopt_long(argc, argv, "u:b:h", longOptions, &index)) != -1) { | ||
switch (code) { | ||
case 'u': | ||
url = strdup(optarg); | ||
break; | ||
case 'b': | ||
bundleId = strdup(optarg); | ||
break; | ||
case 'h': | ||
showhelp = 1; | ||
break; | ||
} | ||
} | ||
|
||
if (argc == 1) { | ||
help(argv[0]); | ||
return 1; | ||
} | ||
|
||
NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:argv[1]]]; | ||
// replicate old behaviour | ||
if (!url && !bundleId && !showhelp) { | ||
url = strdup(argv[1]); | ||
} | ||
|
||
void *fbs = dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_NOW); | ||
NSString * __strong *FBSOpenApplicationOptionKeyUnlockDevice = (NSString *__strong *)dlsym(fbs, "FBSOpenApplicationOptionKeyUnlockDevice"); | ||
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:url withOptions:@{*FBSOpenApplicationOptionKeyUnlockDevice:@YES}]; | ||
if (showhelp == 1) { | ||
help(argv[0]); | ||
} | ||
else if (url) { | ||
NSURL *urlObj = [NSURL URLWithString:[NSString stringWithUTF8String:url]]; | ||
|
||
void *fbs = dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_NOW); | ||
NSString *__strong *FBSOpenApplicationOptionKeyUnlockDevice = (NSString *__strong *)dlsym(fbs, "FBSOpenApplicationOptionKeyUnlockDevice"); | ||
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:urlObj withOptions:@{*FBSOpenApplicationOptionKeyUnlockDevice:@YES}]; | ||
} | ||
else if (bundleId) { | ||
[[LSApplicationWorkspace defaultWorkspace] openApplicationWithBundleID:[NSString stringWithUTF8String:bundleId]]; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters