示例#1
0
/****************************************************************************
*
*    FUNCTION: UnloadDeviceDriver( const TCHAR *)
*
*    PURPOSE: Stops the driver and has the configuration manager unload it.
*
****************************************************************************/
BOOL UnloadDeviceDriver( const TCHAR * Name,BOOL DRemove)
{
	SC_HANDLE	schSCManager;

	if (( strcmp(Name,"MultiDec BT-Treiber") == 0 ) ||
			( strcmp(Name,"MultiDec SAA-Treiber") == 0 ) ||
			( strcmp(Name,"MultiDec HAL-Treiber") == 0 )) return(TRUE); 

	if ( Keep_Driver_Loaded == TRUE ) {
		/*
		if (( strcmp(Name,"MultiDec BT-Treiber") == 0 ) ||
			( strcmp(Name,"MultiDec SAA-Treiber") == 0 ) ||
			( strcmp(Name,"MultiDec HAL-Treiber") == 0 )) 
		*/
		return(TRUE); 
	};

	schSCManager = OpenSCManager(	NULL,                 // machine (NULL == local)
                              		NULL,                 // database (NULL == default)
									SC_MANAGER_ALL_ACCESS // access required
								);

	if ( StopDriver( schSCManager, Name ) == FALSE ) {
    	CloseServiceHandle( schSCManager );
		return(TRUE);
	};

	if ( DRemove == TRUE ) RemoveDriver( schSCManager, Name );
	CloseServiceHandle( schSCManager );

	return TRUE;
}
示例#2
0
void Drixml::RemoveDriver(QString name)
{
    DriDriver *driver;

    if (name == "loader") {
        RemoveDriver(driver_loader);
        return;
    }
    if (name.isNull()) {
        RemoveDriver(driver_all);
        return;
    }
    if (Drixml::getDriver(name, &driver)) {
        RemoveDriver(driver);
        return;
    }
}
示例#3
0
void CNetMgr::TermDrivers()
{
	while (m_Drivers.GetSize() > 0)
	{
		uint32 prevSize = m_Drivers.GetSize();
		RemoveDriver(m_Drivers[0]);
		if (prevSize == m_Drivers.GetSize())
			break;
	}
}
示例#4
0
bool NetServer::listen()
{
	if (!m_pServer)
		return false;

	bool bHasPacket = false;
	ENetEvent event;
	char hostName[256];    
    
    while (enet_host_service (m_pServer, & event, 0) > 0)
    {
        switch (event.type)
        {
        case ENET_EVENT_TYPE_CONNECT:

			enet_address_get_host_ip (&event.peer -> address,hostName,256);

            GfLogTrace ("A new client connected from %s\n",hostName); 

            /* Store any relevant client information here. */
            event.peer -> data = (void*)"Client information";

            break;

        case ENET_EVENT_TYPE_RECEIVE:
			ReadPacket(event); 
			bHasPacket = true;
            break;
           
        case ENET_EVENT_TYPE_DISCONNECT:
			GfLogTrace("\nA client lost the connection.\n");
			enet_address_get_host_ip (&event.peer -> address,hostName,256);
            GfLogTrace ("A new client disconnected from %s\n",hostName); 

			RemoveDriver(event);
			SetRaceInfoChanged(true);

            GfLogTrace ("%s disconected.\n", (char*)event.peer -> data);

            /* Reset the peer's client information. */

            event.peer -> data = NULL;
			break;
			
		case ENET_EVENT_TYPE_NONE:
			// Do nothing.
			break;
        }
    }

	if (bHasPacket)
		m_activeNetworkTime = GfTimeClock();
	
	return bHasPacket;
}
示例#5
0
static BOOL __cdecl remove_driver( void )
{
	SC_HANDLE   schSCManager;
	BOOL ret = FALSE;

	schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
	if(!schSCManager) return(FALSE);
	if(RemoveDriver( schSCManager, sDriverShort )) ret = TRUE;
	CloseServiceHandle( schSCManager );
	return( ret );
}
//------------------------------------------------------------------------------
//! \brief Initialise the sound driver
//------------------------------------------------------------------------------
void CAudioDrv::InitDriver(void)
{
	RemoveDriver();

	// Initialise the audio subsystem
	AESND_Init();

	// Initialise Player
	MODPlay_Init(&methane_music);

	m_AudioValidFlag = 1;
}
示例#7
0
/****************************************************************************
*
*    FUNCTION: UnloadDeviceDriver( const TCHAR *)
*
*    PURPOSE: Stops the driver and has the configuration manager unload it.
*
****************************************************************************/
BOOL UnloadDeviceDriver( const TCHAR * Name )
{
	SC_HANDLE	schSCManager;

	schSCManager = OpenSCManager(	NULL,                 // machine (NULL == local)
                              		NULL,                 // database (NULL == default)
									SC_MANAGER_ALL_ACCESS // access required
								);

	StopDriver( schSCManager, Name );
	RemoveDriver( schSCManager, Name );
	 
	CloseServiceHandle( schSCManager );

	return TRUE;
}
示例#8
0
static BOOL __cdecl start_driver( void )
{
	SC_HANDLE   schSCManager;
	BOOL ret = FALSE;

	schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
	if(!schSCManager) return(FALSE);
	if(!InstallDriver( schSCManager, sDriverShort, sDriverLong )) {
		CloseServiceHandle( schSCManager );
		return(FALSE);
	}
	ret = StartDriver( schSCManager, sDriverShort );
	if(!ret) {
		(void)RemoveDriver( schSCManager, sDriverShort );
	}
	CloseServiceHandle( schSCManager );
	return( ret );
}
示例#9
0
BOOL InstallDriver(PCSTR pszDriverPath, PCSTR pszDriverName)
{
	SC_HANDLE hSCManager;
	SC_HANDLE hService;

	//Remove any previous instance of the driver
	RemoveDriver(pszDriverName);

	hSCManager=OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (hSCManager)
	{
		//Install the driver
		hService=CreateService( hSCManager,
								pszDriverName,
								pszDriverName,
								SERVICE_ALL_ACCESS,
								SERVICE_KERNEL_DRIVER,
								SERVICE_DEMAND_START,
								SERVICE_ERROR_NORMAL,
								pszDriverPath,
								NULL,
								NULL,
								NULL,
								NULL,
								NULL);

		CloseServiceHandle(hSCManager);
	
		if (hService==NULL)
			return FALSE;
	}
	else
		return FALSE;

	CloseServiceHandle(hService);

	return TRUE;
}
示例#10
0
/****************************************************************************
*
*    FUNCTION: LoadDeviceDriver( const TCHAR, const TCHAR, HANDLE *)
*
*    PURPOSE: Registers a driver with the system configuration manager 
*	 and then loads it.
*
****************************************************************************/
BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path, HANDLE * lphDevice )
{
	SC_HANDLE	schSCManager;
	BOOL		okay;

	schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );

	// Remove previous instance
	RemoveDriver( schSCManager, Name );

	// Ignore success of installation: it may already be installed.
	InstallDriver( schSCManager, Name, Path );

	// Ignore success of start: it may already be started.
	StartDriver( schSCManager, Name );

	// Do make sure we can open it.
	okay = OpenDevice( Name, lphDevice );

 	CloseServiceHandle( schSCManager );

	return okay;
}
/*************************************
* int _cdecl main( )
* 功能 加载驱动,进行控制
**************************************/
int _cdecl main()
{
	HANDLE hDevice;
	BOOL bRc;
	ULONG bytesReturned;
	DWORD errNum = 0;
	UCHAR driverLocation[MAX_PATH];

	SC_HANDLE schSCManager;// 服务控制器句柄
	// 打开服务控制器,后续安装、启动都会使用到。
	schSCManager = OpenSCManager(NULL, // 本机
		NULL, // 本机数据库
		SC_MANAGER_ALL_ACCESS // 存取权限
		);
	if (!schSCManager)
	{
		// 打开失败
		printf("Open SC Manager failed! Error = %d \n", GetLastError());
		return 1;
	}
	// 获得驱动文件的路径
	if (!GetDriverPath(driverLocation))
	{
		return 1;
	}
	// 安装驱动服务
	if (InstallDriver(schSCManager,
		DRIVER_NAME,
		driverLocation
		))
	{
		// 安装成功,启动服务,运行驱动
		if(!StartDriver(schSCManager, DRIVER_NAME ))
		{
			printf("Unable to start driver. \n");
			return 1;
		}
	}
	else
	{
		// 安装失败,删除驱动。
		RemoveDriver(schSCManager, DRIVER_NAME );
		printf("Unable to install driver. \n");
		return 1;
	}
	// 打开驱动,获得控制所用的句柄
	// 由驱动创建的符号链接
	hDevice = CreateFile( "\\\\.\\IoctlTest",
		GENERIC_READ | GENERIC_WRITE,
		0,
		NULL,
		CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL,
		NULL);
	if ( hDevice == INVALID_HANDLE_VALUE )
	{
		printf ( "Error: CreatFile Failed : %d\n", GetLastError());
		return 1;
	}

	// 打印,输入输出。
	printf("InputBuffer Pointer = %p, BufLength = %d\n", InputBuffer,
		sizeof(InputBuffer));
	printf("OutputBuffer Pointer = %p BufLength = %d\n", OutputBuffer,
		sizeof(OutputBuffer));
	
	// 输入到内核的数据,
	lstrcpy(InputBuffer,
		"This String is from User Application; using IOCTL_XIOCTL_BUFFER");
	printf("\nCalling DeviceIoControl IOCTL_XIOCTL_BUFFER:\n");
	
	// 清空输出缓存
	memset(OutputBuffer, 0, sizeof(OutputBuffer));
	// 进行IO控制,
	bRc = DeviceIoControl ( hDevice,// 句柄
		(DWORD) IOCTL_XIOCTL_BUFFER,// IOCTL
		&InputBuffer,// 输入数据
		strlen ( InputBuffer )+1,// 输入数据的长度
		&OutputBuffer,// 输出数据
		sizeof( OutputBuffer),// 输出数据长度
		&bytesReturned,// 实际输出的数据长度
		NULL
		);
	// 判断是否成功
	if ( !bRc )
	{
		printf ( "Error in DeviceIoControl : %d", GetLastError());
		return 1;
	}
	// 打印从内核输出的内容
	printf(" OutBuffer (%d): %s\n", bytesReturned, OutputBuffer);
	// 关闭句柄
	CloseHandle ( hDevice );
	// 停止运行
	StopDriver(schSCManager,
		DRIVER_NAME
		);
	// 删除服务
	RemoveDriver(schSCManager,
		DRIVER_NAME
		);
	// 关闭服务控制器
	CloseServiceHandle (schSCManager);
	return 0;
}
示例#12
0
/****************************************************************************
*
*    FUNCTION: StartDriver( IN SC_HANDLE, IN LPCTSTR)
*
*    PURPOSE: Starts the driver service.
*
****************************************************************************/
BOOL StartDriver( IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName )
{
    SC_HANDLE  schService;
    BOOL       ret;
	SERVICE_STATUS ServiceStatus;
	char LogZeile[128];
    DWORD Service_Error ;
	

	schService = OpenService( SchSCManager,
                              DriverName,
                              SERVICE_ALL_ACCESS
                              );
    if ( schService == NULL ) {
    Service_Error  = GetLastError();
	sprintf(LogZeile,"OpenService %s Fail ( Return %x ",DriverName,Service_Error);
	if ( Service_Error == ERROR_ACCESS_DENIED ) strcat(LogZeile,"ACCESS_DENIED");
	 else if ( Service_Error == ERROR_INVALID_HANDLE ) strcat(LogZeile,"INVALID_HANDLE");
	 else if ( Service_Error == ERROR_INVALID_NAME ) strcat(LogZeile,"INVALID_NAME");
	 else if ( Service_Error == ERROR_SERVICE_DOES_NOT_EXIST ) strcat(LogZeile,"SERVICE_DOES_NOT_EXIST");
	 strcat(LogZeile,")");
	Write_Log(LogZeile);
    return(FALSE);
	};


	if ( QueryServiceStatus(schService,&ServiceStatus ) == FALSE ) {
    Service_Error  = GetLastError();
	sprintf(LogZeile,"QueryServiceStatus %s Fail ( Return %x ",DriverName,Service_Error);
	if ( Service_Error == ERROR_ACCESS_DENIED ) strcat(LogZeile,"ACCESS_DENIED");
	 else if ( Service_Error == ERROR_INVALID_HANDLE ) strcat(LogZeile,"INVALID_HANDLE");
	 strcat(LogZeile,")");
	 Write_Log(LogZeile);
     CloseServiceHandle( schService );
	 return(FALSE);
	};

    if ( ServiceStatus.dwCurrentState == SERVICE_RUNNING ) return(TRUE);


    ret = StartService( schService, 0, NULL );

    if ( ret == FALSE )
    {
       Service_Error  = GetLastError();
        if( Service_Error   == ERROR_SERVICE_ALREADY_RUNNING)
        {
           CloseServiceHandle( schService );
		   return(TRUE);
        } else {
            
	    sprintf(LogZeile,"StartService %s Fail ( Return %x ",DriverName,Service_Error);
		if ( Service_Error == ERROR_ACCESS_DENIED ) strcat(LogZeile,"ACCESS_DENIED");
			else if ( Service_Error == ERROR_INVALID_HANDLE ) strcat(LogZeile,"INVALID_HANDLE");
			else if ( Service_Error == ERROR_PATH_NOT_FOUND ) strcat(LogZeile,"PATH_NOT_FOUND");
			else if ( Service_Error == ERROR_SERVICE_DATABASE_LOCKED ) strcat(LogZeile,"SERVICE_DATABASE_LOCKED");
			else if ( Service_Error == ERROR_SERVICE_DEPENDENCY_DELETED ) strcat(LogZeile,"DEPENDENCY_DELETED");
			else if ( Service_Error == ERROR_SERVICE_DEPENDENCY_FAIL ) strcat(LogZeile,"DEPENDENCY_FAIL");
			else if ( Service_Error == ERROR_SERVICE_DISABLED ) strcat(LogZeile,"SERVICE_DISABLED");
			else if ( Service_Error == ERROR_SERVICE_LOGON_FAILED ) strcat(LogZeile,"SERVICE_LOGON_FAILED");
			else if ( Service_Error == ERROR_SERVICE_MARKED_FOR_DELETE ) strcat(LogZeile,"SERVICE_MARKED_FOR_DELETE");
			else if ( Service_Error == ERROR_SERVICE_NO_THREAD ) strcat(LogZeile,"SERVICE_NO_THREAD");
			else if ( Service_Error == ERROR_SERVICE_REQUEST_TIMEOUT ) strcat(LogZeile,"SERVICE_REQUEST_TIMEOUT");
		strcat(LogZeile,")");
		Write_Log(LogZeile);
		RemoveDriver(SchSCManager, DriverName);
        return(FALSE);
        }
    }
 


    CloseServiceHandle( schService );

    return ret;
}
示例#13
0
BOOLEAN
ManageDriver(
    IN LPCTSTR  DriverName,
    IN LPCTSTR  ServiceName,
    IN USHORT   Function
    )
{

    SC_HANDLE   schSCManager;

    BOOLEAN rCode = TRUE;

    //
    // Insure (somewhat) that the driver and service names are valid.
    //

    if (!DriverName || !ServiceName) {

        printf("Invalid Driver or Service provided to ManageDriver() \n");

        return FALSE;
    }

    //
    // Connect to the Service Control Manager and open the Services database.
    //

    schSCManager = OpenSCManager(NULL,                   // local machine
                                 NULL,                   // local database
                                 SC_MANAGER_ALL_ACCESS   // access required
                                 );

    if (!schSCManager) {

        printf("Open SC Manager failed! Error = %d \n", GetLastError());

        return FALSE;
    }

    //
    // Do the requested function.
    //

    switch( Function ) {

        case DRIVER_FUNC_INSTALL:

            //
            // Install the driver service.
            //

            if (InstallDriver(schSCManager,
                              DriverName,
                              ServiceName
                              )) {

                //
                // Start the driver service (i.e. start the driver).
                //

                rCode = StartDriver(schSCManager,
                                    DriverName
                                    );

            } else {

                //
                // Indicate an error.
                //

                rCode = FALSE;
            }

            break;

        case DRIVER_FUNC_REMOVE:

            //
            // Stop the driver.
            //

            StopDriver(schSCManager,
                       DriverName
                       );

            //
            // Remove the driver service.
            //

            RemoveDriver(schSCManager,
                         DriverName
                         );

            //
            // Ignore all errors.
            //

            rCode = TRUE;

            break;

        default:

            printf("Unknown ManageDriver() function. \n");

            rCode = FALSE;

            break;
    }

    //
    // Close handle to service control manager.
    //

    if (schSCManager) {

        CloseServiceHandle(schSCManager);
    }

    return rCode;

}   // ManageDriver
DriverMinifilterCommunicator::~DriverMinifilterCommunicator(void)
{
	RemoveDriver();
}
//------------------------------------------------------------------------------
//! \brief Destroy the sound driver
//------------------------------------------------------------------------------
CAudioDrv::~CAudioDrv()
{
	RemoveDriver();
}
示例#16
0
int main(int argc, char *argv[])
{
    SC_HANDLE   schSCManager;
        BOOL        remove = FALSE;
    char        *test_file = NULL;
        char        *curr_dep;
        char        ServiceName[256] = "";
        char            ServiceExe[256] = "";

        curr_dep = &DependencyList[0];
        for (;;) {
                ++argv;
                --argc;
                if (argv[0] == NULL)
                        break;
                if (argv[0][0] != '-')
                        break;
                switch( argv[0][1] ) {
                        case 'r':
                                remove = TRUE;
                                break;
                        case 'd':
                                strcpy( curr_dep, &argv[0][2] );
                                curr_dep += strlen( curr_dep ) + 1;
                                break;
                        case 's':
                                StartType = atoi( &argv[0][2] );
                                break;
                        case 'e':
                                ErrorControl = atoi( &argv[0][2] );
                                break;
                        case 't':
                                test_file = &argv[0][2];
                                break;
                        case 'q':
                                Quiet = TRUE;
                                break;
                        case 'h':
                                Usage();
                                break;
                        default:
                                fprintf( stderr, "Invalid option '%c'\n", argv[0][1] );
                                Usage();
                                break;
                        }
                }

        // Handle defaults if driver names are not specified
        if (curr_dep == &DependencyList[0]) {
                strcpy(curr_dep, "ParPort");
                curr_dep += strlen(curr_dep) + 1;
                }
        if (argc < 1)
                strcpy(ServiceName,"DbgPort");
        else
                strcpy(ServiceName,argv[0]);
        if (argc < 2) {
                GetSystemDirectory(ServiceExe,sizeof(ServiceExe));
                strcat(ServiceExe,"\\drivers\\dbgport.sys");
                }
        else
                strcpy(ServiceExe,argv[1]);

        if (GetVersion() & 0x80000000) {
                if (!Quiet) printf( "Not on Windows NT, can not install driver.\n" );
                return 0;
                }
        if (test_file != NULL && OpenDevice(test_file)) {
                if (!Quiet) printf( "Driver already running\n" );
                return 0;
                }
        schSCManager = OpenSCManager (NULL,                 // machine (NULL == local)
                                  NULL,                 // database (NULL == default)
                                  SC_MANAGER_ALL_ACCESS // access required
                                  );
        if (schSCManager == NULL) {
        fprintf( stderr, "Can not open service manager (%ld)\n", GetLastError() );
        return 1;
                }
        if (remove) {
                StopDriver( schSCManager, ServiceName );
                RemoveDriver( schSCManager, ServiceName );
                }
        else if (ServiceExe == NULL) {
        fprintf( stderr, "Missing service executable\n" );
        Usage();
                }
        else {
        *curr_dep = '\0';
                if (InstallDriver( schSCManager, ServiceName, ServiceExe ) ) {
                        if (StartDriver( schSCManager, ServiceName ) ) {
                                if (test_file != NULL ) {
                                        if (OpenDevice( test_file ) )
                                                if( !Quiet ) printf( "Driver Installation SUCCESS\n" );
                                        else
                                                fprintf ( stderr, "Driver not started\n" );
                                        }
                                }

                        }
                }
        CloseServiceHandle (schSCManager);
        return 0;
}