Last active
February 4, 2024 14:35
-
-
Save pookjw/6748293c1c31bb1e9fa0c6f410f46407 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
// | |
// main.mm | |
// Practice_PackageKit | |
// | |
// Created by Jinwoo Kim on 2/4/24. | |
// | |
#import <Foundation/Foundation.h> | |
#import <objc/message.h> | |
#import <objc/runtime.h> | |
#import <dlfcn.h> | |
@interface Delegate : NSObject | |
@end | |
@implementation Delegate | |
//- (void)operationControllerDidChangeInstallState:(long)installState withSandbox:(BOOL)sandbox { | |
// | |
//} | |
/* | |
installClient:didFailWithError: | |
installClient:currentState:package:progress:timeRemaining: | |
installClient:discoveredManagedPaths:sandboxPath: | |
installClient:registerBundlesWithLaunchServices: | |
installClientDidBegin: | |
installClientDidFinish: | |
*/ | |
- (void)installClient:(id)client didFailWithError:(NSError *)error { | |
NSLog(@"didFailWithError"); | |
} | |
- (void)installClientDidBegin:(id)client { | |
NSLog(@"installClientDidBegin"); | |
} | |
- (void)installClientDidFinish:(id)client { | |
NSLog(@"installClientDidFinish"); | |
} | |
- (void)installClient:(id)client currentState:(long)state package:(id)package progress:(double)progress timeRemaining:(double)remaining { | |
NSLog(@"progress: %f, time: %f", progress, remaining); | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
void *handle = dlopen("/System/Library/PrivateFrameworks/PackageKit.framework/Versions/A/PackageKit", RTLD_NOW); | |
assert(handle); | |
NSURL *packageURL = [NSURL URLWithString:@"file:///Users/pookjw/Desktop/swift-DEVELOPMENT-SNAPSHOT-2024-01-11-a-osx.pkg"]; | |
// PKInstallRequest, PKInstall PKPackage PKDeferredInstallManager | |
// id package = reinterpret_cast<id (*)(Class, SEL, NSURL *)>(objc_msgSend)(NSClassFromString(@"PKPackage"), NSSelectorFromString(@"packageWithURL:"), packageURL); | |
// NSLog(@"%@", package); | |
// PKXARArchive | |
// id archive = reinterpret_cast<id (*)(Class, SEL, NSString *)>(objc_msgSend)(NSClassFromString(@"PKArchive"), NSSelectorFromString(@"archiveWithPath:"), packageURL.path); | |
// NSLog(@"%@", archive); | |
NSError * _Nullable error = nil; | |
id product = reinterpret_cast<id (*)(Class, SEL, NSURL *, NSError **)>(objc_msgSend)(NSClassFromString(@"PKProduct"), NSSelectorFromString(@"productByLoadingProductAtURL:error:"), packageURL, &error); | |
assert(!error); | |
NSLog(@"%@", product); | |
NSArray *packages = reinterpret_cast<id (*)(id, SEL)>(objc_msgSend)(product, NSSelectorFromString(@"allPackageReferences")); | |
NSMutableArray *packageSpecifiers = [NSMutableArray array]; | |
[packages enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
id specifier = reinterpret_cast<id (*)(id, SEL, id)>(objc_msgSend)([NSClassFromString(@"PKPackageSpecifier") alloc], NSSelectorFromString(@"initWithPackageReference:"), obj); | |
[packageSpecifiers addObject:specifier]; | |
[specifier release]; | |
}]; | |
id installRequest = reinterpret_cast<id (*)(Class, SEL, id, NSString *)>(objc_msgSend)(NSClassFromString(@"PKInstallRequest"), NSSelectorFromString(@"requestWithPackages:destination:"), packageSpecifiers, @"/"); | |
NSLog(@"%@", installRequest); | |
// id install = reinterpret_cast<id (*)(id, SEL, id, id, NSError **)>(objc_msgSend)([NSClassFromString(@"PKInstall") alloc], NSSelectorFromString(@"initWithRequest:delegate:error:"), installRequest, nil, &error); | |
// assert(!error); | |
// NSLog(@"%@", install); | |
id delegate = [Delegate new]; | |
id installClient = reinterpret_cast<id (*)(id, SEL, id, BOOL, BOOL, id, NSError **)>(objc_msgSend)([NSClassFromString(@"PKInstallClient") alloc], NSSelectorFromString(@"initWithRequest:inUserContext:holdingBoostDuringInstall:delegate:error:"), installRequest, YES, NO, delegate, &error); | |
assert(!error); | |
NSLog(@"%@", installClient); | |
// NSLog(@"%@", reinterpret_cast<id (*)(id, SEL)>(objc_msgSend)(installRequest, NSSelectorFromString(@"_installItems"))); | |
// NSLog(@"%f", reinterpret_cast<double (*)(Class, SEL, id)>(objc_msgSend)(NSClassFromString(@"PKInstallClient"), NSSelectorFromString(@"estimatedTimeForInstallRequest:"), installRequest)); | |
// reinterpret_cast<void (*)(id, SEL)>(objc_msgSend)(installRequest, NSSelectorFromString(@"requiresAuthorization")); | |
// id controller = reinterpret_cast<id (*)(id, SEL, id, id)>(objc_msgSend)([NSClassFromString(@"PKInstallOperationController") alloc], NSSelectorFromString(@"initWithRequest:analyzer:"), installRequest, nil); | |
// | |
// if (reinterpret_cast<long (*)(id, SEL)>(objc_msgSend)(installRequest, NSSelectorFromString(@"installPhases")) != 0) { | |
// reinterpret_cast<void (*)(id, SEL, id, BOOL)>(objc_msgSend)(controller, NSSelectorFromString(@"addStageOperationsIntoSandbox:inBackground:"), nil, NO); | |
// | |
// if (reinterpret_cast<long (*)(id, SEL)>(objc_msgSend)(installRequest, NSSelectorFromString(@"installPhases")) != 0) { | |
// reinterpret_cast<void (*)(id, SEL, BOOL)>(objc_msgSend)(controller, NSSelectorFromString(@"addPreLogoutCommitOperationsIntoSandbox:"), NO); | |
// | |
// if (reinterpret_cast<long (*)(id, SEL)>(objc_msgSend)(installRequest, NSSelectorFromString(@"installPhases")) != 0) { | |
// reinterpret_cast<void (*)(id, SEL, id, BOOL)>(objc_msgSend)(controller, NSSelectorFromString(@"addCommitOperationsFromSandbox:usingManager:"), nil, NO); | |
// } | |
// } | |
// } | |
} | |
CFRunLoopRun(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment