首页
社区
课程
招聘
[求助]ObReferenceObjectByHandle
发表于: 2008-8-19 15:22 15769

[求助]ObReferenceObjectByHandle

2008-8-19 15:22
15769
我hook了zwcreatefile,在Hook_ZwCreatefile里面调用ObReferenceObjectByHandle来获得fileobject,但是返回NULL,请问是什么原因?
PFILE_OBJECT pFileObj=NULL;
DbgPrint( "ZwCreateFile : %S" , ObjectAttributes->ObjectName ? ObjectAttributes->ObjectName->Buffer : L"" ) ;
rc=ObReferenceObjectByHandle(FileHandle,0,*IoFileObjectType,KernelMode,(PVOID)&pFileObj,0);//pFileObj总是为NULL

rc返回c0000008

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (9)
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
ObReferenceObjectByHandle
The ObReferenceObjectByHandle routine provides access validation on the object handle, and, if access can be granted, returns the corresponding pointer to the object’s body.

NTSTATUS
  ObReferenceObjectByHandle(
    IN HANDLE  Handle,
    IN ACCESS_MASK  DesiredAccess,
    IN POBJECT_TYPE  ObjectType  OPTIONAL,
    IN KPROCESSOR_MODE  AccessMode,
    OUT PVOID  *Object,
    OUT POBJECT_HANDLE_INFORMATION  HandleInformation  OPTIONAL
    );
Parameters
Handle
Specifies an open handle for an object.
DesiredAccess
Specifies the requested types of access to the object. The interpretation of this field is dependent on the object type.
ObjectType
Pointer to the object type. ObjectType can be either *IoFileObjectType or *ExEventObjectType. This parameter can also be NULL if AccessMode is KernelMode.
AccessMode
Specifies the access mode to use for the access check. It must be either UserMode or KernelMode. Lower-level drivers should specify KernelMode.
Object
Pointer to a variable that receives a pointer to the object’s body.
HandleInformation
Drivers set this to NULL.
Return Value
ObReferenceObjectByHandle returns an NTSTATUS value. The possible return values include:

STATUS_SUCCESS
STATUS_OBJECT_TYPE_MISMATCH
STATUS_ACCESS_DENIED
STATUS_INVALID_HANDLE

Headers
Declared in wdm.h and ntddk.h. Include wdm.h or ntddk.h.

Comments
A pointer to the object body is retrieved from the object table entry and returned to the caller by means of the Object parameter.

If the AccessMode parameter is KernelMode, the requested access is always allowed. If AccessMode is UserMode, the requested access is compared to the granted access for the object. Only highest-level drivers can safely specify UserMode for the input AccessMode.

If the call succeeds, a pointer to the object body is returned to the caller and the pointer reference count is incremented. Incrementing this count prevents the object from being deleted while the pointer is being referenced. The caller must decrement the reference count with ObDereferenceObject as soon as it is done with the object.

Callers of ObReferenceObjectByHandle must be running at IRQL = PASSIVE_LEVEL.
2008-8-20 11:31
0
雪    币: 40
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
我也遇到这个问题, 帮楼主顶下 。 下午大牛们帮忙解决!
2009-8-15 11:53
0
雪    币: 7651
活跃值: (523)
能力值: ( LV9,RANK:610 )
在线值:
发帖
回帖
粉丝
4
你调用的时机呢?你判断句柄有效了吗?
2009-8-15 13:43
0
雪    币: 40
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
UNICODE_STRING                DosName;
                PFILE_OBJECT                pFileObject;

                FILE_OBJECT FileObj = {0};

                ntStatus = ((PZWCREATEFILE)(OldZwCreateFile))(FileHandle,
                        DesiredAccess,
                        ObjectAttributes,
                        IoStatusBlock,
                        AllocationSize,
                        FileAttributes,
                        ShareAccess,
                        CreateDisposition,
                        CreateOptions,
                        EaBuffer,
                        EaLength);               
               
                if(ntStatus==STATUS_SUCCESS && FileHandle!=NULL){

                        ntQueryStatus = ObReferenceObjectByHandle(FileHandle,0,0,KernelMode,(PVOID*)&pFileObject,NULL);

                        DbgPrint("Status:%d",ntQueryStatus);

                        ntQueryStatus = IoVolumeDeviceToDosName(pFileObject->DeviceObject, &DosName);
                       
                        DbgPrint("DosName:%wZ",&DosName);

                        //ntQueryStatus = ZwQueryVolumeInformationFile(FileHandle,&io,&fsAttrInfo,sizeof(FILE_FS_DEVICE_INFORMATION),FileFsDeviceInformation);

                        DbgPrint("FileName:%wZ",ObjectAttributes->ObjectName);
                }

请老大帮忙看看。。。。。。
2009-8-15 14:05
0
雪    币: 290
活跃值: (20)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
6
rc=ObReferenceObjectByHandle(*FileHandle,0,*IoFileObjectType,KernelMode,(PVOID)&pFileObj,0);//pFileObj总是为NULL

搞明白指针好不?
2009-8-15 14:20
0
雪    币: 40
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
, 谢了, 已解决!
2009-8-15 14:58
0
雪    币: 230
活跃值: (10)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
8
哈哈,指针这玩意好用ye害人。
2009-8-24 09:52
0
雪    币: 95
活跃值: (10)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
9
嗯,这里需要注意下是不是用的指针
2009-8-26 10:15
0
雪    币: 27
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
SIP
10
还是不怎么明白,哪里要指针?
第一个参数是句柄,怎么是指针了。?
2009-8-27 17:38
0
游客
登录 | 注册 方可回帖
返回
//