int on_app_start( wchar_t *cmd_line ) { PROCESS_BASIC_INFORMATION pbi; wchar_t name[MAX_PATH]; wchar_t path[MAX_PATH]; HKEY h_key; int resl, autorn; u32 cb, pid; int isvista; NTSTATUS status; HANDLE h_proc; STARTUPINFO si; PROCESS_INFORMATION pi; wchar_t *w_pid; pid = 0; autorn = 0; #ifdef LOG_FILE _log( L"func:app start; cmd line == \"%s\"", cmd_line ); #endif if ( wcsstr( cmd_line, L"-h" ) != NULL ) { autorn = 1; } else { if ( w_pid = wcsstr( cmd_line, L"-p" ) ) { autorn = 1; pid = wcstoul( w_pid + 2, NULL, 10 ); } } #ifdef LOG_FILE _log( L"func:app start; autorn == %d", autorn ); #endif isvista = is_win_vista( ); #ifdef LOG_FILE _log( L"func:app start; isvista == %d", isvista ); #endif if ( isvista != 0 ) { /* update autorun if old autorun found */ if ( RegCreateKey(HKEY_LOCAL_MACHINE, run_key, &h_key ) == 0) { cb = sizeof(path); if ( RegQueryValueEx( h_key, run_v_name, 0, NULL, pv(path), &cb ) == 0 ) { #ifdef LOG_FILE _log( L"func:app start; autorun set" ); #endif RegDeleteValue( h_key, run_v_name ); autorun_set(1); } RegCloseKey(h_key); } } do { if ( autorn == 0 ) { resl = ST_OK; break; } if ( isvista != 0 ) { if ( pid == 0 ) { status = NtQueryInformationProcess( GetCurrentProcess( ), ProcessBasicInformation, &pbi, sizeof(pbi), NULL ); #ifdef LOG_FILE _log( L"func:app start; %0.8X query information process" ); #endif if ( status == 0 ) { GetModuleFileName( NULL, name, sizeof(name) ); #ifdef LOG_FILE _log( L"func:app start; module file name == %s", name ); #endif _snwprintf( path, countof(path), L"\"%s\" -p%u", name, (u32)(pbi.InheritedFromUniqueProcessId) ); memset( &si, 0, sizeof(si) ); si.cb = sizeof(si); #ifdef LOG_FILE _log( L"func:app start; before create process \"%s\"", path ); #endif if ( CreateProcess( NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) ) { #ifdef LOG_FILE _log( L"func:app start; process created" ); #endif CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } resl = ST_NEED_EXIT; } else { if ( h_proc = OpenProcess( SYNCHRONIZE, FALSE, pid ) ) { #ifdef LOG_FILE _log( L"func:app start; %0.8X open process", h_proc ); #endif WaitForSingleObject( h_proc, INFINITE ); CloseHandle( h_proc ); #ifdef LOG_FILE _log( L"func:app start; return wait for single object", h_proc ); #endif } else { Sleep( 500 ); } autorun_set(1); resl = ST_AUTORUNNED; } } else { resl = ST_AUTORUNNED; } } while (0); #ifdef LOG_FILE _log( L"func:app start; %0.8X return", resl ); #endif return resl; }
INT_PTR CALLBACK _options_dlg_proc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { _ctl_init ctl_chk_general[ ] = { { STR_NULL, IDC_AUTO_MOUNT_ON_BOOT, CONF_AUTOMOUNT_BOOT }, { STR_NULL, IDC_EXPLORER_ON_MOUNT, CONF_EXPLORER_MOUNT }, { STR_NULL, IDC_CACHE_PASSWORDS, CONF_CACHE_PASSWORD }, { STR_NULL, IDC_UNMOUNT_LOGOFF, CONF_DISMOUNT_LOGOFF }, { STR_NULL, IDC_FORCE_UNMOUNT, CONF_FORCE_DISMOUNT }, { STR_NULL, IDC_WIPE_LOGOFF, CONF_WIPEPAS_LOGOFF }, { STR_NULL, IDC_AUTO_START, CONF_AUTO_START } }; _ctl_init ctl_chk_extended[ ] = { { STR_NULL, IDC_HARD_CRYPTO_SUPPORT, CONF_HW_CRYPTO }, { STR_NULL, IDC_HIDE_FILES, CONF_HIDE_DCSYS }, { STR_NULL, IDC_DISABLE_TRIM, CONF_DISABLE_TRIM }, { STR_NULL, IDC_SSD_OPTIMIZATION, CONF_ENABLE_SSD_OPT } }; _ctl_init static_head_general[ ] = { { L"# Mount Settings", IDC_HEAD1, 0 }, { L"# Password Caching", IDC_HEAD2, 0 }, { L"# Boot Options", IDC_HEAD3, 0 } }; _ctl_init static_head_extended[ ] = { { L"# Extended Settings", IDC_HEAD1, 0 } }; WORD code = LOWORD(wparam); WORD id = LOWORD(wparam); DWORD _flags = 0; DWORD _hotkeys[HOTKEYS] = { 0 }; _wnd_data *wnd; int check = 0; int k = 0; switch ( message ) { case WM_INITDIALOG : { TCITEM tab_item = { TCIF_TEXT }; HWND h_tab = GetDlgItem( hwnd, IDT_TAB ); _tab_data *d_tab = malloc(sizeof(_tab_data)); wnd = _sub_class( h_tab, SUB_NONE, CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_GENERAL), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_EXTNDED), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), CreateDialog( __hinst, MAKEINTRESOURCE(DLG_CONF_HOTKEYS), GetDlgItem(hwnd, IDC_TAB), _tab_proc ), HWND_NULL ); memset(d_tab, 0, sizeof(_tab_data)); d_tab->active = wnd->dlg[0]; wnd_set_long(hwnd, GWL_USERDATA, d_tab); { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { _sub_class( GetDlgItem( wnd->dlg[0], ctl_chk_general[k].id ), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[0], ctl_chk_general[k].id, __config.conf_flags & ctl_chk_general[k].val ); } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { _sub_class( GetDlgItem( wnd->dlg[1], ctl_chk_extended[k].id ), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[1], ctl_chk_extended[k].id, __config.conf_flags & ctl_chk_extended[k].val ); } if ( ! (__config.load_flags & DST_HW_CRYPTO) ) { wchar_t s_ch_label[MAX_PATH] = { 0 }; HWND h_check = GetDlgItem( wnd->dlg[1], IDC_HARD_CRYPTO_SUPPORT ); EnableWindow( h_check, FALSE ); GetWindowText( h_check, s_ch_label, sizeof_w(s_ch_label) ); wcscat( s_ch_label, L" (not supported)" ); SetWindowText( h_check, s_ch_label ); } for ( k = 0; k < array_num(static_head_general); k++ ) { SetWindowText(GetDlgItem(wnd->dlg[0], static_head_general[k].id), static_head_general[k].display); SendMessage(GetDlgItem(wnd->dlg[0], static_head_general[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); } for ( k = 0; k < array_num(static_head_extended); k++ ) { SetWindowText(GetDlgItem(wnd->dlg[1], static_head_extended[k].id), static_head_extended[k].display); SendMessage(GetDlgItem(wnd->dlg[1], static_head_extended[k].id), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0); } SendMessage( wnd->dlg[0], WM_USER_CLICK, (WPARAM)GetDlgItem(wnd->dlg[0], IDC_AUTO_START), 0 ); _sub_class( GetDlgItem(wnd->dlg[2], IDC_KEY_USEEXT), SUB_STATIC_PROC, HWND_NULL ); k = 0; while ( hotks_edit[k].id != -1 ) { wchar_t key[200] = { 0 }; _sub_class( GetDlgItem(wnd->dlg[2], hotks_edit[k].id), SUB_KEY_PROC, HWND_NULL ); _sub_class( GetDlgItem(wnd->dlg[2], hotks_chk[k].id), SUB_STATIC_PROC, HWND_NULL ); _set_check( wnd->dlg[2], hotks_chk[k].id, __config.hotkeys[k] ); SendMessage( wnd->dlg[2], WM_USER_CLICK, (WPARAM)GetDlgItem(wnd->dlg[2], hotks_chk[k].id), 0 ); _key_name(HIWORD( __config.hotkeys[k]), LOWORD(__config.hotkeys[k]), key ); SetWindowText(GetDlgItem(wnd->dlg[2], hotks_edit[k].id), key); ((_wnd_data *)wnd_get_long( GetDlgItem(wnd->dlg[2], hotks_edit[k].id), GWL_USERDATA) )->vk = __config.hotkeys[k]; k++; } } tab_item.pszText = L"General"; TabCtrl_InsertItem(h_tab, 0, &tab_item); tab_item.pszText = L"Extended"; TabCtrl_InsertItem(h_tab, 1, &tab_item); tab_item.pszText = L"Hot Keys"; TabCtrl_InsertItem(h_tab, 2, &tab_item); { k = 1; while ( wnd->dlg[k] != 0 ) { ShowWindow( wnd->dlg[k], SW_HIDE ); k++; } } SetForegroundWindow( hwnd ); return 1L; } break; case WM_NOTIFY : { if ( wparam == IDT_TAB ) { if ( ((NMHDR *)lparam)->code == TCN_SELCHANGE ) { HWND h_tab = GetDlgItem(hwnd, IDT_TAB); if ( !_is_curr_in_group(h_tab) ) { _change_page( h_tab, TabCtrl_GetCurSel(h_tab) ); } } } } break; case WM_COMMAND : { /* switch (id) { case ID_SHIFT_TAB : case ID_TAB : { HWND h_current = GetFocus( ); HWND h_next = GetNextDlgTabItem( sheets[index].hwnd, h_current, id == ID_SHIFT_TAB ); SetFocus( h_next ); } break; */ if ( (id == IDOK) || (id == IDCANCEL) ) { wnd = wnd_get_long( GetDlgItem(hwnd, IDT_TAB), GWL_USERDATA ); if ( wnd ) { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { _flags |= _get_check(wnd->dlg[0], ctl_chk_general[k].id) ? ctl_chk_general[k].val : FALSE; } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { _flags |= _get_check(wnd->dlg[1], ctl_chk_extended[k].id) ? ctl_chk_extended[k].val : FALSE; } k = 0; while ( hotks_edit[k].id != -1 ) { if ( _get_check(wnd->dlg[2], hotks_chk[k].id) ) { _hotkeys[k] = ( (_wnd_data *)wnd_get_long(GetDlgItem(wnd->dlg[2], hotks_edit[k].id), GWL_USERDATA) )->vk; } k++; } } if ( id == IDCANCEL ) check = TRUE; if ( id == IDOK ) { _unset_hotkeys(__config.hotkeys); check = _check_hotkeys(wnd->dlg[0], _hotkeys); if ( check ) { if ( _hotkeys[3] && !__config.hotkeys[3] ) { if (! __msg_w( hwnd, L"Set Hotkey for call BSOD?" ) ) { _hotkeys[3] = 0; } } if ( (_flags & CONF_AUTO_START) != (__config.conf_flags & CONF_AUTO_START) ) { autorun_set(_flags & CONF_AUTO_START); } __config.conf_flags = _flags; memcpy(&__config.hotkeys, &_hotkeys, sizeof(DWORD)*HOTKEYS); dc_save_conf(&__config); } _set_hotkeys(hwnd, __config.hotkeys, FALSE); } if ( check ) { EndDialog (hwnd, id); } return 1L; } } break; case WM_DESTROY : { wnd = wnd_get_long( GetDlgItem(hwnd, IDT_TAB), GWL_USERDATA ); if ( wnd ) { for ( k = 0; k < array_num(ctl_chk_general); k++ ) { __unsub_class(GetDlgItem(wnd->dlg[0], ctl_chk_general[k].id)); } for ( k = 0; k < array_num(ctl_chk_extended); k++ ) { __unsub_class(GetDlgItem(wnd->dlg[1], ctl_chk_extended[k].id)); } __unsub_class(GetDlgItem(wnd->dlg[1], IDC_KEY_USEEXT)); k = 0; while ( hotks_edit[k].id != -1 ) { __unsub_class(GetDlgItem(wnd->dlg[2], hotks_edit[k].id)); __unsub_class(GetDlgItem(wnd->dlg[2], hotks_chk[k].id)); k++; } } __unsub_class(GetDlgItem(hwnd, IDT_TAB)); } break; default : { int rlt = _draw_proc(message, lparam); if ( rlt != -1 ) { return rlt; } } } return 0L; }