__declspec(dllexport) BOOL WINAPI QSI_Deinit(DWORD device_context) { SshInterceptor interceptor = (SshInterceptor)device_context; HANDLE qs_handle; /* Validate the device context. */ if (interceptor != the_interceptor) return FALSE; /* Perform unload processing. */ DriverUnload(interceptor->driver_object); /* Decrement this modules reference count. */ qs_handle = GetModuleHandle(FNAME_QUICKSEC); if (qs_handle) FreeLibrary(qs_handle); return TRUE; }
DLLEXPORT BOOL APIENTRY UnloadTrueCryptDriver(void) { TCAPI_CHECK_INITIALIZED(0); return DriverUnload (); }
// Service "main" function void _ServiceMain( void* ) { ThreadBag *pBag = NULL; //HANDLE hEvent; int tryTimes = 0; DWORD Current = 0; DWORD Previous = 0; LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\__gingko_pipe_server"); DWORD dwWaitRet = WaitForMultipleObjects(2, g_hServiceEvents, FALSE, 10000); LOG_START(); if( GkoInitialize() == FALSE ) { return; } InitCheapman(); LOG(L"GkCryptoInitialize\n"); //InstallAndLoadDriver(); LOG(L"InstallAndLoadDriver\n"); //StartGingkoService(); //StartGingkoHookingBackendThread(); //GingkoOneProcess( 1256, 0 ); //hEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); //if( hEvent == NULL || hEvent == INVALID_HANDLE_VALUE ) //{ // LOG(L"Error to CreateEvent. Error Code: %d.\n", GetLastError()); //} PipeListenerServerThreadStart(); if( DriverLoad() != ERROR_SUCCESS ) { PipeListenerServerThreadStop(); GkoUnInitialize(); UninitCheapman(); ServiceStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus( ServiceStatusHandle, &ServiceStatus ); return; } StartThread(DeviceIoThreadProc, NULL, &pBag ); if( pBag == NULL ) { LOG(L"Error to Start DeviceIoThreadProc. Error Code: %d.\n", GetLastError()); } while (dwWaitRet != WAIT_OBJECT_0) //do until receive a STOP events { dwWaitRet = WaitForMultipleObjects(2, g_hServiceEvents, FALSE, 2000000); if (dwWaitRet == WAIT_OBJECT_0 + 1) // Receive PAUSE events { WaitForSingleObject( g_hServiceEvents[2], INFINITE); // Wait for CONTINUE events } //LOG(L"CALL PING\n"); Current = GetTickCount(); if( Previous == 0 ) { Previous = GetTickCount(); } if( Current - Previous > 10000 ) { Previous = Current; if( TRUE ) { tryTimes ++; } if( tryTimes > 10 ) { tryTimes = 0; } } } //SERVICE_STATUS ServiceStatus = {0}; ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; SetServiceStatus( ServiceStatusHandle, &ServiceStatus ); LOG(_T("Service stop pending\n") ); LOG(_T("Service stop pending\n") ); UninitCheapman(); StopThread( pBag ); LOG(_T("Service stop pending\n") ); PipeListenerServerThreadStop(); //SetEvent( hEvent ); ///Exit the server thread. // Let's delete itself, after the service stopped //DeleteSvc(); LOG(_T("Close the Service Event Handle\n") ); CloseHandle( g_hServiceEvents[0] ); CloseHandle( g_hServiceEvents[1] ); CloseHandle( g_hServiceEvents[2] ); LOG(_T("Unload Driver\n") ); CloseBluefishDriver(); DriverUnload(); LOG(_T("Uninitialize Gingko System.\n") ); GkoUnInitialize(); LOG(_T("Shutdown LOG\n") ); LOG_SHUTDOWN(); ServiceStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus( ServiceStatusHandle, &ServiceStatus ); }
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; }