记录两个函数
来源:互联网 发布:ipad淘宝怎么开店 编辑:程序博客网 时间:2024/04/30 14:28
直接贴WRK的源码吧,包括注释
NTSTATUS
IoGetDeviceObjectPointer(
IN PUNICODE_STRING ObjectName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject
)
/*++
Routine Description:
This routine returns a pointer to the device object specified by the
object name. It also returns a pointer to the referenced file object
that has been opened to the device that ensures that the device cannot
go away.
To close access to the device, the caller should dereference the file
object pointer.
Arguments:
ObjectName - Name of the device object for which a pointer is to be
returned.
DesiredAccess - Access desired to the target device object.
FileObject - Supplies the address of a variable to receive a pointer
to the file object for the device.
DeviceObject - Supplies the address of a variable to receive a pointer
to the device object for the specified device.
Return Value:
The function value is a referenced pointer to the specified device
object, if the device exists. Otherwise, NULL is returned.
--*/
{
PFILE_OBJECT fileObject;
OBJECT_ATTRIBUTES objectAttributes;
HANDLE fileHandle;
IO_STATUS_BLOCK ioStatus;
NTSTATUS status;
PAGED_CODE();
//
// Initialize the object attributes to open the device.
//
InitializeObjectAttributes( &objectAttributes,
ObjectName,
OBJ_KERNEL_HANDLE,
(HANDLE) NULL,
(PSECURITY_DESCRIPTOR) NULL );
status = ZwOpenFile( &fileHandle,
DesiredAccess,
&objectAttributes,
&ioStatus,
0,
FILE_NON_DIRECTORY_FILE );
if (NT_SUCCESS( status )) {
//
// The open operation was successful. Dereference the file handle
// and obtain a pointer to the device object for the handle.
//
status = ObReferenceObjectByHandle( fileHandle,
0,
IoFileObjectType,
KernelMode,
(PVOID *) &fileObject,
NULL );
if (NT_SUCCESS( status )) {
*FileObject = fileObject;
//
// Get a pointer to the device object for this file.
//
*DeviceObject = IoGetRelatedDeviceObject( fileObject );
}
(VOID) ZwClose( fileHandle );
}
return status;
}
PDEVICE_OBJECT
IoGetRelatedDeviceObject(
IN PFILE_OBJECT FileObject
)
/*++
Routine Description:
This routine returns a pointer to the actual device object than an I/O
Request Packet (IRP) should be given to based on the specified file
object.
N.B. - Callers of this function must ensure no device object is
attaching or detaching from this stack for the duration of this call.
This is because the database lock is *not* held!
Arguments:
FileObject - Pointer to the file object representing the open file.
Return Value:
The return value is a pointer to the device object for the driver to
whom the request is to be given.
--*/
{
PDEVICE_OBJECT deviceObject;
//
// If the file object was taken out against the mounted file system, it
// will have a Vpb. Traverse it to get to the DeviceObject. Note that in
// this case we should never follow FileObject->DeviceObject, as that
// mapping may be invalid after a forced dismount.
//
if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL) {
ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN));
deviceObject = FileObject->Vpb->DeviceObject;
//
// If a driver opened a disk device using direct device open and
// later on it uses IoGetRelatedTargetDeviceObject to find the
// device object it wants to send an IRP then it should not get the
// filesystem device object. This is so that if the device object is in the
// process of being mounted then vpb is not stable.
//
} else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
FileObject->DeviceObject->Vpb != NULL &&
FileObject->DeviceObject->Vpb->DeviceObject != NULL) {
deviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
//
// This is a direct open against the device stack (and there is no mounted
// file system to strain the IRPs through).
//
} else {
deviceObject = FileObject->DeviceObject;
}
ASSERT( deviceObject != NULL );
//
// Check to see whether or not the device has any associated devices.
// If so, return the highest level device; otherwise, return a pointer
// to the device object itself.
//
if (deviceObject->AttachedDevice != NULL) {
if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION) {
PIOP_FILE_OBJECT_EXTENSION fileObjectExtension =
(PIOP_FILE_OBJECT_EXTENSION)(FileObject + 1);
ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN));
if (fileObjectExtension->TopDeviceObjectHint != NULL &&
IopVerifyDeviceObjectOnStack(deviceObject, fileObjectExtension->TopDeviceObjectHint)) {
return fileObjectExtension->TopDeviceObjectHint;
}
}
deviceObject = IoGetAttachedDevice( deviceObject );
}
return deviceObject;
}
- 记录两个函数
- 汉字转换拼音或拼音首字母(两个函数)--记录一下
- 记录两个css的技巧和一个js的函数
- 利用oracle中的MINUS函数和OVER函数,进行两个记录的比较
- 利用oracle中的MINUS函数和OVER函数,进行两个记录的比较
- 两个函数
- 两个函数
- 记录两个dos命令
- 记录两个CakePHP知识点
- 记录两个小工具:
- vc6 两个问题记录
- 记录两个问题
- 记录两个操作间隔时间
- 利用ORACLE的MINUS函数,直接实现两个记录集的比较
- 数据结构学习记录-两个链表相加之函数指针的运用
- 发现和记录--页面中定义两个同名的JS函数,调用会是什么结果
- 函数记录
- 函数记录
- 判断正负
- VS中cl.exe 各命令行
- memcache/memcached/memcachedb 配置、安装
- Java基础(二)
- 呃
- 记录两个函数
- DNS域名劫持的几种解决方法
- ubuntu 64位新装系统无线网卡无法使用
- 双核心CPU的5个“秘密”
- 开机密码破解
- Winform中的linq to XML和listview
- java get乱码
- ASP.NET MVC2.0实现数据的增、删、改、查(续)客户端验证
- 我们是不是把MVC、ORM等技术的主次颠倒了?