概述
得到驱动对象
.h
/// 系统全局变量声明
extern POBJECT_TYPE *IoDriverObjectType;
/// 常量, 用WinObj.exe 可以看到
#define DRVOBJ_NAME_XX L"\xx"
NTSTATUS
GetDriverObject(
WCHAR * pcDriverObjectName,
PDRIVER_OBJECT * ppDrvObj);
.c
NTSTATUS GetDriverObject(WCHAR * pcDriverObjectName, PDRIVER_OBJECT * ppDrvObj)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
UNICODE_STRING strDrvObjName;
if (NULL == ppDrvObj)
return status;
/// 得到驱动对象
/// 参数2 参考 InitializeObjectAttributes.Attributes
/// 内核句柄 |大小写不敏感
RtlInitUnicodeString(&strDrvObjName, pcDriverObjectName);
status = ObReferenceObjectByName(
&strDrvObjName, ///< IN PUNICODE_STRING ObjectName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, ///< IN ULONG Attributes,
NULL, ///< IN PACCESS_STATE PassedAccessState OPTIONAL,
0, ///< IN ACCESS_MASK DesiredAccess OPTIONAL,
*IoDriverObjectType, ///< IN POBJECT_TYPE ObjectType,
KernelMode, ///< IN KPROCESSOR_MODE AccessMode,
NULL, ///< IN OUT PVOID ParseContext OPTIONAL,
ppDrvObj ///< OUT PVOID *Object
);
return status;
}
调用代码
NTSTATUS ProcessXX()
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
PDRIVER_OBJECT pDrvObj = NULL;
DBGPRT((">> ProcessXXn"));
status = GetDriverObject(DRVOBJ_NAME_XX, &pDrvObj);
if (!NT_SUCCESS(status))
goto _ProcessXX_END;
DBGPRT((
"pDrvObj->DriverName = %wZn"
"pDrvObj->HardwareDatabase = %wZrn",
&pDrvObj->DriverName,
pDrvObj->HardwareDatabase));
_ProcessXX_END:
if (NULL != pDrvObj)
ObDereferenceObject(pDrvObj); ///< !
DBGPRT(("<< ProcessXXn"));
return status;
}
最后
以上就是体贴金鱼为你收集整理的note : ObReferenceObjectByName usage的全部内容,希望文章能够帮你解决note : ObReferenceObjectByName usage所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复