阅读:1810回复:11
我在开发防删除文件的驱动的时候,遇到一个问题。
rc=(RealZwSetInformationFile)(FileHandle,IoStatusBlock,FileInformation,Length,FileInformationClass);
我想从它的返回值IoStatusBlock中得到操作的文件名称。请问如何得到呢?? |
|
最新喜欢:![]() |
沙发#
发布于:2003-12-25 20:53
请大家帮帮我好吗??这里是我的最后一丝希望了!!!
|
|
板凳#
发布于:2003-12-25 22:23
IoStatusBlock里哪有什么文件名称?
如果你只是不想文件给人删除的话,给你出个损招,不过很管用的噢。:):):):) 用ZwCreateFile打开那个不想被人删除的文件,ShareAccess参数给成 (FILE_SHARE_READ | FILE_SHARE_WRITE)... ...嘿嘿... ...:):):):) 不过这样一来,别的程序也只能用(FILE_SHARE_READ | FILE_SHARE_WRITE)开打这个文件了... ... |
|
|
地板#
发布于:2003-12-25 23:04
不好不好。
我想这样做,当删除这个文件的时候,如果文件的名字和我保护的文件名字一直,我就跳过不执行删除操作就是了。 可是删除文件好想就要用到ZwSetInformationFile函数,可是我就是不能得到文件名称。能帮帮我吗??? |
|
地下室#
发布于:2003-12-25 23:23
NTSYSAPI
NTSTAUTS NTAPI ObQueryNameString(POBJECT Object, PUNICODE_STRING Name, ULONG MaximumLength, PULONG ActualLength ); |
|
5楼#
发布于:2003-12-26 00:26
不好不好。 你可以用slwqw提到的那个(未公开的?)函数(我没用过),或用ZwQueryInformationFile(这个视忽文件打开的方式,可能不合适),还有一个ZwQueryObject(我也没用过)不知道合不合用。 还有一个ZwDeleteFile(非公开的,不知道里面是不是也用ZwSetInformationFile干活)。 如果使用ZwSetInformationFile删除文件,需要先ZwOpenFile或ZwCreateFile打开文件(DesiredAccess=DELETE),你还不如Hook ZwCreateFile和ZwOpenFile,看到DesiredAccess=DELETE并且那个ObjectAttributes里的文件名是你要保护的... ... 从ObjectAttributes得到文件名似乎要容易一些。 [编辑 - 12/26/03 by cool-net] |
|
|
6楼#
发布于:2003-12-26 09:37
[quote]不好不好。 你可以用slwqw提到的那个(未公开的?)函数(我没用过),或用ZwQueryInformationFile(这个视忽文件打开的方式,可能不合适),还有一个ZwQueryObject(我也没用过)不知道合不合用。 还有一个ZwDeleteFile(非公开的,不知道里面是不是也用ZwSetInformationFile干活)。 如果使用ZwSetInformationFile删除文件,需要先ZwOpenFile或ZwCreateFile打开文件(DesiredAccess=DELETE),你还不如Hook ZwCreateFile和ZwOpenFile,看到DesiredAccess=DELETE并且那个ObjectAttributes里的文件名是你要保护的... ... 从ObjectAttributes得到文件名似乎要容易一些。 [编辑 - 12/26/03 by cool-net] [/quote] IFS Kit公开这个函数,所以你不用怕这个函数以后会失效。我 以前 Hook ZwQueryDriectoryFile()时调用过这个函数。下面干 脆就贴代码给你了。 PVOID *pFileObject; UNICODE_STRING *pFullPath; ULONG ActualLength; // // 查询全路径以便可以进行正确地比较 // ntStatus = ObReferenceObjectByHandle( FileHandle, 0, NULL, KernelMode, (PVOID*)&pFileObject, NULL ); if(ntStatus != STATUS_SUCCESS) { return ntStatus; } pFullPath = (UNICODE_STRING *)ExAllocatePool(PagedPool,1024); RtlZeroMemory(pFullPath,1024); pFullPath->MaximumLength = 1024; ntStatus = ObQueryNameString(pFileObject,pFullPath,1024,&ActualLength); if(ntStatus != STATUS_SUCCESS) { ExFreePool(pFullPath); ObDereferenceObject(pFileObject); return ntStatus; } /////// DbgPrint(\"OK.Query Full Dir = %ws , Len = %d , ActualLen = %d\",pFullPath->Buffer,pFullPath->Length,ActualLength); |
|
7楼#
发布于:2003-12-26 10:21
ok,谢谢slwqw,您给我的关于文件路径和文件名称获得的方法。谢谢cool-net提出的新的思路,很不错的。
谢谢各位,我现在就试一试哈哈谢谢大家了。 |
|
8楼#
发布于:2003-12-26 13:19
ObQueryNameString
ObQueryNameString supplies the name, if any, of a given object to which the caller has a pointer. NTSTATUS ObQueryNameString( IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength ); Parameters Object Pointer to the object for which the name is requested. ObjectNameInfo Pointer to caller-allocated storage in which the object name is to be returned, formatted as follows: typedef struct _OBJECT_NAME_INFORMATION { UNICODE_STRING Name; } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; Length Size in bytes of the storage at ObjectNameInfo. ReturnLength Pointer to a variable to be set to the size in bytes of the returned object name, including a NULL terminator and all path separators in the name. Headers ntifs.h Return Value ObQueryNameString returns STATUS_SUCCESS if it supplied the name at ObjectNameInfo and the length of this string, including the NULL terminator, at ReturnLength. Otherwise, it can return STATUS_INFO_LENGTH_MISMATCH or a STATUS_XXX returned by the query-name method supplied by the component that created the object type. Comments If the given object is unnamed, or if the creator of the object type does not supply a query-name method, ObQueryNameString returns a null Name.Buffer pointer and zeros for Name.Length and Name.MaximumLength at ObjectNameInfo, as well as STATUS_SUCCESS. If the given object is named and the type-specific query-name method succeeds, the returned string is the full path to the given object. The storage for ObjectNameInfo can be allocated from paged or nonpaged pool. The caller is responsible for freeing the returned ObjectNameInfo string with ExFreePool when it is no longer needed. Callers of ObQueryNameString must be running at IRQL < DISPATCH_LEVEL. |
|
|
9楼#
发布于:2003-12-26 15:41
这种做法有缺陷,建议用IFS
|
|
10楼#
发布于:2003-12-27 14:01
我也知道有缺陷,可是我没有IFS相关的资料,楼上的侠您有吗?可以给我一份吗????不胜感激!!!
|
|
11楼#
发布于:2003-12-29 21:27
老天那,我在高级会员区现在IFS,需要20个小时,天哪,都下了一天了!!
|
|