iosobjective-chooktheostweak

How to hook obj-c selector from string(by tweak)?


We can get ios installed bundle id list like this:

Class lsawsc = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [lsawsc performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *arr = [workspace performSelector:NSSelectorFromString(@"allInstalledApplications")];
for (NSString * tmp in arr)
{       
   NSLog(@"%@", tmp);
}

The arr(NSArray) is bundle id list. And I want to hide some bundle id by hook, in tweak. But I don't know how to write code for hook selector...Please help, thanks!


Solution

  • You could just fill a new array with the filtered apps and use that:

    NSArray *installedApps = /* result of allInstalledApplications invocation */;
    
    NSMutableArray *filteredApps = [NSMutableArray new];
    
    for (NSString *app in installedApps) {
        if (/* filter/hook allows app */) {
            [filteredApps addObject:app];
        }
    }
    
    // Use filteredApps
    

    Note: LSApplicationWorkspace is a private API, so using it will prevent publication in the Apple App Store.