chentqjl
驱动牛犊
驱动牛犊
  • 注册日期2004-12-06
  • 最后登录2007-11-01
  • 粉丝0
  • 关注0
  • 积分37分
  • 威望6点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
阅读:1396回复:4

怎样通过INF文件给一个设备安装upper filter driver

楼主#
更多 发布于:2005-01-27 11:15
我有个USB设备,没有驱动源代码,还有一个BDA filter驱动,我想使这个BDA filter驱动成为USB设备的upper filter driver,听说只要修改USB设备驱动的INF文件就可以了,可小弟实在功力太弱,看了半天文档,仍然一头雾水,望大侠指教.

最新喜欢:

aasa2aasa2
陈涛
bmyyyud
驱动老牛
驱动老牛
  • 注册日期2002-02-22
  • 最后登录2010-01-21
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望130点
  • 贡献值0点
  • 好评度106点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-01-27 12:15
我有个USB设备,没有驱动源代码,还有一个BDA filter驱动,我想使这个BDA filter驱动成为USB设备的upper filter driver,听说只要修改USB设备驱动的INF文件就可以了,可小弟实在功力太弱,看了半天文档,仍然一头雾水,望大侠指教.

根本不用,加个注册表键就可以
滚滚长江东逝水 浪花淘尽英雄 是非成败转头空 青山依旧在 几度夕阳红 白发渔樵江渚上 惯看秋月春风 一壶浊酒喜相逢 古今多少事 尽付笑谈中
chentqjl
驱动牛犊
驱动牛犊
  • 注册日期2004-12-06
  • 最后登录2007-11-01
  • 粉丝0
  • 关注0
  • 积分37分
  • 威望6点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-01-27 13:59
怎么加,请具体说明,一定送分
陈涛
bmyyyud
驱动老牛
驱动老牛
  • 注册日期2002-02-22
  • 最后登录2010-01-21
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望130点
  • 贡献值0点
  • 好评度106点
  • 原创分0分
  • 专家分0分
地板#
发布于:2005-01-27 15:41
怎么加,请具体说明,一定送分

看段代码:
//----------------------------------------------------------------------
//
// Ctrl2cap Installation Program
//
// This program installs and uninstalls the ctrl2cap keyboard
// filter driver. Its actions vary depending on whether running
// on NT 4 or Win2K.
//
//----------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>

//
// Registry keys we access
//
#define CTRL2CAP_DRIVER_KEY "System\\CurrentControlSet\\Services\\Ctrl2cap"
#define CTRL2CAP_FILTER_KEY "System\\CurrentControlSet\\Control\\Class\\{4D36E96B-E325-11CE-BFC1-08002BE10318}"

//----------------------------------------------------------------------
//
// SearchMultiSz
//
// Finds the specified string in a multiSz.
//
//----------------------------------------------------------------------
char *
SearchMultiSz(
char *Value,
DWORD ValueLength,
char *String
)
{
DWORD len;

if( ValueLength < strlen( String )) return NULL;

len = ValueLength - strlen(String);
do {

if( !stricmp( &Value[len], String )) return &Value[len];

} while( len-- );
return NULL;
}


//----------------------------------------------------------------------
//
// PrintError
//
// Presents an error as an easy to read message.
//
//----------------------------------------------------------------------
void
PrintError(
   DWORD Code
   )
{
   CHAR                                     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),
                          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;
   }
}


//----------------------------------------------------------------------
//
// Ctrl2capUninstall
//
// Uninstalls the ctrl2cap driver.
//
//----------------------------------------------------------------------
void
Ctrl2capUninstall(
    BOOLEAN Silent,
    DWORD Version,
    char *SystemDirectory
    )
{
    HKEY hKey;
    DWORD error, type, length;
char filters[MAX_PATH], *ptr;

    //
    // Delete the driver file.
    //
    if( !DeleteFile( SystemDirectory ) && !Silent) {

        printf("Error deleting \\system32\\drivers\\ctrl2cap.sys:\n");
        PrintError( GetLastError());
    }

    //
    // Delete the driver Registry key.
    //
RegDeleteKey( HKEY_LOCAL_MACHINE, CTRL2CAP_DRIVER_KEY"\\Security" );
RegDeleteKey( HKEY_LOCAL_MACHINE, CTRL2CAP_DRIVER_KEY"\\Enum" );
if(( error = RegDeleteKey( HKEY_LOCAL_MACHINE, CTRL2CAP_DRIVER_KEY )) !=
ERROR_SUCCESS && !Silent ) {

printf("Error deleting ctrl2cap driver key:\n");
PrintError( error );
}

//
// Delete ctrl2cap from keyboard filter value
//
if( Version > 4 ) {

if( (error = RegOpenKey( HKEY_LOCAL_MACHINE,
CTRL2CAP_FILTER_KEY,
&hKey )) != ERROR_SUCCESS ) {

if( !Silent ) {
printf("Could not open Ctrl2cap filter Registry key:\n");
PrintError( error );
}
return;
}

length = sizeof( filters );
if( (error = RegQueryValueEx( hKey, "UpperFilters", 0, &type, filters, &length )) !=
ERROR_SUCCESS ) {

if( !Silent ) {

error = GetLastError();
printf("Could not query Ctrl2cap filter Registry key:\n");
PrintError( error );
RegCloseKey( hKey );
}
return;
}
if( ptr = SearchMultiSz( filters, length, "ctrl2cap" )) {

//
// Zap it.
//
memcpy( ptr, ptr + strlen("ctrl2cap")+1,
length - (ptr-filters) - strlen("ctrl2cap") -1 );
length -= strlen("ctrl2cap")+1;

if( (error = RegSetValueEx( hKey, "UpperFilters", 0, type,
filters, length )) != ERROR_SUCCESS ) {

if( !Silent ) {

printf("Could not reset Ctrl2cap filter Registry key:\n");
PrintError( error );
}
}
}
RegCloseKey( hKey );
}
printf("Ctrl2cap uninstalled. You must reboot for this to take effect.\n\n");
}


//----------------------------------------------------------------------
//
// Ctrl2capInstall
//
// Installs the ctrl2cap driver.
//
//----------------------------------------------------------------------
void
Ctrl2capInstall(
    DWORD Version,
    char *SystemDirectory
    )
{
    HKEY hKey;
    DWORD error, value, type, length;
char filters[MAX_PATH];

    //
    // First, copy the driver file to the system directory.
    //
   if( Version > 4 ) {

        if( !CopyFile( "ctrl2cap.nt5.sys", SystemDirectory, FALSE )) {

            printf("Could not copy ctrl2cap.nt5.sys to \\system32\\drivers.:\n");
            PrintError( GetLastError());
            exit(1);
        }
    } else {

        if( !CopyFile( "ctrl2cap.nt4.sys", SystemDirectory, FALSE )) {

            printf("Could not copy ctrl2cap.nt4.sys to \\system32\\drivers.:\n");
            PrintError( GetLastError());
            exit(1);
        }
    }

    //
    // Create the driver Registry key.
    //
    if( (error = RegCreateKey( HKEY_LOCAL_MACHINE,
                       CTRL2CAP_DRIVER_KEY,
                       &hKey )) != ERROR_SUCCESS ) {

error = GetLastError();
        PrintError( error );
        Ctrl2capUninstall( TRUE, Version, SystemDirectory );
        exit(1);
    }

    //
    // Add the appropriate values.
    //
    value = 1;
    RegSetValueEx( hKey, "Type", 0, REG_DWORD, (PCHAR) &value, sizeof(value));
    value = 1;
    RegSetValueEx( hKey, "ErrorControl", 0, REG_DWORD, (PCHAR) &value, sizeof(value));
    
    //
    // On Win2K, add the driver as a keyboard filter.
    //
    if( Version > 4 ) {

value = 3;
RegSetValueEx( hKey, "Start", 0, REG_DWORD, (PCHAR) &value, sizeof(value));
RegCloseKey( hKey );
if( (error = RegOpenKey( HKEY_LOCAL_MACHINE,
CTRL2CAP_FILTER_KEY,
&hKey )) != ERROR_SUCCESS ) {

printf("Could not create Ctrl2cap filter Registry key:\n");
goto error;
}

length = sizeof( filters );
if( (error = RegQueryValueEx( hKey, "UpperFilters", 0, &type, filters, &length )) !=
ERROR_SUCCESS ) {

error = GetLastError();
printf("Could not open Ctrl2cap filter Registry key:\n");
RegCloseKey( hKey );
goto error;
}

//
// Append ctrl2cap to the end.
//
if( !SearchMultiSz( filters, length, "ctrl2cap" )) {

strcpy( &filters[length-1], "ctrl2cap");
length = length + strlen("ctrl2cap");
filters[ length ] = 0;

if( (error = RegSetValueEx( hKey, "UpperFilters", 0, type,
filters, length + 1 )) != ERROR_SUCCESS ) {

error = GetLastError();
printf("Could not set Ctrl2cap filter Registry key:\n");
RegCloseKey( hKey );
goto error;
}
}
RegCloseKey( hKey );
    } else {

value = 1;
RegSetValueEx( hKey, "Start", 0, REG_DWORD, (PCHAR) &value, sizeof(value));
RegSetValueEx( hKey, "Group", 0, REG_SZ, "KeyboardClass", strlen("KeyboardClass")+1);
RegCloseKey( hKey );
}

printf("Ctrl2cap successfully installed. You must reboot for it to take effect.\n\n");
return;

error:
//
// Cleanup path when we have to uninstall stuff on the way out.
//
PrintError( error );
Ctrl2capUninstall( TRUE, Version, SystemDirectory );
exit(1);
}


//----------------------------------------------------------------------
//
// Usage
//
// Tell the user the proper arguments.
//
//----------------------------------------------------------------------
void
Usage(
    char *name
    )
{
    printf("usage: %s [/install | /uninstall]\n\n", name );
    exit(1);
}


//----------------------------------------------------------------------
//
// Main
//
// Just prints banner and calls the uninstall or install function.
//
//----------------------------------------------------------------------
void
main(
    int argc,
    char *argv[]
    )
{
    DWORD   version;
    CHAR    systemDirectory[MAX_PATH] ;

    //
    // Print banner
    //
    printf("\nCtrl2cap Installation Applet\n");
    printf("Copyright (C) 1999 Mark Russinovich\n");
    printf("Systems Internals - http://www.sysinternals.com\n\n");
    if( argc != 2 ||
        (stricmp( argv[1], "/install") && stricmp( argv[1], "/uninstall") )) {
        
        Usage( argv[0] );
    }

    //
    // Get NT version
    //
    version = GetVersion();
    if( version >= 0x80000000 ) {

        printf("This version of ctrl2cap works on NT 4 and Win2K.\n"
               "Visit http://www.sysinternals.com for a version that works on Windows 9x\n\n");
        return;
    }

    //
    // Get the system directory
    //
    GetSystemDirectory( systemDirectory, sizeof (systemDirectory)) ;
    strcat( systemDirectory, "\\drivers\\ctrl2cap.sys") ;

    //
    // Do the install or uninstall routine.
    //
    if( !stricmp( argv[1], "/install" )) {

        Ctrl2capInstall( version & 0xFF, systemDirectory );

    } else {
        
        Ctrl2capUninstall( FALSE, version & 0xFF, systemDirectory );
    }
}
滚滚长江东逝水 浪花淘尽英雄 是非成败转头空 青山依旧在 几度夕阳红 白发渔樵江渚上 惯看秋月春风 一壶浊酒喜相逢 古今多少事 尽付笑谈中
chentqjl
驱动牛犊
驱动牛犊
  • 注册日期2004-12-06
  • 最后登录2007-11-01
  • 粉丝0
  • 关注0
  • 积分37分
  • 威望6点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-01-27 17:12
楼上,谢谢,我要给你分可总是不成功,我新开个帖子,你来取吧.
另外还想问一下,我这样改完以后,有没有什么工具可以查看一下我的这个filter的下游driver是否正确.
陈涛
游客

返回顶部