Ejemplo n.º 1
0
DWORD 
WINAPI 
_thread_enc_iso_proc(
		LPVOID lparam
	)
{
	_dnode *node;
	dc_open_device( );

	if ( (node = pv(lparam)) != NULL )
	{
		node->dlg.rlt = ST_OK;

		node->dlg.rlt = dc_encrypt_cd(
			node->dlg.iso.s_iso_src, node->dlg.iso.s_iso_dst, node->dlg.iso.pass, node->dlg.iso.cipher_id, dc_cd_callback, lparam
			);
		{
			secure_free( node->dlg.iso.pass );
			SendMessage( GetParent(GetParent(node->dlg.h_page)), WM_CLOSE_DIALOG, 0, 0 );
		}

	}
	//EnterCriticalSection(&crit_sect);
	//LeaveCriticalSection(&crit_sect);

	dc_close_device( );
	return 1L;
}
Ejemplo n.º 2
0
int WINAPI wWinMain(
		HINSTANCE hinst,
		HINSTANCE hprev,
		LPWSTR    cmd_line,
		int       cmd_show
	)
{
	int rlt;
	int ver;
	int app_start = on_app_start( cmd_line );

#ifdef LOG_FILE
	_log( L"%0.8X app start", app_start );
#endif

	if ( app_start == ST_NEED_EXIT )
	{
		return 0;
	}
	if ( _ui_init(hinst) == 0 )
	{
		__error_s( HWND_DESKTOP, L"Error GUI initialization", ST_OK );
		return 0;
	}
	if ( is_admin( ) != ST_OK )
	{
		__error_s( HWND_DESKTOP, L"Admin Privileges Required", ST_OK );
		return 0;
	}
#ifdef _M_IX86 
	if ( is_wow64( ) != 0 )
	{
		__error_s( HWND_DESKTOP, L"Please use x64 version of DiskCryptor", ST_OK );
		return 0;
	}
#endif
	if ( dc_is_old_runned( ) != 0 )
	{
		__error_s(
			HWND_DESKTOP, 
			L"DiskCryptor 0.1-0.4 installed, please completely uninstall it before use this version.", ST_OK
			);

		return 0;
	}
#ifdef LOG_FILE
	_log( L"%0.8X driver status", dc_driver_status( ) );
#endif
	if ( dc_is_driver_works( ) == FALSE )
	{
		if ( ( rlt = _drv_action(DA_INSTAL, 0) ) != NO_ERROR )
		{
			__error_s( HWND_DESKTOP, NULL, rlt );
		}
		return 0;
	}
	if ( ( rlt = dc_open_device( ) ) != ST_OK )
	{
		__error_s( HWND_DESKTOP, L"Can not open DC device", rlt );
		return 0; 
	}
	
	ver = dc_get_version( );

#ifdef LOG_FILE
	_log( L"%0.8X dc version", ver );
#endif

	if ( ver < DC_DRIVER_VER )
	{
		if ( ( rlt = _drv_action(DA_UPDATE, ver) ) != NO_ERROR )
		{
			__error_s( HWND_DESKTOP, NULL, rlt );
		}
		return 0;
	}

	if ( ver > DC_DRIVER_VER )
	{
		__msg_i(
			HWND_DESKTOP,
			L"DiskCryptor driver v%d detected\n"
			L"Please use last program version", ver
			);

		return 0;
	}
	{
		HWND h_find;
		WNDCLASS wc = { 0 };

		wc.lpszClassName = DC_CLASS;
		wc.lpfnWndProc   = &_class_dlg_proc;
		wc.cbWndExtra    = DLGWINDOWEXTRA;
		wc.hIcon         = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON_TRAY));

		dlg_class = RegisterClass(&wc);

#ifdef LOG_FILE
	_log( L"%0.8X register class", dlg_class );
#endif

		h_find = FindWindow(DC_CLASS, NULL);

#ifdef LOG_FILE
	_log( L"%0.8X find window", h_find );
#endif

		if ( h_find != NULL )
		{
			ShowWindow( h_find, SW_SHOW );
			SetForegroundWindow( h_find );

#ifdef LOG_FILE
	_log( L"show window [ %0.8X ] return", h_find );
#endif
			return 0;
		}
	}
	if ( ( rlt = rnd_init( ) ) != ST_OK )
	{
		__error_s( HWND_DESKTOP, L"Can not initialize RNG", rlt );
		return 0;
	}

	if ( (rlt = dc_load_config(&__config) == NO_ERROR ? ST_OK : ST_ERROR) != ST_OK )
	{
		__error_s( HWND_DESKTOP, L"Error get config", rlt );
		return 0;		
	}
	InitializeCriticalSection( &crit_sect );

#ifdef LOG_FILE
	_log( L"initialize critical section" );
#endif

	_init_list_head( &__drives );
	_init_list_head( &__action );

	_init_keyfiles_list( );

#ifdef LOG_FILE
	_log( L"init keyfiles list" );
#endif
	{
		HWND   h_dialog;
		MSG    msg;

		__hacc = LoadAccelerators( hinst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );

#ifdef LOG_FILE
		_log( L"before create dialog" );
#endif

		h_dialog = CreateDialog( GetModuleHandleA(NULL), MAKEINTRESOURCE(IDD_MAIN_DLG), HWND_DESKTOP, _main_dialog_proc );

#ifdef LOG_FILE
		_log( L"%0.8X create dialog", h_dialog );
#endif

		rlt = ShowWindow( h_dialog, app_start == ST_AUTORUNNED ? SW_HIDE : SW_SHOW );

#ifdef LOG_FILE
		_log( L"%0.8X show window", rlt );
#endif

		while ( GetMessage( &msg, NULL, 0, 0 ) )
		{
			if ( !TranslateAccelerator( h_dialog, __hacc, &msg ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
		}
		DestroyAcceleratorTable( __hacc );
	}

	return TRUE;
}
Ejemplo n.º 3
0
DWORD 
WINAPI 
_thread_format_proc(
		LPVOID lparam
	)
{
	int i = 0;
	int rlt, wp_mode;

	wchar_t device[MAX_PATH];
	_dnode *node;
	_dact  *act;

	dc_open_device( );
	EnterCriticalSection(&crit_sect);

	node = pv(lparam);
	act = _create_act_thread(node, -1, -1);

	if ( !node || !act ) 
	{
		return 0L;
	}
	wcscpy(device, act->device);
	do 
	{
		if ( act->status != ACT_RUNNING )
		{
			break;
		}
		if ( i-- == 0 )
		{
			dc_sync_enc_state(device); 
			i = 20;
		}
		wp_mode = act->wp_mode;
		LeaveCriticalSection( &crit_sect );

		rlt = dc_format_step( device, wp_mode );
		
		EnterCriticalSection( &crit_sect );
		if ( rlt == ST_FINISHED )
		{
			act->status = ACT_STOPPED;
			break;
		}
		if ( ( rlt != ST_OK ) && ( rlt != ST_RW_ERR ) )
		{
			dc_status st;
			dc_get_device_status( device, &st );

			__error_s(
				HWND_DESKTOP,
				L"Format error on volume [%s]", rlt, st.mnt_point
				);
			
			act->status = ACT_STOPPED;
			break;
		}
	} while (1);

	if ( rlt == ST_FINISHED )
	{
		_finish_formating( node );
	}
	LeaveCriticalSection( &crit_sect );

	return 1L;

}
Ejemplo n.º 4
0
static
DWORD WINAPI 
_thread_enc_dec_proc(
		LPVOID lparam
	)
{
	BOOL encrypting;
	int i = 0;
	int rlt, wp_mode;

	wchar_t device[MAX_PATH];
	_dnode *node;
	_dact *act;

	dc_open_device( );
	EnterCriticalSection( &crit_sect );

	node = pv(lparam);
	act = _create_act_thread(node, -1, -1);

	if ( !node || !act )
	{
		return 0L;
	}

	wcscpy( device, act->device );
	do 
	{
		if ( act->status != ACT_RUNNING )
		{
			break;
		}
		if ( i-- == 0 )
		{
			dc_sync_enc_state( device );
			i = 20;
		}
		encrypting = act->act != ACT_DECRYPT;
		wp_mode = act->wp_mode;

		LeaveCriticalSection( &crit_sect );

		rlt = encrypting ?
			dc_enc_step(device, wp_mode) :
			dc_dec_step(device);

		EnterCriticalSection(&crit_sect);
		if ( rlt == ST_FINISHED )
		{
			act->status = ACT_STOPPED;
			break;
		}
		if ( rlt == ST_CANCEL )
		{
			Sleep(5000);
		}
		if ( ( rlt != ST_OK ) && ( rlt != ST_RW_ERR ) && ( rlt != ST_CANCEL ) )
		{
			dc_status st;
			wchar_t *act_name;

			dc_get_device_status( device, &st );
			switch ( act->act )
			{
				case ACT_ENCRYPT:   act_name = L"Encryption";   break;
				case ACT_DECRYPT:   act_name = L"Decryption";   break;
				case ACT_REENCRYPT: act_name = L"Reencryption"; break;
			}
			__error_s(
				HWND_DESKTOP,
				L"%s error on volume [%s]", rlt, act_name, st.mnt_point
				);
			
			act->status = ACT_STOPPED;
			break;
		}
	} while (1);

	dc_sync_enc_state(device);
	LeaveCriticalSection(&crit_sect);

	return 1L;

}
Ejemplo n.º 5
0
int WINAPI wWinMain(
		HINSTANCE hinst,
		HINSTANCE hprev,
		LPWSTR    cmd_line,
		int       cmd_show
		)
{
	int d_st;
	int resl;

	if (dc_is_old_runned() != 0) {
		return ST_INCOMPATIBLE;
	}

	/* open DC driver device */
	dc_open_device();
	/* get DC sriver status */
	d_st = dc_driver_status();
	resl = ST_ERROR;

	do
	{
		if (wcscmp(cmd_line, L"-setup") == 0)
		{
			if (d_st == ST_ERROR) {
				resl = dc_install_driver(NULL);
			} else
			{
				resl = dc_update_boot(-1);

				if ( (resl != ST_OK) && (resl != ST_BLDR_NOTINST) ) {
					break;
				}
				resl = dc_update_driver();
			}
			break;
		}

		if (wcscmp(cmd_line, L"-unins") == 0)
		{
			if (d_st == ST_ERROR) {
				resl = ST_ERROR; break;
			}
			resl = dc_remove_driver(); 
			break;
		}

		if (wcscmp(cmd_line, L"-unldr") == 0) {
			resl = dc_unset_mbr(-1);
			break;
		}

		if (wcscmp(cmd_line, L"-isboot") == 0) {
			ldr_config conf;
			resl = dc_get_mbr_config(-1, NULL, &conf);
			break;
		}		

		if (wcscmp(cmd_line, L"-isenc") == 0)
		{
			vol_inf info;
			u32     flags;
			wchar_t boot_dev[MAX_PATH];
			int     is_enc = 0;

			if (dc_open_device() != ST_OK) {
				resl = ST_ERROR; break;
			}

			if (dc_get_boot_device(boot_dev) != ST_OK) {
				boot_dev[0] = 0;
			}
	
			if (dc_first_volume(&info) == ST_OK)
			{
				do
				{
					flags = info.status.flags;

					if ( ((flags & F_SYSTEM) || 
						  (wcscmp(info.device, boot_dev) == 0)) && (flags & F_ENABLED) )
					{
						is_enc = 1;
					}
				} while (dc_next_volume(&info) == ST_OK);
			}

			dc_close_device();
			resl = is_enc != 0 ? ST_ENCRYPTED : ST_OK; break;
		}
	} while (0);

	return resl;
}