macOS:获取task_for_pid()的权限

时间:2018-01-19 15:48:58

标签: c++ macos

我正在尝试在我的程序中调用task_for_pid()。我创建了一个自签名证书,并在Info.plist中添加了“SecTaskAccess”。我正在使用Security / Authorization.h,但task_for_pid()失败。

OSStatus status;
AuthorizationItem item[] = {{"system.privilege.taskport:"}};
AuthorizationRights rights = {1, item}, *rightsGot = nullptr;
AuthorizationRef author;

AuthorizationFlags authFlags = kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize | kAuthorizationFlagInteractionAllowed | ( 1 << 5);
status = AuthorizationCreate(nullptr, kAuthorizationEmptyEnvironment, authFlags, &author);
if(status != errAuthorizationSuccess)
{
    return false;
}
status = AuthorizationCopyRights(author, &rights, kAuthorizationEmptyEnvironment, authFlags, &rightsGot);
if(status != errAuthorizationSuccess)
{
    return false;
}
if(task_for_pid(mach_task_self(), m_pid, &m_task) != KERN_SUCCESS)
{
    std::cout << "Failed to get task from pid" << std::endl;
    return false;    //Fails here
}

0 个答案:

没有答案