sc_wolf
驱动小牛
驱动小牛
  • 注册日期2006-09-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分35分
  • 威望278点
  • 贡献值1点
  • 好评度150点
  • 原创分0分
  • 专家分0分
阅读:2880回复:5

IoGetDeviceObjectPointer获取设备指针

楼主#
更多 发布于:2007-10-25 18:34
利用这个函数取得的设备指针,但是,可能会IoGetDeviceObjectPointer返回的并不是下层设备对象的指针。而是该设备堆栈中顶层的设备对象的指针。


请问,我怎么才能得到堆栈的低部指针呢...

再请教一下,我可不可以像HOOK API 一样HOOK这个函数呢...IoGetDeviceObjectPointer

谢谢,请指点一下
sc_wolf
驱动小牛
驱动小牛
  • 注册日期2006-09-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分35分
  • 威望278点
  • 贡献值1点
  • 好评度150点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2007-10-25 22:22
各位指点一下,我应该如何HOOK这个函数呀.说一下,大约的思路就行了..谢谢
sc_wolf
驱动小牛
驱动小牛
  • 注册日期2006-09-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分35分
  • 威望278点
  • 贡献值1点
  • 好评度150点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2007-10-26 00:20
我的目的是拦截他查询一个指定的设备..这个设备名,我是知道的..我的驱动刚好是他的上层过滤驱动
WQXNETQIQI
驱动大牛
驱动大牛
  • 注册日期2006-06-12
  • 最后登录2010-10-26
  • 粉丝0
  • 关注0
  • 积分13分
  • 威望1076点
  • 贡献值0点
  • 好评度895点
  • 原创分1分
  • 专家分0分
地板#
发布于:2007-10-26 08:38
IoGetBaseFileSystemDeviceObject
驱动开发者 呵呵
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
地下室#
发布于:2007-10-26 08:50
NTSTATUS
MyIoGetDeviceObjectPointer(
    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 = IoGetBaseFileSystemDeviceObject( fileObject );
        }

        (VOID) ZwClose( fileHandle );
    }

    return status;
}
BTW inline hook 即可.
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
sc_wolf
驱动小牛
驱动小牛
  • 注册日期2006-09-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分35分
  • 威望278点
  • 贡献值1点
  • 好评度150点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2007-10-26 12:15
呵..谢谢....
游客

返回顶部