首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SMJobBless返回错误4098

SMJobBless返回错误4098
EN

Stack Overflow用户
提问于 2012-05-30 21:56:35
回答 1查看 845关注 0票数 4

我正在尝试用SMJobBless安装一个安全的助手工具。当它失败时,在调用SMJobBless之前,我调用SMJobRemove,因为我需要删除该工具的一个较旧版本,而这成功了。SMJobBless返回错误代码4098。NSError对象只告诉我“操作无法完成,CodeSigning子系统出现错误”。

如果我重新运行我的代码,SMJobBless函数可以工作。我假设这是因为它之前被删除了,但为什么它在第一次就不能工作呢?然后我就可以和这个工具通信了,一切都正常了。观察到一切都运行正常,我相信我可以确定我满足了文档中描述的SMJobBless的五个要求。

如果我递增工具的版本并重试,SMJobRemove将工作,但再次执行SMJobBless,错误代码为4098。

如果重要的话,我使用的是OS 10.7.3。

EN

回答 1

Stack Overflow用户

发布于 2013-03-01 02:16:37

会不会是你在代码签名帮助器工具上调用CFBundleCopyInfoDictionaryForURL

如果是这样的话,这个函数似乎破坏了代码签名的有效性。(可能是因为CFBundle修改了内存中的Info.plist数据,但这只是我的猜测。)

解决方案是使用SecCodeCopySigningInformation读取辅助工具的版本信息:

代码语言:javascript
复制
-(NSString *) bundleVersionForCodeSignedItemAtURL:(NSURL *)url {
    OSStatus status;

    // Sanity check -- nothing begets nothing
    if (!url) {
        return nil;
    }

    // Get the binary's static code
    SecStaticCodeRef codeRef;
    status = SecStaticCodeCreateWithPath((CFURLRef)url, kSecCSDefaultFlags, &codeRef);
    if (status != noErr) {
        NSLog(@"SecStatucCodeCreateWithPath() error for %@: %d", url, status);
        return nil;
    }

    // Get the code signature info
    CFDictionaryRef codeInfo;
    status = SecCodeCopySigningInformation(codeRef, kSecCSDefaultFlags, &codeInfo);
    if (status != noErr) {
        NSLog(@"SecCodeCopySigningInformation() error for %@: %d", url, status);
        CFRelease(codeRef);
        return nil;
    }

    // The code signature info gives us the Info.plist that was signed, and
    // from there we can retrieve the version
    NSDictionary *bundleInfo = (NSDictionary *) CFDictionaryGetValue(codeInfo, kSecCodeInfoPList);
    NSString *version = [bundleInfo objectForKey:@"CFBundleVersion"];

    // We have ownership of the code signature info, so we must release it.
    // Before we do that, we need to hold onto the version otherwise we go
    // crashing and burning.
    [[version retain] autorelease];
    CFRelease(codeInfo);
    CFRelease(codeRef);

    return version;
}

值得称赞的是:关于CFBundleCopyInfoDictionaryForURL的重要信息来自Ian MacLeod's SMJobKit

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10817785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档