示例#1
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;
}
示例#2
0
void 
_add_drive_node(
		_dnode    *exist_node,
		drive_inf *new_drv,
		vol_inf   *vol, 
		int        disk_number
	)
{
	wchar_t drvname[MAX_PATH];

	wchar_t fs[MAX_PATH]    = { 0 };
	wchar_t label[MAX_PATH] = { 0 };

	wchar_t path[MAX_PATH];

	list_entry *node;
	BOOL root_exists = FALSE;

	_dnode *root;
	_dnode *mnt;

	mnt = exist_node;
	if ( mnt == NULL )
	{
		mnt = malloc( sizeof(_dnode) );
		memset( mnt, 0, sizeof(_dnode) );
	}
	mnt->exists = TRUE;
	memcpy( &mnt->mnt.info, vol, sizeof(vol_inf) );

	_snwprintf( path, sizeof_w(path), L"%s\\", vol->status.mnt_point );
	GetVolumeInformation( path, label, sizeof_w(label), 0, 0, 0, fs, sizeof_w(fs) );

	wcscpy( mnt->mnt.label, label );
	wcscpy( mnt->mnt.fs, fs );

	if (! exist_node )
	{
		dc_get_hw_name(
			disk_number, vol->status.flags & F_CDROM, drvname, sizeof_w(drvname)
			);

		if (! ( vol->status.flags & F_CDROM ) )
		{
			for ( node  = __drives.flink;
				  node != &__drives;
				  node  = node->flink ) 
			{
				root = contain_record(node, _dnode, list);
				if ( root->root.dsk_num == disk_number )
				{
					root_exists = TRUE;
					break;
				}
			}
		}
		mnt->is_root = FALSE;
		memcpy( &mnt->root.info, new_drv, sizeof(drive_inf) );

		if (! root_exists )
		{
			root = malloc(sizeof(_dnode));	
			root->is_root = TRUE;

			memcpy(&root->mnt.info, vol, sizeof(vol_inf));
			memcpy(&root->root.info, new_drv, sizeof(drive_inf));

			wcscpy(root->root.dsk_name, drvname);
			root->root.dsk_num = disk_number;	

			_init_list_head(&root->root.vols);
			_insert_tail_list(&__drives, &root->list);

		} 
		_insert_tail_list(&root->root.vols, &mnt->list);

	} 		
	if ( vol->status.flags & F_SYNC && _create_act_thread(mnt, -1, -1) == NULL )
	{
		_create_act_thread(mnt, ACT_ENCRYPT, ACT_PAUSED);
	}
}
示例#3
0
void _init_keyfiles_list( )
{
	_init_list_head(& __key_files );
	_init_list_head(& __key_files_new );
}