ExitKext function
退出指定内核模块进程
Parameters:
- (int) hKextService:内核模块服务句柄号
Return value:
- Type:int
- Text:成功返回指定内核扩展服务退出码,失败返回 NULL
- Error:执行失败会设置 GetErrorInfo
Remarks:
ExitKext function 将指定内核扩展服务从内核退出(Exit / Uninst),届时指定内核扩展服务会收到 KEXT_FLAGS_EXIT 通知例程
ExitKext function 仅将指定内核扩展服务从内核退出,并不能保证其内核扩展服务所使用的资源得到释放
关于内核代码安全,通常情况下开发者应通过调用 SendKextNotify function 向指定内核扩展服务发送通知,以停止其功能后要求重新启动当前实例以完成退出
当前扩展程序进程 Token 应具有 TOKEN_PRIVILEGE_USER 特权
当前扩展程序进程 Token 应具有 TOKEN_FLAGS_KEXT 许可标志
指定内核扩展服务不应在卸载例程操作成功后返回退出码为 NULL,这样可能会导致扩展程序进行了错误的判断
C++ code:
#include <h.studio>
#include <h.kext>
int hello(){
int uExitcode=NULL;
int hKextService=OpenKext("mykit.kextes");
if(hKextService){
// There is no decision on whether the operation is successful, or if the operation fails, the exit code is NULL
// Specifies that the kernel extension service should not return NULL after a successful operation
uExitcode=ExitKext(hKextService);
output("Operation completed, exit code:"+tolpcstr(uExitcode));
}else{
output("Open mykit.kextes failure, Error:"+tolpcstr(GetErrorInfo(NULL)));
}
return RETEXT_NULL;
}