Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Mac OS上的应用内内核扩展卸载/加载_Macos_Qt_Admin_Qprocess_Kernel Extension - Fatal编程技术网

Macos Mac OS上的应用内内核扩展卸载/加载

Macos Mac OS上的应用内内核扩展卸载/加载,macos,qt,admin,qprocess,kernel-extension,Macos,Qt,Admin,Qprocess,Kernel Extension,我需要在Mac OS上的Qt桌面应用程序开始时卸载一堆驱动程序(kext)。 我尝试使用QProcess,但kextunload要求具有管理员权限。 有人知道解决办法吗?或者如何使用sudo启动QProcess? 我需要这对最终用户来说很容易:一个只需要在提示时输入管理员密码,其余的由应用程序完成 问题是苹果在我想与特定驱动程序一起使用的设备上加载了自己的驱动程序(FTDI232H和FT2Dxx驱动程序)。我发现了一些似乎适合我的东西: QString password = "yourRootP

我需要在Mac OS上的Qt桌面应用程序开始时卸载一堆驱动程序(kext)。 我尝试使用QProcess,但kextunload要求具有管理员权限。 有人知道解决办法吗?或者如何使用sudo启动QProcess? 我需要这对最终用户来说很容易:一个只需要在提示时输入管理员密码,其余的由应用程序完成


问题是苹果在我想与特定驱动程序一起使用的设备上加载了自己的驱动程序(FTDI232H和FT2Dxx驱动程序)。

我发现了一些似乎适合我的东西:

QString password = "yourRootPassword"; //could be asked with QInputDialog::getText(...)
QString cmd = QString("sudo -S kextunload -b %1 > /dev/null").arg(driverName);
FILE *pipe = popen(cmd.toStdString().c_str(), "w");
if(pipe != nullptr)
{
    fprintf(pipe, "%s\n", password.toStdString().c_str());
    if (ferror(pipe))
    {
        qDebug() << "Failed to write to pipe";
    }
    else
    {
        qDebug() << "Written to pipe";
    }
}
else
{
   qDebug() << "Failed to open pipe";
}
qDebug() << "Pipe returned : " << pclose(pipe);
QString password=“yourRootPassword”//可以使用QInputDialog::getText(…)进行询问
QString cmd=QString(“sudo-S kextunload-b%1>/dev/null”).arg(driverName);
FILE*pipe=popen(cmd.toStdString().c_str(),“w”);
如果(管道!=nullptr)
{
fprintf(管道,“%s\n”,password.toStdString().c_str());
if(铁合金(管道))
{

qDebug()除非您尝试加载或卸载的kext已被非特权用户明确标记为可加载,否则您肯定需要具有根权限。有一个用于加载和卸载kext的C API。它在
中定义,您要使用的函数可能有:

  • OSKextCreate()
  • OSKextLoadWithOptions()
  • OSKextUnloadKextWithIdentifier()
使用提升权限调用函数的推荐方法是使用安装特权助手工具,并启动它并通过XPC与之通信。这样,在
SMJobBless
调用期间,用户的管理员密码只需要一次,并且它也适用于
sudo
不起作用的用户。(
sudo
仅当用户在
wheel
组中时有效,并且仅当他们设置了用户密码时有效。)

可能重复的