Created
July 17, 2024 04:40
-
-
Save pookjw/dcb47cec65e823a6bdbd3189e0728b6c to your computer and use it in GitHub Desktop.
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
import UIKit | |
import ObjectiveC | |
import CoreServices | |
// LSApplicationWorkspace * | |
fileprivate var applicationWorkspace: AnyObject { | |
let isa: AnyClass = objc_lookUpClass("LSApplicationWorkspace")! | |
let cmd = sel_registerName("defaultWorkspace") | |
let method = class_getClassMethod(isa, cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyClass, Selector) -> AnyObject).self) | |
return casted(isa, cmd) | |
} | |
// NSArray<LSApplicationProxy *> * | |
fileprivate var allApplications: [AnyObject] { | |
let applicationWorkspace = applicationWorkspace | |
let cmd = sel_registerName("allApplications") | |
let method = class_getInstanceMethod(type(of: applicationWorkspace), cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyObject, Selector) -> [AnyObject]).self) | |
return casted(applicationWorkspace, cmd) | |
} | |
fileprivate func bundleContainerURL(_ applicationProxy: AnyObject) -> URL? { | |
let cmd = sel_registerName("bundleContainerURL") | |
let method = class_getInstanceMethod(type(of: applicationProxy), cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyObject, Selector) -> URL?).self) | |
return casted(applicationProxy, cmd) | |
} | |
fileprivate func localizedShortName(_ applicationProxy: AnyObject) -> String? { | |
let cmd = sel_registerName("localizedShortName") | |
let method = class_getInstanceMethod(type(of: applicationProxy), cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyObject, Selector) -> String?).self) | |
return casted(applicationProxy, cmd) | |
} | |
fileprivate func bundleIdentifier(_ applicationProxy: AnyObject) -> String? { | |
let cmd = sel_registerName("bundleIdentifier") | |
let method = class_getInstanceMethod(type(of: applicationProxy), cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyObject, Selector) -> String?).self) | |
return casted(applicationProxy, cmd) | |
} | |
// https://x.com/Rednick16_/status/1813411959565336695 | |
// Internally uses -[ISBundleIdentifierIcon prepareImageForDescriptor:] | |
fileprivate func applicationIconImage(_ bundleIdentifier: String) -> UIImage? { | |
let isa: AnyClass = UIImage.self | |
let cmd = sel_registerName("_applicationIconImageForBundleIdentifier:format:scale:") | |
let method = class_getClassMethod(isa, cmd) | |
let imp = method_getImplementation(method!) | |
let casted = unsafeBitCast(imp, to: (@convention(c) (AnyClass, Selector, String, Int, CGFloat) -> UIImage?).self) | |
let format: Int | |
if UIDevice.current.userInterfaceIdiom == .pad { | |
format = 8 | |
} else { | |
format = 10 | |
} | |
return casted(isa, cmd, bundleIdentifier, format, UIScreen.main.scale) | |
} | |
@main | |
struct Foo { | |
static func main() { | |
for applicationProxy in allApplications { | |
print("---------------") | |
if let localizedShortName = localizedShortName(applicationProxy) { | |
print(localizedShortName) | |
} | |
if let bundleContainerURL = bundleContainerURL(applicationProxy) { | |
print(bundleContainerURL) | |
} | |
if let bundleIdentifier = bundleIdentifier(applicationProxy), | |
let iconImage = applicationIconImage(bundleIdentifier) | |
{ | |
print(iconImage) | |
} | |
print("---------------") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Omg thank you so much 😭😭😭🥳🥳🥳