BOOL CINSTALLSYS::InstallDriver( CString DriverName, CString DriverFromPath) { if(IsDriverStarted(DriverName)==TRUE) { AfxMessageBox("驱动已经加载,或无法得到驱动信息,操作已停止"); return TRUE; } _TCHAR System32Directory[_MAX_PATH]; if( 0==GetSystemDirectory(System32Directory,_MAX_PATH)) { AfxMessageBox("Could not find Windows system directory"); return FALSE; } ///////////////////////////////////////////////////////////////////////// // Copy driver .sys file across CString DriverFullPath = (CString)System32Directory+"\\Drivers\\"+DriverName+".sys"; if( 0==CopyFile( DriverFromPath, DriverFullPath, FALSE)) // Overwrite OK { AfxMessageBox("Could not find Windows system directory"); return FALSE; } CString SubDriverFromPath=Replace(DriverFromPath,DriverName,"DebugPrt"); CString SubDriverFullPath=(CString)System32Directory+"\\Drivers\\"+"DebugPrt.sys"; if(0==CopyFile(SubDriverFromPath,SubDriverFullPath,FALSE)) { AfxMessageBox("Could not find Windows system directory"); return FALSE; } //创建服务 if(!CreateDriverService(DriverName)) return FALSE; if(!RegeditKey(DriverName) || !RegeditKey(TEXT("DebugPrt"))) return FALSE; //开始服务 if(!StartDriverService(DriverName)) return FALSE; AfxMessageBox("传输驱动程序安装成功!"); return TRUE; }
int _tmain(int argc, _TCHAR* argv[]) { if( argc > 1 ) { if( wcscmp( argv[1], L"-Install" ) == 0 ){ DriverLoad (); DatabaseInstall(); } else if( wcscmp( argv[1], L"-Remove" ) == 0 ){ DriverUnload(); } else if( wcscmp( argv[1], L"-Map" ) == 0 ) { if( argc > 2 ) { TestEncryptFileMapping( argv[2] ); } } else if( wcscmp( argv[1], L"-Run" ) == 0 ){ StartDriverService(); OpenDatabase( FALSE ); HANDLE RequestReadQueueEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); ThreadBag* bag; //Randinit(); StartThread( DeviceIoThreadProc, NULL, &bag ); if( bag != NULL ) { } //WaitForSingleObject( bag->hThread, INFINITE ); getchar(); CloseDatabase(); } else if( wcscmp( argv[1], L"-Write" ) == 0 ){ StartDriverService(); if( argc > 3 ) { EncryptionControl(TRUE); TestEncryptProcess( argv[2], argv[3] ); EncryptionControl(FALSE); }else{ wprintf(L"%s: -Write <Input File> <Output File>\n", argv[0]); return 1; } }else if( wcscmp( argv[1], L"-DB" ) == 0 ) { //Randinit(); DatabaseInstall(); wprintf(L"Install database is OK.\n"); OpenDatabase( FALSE ); wprintf(L"Try to open database is OK.\n"); PrivateKeyRequest* request = (PrivateKeyRequest*) malloc( sizeof(PrivateKeyRequest) + sizeof(WCHAR)* MAX_PATH ); PrivateKeyResponse response; if( request != NULL ) { memset( request, 0, sizeof(PrivateKeyRequest) + sizeof(WCHAR)* MAX_PATH ); HexToBytes( (const unsigned char*)"585a59303031", request->Company, 12 ); HexToBytes( (const unsigned char*)"6fe244d8d619064a8abfe23608d27d15", request->Md5, 32 ); memcpy( request->Filename, L"E:\\testing\\test.doc", 19 * 2 ); request->FilenameLength = 19 * 2; QueryPrimaryKey( request, &response ); RenewPrimaryKey( request, &response ); free( request ); } } else if( wcscmp( argv[1], L"-Combine" ) == 0 ){ WCHAR* Path = NULL; if( argc <= 2 ) { wprintf(L"%s: -Combine <File Pattern> [<OutputFileName>] [<Changed Directory>]\n", argv[0]); return 1; } if( argc < 4 ) { DWORD nSize = GetCurrentDirectory( 0, NULL ); if( nSize > 0 ) { Path = (WCHAR*) malloc( sizeof(WCHAR) * (nSize + 1) ); if( Path != NULL ) { if( GetCurrentDirectory( nSize, Path ) == 0 ) { free( Path ); Path = NULL; } } } } CombineDirectory( argv[2], argc > 3 ? argv[3] : L"combined.out", Path ); if( Path != NULL ) { free( Path ); } } else if( wcscmp( argv[1], L"-Copy" ) == 0 ) { if( argc >= 4 ) { CopyFileDest( argv[2], argv[3], FALSE ); }else{ wprintf(L"%s: -Copy <Source File> <Dest File>\n", argv[0]); } }else if( argv[1][0] == L'-' ){ wprintf( L"%s: -Install\n%s: -Remove\n", argv[0], argv[0] ); }else{ StartDriverService(); TestDecryptProcess( L"c:\\Test\\test_out--gko-512.pdf" ); } } return 0; }