[AltServer] Fixes “SDK does not contain libarclite” error when archiving

This commit is contained in:
Riley Testut
2023-09-08 14:38:35 -05:00
parent 61f2347ece
commit 6af7651a25
12 changed files with 176 additions and 164 deletions

View File

@@ -1,8 +1,10 @@
# STPrivilegedTask - Objective C class
# STPrivilegedTask - Objective-C class
An NSTask-like wrapper around [AuthorizationExecuteWithPrivileges()](https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/#//apple_ref/c/func/AuthorizationExecuteWithPrivileges) in the Security API to run shell commands with root privileges in Mac OS X.
An NSTask-like wrapper class around [AuthorizationExecuteWithPrivileges()](https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/#//apple_ref/c/func/AuthorizationExecuteWithPrivileges)
in the macOS Security API to run shell commands with root privileges.
STPrivilegedTask was created a long time ago. It has now been updated to support ARC and is available via <a href="https://cocoapods.org">CocoaPods</a>.
STPrivilegedTask was created a long time ago. It has been updated over the years to work with the latest
versions of macOS and is available via [CocoaPods](https://cocoapods.org).
## Examples
@@ -10,7 +12,7 @@ STPrivilegedTask was created a long time ago. It has now been updated to support
```objective-c
// Create task
STPrivilegedTask *privilegedTask = [[STPrivilegedTask alloc] init];
STPrivilegedTask *privilegedTask = [STPrivilegedTask new];
[privilegedTask setLaunchPath:@"/usr/bin/touch"];
[privilegedTask setArguments:@[@"/etc/my_test_file"]];
@@ -18,7 +20,7 @@ STPrivilegedTask *privilegedTask = [[STPrivilegedTask alloc] init];
// NSString *path = [[NSBundle mainBundle] resourcePath];
// [privilegedTask setCurrentDirectoryPath:path];
// Launch it, user is prompted for password
// Launch it, user is prompted for password (blocking)
OSStatus err = [privilegedTask launch];
if (err == errAuthorizationSuccess) {
NSLog(@"Task successfully launched");
@@ -30,7 +32,8 @@ else {
NSLog(@"Something went wrong");
}
```
See [Authorization.h](http://www.opensource.apple.com/source/libsecurity_authorization/libsecurity_authorization-36329/lib/Authorization.h) for a list of possible error codes.
See [Authorization.h](http://www.opensource.apple.com/source/libsecurity_authorization/libsecurity_authorization-36329/lib/Authorization.h)
for a list of possible error codes.
### Launch task one-liner
@@ -45,9 +48,9 @@ OSStatus err = [STPrivilegedTask launchedPrivilegedTaskWithLaunchPath:@"/bin/sh"
### Getting task output
```objective-c
// ... launch task
// ... Launch task
[privilegedTask waitUntilExit];
[privilegedTask waitUntilExit]; // This is blocking
// Read output file handle for data
NSData *outputData = [[privilegedTask outputFileHandle] readDataToEndOfFile];
@@ -59,28 +62,31 @@ NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUT
```objective-c
// ... launch task
// ... Launch task
NSFileHandle *readHandle = [privilegedTask outputFileHandle];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getOutputData:) name:NSFileHandleReadCompletionNotification object:readHandle];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getOutputData:)
name:NSFileHandleReadCompletionNotification
object:readHandle];
[readHandle readInBackgroundAndNotify];
// ...
- (void)getOutputData:(NSNotification *)aNotification {
//get data from notification
// Get data from notification
NSData *data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
//make sure there's actual data
// Make sure there's actual data
if ([data length]) {
// do something with the data
// Do something with the data
NSString *outputString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(outputString);
NSLog(@"%@", outputString);
// go read more data in the background
// Go read more data in the background
[[aNotification object] readInBackgroundAndNotify];
} else {
// do something else
// Do something else
}
}
```
@@ -90,14 +96,17 @@ NSFileHandle *readHandle = [privilegedTask outputFileHandle];
You can observe STPrivilegedTaskDidTerminateNotification:
```objective-c
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(privilegedTaskFinished:) name:STPrivilegedTaskDidTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(privilegedTaskFinished:)
name:STPrivilegedTaskDidTerminateNotification
object:nil];
- (void)privilegedTaskFinished:(NSNotification *)aNotification {
// do something
// Do something
}
```
Or alternately, set a termination handler:
Or alternatively, set a termination handler:
```objective-c
privilegedTask.terminationHandler = ^(STPrivilegedTask *privilegedTask) {
@@ -110,17 +119,17 @@ privilegedTask.terminationHandler = ^(STPrivilegedTask *privilegedTask) {
```objective-c
// ... Create your own AuthorizationRef
[STPriviledTask launchedPrivilegedTaskWithLaunchPath:@"/bin/sh"
arguments:@"/path/to/script"
currentDirectory:@"/"
authorization:authRef]
[STPrivilegedTask launchedPrivilegedTaskWithLaunchPath:@"/bin/sh"
arguments:@"/path/to/script"
currentDirectory:@"/"
authorization:authRef]
```
### AuthorizationExecuteWithPrivileges() is deprecated
[AuthorizationExecuteWithPrivileges()](https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/#//apple_ref/c/func/AuthorizationExecuteWithPrivileges) is deprecated as of macOS 10.7 but remains available
in 10.14 Mojave. If you want to be future-proof, here's how you check if STPrivilegedTask
works in the running version of macOS:
[AuthorizationExecuteWithPrivileges()](https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/#//apple_ref/c/func/AuthorizationExecuteWithPrivileges)
is deprecated as of macOS 10.7 but still remains available in macOS 12 "Monterey". If you want to be future-proof,
here's how you check if STPrivilegedTask works in the running version of macOS:
```objective-c
OSStatus err = [privilegedTask launch];
@@ -164,7 +173,7 @@ It then presents the output of the script in a window, along with the exit code.
## BSD License
Copyright (c) Sveinbjorn Thordarson &lt;sveinbjorn@sveinbjorn.org&gt;
Copyright (c) 2008-2021 Sveinbjorn Thordarson &lt;sveinbjorn@sveinbjorn.org&gt;
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,