galunphendo
驱动牛犊
驱动牛犊
  • 注册日期2007-11-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望40点
  • 贡献值0点
  • 好评度19点
  • 原创分0分
  • 专家分0分
阅读:1329回复:3

应用程序无法打开文件系统过滤器驱动……求助,急

楼主#
更多 发布于:2008-03-05 20:35
我在tooflat的透明过滤驱动的DriverEntry中,在创建控制设备对象的后面创建了符号链接:
RtlInitUnicodeString(&DeviceLinkUnicodeString, DEVICE_LINK_NAME);
Status = IoCreateSymbolicLink(&DeviceLinkUnicodeString, &NameString);
if (!NT_SUCCESS(Status)) {
IoDeleteSymbolicLink(&DeviceLinkUnicodeString);
Status = IoCreateSymbolicLink(&DeviceLinkUnicodeString, &NameString);
}
其中DEVICE_LINK_NAME为:
#define DEVICE_LINK_NAME L"\\DosDevices\\SFilter"

NameString被初始化为:L"\\FileSystem\\Filters\\SFilter"


应用程序的源代码是:
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "winioctl.h"

#define SFILTER_W32_DEVICE_NAME L"\\\\.\\SFilter"
#define SFILTER_SERVICE_NAME L"SFilter"
#define SFILTER_SERVICE_ACCESS (STANDARD_RIGHTS_REQUIRED | \
SERVICE_QUERY_CONFIG | \
SERVICE_QUERY_STATUS | \
SERVICE_START)

VOID
DisplayError (
DWORD Code
);


int _cdecl main()
{
HANDLE hDev = NULL;
SC_HANDLE hSCManager = NULL;
SC_HANDLE hService = NULL;
SERVICE_STATUS_PROCESS serviceInfo;
DWORD bytesNeeded;
DWORD result;


hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL) {
printf("Open Service Manager failed!\n");
exit(1);
}

hService = OpenService(hSCManager, SFILTER_SERVICE_NAME, SFILTER_SERVICE_ACCESS);

if (hService == NULL) {
printf("Open SFilter service failed!\n");
exit(1);
}

if(!QueryServiceStatusEx(hService,
SC_STATUS_PROCESS_INFO,
(UCHAR *) &serviceInfo,
sizeof(serviceInfo),
&bytesNeeded))
{
printf("Query service failed!\n");
exit(1);
}

if(serviceInfo.dwCurrentState != SERVICE_RUNNING)
{
if(!StartService(hService, 0, NULL))
{
printf("Start SFilter service failed!\n");
exit(1);
}
}

hDev = CreateFile(SFILTER_W32_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if (hDev == INVALID_HANDLE_VALUE) {
result = GetLastError();
printf("Open Device Failed!\n");
DisplayError(result);
}

system("pause");
return 0;
}

VOID
DisplayError (
DWORD Code
)
{
WCHAR buffer[80];
DWORD count;

//
// Translate the Win32 error code into a useful message.
//

count = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
Code,
0,
buffer,
sizeof( buffer )/sizeof( WCHAR ),
NULL );

//
// Make sure that the message could be translated.
//

if (count == 0) {

printf( "\nError could not be translated.\n Code: %d\n", Code );
return;

} else {

//
// Display the translated error.
//

printf( "%S\n", buffer );
return;
}
}
可是就是无法打开设备,不是是何缘故。
紧急求救!!!!!
abc13271552
驱动小牛
驱动小牛
  • 注册日期2007-08-13
  • 最后登录2023-12-05
  • 粉丝0
  • 关注0
  • 积分34分
  • 威望552点
  • 贡献值0点
  • 好评度160点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2008-03-06 15:20
1.Entry中加入符号。
2.create, close cleaup加入想应上层代码。
驱网无线,快乐无限
jl2004
驱动小牛
驱动小牛
  • 注册日期2007-04-10
  • 最后登录2011-02-22
  • 粉丝0
  • 关注0
  • 积分21分
  • 威望276点
  • 贡献值0点
  • 好评度129点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2008-03-07 11:23
在sfcreate中要做修改



    if (IS_MY_CONTROL_DEVICE_OBJECT(DeviceObject)) {

        //
        //  Sfilter doesn't allow for any communication through its control
        //  device object, therefore it fails all requests to open a handle
        //  to its control device object.
        //
        //  See the FileSpy sample for an example of how to allow creates to
        //  the filter's control device object and manage communication via
        //  that handle.
        //

        Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest( Irp, IO_NO_INCREMENT );

        return STATUS_INVALID_DEVICE_REQUEST;
    }

STATUS_INVALID_DEVICE_REQUEST
修改成STATUS_SUCCESS
向前,向前,向前....
galunphendo
驱动牛犊
驱动牛犊
  • 注册日期2007-11-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望40点
  • 贡献值0点
  • 好评度19点
  • 原创分0分
  • 专家分0分
地板#
发布于:2008-03-08 20:20
果然~一试就灵~~~多谢多谢~~~!
游客

返回顶部