Skip to content

Commit

Permalink
Updated to v1.0.8
Browse files Browse the repository at this point in the history
- Fixed issue preventing tweaksettings-utility from running on rootless jailbreaks
- Fixed package icon not showing in package managers on rootless jailbreaks
- Switched to os_log for logging
  • Loading branch information
CreatureSurvive committed May 7, 2023
1 parent 4162605 commit d893754
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ after-stage::
$(ECHO_BEGIN)$(PRINT_FORMAT_MAGENTA) "Set bundle version to: ${PACKAGE_VERSION}"$(ECHO_END)
$(ECHO_BEGIN)$(PRINT_FORMAT_MAGENTA) "Built for $(or $(THEOS_PACKAGE_SCHEME),rootful)"$(ECHO_END)

before-package::
$(ECHO_NOTHING)# Update the Icon: field in the control file to support rootless$(ECHO_END)
@sed -i '' 's|Icon: file:///Applications|Icon: file://$(THEOS_PACKAGE_INSTALL_PREFIX)/Applications|' $(THEOS_STAGING_DIR)/DEBIAN/control

after-install::
install.exec "killall -9 ${XCODEPROJ_NAME}; uicache -p $(THEOS_PACKAGE_INSTALL_PREFIX)/Applications/${XCODEPROJ_NAME}.app; uiopen tweaks:$(LAUNCH_URL)"
Binary file not shown.
Binary file not shown.
15 changes: 11 additions & 4 deletions TweakSettings-App/TS-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
#ifdef __OBJC__

#import <Foundation/Foundation.h>
#import <os/log.h>

#endif

#ifndef TS_Prefix_pch
#define TS_Prefix_pch

#define Log(format, ...) os_log(OS_LOG_DEFAULT, ("(com.creaturecoding.tweaksettings) %s [LOG Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define Info(format, ...) os_log_info(OS_LOG_DEFAULT, ("(com.creaturecoding.tweaksettings) %s [INFO Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define Error(format, ...) os_log_error(OS_LOG_DEFAULT, ("(com.creaturecoding.tweaksettings) %s [ERROR Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define Fault(format, ...) os_log_fault(OS_LOG_DEFAULT, ("(com.creaturecoding.tweaksettings) %s [FAULT Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define LogWithType(type, format, ...) os_log_with_type(OS_LOG_DEFAULT, type, ("(com.creaturecoding.tweaksettings) %s [Line %d] " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

NS_INLINE __unused void MAIN_QUEUE(void (^block)(void)) {
[NSThread isMainThread] ? block() : dispatch_async(dispatch_get_main_queue(), ^{
@autoreleasepool {block();}
Expand All @@ -40,10 +47,10 @@ NS_INLINE __unused NSObject *OBJECT_WITH_PLIST_OPTIONS(NSString *path, NSPropert
if (object && !err2) {
return object;
}
NSLog(@"ERROR (failed to read property-list file): %@", err2.localizedDescription);
Error("(failed to read property-list file): %@", err2.localizedDescription);
return nil;
}
NSLog(@"ERROR (failed to read property-list file): %@", err1.localizedDescription);
Error("(failed to read property-list file): %@", err1.localizedDescription);
return nil;
}

Expand All @@ -52,7 +59,7 @@ NS_INLINE __unused NSDictionary *DICTIONARY_WITH_PLIST_OPTIONS(NSString *path, N
if (object && [object isKindOfClass:NSDictionary.class]) {
return (NSDictionary *) object;
}
NSLog(@"ERROR (property-list file at %@ is not a dictionary)", path);
Error("(property-list file at %@ is not a dictionary)", path);
return nil;
}

Expand All @@ -65,7 +72,7 @@ NS_INLINE __unused NSArray *ARRAY_WITH_PLIST_OPTIONS(NSString *path, NSPropertyL
if (object && [object isKindOfClass:NSArray.class]) {
return (NSArray *) object;
}
NSLog(@"ERROR (property-list file at %@ is not an array)", path);
Error("(property-list file at %@ is not an array)", path);
return nil;
}

Expand Down
2 changes: 1 addition & 1 deletion TweakSettings-App/TSAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


static void HandleExceptions(NSException *exception) {
NSLog(@"TweakSettings unhandled exception: %@", exception.debugDescription);
Error("TweakSettings unhandled exception: %@", exception.debugDescription);
}

@implementation TSAppDelegate
Expand Down
10 changes: 9 additions & 1 deletion TweakSettings-App/TSPackageUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,17 @@ @implementation TSPackageUtility {
}

[CSSearchableIndex.defaultSearchableIndex deleteAllSearchableItemsWithCompletionHandler:^(NSError *error) {
[CSSearchableIndex.defaultSearchableIndex indexSearchableItems:searchableItems completionHandler:nil];
[CSSearchableIndex.defaultSearchableIndex indexSearchableItems:searchableItems completionHandler:^(NSError *error) {
if (error) {
Error("Updating searchable item index (%@)", error.localizedDescription);
} else {
Log("Finished updating searchable item index with items (%@)", searchableItems);
}
}];
}];

Log("Loaded Specifiers (%lu)", (unsigned long)preferenceSpecifiers.count)

return preferenceSpecifiers;
}

Expand Down
12 changes: 9 additions & 3 deletions TweakSettings-App/TSUtilityActionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct TaskResult ExecuteCommand(NSString *command) {

if (errorData && errorData.length > 0) {
error = [[NSString alloc] initWithData:errorData encoding:NSASCIIStringEncoding];
NSLog(@"TweakSettings: TASK INPUT: %@ ERROR: %@, STATUS: %d", task.arguments.lastObject, error, task.terminationStatus);
Error("TASK INPUT: %@ ERROR: %@, STATUS: %d", task.arguments.lastObject, error, task.terminationStatus)
}

struct TaskResult result;
Expand Down Expand Up @@ -99,9 +99,15 @@ int HandleActionForType(NSString *actionType) {

if (!actionType || !actionType.length) return EXIT_FAILURE;

int status = ExecuteCommand(CommandForActionType(actionType)).status;
NSString *command = CommandForActionType(actionType);
Log("Will execute command: %@", command);
struct TaskResult result = ExecuteCommand(command);

return status;
if (result.status != 0) {
Error("TaskResult (E: %@ O: %@ S: %d)", result.error, result.output, result.status);
}

return result.status;
}

UIAlertController *ActionAlertForType(NSString *actionType) {
Expand Down
22 changes: 9 additions & 13 deletions TweakSettings-Utility/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,24 @@ int main(int argc, char **argv, char **envp) {

// check that TweakSettings.app exists
struct stat correct;
if (lstat(ROOT_PATH("/Applications/TweakSettings.app/TweakSettings"), &correct) == -1){
printf("tweaksettings-utility can only be used by TweakSettings.app,\n");
if (lstat(ROOT_PATH("/Applications/TweakSettings.app/TweakSettings"), &correct) == -1) {
perror("tweaksettings-utility can only be used by TweakSettings.app, (stat failed)\n");
return EX_NOPERM;
}

pid_t parent = getppid();
bool tweaksettings = false;

// check that TweakSettings.app is the parent process pid
char buffer[(1024)] = {0};
int pidpath = proc_pidpath(parent, buffer, sizeof(buffer));
if (pidpath > 0){
if (strcmp(buffer, ROOT_PATH("/Applications/TweakSettings.app/TweakSettings")) == 0){
tweaksettings = true;
if (pidpath > 0) {
// exit if the parent process was not TweakSettings.app
if (strstr(buffer, "/Applications/TweakSettings.app/TweakSettings") == NULL) {
perror("tweaksettings-utility can only be used by TweakSettings.app, (incorrect parent)\n");
return EX_NOPERM;
}
}

// exit if the parent process was not TweakSettings.app
if (tweaksettings == false){
printf("tweaksettings-utility can only be used by TweakSettings.app,\n");
return EX_NOPERM;
}

// patch setuid if needed
patch_setuid(0);

Expand Down Expand Up @@ -154,10 +149,11 @@ int main(int argc, char **argv, char **envp) {
// handle operation execution
switch (flags) {
case TSUtilityActionTypeNone: {
printf("invalid arguments, canceling operation\n");
perror("invalid arguments, canceling operation\n");
} break;
case TSUtilityActionTypeHelp: {
print_usage();
status = EXIT_SUCCESS;
} break;
case TSUtilityActionTypeRespring: {
status = execl(ROOT_PATH("/usr/bin/killall"), "killall", "backboardd", NULL);
Expand Down
2 changes: 1 addition & 1 deletion layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.creaturecoding.tweaksettings
Name: TweakSettings
Depends: firmware (>= 10.0), preferenceloader | com.creaturecoding.preferred
Version: 1.0.7
Version: 1.0.8
Priority: optional
Architecture: iphoneos-arm
Description: Dedicated settings app for tweaks
Expand Down

0 comments on commit d893754

Please sign in to comment.