Reject modified Dayu Color bundles at registration, service startup and update

这个提交包含在:
mac 于 2026-11-05 23:06:15 +08:00 提交
1 父节点 a7508203d1
当前提交 db6b2b05b3
9 个文件已更改
+237 -22

没有与搜索条件相匹配的文件

+73 -9
查看文件
@@ -1,9 +1,16 @@
#import "AppDelegate.h"
#import "DYBetaUpdater.h"
#import "../Shared/DYBetaDiagnostics.h"
#import "../Shared/DYCodeIntegrity.h"
static NSString *const DYPluginID = @"com.dayu.color.XPC";
static NSString *const DYReleaseAddress = @"https://dayu.media";
static dispatch_queue_t DYPluginRegistrationQueue(void) {
static dispatch_queue_t queue;
static dispatch_once_t once;
dispatch_once(&once, ^{ queue = dispatch_queue_create("com.dayu.color.registration", DISPATCH_QUEUE_SERIAL); });
return queue;
}
static NSColor *DYColor(CGFloat r, CGFloat g, CGFloat b) { return [NSColor colorWithSRGBRed:r green:g blue:b alpha:1]; }
static NSColor *DYBlue(void) { return DYColor(.36,.65,1); }
static NSColor *DYGreen(void) { return DYColor(.26,.86,.53); }
@@ -125,6 +132,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
@property(assign) NSProgressIndicator *updateProgress;
@property(retain) NSTimer *updateProgressTimer;
@property BOOL updateCheckDone;
@property BOOL integrityRejected;
@end
@implementation AppDelegate
@@ -278,32 +286,84 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
}
return NO;
}
- (BOOL)registry:(NSDictionary *)query listsExactPath:(NSString *)path {
NSString *suffix = [@"\t" stringByAppendingString:path];
for (NSString *line in [query[@"output"] componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) {
if ([line hasSuffix:suffix]) return YES;
}
return NO;
}
- (NSString *)removeRejectedPluginRegistration:(NSString *)path {
NSArray *arguments = @[@"-m",@"-A",@"-D",@"-v",@"-i",DYPluginID];
NSDictionary *before = [self runPluginKit:arguments];
if ([before[@"code"] intValue] != 0) return @"query-failed";
if (![self registry:before listsExactPath:path]) return @"not-registered";
if (![path.stringByStandardizingPath isEqualToString:path.stringByResolvingSymlinksInPath]) return @"skipped-symlink";
[self runPluginKit:@[@"-r",path]];
NSDictionary *after = [self runPluginKit:arguments];
if ([after[@"code"] intValue] != 0 || [self registry:after listsExactPath:path]) return @"removal-unverified";
return @"removed";
}
- (void)rejectModifiedInstallation:(NSDictionary *)results {
if (self.integrityRejected || self.terminating) return;
self.integrityRejected = YES;
[self.updater stopForIntegrityFailure];
[self finishRegistration:NO details:DYIntegrityRecoveryMessage results:results];
self.retryButton.enabled = NO;
self.exitDetail.stringValue = @"此副本的自动更新已停用。请安装原始安装包后重新打开。";
NSString *path = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:DYPluginRelativePath];
dispatch_async(DYPluginRegistrationQueue(), ^{
@autoreleasepool {
NSString *removal = [self removeRejectedPluginRegistration:path];
dispatch_async(dispatch_get_main_queue(), ^{
self.diagnostics[@"registrationRevocation"] = removal;
[self writeDiagnostics];
});
}
});
}
- (void)checkRegistration:(id)sender {
if (self.integrityRejected) return;
if (self.diagnostics && (self.registrationState == DYChecking || self.registrationState == DYRegistering)) return;
[self.exitTimer invalidate]; self.exitTimer = nil; self.registrationState = DYChecking;
self.retryButton.enabled = NO; self.retryButton.title = @"检查中…";
self.statusTitle.stringValue = @"正在检查插件…"; self.statusTitle.textColor = NSColor.whiteColor;
self.statusDetail.stringValue = @"正在检查本机插件登记,随后自动提交注册。";
self.progress.indeterminate = YES; [self.progress startAnimation:nil];
NSString *path = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"Contents/PlugIns/大鱼调色 XPC Service.pluginkit"];
NSString *path = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:DYPluginRelativePath];
self.diagnostics = [NSMutableDictionary dictionaryWithDictionary:@{
@"bundleID":NSBundle.mainBundle.bundleIdentifier,@"version":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"build":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"],@"executable":NSBundle.mainBundle.executablePath,
@"bundleID":NSBundle.mainBundle.bundleIdentifier ?: @"",@"version":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"",
@"build":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"] ?: @"",@"executable":NSBundle.mainBundle.executablePath ?: @"",
@"pid":@(NSProcessInfo.processInfo.processIdentifier),@"plugin":path,@"status":@"checking"}];
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0), ^{
dispatch_async(DYPluginRegistrationQueue(), ^{
@autoreleasepool {
NSString *failedComponent = nil;
OSStatus status = DYValidateRunningInstallation(DYCodeRoleWrapper, &failedComponent);
if (status != errSecSuccess) {
NSDictionary *results = @{@"integrity":@"rejected", @"integrityComponent":failedComponent,
@"integrityOSStatus":@(status)};
dispatch_async(dispatch_get_main_queue(), ^{
[self rejectModifiedInstallation:results];
});
return;
}
NSBundle *plugin = [NSBundle bundleWithPath:path];
NSDictionary *attributes = [plugin objectForInfoDictionaryKey:@"PlugInKit"][@"Attributes"];
BOOL validComponent = [plugin.bundleIdentifier isEqualToString:DYPluginID] &&
[[plugin objectForInfoDictionaryKey:@"CFBundleVersion"] isEqual:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]] &&
[attributes[@"com.apple.protocol"] isEqual:@"FxPlug"] && [attributes[@"com.apple.version"] isEqual:@"1.1"];
if (!validComponent) {
dispatch_async(dispatch_get_main_queue(), ^{ [self finishRegistration:NO details:@"未找到完整的插件组件。请从发布地址重新安装大鱼调色。" results:@{}]; }); return;
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.integrityRejected)
[self finishRegistration:NO details:@"未找到完整的插件组件。请从发布地址重新安装大鱼调色。" results:@{}];
}); return;
}
// The stand-alone wrapper can inspect the registry directly. Registration
// and actual host rendering remain separate states; the user confirms FCP.
NSDictionary *before = [self runPluginKit:@[@"-m",@"-v",@"-i",DYPluginID]];
dispatch_async(dispatch_get_main_queue(), ^{
if (self.integrityRejected) return;
self.registrationState = DYRegistering; self.statusTitle.stringValue = @"正在注册插件…";
self.statusDetail.stringValue = @"正在向系统提交插件注册,并核对当前安装位置。";
});
@@ -318,10 +378,12 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
NSString *message = registered ?
@"已确认当前插件登记。请在 Final Cut Pro 中实际应用并确认效果正常;若宿主已打开,请保存后重新打开。" :
@"插件注册尚未完成。请点击“重新检查”,或重新安装后再试。窗口将保持打开。";
NSDictionary *results = @{@"before":before,@"submission":add,@"after":after ?: @{},@"registered":@(registered),
NSDictionary *results = @{@"integrity":@"verified",@"before":before,@"submission":add,@"after":after ?: @{},@"registered":@(registered),
@"discoveryVerified":@(registered),@"submissionAccepted":@(submissionAccepted),@"hostVerification":@"awaiting-user-confirmation",
@"confirmationMethod":registered ? @"exact-path-discovery" : @"unconfirmed"};
dispatch_async(dispatch_get_main_queue(), ^{ [self finishRegistration:registered details:message results:results]; });
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.integrityRejected) [self finishRegistration:registered details:message results:results];
});
}
});
}
@@ -330,7 +392,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
self.registrationState = success ? DYReady : DYFailed;
[self.progress stopAnimation:nil]; self.progress.indeterminate = NO; self.progress.doubleValue = success ? 100 : 0;
self.registrationCard.tint = success ? DYGreen() : DYColor(1,.67,.30); [self.registrationCard setNeedsDisplay:YES];
self.statusTitle.stringValue = success ? @"✓ 插件注册成功" : @"需要重新检查";
self.statusTitle.stringValue = success ? @"✓ 插件注册成功" : (self.integrityRejected ? @"安装完整性验证失败" : @"需要重新检查");
self.statusTitle.textColor = success ? DYGreen() : DYColor(1,.75,.4); self.statusDetail.stringValue = details;
self.retryButton.title = @"重新检查"; self.retryButton.enabled = YES;
self.confirmationButton.enabled = success;
@@ -352,12 +414,14 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
- (void)updateChanged:(NSDictionary *)state {
if(self.terminating)return;
NSString *phase=state[@"phase"];
BOOL rejected = [phase isEqual:@"integrity_rejected"];
if (rejected) [self rejectModifiedInstallation:@{@"integrity":@"rejected"}];
BOOL busy=[@[@"checking",@"downloading",@"validating"]containsObject:phase];
BOOL available=[@[@"available",@"ready",@"host_wait",@"installer"]containsObject:phase];
if(![phase isEqual:@"checking"]){self.updateCheckDone=YES;if(available)[self keepIntroduction:nil];}
self.updateTitle.stringValue=[phase isEqual:@"available"]?state[@"message"]:@"公测更新";
self.updateDetail.stringValue=state[@"message"]?:@"";
self.updateCheckButton.enabled=!busy;
self.updateCheckButton.enabled=!busy && !rejected;
self.updateInstallButton.enabled=[@[@"available",@"ready",@"host_wait",@"installer"]containsObject:phase];
self.updateInstallButton.title=[phase isEqual:@"available"]?@"下载更新":@"安装更新";
self.updateCancelButton.hidden=![phase isEqual:@"downloading"];