Exemplo n.º 1
0
void
as_destroy(struct addrspace *as)
{
    /*
     * Clean up as needed.
     */
    unsigned len, i;
    pt_destroy(as, as->pagetable);
    struct region *region_ptr;

    for (i = 0; i < PT_LEVEL_SIZE; i++) {
    	if (as->pt_locks[i])
	    	lock_destroy(as->pt_locks[i]);
    }
    
    len = array_num(as->as_regions);
    // for (i = len - 1; i > 0; i--){
    //  region_ptr = array_get(as->as_regions, i);
    //  kfree(region_ptr);
    //  array_remove(as->as_regions, i);
    // }

    i = len - 1;
    while (len > 0){
        region_ptr = array_get(as->as_regions, i);
        kfree(region_ptr);
        array_remove(as->as_regions, i);
        if (i == 0)
            break;
        i--;
    }
    array_destroy(as->as_regions);
    kfree(as);
}
static void removePagesWithinRegion(struct addrspace* as, struct region* reg) {
	int pageCount = array_num(as->as_pagetable);
	int i;
	for (i = 0; i < pageCount; i++) {
		struct page *pageCandidate = array_get(as->as_pagetable, i);
		if (pageCandidate != NULL
				&& pageCandidate->pt_virtbase >= reg->rg_vaddr / PAGE_SIZE
				&& pageCandidate->pt_virtbase
						<= (reg->rg_vaddr + reg->rg_size) / PAGE_SIZE) {
			array_remove(as->as_pagetable, i);
			freePage(pageCandidate);
			kfree(pageCandidate);
			i--;
			pageCount = array_num(as->as_pagetable);
		}
	}
}
Exemplo n.º 3
0
bool stack_increase(struct stack_s* self, int increase_num)
{
    bool ret = array_increase(self->array, increase_num);
    if(ret)
    {
        self->element_num = array_num(self->array);
    }

    return ret;
}
static int getftarrayindex(struct array* ft, int fd) {
	unsigned int i;
	unsigned int ft_len = array_num(ft);
	for (i = 0; i < ft_len; i++) {
		if (((struct filetable_entry*) array_get(ft, i))->ft_fd == fd) {
			return i;
		}
	}
	return -1;
}
struct proc* proc_createchild(struct proc* parent, struct addrspace** as) {
	struct proc* child = proc_create(parent->p_name);
	if (child == NULL) {
		return NULL;
	}

	unsigned int i;
	// TODO Move this to a separate method
	for (i = 0; i < array_num(parent->p_filetable); i++) {
		struct filetable_entry* entry = array_get(parent->p_filetable, i);
		struct filetable_entry* newentry = (struct filetable_entry*) kmalloc(sizeof(struct filetable_entry));
		if(entry == NULL) {
			proc_destroy(child);
			return NULL;
		}
		newentry->ft_fd =  entry->ft_fd;

		newentry->ft_handle = entry->ft_handle;
		filehandle_incref(entry->ft_handle);
		int s = array_add(child->p_filetable, newentry, NULL);

		if (s == ENOMEM) {
			proc_destroy(child);
			return NULL;
		}
	}

	child->p_fdcounter = parent->p_fdcounter;

	/** process table */
	if (addTo_processtable(child) != 0) {
		return NULL;
	}
	child->p_ppid = parent->p_pid;

	/** cwd */
	/*
	 * Lock the current process to copy its current directory.
	 * (We don't need to lock the new process, though, as we have
	 * the only reference to it.)
	 */
	spinlock_acquire(&(parent->p_lock));
	if (parent->p_cwd != NULL) {
		VOP_INCREF(parent->p_cwd);
		child->p_cwd = parent->p_cwd;
	}
	spinlock_release(&(parent->p_lock));

	/** address space */
	(void) as;
	return child;
}
static struct page* findPageForFaultAddress(struct addrspace* as,
		vaddr_t faultaddress) {
	int pageCount = array_num(as->as_pagetable);
	int i;
	for (i = 0; i < pageCount; i++) {
		struct page *pageCandidate = array_get(as->as_pagetable, i);
		if (pageCandidate != NULL
				&& pageCandidate->pt_virtbase == faultaddress / PAGE_SIZE) {
			return pageCandidate;
		}
	}
	return NULL;
}
static struct page* findPageFromCoreMap(struct core_map_entry* cm, int idx) {
	int num = array_num(cm->as->as_pagetable);
	int i;
	for (i = 0; i < num; i++) {
		struct page* pg = array_get(cm->as->as_pagetable, i);
		if (pg->pt_pagebase == cm_getEntryPaddr(idx) / PAGE_SIZE) {
			return pg;
		}
	}
	panic("couldnt find page in address space\n");
	return NULL;

}
static int reduceHeapSize(userptr_t amount, int32_t* retval,
		struct addrspace* as) {
	vaddr_t newStart = as->as_addrPtr + (vaddr_t) amount;
	vaddr_t oldStart = as->as_addrPtr;
	unsigned int regionCount = array_num(as->as_regions);
	unsigned int i;
	if (as->as_heapBase > newStart) {
		//kprintf("Invalid because it falls within code page %x\n",
		//		codepage->rg_vaddr + codepage->rg_size);
		*retval = -1;
		return ENOMEM;
	}
	for (i = 0; i < regionCount; i++) {
		struct region* reg = array_get(as->as_regions, i);
		if (reg != NULL && reg->rg_vaddr >= as->as_stackBase
				&& reg->rg_vaddr + reg->rg_size >= as->as_stackBase) {
			continue;
		}
		if (reg != NULL && reg->rg_vaddr >= newStart) {
			removePagesWithinRegion(as, reg);
			array_remove(as->as_regions, i);
			kfree(reg);
			i--;
			regionCount = array_num(as->as_regions);
		} else if (reg != NULL && reg->rg_vaddr <= newStart
				&& reg->rg_vaddr + reg->rg_size >= newStart) {
			struct region tempReg;
			tempReg.rg_vaddr = newStart;
			tempReg.rg_size = newStart - (reg->rg_vaddr + reg->rg_size);
			reg->rg_size = newStart - reg->rg_vaddr;
			removePagesWithinRegion(as, &tempReg);
		}
	}
	as->as_addrPtr = newStart;
	*retval = oldStart;
	//kprintf("retval is = %x\n", as->as_addrPtr);
	return 0;
}
static struct region* findRegionForFaultAddress(struct addrspace* as,
		vaddr_t address) {
	int regionCount = array_num(as->as_regions);
	int i;
	for (i = 0; i < regionCount; i++) {
		struct region* reg = array_get(as->as_regions, i);
		if (reg != NULL && reg->rg_vaddr <= address
				&& (reg->rg_vaddr + reg->rg_size) > address) {
			return reg;
		}
	}
	//kprintf("Region count is : %u\n",regionCount);
	return NULL;
}
Exemplo n.º 10
0
int test_pkcs5()
{
	const char *p_key, *data;
	u8          hmac[SHA512_DIGEST_SIZE];
	const char *pass, *salt;
	int         i, dklen;	
	u8          dk[144];

	/* test HMAC-SHA-512 */
	for (i = 0; i < array_num(sha512_hmac_vectors); i++) 
	{
		p_key = sha512_hmac_vectors[i].key;
		data  = sha512_hmac_vectors[i].data;

		sha512_hmac(p_key, strlen(p_key), data, strlen(data), hmac);

		if (memcmp(hmac, sha512_hmac_vectors[i].hmac, sizeof(hmac)) != 0) {
			return 0;
		}
	}
	/* test PKDBF2 */
	for (i = 0; i < array_num(pkcs5_vectors); i++)
	{
		pass  = pkcs5_vectors[i].password;
		salt  = pkcs5_vectors[i].salt;
		dklen = pkcs5_vectors[i].dklen;

		sha512_pkcs5_2(
			pkcs5_vectors[i].i_count, pass, strlen(pass), salt, strlen(salt), dk, dklen);

		if (memcmp(dk, pkcs5_vectors[i].key, dklen) != 0) {
			return 0;
		}
	}	
	return 1;
}
Exemplo n.º 11
0
int
as_check_region(struct addrspace *as, vaddr_t va)
{
	int i;
	struct region *region;
	int len = array_num(as->as_regions);

	for (i = 0; i < len; i++){
		region = array_get(as->as_regions, i);
		if (va >= region->base && va < (region->base + region->size)){
			return region->permission;
		}
	}
	// Can't find the addr in region, this is a segfault
	return -1;
}
Exemplo n.º 12
0
static
void
commandline_macros_cleanup(void)
{
	unsigned i, num;
	struct commandline_macro *cm;

	num = array_num(&commandline_macros);
	for (i=0; i<num; i++) {
		cm = array_get(&commandline_macros, i);
		dofree(cm, sizeof(*cm));
	}
	array_setsize(&commandline_macros, 0);
	
	array_cleanup(&commandline_macros);
}
void filetable_empty(struct array* ft) {
	int i;
	for (i = array_num(ft) -1 ; i >=0 ; i--) {
		struct filetable_entry* entry = (struct filetable_entry*) array_get(ft,
				i);
		filehandle_destroy(entry->ft_handle);

		// free memory allocated for the entry
		kfree(entry);

		// remove the entry from the filetable
		array_remove(ft, i);

	}

}
Exemplo n.º 14
0
void free_children(int ppid){
  struct procinfo *cpi;

  //struct procinfo *ppi = array_get(procinfotable, ppid);
  for(unsigned int i = 0; i<array_num(procinfotable); i++){
    cpi = array_get(procinfotable, i);
    if(cpi == NULL){
      continue;
    }
    if(cpi->parent_pid == ppid){
      cv_destroy(cpi->waitpid_cv);
      array_set(procinfotable, i, NULL);
      kfree(cpi);
    } 
  }
}
Exemplo n.º 15
0
static
void
commandline_files_cleanup(void)
{
	unsigned i, num;
	struct commandline_file *cf;

	num = array_num(&commandline_files);
	for (i=0; i<num; i++) {
		cf = array_get(&commandline_files, i);
		if (cf != NULL) {
			dofree(cf, sizeof(*cf));
		}
	}
	array_setsize(&commandline_files, 0);

	array_cleanup(&commandline_files);
}
Exemplo n.º 16
0
static
void
apply_commandline_macros(void)
{
	struct commandline_macro *cm;
	unsigned i, num;

	num = array_num(&commandline_macros);
	for (i=0; i<num; i++) {
		cm = array_get(&commandline_macros, i);
		if (cm->expansion != NULL) {
			macro_define_plain(&cm->where, cm->macro,
					   &cm->where2, cm->expansion);
		} else {
			macro_undef(cm->macro);
		}
		dofree(cm, sizeof(*cm));
	}
	array_setsize(&commandline_macros, 0);
}
Exemplo n.º 17
0
int test_twofish256()
{
	twofish256_key skey;
	char           tmp[16];	
	int            i;
	
	for (i = 0; i < array_num(twofish_vectors); i++) 
	{
		twofish256_set_key(twofish_vectors[i].key, &skey);

		twofish256_encrypt(twofish_vectors[i].plaintext, tmp, &skey);

		if (memcmp(twofish_vectors[i].ciphertext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}

		twofish256_decrypt(twofish_vectors[i].ciphertext, tmp, &skey);

		if (memcmp(twofish_vectors[i].plaintext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}
	}	
	return 1;
}
Exemplo n.º 18
0
static
void
read_commandline_files(void)
{
	struct commandline_file *cf;
	unsigned i, num;
	bool save = false;

	num = array_num(&commandline_files);
	for (i=0; i<num; i++) {
		cf = array_get(&commandline_files, i);
		array_set(&commandline_files, i, NULL);
		if (cf->suppress_output) {
			save = mode.do_output;
			mode.do_output = false;
			file_readquote(&cf->where, cf->name);
			mode.do_output = save;
		} else {
			file_readquote(&cf->where, cf->name);
		}
		dofree(cf, sizeof(*cf));
	}
	array_setsize(&commandline_files, 0);
}
Exemplo n.º 19
0
int _init_wizard_encrypt_pages(
		HWND        parent,
		_wz_sheets *sheets,
		_dnode     *node
	)
{
	wchar_t *static_head[ ] = 
	{
		L"# Choice iso-file",
		L"# Format Options",
		L"# Encryption Settings",
		L"# Boot Settings",
		L"# Volume Password",
		L"# Encryption Progress"
	};

	HWND    hwnd;
	dc_conf dcfg;
	int     k;
	int     count       = 0;

	BOOL    boot_device = (
		_is_boot_device( &node->mnt.info )
	);
	BOOL    force_small = (
		boot_device && ( dc_get_conf_flags(&dcfg) == ST_OK ) && ( dcfg.load_flags & DST_SMALL_MEM )
	);

	while ( sheets[count].id != -1 )
	{
		HWND hwnd;

		sheets[count].hwnd = 
			CreateDialog(
				__hinst, MAKEINTRESOURCE(sheets[count].id), GetDlgItem(parent, IDC_TAB), _tab_proc
				);

		hwnd = sheets[count].hwnd;

		EnumChildWindows( hwnd, __sub_enum, (LPARAM)NULL );

		SetWindowText( GetDlgItem( hwnd, IDC_HEAD ), static_head[count] );
		SendMessage( GetDlgItem( hwnd, IDC_HEAD ), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 );

		sheets[count].first_tab_hwnd = 
			(
				( sheets[count].first_tab_id != -1 ) ? GetDlgItem( hwnd, sheets[count].first_tab_id ) : HWND_NULL
			);

		count++;
	}
	///////////////////////////////////////////////////////////////
	hwnd = sheets[WPAGE_ENC_FRMT].hwnd;
	///////////////////////////////////////////////////////////////
	/////// FORMAT OPTIONS PAGE ///////////////////////////////////
	{
		HWND h_fs = GetDlgItem(hwnd, IDC_COMBO_FS_LIST);

		_sub_class( GetDlgItem(hwnd, IDC_CHECK_QUICK_FORMAT), SUB_STATIC_PROC, HWND_NULL );
		_set_check( hwnd, IDC_CHECK_QUICK_FORMAT, FALSE );

		for ( k = 0; k < array_num(fs_names); k++ )
		{
			SendMessage( h_fs, (UINT)CB_ADDSTRING, 0, (LPARAM)fs_names[k] );
		}
		SendMessage( h_fs, CB_SETCURSEL, 2, 0 );			
	}
	///////////////////////////////////////////////////////////////
	hwnd = sheets[WPAGE_ENC_CONF].hwnd;
	///////////////////////////////////////////////////////////////
	/////// ENCRYPTION SETTINGS PAGE //////////////////////////////
	{
		HWND h_combo_wipe = GetDlgItem(hwnd, IDC_COMBO_PASSES);

		_init_combo( h_combo_wipe, wipe_modes, WP_NONE, FALSE, -1 );

		EnableWindow( h_combo_wipe, node->dlg.act_type != ACT_ENCRYPT_CD);
		EnableWindow( GetDlgItem(hwnd, IDC_STATIC_PASSES_LIST), node->dlg.act_type != ACT_ENCRYPT_CD );

		_init_combo(
			GetDlgItem(hwnd, IDC_COMBO_ALGORT), cipher_names, CF_AES, FALSE, -1
			);

		if ( force_small )
		{
			EnableWindow( GetDlgItem(hwnd, IDC_COMBO_ALGORT), FALSE );
			SendMessage( GetDlgItem(hwnd, IDC_WIZ_CONF_WARNING), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 );

			SetWindowText( 
				GetDlgItem(hwnd, IDC_WIZ_CONF_WARNING),
				L"Your BIOS does not provide enough base memory,\n"
				L"you can only use AES to encrypt the boot partition!"
			);
		}
		for ( k = 0; k < array_num(combo_sel); k++ )
		{
			SendMessage( GetDlgItem(hwnd, combo_sel[k]), CB_SETCURSEL, 0, 0 );
		}	
	}
	///////////////////////////////////////////////////////////////
	hwnd = sheets[WPAGE_ENC_BOOT].hwnd;
	///////////////////////////////////////////////////////////////
	/////// BOOT SETTINGS PAGE ////////////////////////////////////
	{
		int dsk_num = -1;
		int rlt = _get_info_install_boot_page( &node->mnt.info, sheets, &dsk_num );

		__lists[HENC_WIZARD_BOOT_DEVS] = GetDlgItem(hwnd, IDC_BOOT_DEVS);

		_list_devices( __lists[HENC_WIZARD_BOOT_DEVS], TRUE, dsk_num );
		SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), (UINT)CB_ADDSTRING, 0, (LPARAM)L"Use external bootloader" ); 

		if ( rlt != ST_OK )
		{
			SetWindowText( GetDlgItem(hwnd, IDC_WARNING), L"Bootable HDD not found!" );
			SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), CB_SETCURSEL, 0, 0 );

			SendMessage( GetDlgItem(hwnd, IDC_WARNING), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 );
			EnableWindow( GetDlgItem(hwnd, IDB_BOOT_PREF), TRUE );
		} else {		
			SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), (UINT)CB_ADDSTRING, 0, (LPARAM)L"Install to HDD" );
			SendMessage( GetDlgItem(hwnd, IDC_COMBO_BOOT_INST), CB_SETCURSEL, 1, 0 );
		}
	}
	///////////////////////////////////////////////////////////////
	hwnd = sheets[WPAGE_ENC_PASS].hwnd;
	///////////////////////////////////////////////////////////////
	/////// VOLUME PASSWORD PAGE //////////////////////////////////
	{
		int kbd_layout;
		_update_layout( node, -1, &kbd_layout );

		_init_combo( GetDlgItem(hwnd, IDC_COMBO_KBLAYOUT), kb_layouts, kbd_layout, FALSE, -1 );
		SetWindowText(GetDlgItem( hwnd, IDC_USE_KEYFILES), boot_device ? IDS_USE_KEYFILE : IDS_USE_KEYFILES );

		_sub_class( GetDlgItem(hwnd, IDC_CHECK_SHOW), SUB_STATIC_PROC, HWND_NULL );
		_set_check( hwnd, IDC_CHECK_SHOW, FALSE );

		_sub_class( GetDlgItem(hwnd, IDC_USE_KEYFILES), SUB_STATIC_PROC, HWND_NULL );
		_set_check( hwnd, IDC_USE_KEYFILES, FALSE );

		SendMessage(
			GetDlgItem( hwnd, IDP_BREAKABLE ),
			PBM_SETBARCOLOR, 0, _cl( COLOR_BTNSHADOW, DARK_CLR-20 )
		);	
		SendMessage(
			GetDlgItem(hwnd, IDP_BREAKABLE),
			PBM_SETRANGE, 0, MAKELPARAM(0, 193)
		);
		SetWindowText( GetDlgItem(hwnd, IDC_HEAD2), L"# Password Rating" );
		SendMessage( GetDlgItem(hwnd, IDC_HEAD2), (UINT)WM_SETFONT, (WPARAM)__font_bold, 0 );

		SendMessage( GetDlgItem(hwnd, IDE_PASS), EM_LIMITTEXT, MAX_PASSWORD, 0 );
		SendMessage( GetDlgItem(hwnd, IDE_CONFIRM), EM_LIMITTEXT, MAX_PASSWORD, 0 );
	}
	///////////////////////////////////////////////////////////////
	hwnd = sheets[WPAGE_ENC_PROGRESS].hwnd;
	///////////////////////////////////////////////////////////////
	/////// ENCRYPTION PROGRESS PAGE //////////////////////////////
	{
		_colinfo _progress_iso_crypt_headers[ ] = 
		{
			{ STR_HEAD_NO_ICONS, 100, LVCFMT_LEFT, FALSE },
			{ STR_HEAD_NO_ICONS, 120, LVCFMT_LEFT, FALSE },
			{ STR_NULL }
		};

		HWND h_list = GetDlgItem( hwnd, IDC_ISO_PROGRESS );
		int  rlt    = ST_OK;
		int  j      = 0;

		ListView_SetBkColor( h_list, GetSysColor(COLOR_BTNFACE) );
		_init_list_headers( h_list, _progress_iso_crypt_headers );

		while ( wcslen(_act_table_items[j]) > 0 )
		{
			_list_insert_item( h_list, j, 0, _act_table_items[j], 0 );
			if ( j != 2 ) ListView_SetItemText( h_list, j, 1, STR_EMPTY );

			j++;
		}
		SendMessage(
			GetDlgItem( hwnd, IDC_PROGRESS_ISO ),
			PBM_SETBARCOLOR, 0, _cl(COLOR_BTNSHADOW, DARK_CLR-20)
		);

		SendMessage(
			GetDlgItem( hwnd, IDC_PROGRESS_ISO ),
			PBM_SETRANGE, 0, MAKELPARAM(0, PRG_STEP)
		);
	}

	return count;

}
Exemplo n.º 20
0
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;

}
Exemplo n.º 21
0
INT_PTR 
CALLBACK
_main_dialog_proc(
		HWND	hwnd,
		UINT	message,
		WPARAM	wparam,
		LPARAM	lparam
	)
{
	WORD id		= LOWORD(wparam);
	WORD code	= HIWORD(wparam);

	_wnd_data	*wnd;
	_dnode		*sel;
	_dmnt		*mnt;

	int k = 0;
	switch ( message )
	{
		case WM_INITDIALOG :
		{
			memset( __lists, HWND_NULL, sizeof(__lists) );

			__lists[HMAIN_DRIVES] = GetDlgItem( hwnd, IDC_DISKDRIVES );
			__dlg = hwnd;

			_init_main_dlg( hwnd );

			_load_diskdrives( hwnd, &__drives, _list_volumes(0) );
			{
				TCITEM     tab_item = { TCIF_TEXT };
				HWND       h_tab    = GetDlgItem(hwnd, IDT_INFO);
				_tab_data *d_tab    = malloc(sizeof(_tab_data));

				zeroauto( d_tab, sizeof(_tab_data) );
				d_tab->curr_tab = 1;

				wnd_set_long( hwnd, GWL_USERDATA, d_tab );

				wnd = _sub_class(
						h_tab, SUB_NONE,
						CreateDialog( __hinst, MAKEINTRESOURCE(DLG_MAIN_INFO),   GetDlgItem(hwnd, IDC_MAIN_TAB), _tab_proc ),
						CreateDialog( __hinst, MAKEINTRESOURCE(DLG_MAIN_ACTION), GetDlgItem(hwnd, IDC_MAIN_TAB), _tab_proc ),
						HWND_NULL
					);
				{
					__lists[HMAIN_INFO] = GetDlgItem( wnd->dlg[0], IDC_INF_TABLE );
					__lists[HMAIN_ACT]  = GetDlgItem( wnd->dlg[1], IDC_ACT_TABLE );
				}
				{
					__dlg_act_info = wnd->dlg[1];

					_list_insert_col( __lists[HMAIN_INFO], 380 );
					_list_insert_col( __lists[HMAIN_INFO], 90 );
					
					while (
						_list_insert_item( __lists[HMAIN_INFO], k, 0, _info_table_items[k], 0 )
						) k++;

					_set_header_text( 
						__lists[HMAIN_INFO], 0, STR_HEAD_NO_ICONS, sizeof_w(STR_HEAD_NO_ICONS) 
						);

					_list_insert_col( __lists[HMAIN_ACT], 90 );
					_list_insert_col( __lists[HMAIN_ACT], 70 );

					_list_insert_col( __lists[HMAIN_ACT], 85 );
					_list_insert_col( __lists[HMAIN_ACT], 50 );
						
					_list_insert_item( __lists[HMAIN_ACT],    0, 0, _act_table_items[0], 0 );
					ListView_SetItemText( __lists[HMAIN_ACT], 0, 2, _act_table_items[3] );

					_list_insert_item( __lists[HMAIN_ACT],    1, 0, _act_table_items[1], 0 );
					ListView_SetItemText( __lists[HMAIN_ACT], 1, 2, _act_table_items[4] );

					_init_combo(
						GetDlgItem( __dlg_act_info, IDC_COMBO_PASSES), wipe_modes, WP_NONE, FALSE, -1
						);

					SendMessage(
						GetDlgItem( __dlg_act_info, IDC_PROGRESS ),
						PBM_SETBARCOLOR, 0, _cl( COLOR_BTNSHADOW, DARK_CLR - 20 )
						);

					SendMessage(
						GetDlgItem( __dlg_act_info, IDC_PROGRESS ),
						PBM_SETRANGE, 0, MAKELPARAM(0, PRG_STEP)
						);
				}
				tab_item.pszText = L"Info";
				TabCtrl_InsertItem( h_tab, 0, &tab_item );
				{
					NMHDR mhdr = { 0, 0, TCN_SELCHANGE };
					TabCtrl_SetCurSel( h_tab, 0 );

					SendMessage(hwnd, WM_NOTIFY, IDT_INFO, (LPARAM)&mhdr);
				}
			}
			SendMessage( hwnd, WM_SYSCOLORCHANGE, 0, 0 );

			_set_timer( MAIN_TIMER, TRUE, TRUE );
			_set_timer( RAND_TIMER, TRUE, FALSE );
			_set_timer( POST_TIMER, TRUE, FALSE );

			return 0L;
		} 
		break;

		case WM_WINDOWPOSCHANGED :
		{
			WINDOWPOS *pos = (WINDOWPOS *)lparam;
			int flags = pos->flags;

			_dlg_right  = pos->cx + pos->x;
			_dlg_bottom = pos->cy + pos->y;
			_dlg_left   = pos->x;

			if ( ( flags & SWP_SHOWWINDOW ) || ( flags & SWP_HIDEWINDOW ) )
			{
				_set_timer( MAIN_TIMER, flags & SWP_SHOWWINDOW, TRUE );
			}
			return 0L;
		}
		break;

		case WM_ENTERSIZEMOVE :
		{
			//_middle_ctl(
			//	GetDlgItem(hwnd, IDC_DISKDRIVES),
			//	GetDlgItem(hwnd, IDC_RESIZING),
			//	TRUE
			//	);

			//ShowWindow(GetDlgItem(hwnd, IDC_DISKDRIVES), SW_HIDE);
			return 0L;
		}
		break;

		case WM_EXITSIZEMOVE :
		{
			//ShowWindow(GetDlgItem(hwnd, IDC_DISKDRIVES), SW_SHOW);
			return 0L;
		}
		break;

		case WM_SIZING :
		{
			RECT *rect = ((RECT *)lparam);

			rect->right = _dlg_right;
			rect->left  = _dlg_left;

			if ( rect->bottom - rect->top < MAIN_DLG_MIN_HEIGHT ) 
			{
				rect->bottom = rect->top + MAIN_DLG_MIN_HEIGHT;
			}
			return 1L;
		}
		break;

		case WM_SIZE :
		{
			int height = HIWORD(lparam);
			int width  = LOWORD(lparam);
			int k;

			_size_move_ctls _resize[ ] = 
			{
				{ -1, IDC_DISKDRIVES,   FALSE, 0, 0 },
				{ -1, IDC_STATIC_LIST,  TRUE,  0, 0 },
				{ -1, IDC_STATIC_RIGHT, TRUE,  0, 0 }
			};

			_size_move_ctls _move[ ] =
			{
				{ IDC_STATIC_LIST, IDC_MAIN_TAB,    TRUE,  0, 6 },
				{ IDC_STATIC_LIST, IDT_INFO,        FALSE, 0, 3 },
				{ IDT_INFO,        IDC_LINE_BOTTOM, TRUE,  0, 2 }
			};
			{
				int c_size_hide = _main_headers[1].width;
				int c_size_show = c_size_hide - GetSystemMetrics(SM_CXVSCROLL);
				int c_size_curr = ListView_GetColumnWidth( __lists[HMAIN_DRIVES], 1 );

				if ( GetWindowLong(__lists[HMAIN_DRIVES], GWL_STYLE) & WS_VSCROLL )
				{
					if ( c_size_curr != c_size_show ) ListView_SetColumnWidth( __lists[HMAIN_DRIVES], 1, c_size_show );
				} else {
					if ( c_size_curr != c_size_hide ) ListView_SetColumnWidth( __lists[HMAIN_DRIVES], 1, c_size_hide );
				}
			}

			if ( height == 0 || width == 0 )
			{
				return 0L;
			}
			for ( k = 0; k < array_num(_resize); k++ )
			{
				_resize_ctl(
					GetDlgItem(hwnd, _resize[k].id), height - _dlg_height, 0, _resize[k].val
					);
			}
			_dlg_height = height;

			for ( k = 0; k < array_num(_move); k++ )
			{
				_relative_move(
					GetDlgItem( hwnd, _move[k].anchor ), GetDlgItem( hwnd, _move[k].id ), _move[k].dy, _move[k].dy, _move[k].val
					);
				InvalidateRect( GetDlgItem( hwnd, _move[k].id ), NULL, TRUE );
			}
			_middle_ctl(
				GetDlgItem( hwnd, IDC_DISKDRIVES ),
				GetDlgItem( hwnd, IDC_RESIZING ),
				TRUE
				);

			return 0L;
		}
		break;

		case WM_SYSCOMMAND :
		{
			if ( wparam == SC_MINIMIZE || wparam == SC_RESTORE )
			{
				_set_timer( MAIN_TIMER, wparam == SC_RESTORE, TRUE );
			}
			return 0L;
		}
		break;

		case WM_APP + WM_APP_SHOW :
		{
			ShowWindow( hwnd, SW_HIDE );
		}
		break;

		case WM_NOTIFY :
		{
			if ( wparam == IDT_INFO )
			{
				if ( ((NMHDR *)lparam)->code == TCN_SELCHANGE )
				{
					HWND h_tab = GetDlgItem( hwnd, IDT_INFO );
					if ( !_is_curr_in_group(h_tab) )
					{
						_change_page( h_tab, TabCtrl_GetCurSel(h_tab) );
					}
				}
			}
			if ( wparam == IDC_DISKDRIVES )
			{
				sel = pv( _get_sel_item( __lists[HMAIN_DRIVES] ) );
				mnt = &sel->mnt;

				if ( ((NMHDR *)lparam)->code == LVN_ITEMCHANGED &&
					 (((NMLISTVIEW *)lparam)->uNewState & LVIS_FOCUSED ) )
				{
					_update_info_table( FALSE );
					_activate_page( );
					_refresh_menu( );					

					return 1L;
				}
				if ( ((NMHDR *)lparam)->code == LVN_ITEMACTIVATE )
				{
					BOOL mount = 
						( !(sel->mnt.info.status.flags & F_ENABLED) ) && 
						( sel->mnt.fs[0] == '\0' );
					
					if (! mount )
					{
						if (! sel->is_root ) __execute( mnt->info.status.mnt_point );
					} else {
						_menu_mount( sel );
					}
				}
				switch( ((NM_LISTVIEW *)lparam)->hdr.code )
				{
					case LVN_KEYDOWN : 
					{
						WORD key = ((NMLVKEYDOWN *)lparam)->wVKey;
						int item = ListView_GetSelectionMark( __lists[HMAIN_DRIVES] );

						switch ( key )
						{
							case VK_UP:   item -= 1; break;
							case VK_DOWN: item += 1; break;
						}
						if ( _is_root_item(_get_item_index( __lists[HMAIN_DRIVES], item )) )
						{
							ListView_SetItemState( __lists[HMAIN_DRIVES], item, LVIS_FOCUSED, TRUE );
						}
						if ( key != VK_APPS )
						{
							break;
						}
					}

					case NM_RCLICK :
					{
						int item;
						HMENU h_popup = CreatePopupMenu( );

						_dact *act = _create_act_thread( sel, -1, -1 );

						_update_info_table( FALSE );
						_activate_page( );

						_set_timer(MAIN_TIMER, FALSE, FALSE);

						_refresh_menu( );
						
						if ( ListView_GetSelectedCount( __lists[HMAIN_DRIVES] ) && 
							 !_is_root_item((LPARAM)sel) && _is_active_item((LPARAM)sel)
							 )
						{
							if ( mnt->info.status.flags & F_ENABLED )
							{
								if ( mnt->info.status.flags & F_CDROM )
								{
									AppendMenu( h_popup, MF_STRING, ID_VOLUMES_UNMOUNT, IDS_UNMOUNT );
								} else 
								{
									if ( mnt->info.status.flags & F_FORMATTING )
									{
										AppendMenu( h_popup, MF_STRING, ID_VOLUMES_FORMAT, IDS_FORMAT );
									} else
									{
										if ( IS_UNMOUNTABLE(&mnt->info.status) )
										{
											AppendMenu( h_popup, MF_STRING, ID_VOLUMES_UNMOUNT, IDS_UNMOUNT );
										}
										if ( !(mnt->info.status.flags & F_SYNC) )
										{
											AppendMenu( h_popup, MF_SEPARATOR, 0, NULL );
											AppendMenu( h_popup, MF_STRING, ID_VOLUMES_CHANGEPASS, IDS_CHPASS );
										}
										if ( !(act && act->status == ACT_RUNNING) )
										{
											if ( mnt->info.status.flags & F_SYNC )
											{
												if ( GetMenuItemCount(h_popup) > 0 )
												{
													AppendMenu( h_popup, MF_SEPARATOR, 0, NULL );
												}
												AppendMenu( h_popup, MF_STRING, ID_VOLUMES_ENCRYPT, IDS_ENCRYPT );
											} else
											{
												if ( GetMenuItemCount(h_popup) > 0 )
												{
													AppendMenu( h_popup, MF_SEPARATOR, 0, NULL );
												}
												AppendMenu( h_popup, MF_STRING, ID_VOLUMES_REENCRYPT, IDS_REENCRYPT );
											}
											AppendMenu( h_popup, MF_STRING, ID_VOLUMES_DECRYPT, IDS_DECRYPT );
										}
									}								
								}
							} else 
							{
								if ( mnt->info.status.flags & F_CDROM )
								{
									if ( *mnt->fs == '\0' )
									{
										AppendMenu( h_popup, MF_STRING, ID_VOLUMES_MOUNT, IDS_MOUNT );
									}
								} else {
									if ( *mnt->fs == '\0' )
									{
										AppendMenu( h_popup, MF_STRING, ID_VOLUMES_MOUNT, IDS_MOUNT );
									} else {
										AppendMenu( h_popup, MF_STRING, ID_VOLUMES_ENCRYPT, IDS_ENCRYPT );
									}
									if ( IS_UNMOUNTABLE(&mnt->info.status) )
									{
										AppendMenu( h_popup, MF_SEPARATOR, 0, NULL );
										AppendMenu( h_popup, MF_STRING, ID_VOLUMES_FORMAT, IDS_FORMAT );
									}
								}
							}
						}
						/*
						_state_menu(
							popup, sel && sel->status.flags & F_LOCKED ? MF_GRAYED : MF_ENABLED
							);
						*/
						item = TrackPopupMenu(
							h_popup,
							TPM_RETURNCMD | TPM_LEFTBUTTON,
							LOWORD(GetMessagePos( )),
							HIWORD(GetMessagePos( )),
							0,
							hwnd,
							NULL
						);

						DestroyMenu( h_popup );
						switch ( item )
						{
							case ID_VOLUMES_DECRYPT		: _menu_decrypt(sel);	break;
							case ID_VOLUMES_ENCRYPT		: _menu_encrypt(sel);	break;

							case ID_VOLUMES_FORMAT		: _menu_format(sel);	break;
							case ID_VOLUMES_REENCRYPT	: _menu_reencrypt(sel);	break;

							case ID_VOLUMES_UNMOUNT		: _menu_unmount(sel);	break;
							case ID_VOLUMES_MOUNT		: _menu_mount(sel);		break;

							case ID_VOLUMES_CHANGEPASS	: _menu_change_pass(sel); break;						
						}
						if ( item )
						{
							_refresh( TRUE );
						}
						_set_timer( MAIN_TIMER, TRUE, TRUE );

					}
					break;

					case NM_CLICK :
					{
						sel = pv(
							_get_item_index( __lists[HMAIN_DRIVES], ((NM_LISTVIEW *)lparam)->iItem )
							);

						_update_info_table( FALSE );
						_activate_page( );
						_refresh_menu( );						
					}
					break;

				}
			}
			if ( ((NMHDR *)lparam)->code == HDN_ITEMCHANGED )
			{
				InvalidateRect( __lists[HMAIN_DRIVES], NULL, TRUE );
			}
			if ( ((NMHDR *)lparam)->code == HDN_ITEMCHANGING )
			{
				return 0L;
			}
			if ( ((NMHDR *)lparam)->code == HDN_BEGINTRACK )
			{
				return 1L;
			}
		}
		break;

		case WM_COMMAND: 
		{
			_dnode *node = pv( _get_sel_item( __lists[HMAIN_DRIVES] ) );

			switch (id) 
			{
			case ID_SHIFT_TAB :
			case ID_TAB :
			{
				HWND h_current = GetFocus( );
				HWND h_next    = GetNextDlgTabItem( hwnd, h_current, id == ID_SHIFT_TAB );

				SetFocus( h_next );
			}
			break;

			case ID_TOOLS_DRIVER :
			{
				if ( __msg_q( __dlg, L"Remove DiskCryptor driver?") )
				{
					int rlt;
					if ( (rlt = _drv_action(DA_REMOVE, 0)) != ST_OK )
					{
						__error_s( __dlg, L"Error remove DiskCryptor driver", rlt );
					} else {
						return 0L;
					}
				}
			}
			break;

			case ID_TOOLS_BENCHMARK : _dlg_benchmark( __dlg ); break;
			case ID_HELP_ABOUT :      _dlg_about( __dlg ); break;
			
			case ID_HOMEPAGE : __execute( DC_HOMEPAGE ); break;			
			case ID_EXIT :
			{
				SendMessage( hwnd, WM_CLOSE, 0, 1 );
			}
			break;

			case IDC_BTN_WIZARD : _menu_wizard(node); break;
			case ID_VOLUMES_DELETE_MNTPOINT :
			{
				wchar_t *mnt_point = node->mnt.info.status.mnt_point;				
				if ( __msg_q( __dlg, L"Are you sure you want to delete mount point [%s]?", mnt_point ) )
				{
					_set_trailing_slash(mnt_point);
					DeleteVolumeMountPoint(mnt_point);
				}
			}
			break;

			case IDC_BTN_DECRYPT_ :
			case ID_VOLUMES_DECRYPT : _menu_decrypt( node ); break;

			case IDC_BTN_ENCRYPT_ :
			case ID_VOLUMES_ENCRYPT : _menu_encrypt( node ); break;

			case ID_VOLUMES_MOUNTALL : 
			case IDC_BTN_MOUNTALL_ : _menu_mountall( ); break;

			case ID_VOLUMES_DISMOUNTALL : 
			case IDC_BTN_UNMOUNTALL_ : _menu_unmountall( ); break;

			case ID_VOLUMES_DISMOUNT : _menu_unmount( node ); break;
			case ID_VOLUMES_MOUNT :    _menu_mount( node ); break;

			case ID_VOLUMES_FORMAT :    _menu_format(node); break;
			case ID_VOLUMES_REENCRYPT : _menu_reencrypt( node ); break;

			case ID_TOOLS_SETTINGS : _dlg_options( __dlg ); break;
			case ID_BOOT_OPTIONS :   _dlg_config_loader( __dlg, FALSE ); break;

			case ID_VOLUMES_CHANGEPASS : _menu_change_pass( node ); break;
			case ID_TOOLS_CLEARCACHE :   _menu_clear_cache( ); break;

			case ID_VOLUMES_BACKUPHEADER :  _menu_backup_header( node ); break;
			case ID_VOLUMES_RESTOREHEADER : _menu_restore_header( node ); break;

			case ID_TOOLS_ENCRYPT_CD: _menu_encrypt_cd( ); break;

			}
			switch ( id ) {
			case IDC_BTN_MOUNT_: 
			{		
				node->mnt.info.status.flags & F_ENABLED ?
					_menu_unmount(node) : 
					_menu_mount(node);
			}
			break;
			case ID_TOOLS_BSOD : 
			{
				if ( __msg_q( __dlg, L"Crash?" ) ) 
				{
					dc_get_bsod( );
				}
			}
			break;
			}
			if ( id == IDCANCEL )
			{
				ShowWindow(hwnd, SW_HIDE);
			}
			_refresh(TRUE);
		}
		break;

		case WM_CLOSE :
		{
			if ( lparam )
			{
				_tray_icon(FALSE);

				EndDialog(hwnd, 0);
				ExitProcess(0);
			} else {
				ShowWindow(hwnd, SW_HIDE);
			}
			return 0L;
		}
		break;

		case WM_DESTROY : 
		{
			PostQuitMessage(0);
			return 0L;
		}
		break;

		case WM_HOTKEY :
		{
			switch (wparam) 
			{
				case 0 : 
				{
					int mount_cnt;
					dc_mount_all(NULL, &mount_cnt, 0); 
				}
				break;

				case 1 : dc_unmount_all( ); break;
				case 2 : dc_clean_pass_cache( ); break;
				case 3 : dc_get_bsod( ); break;
			}
			return 1L;
		}
		break;

		case WM_ENDSESSION : 
		{
			if ( lparam & ENDSESSION_LOGOFF ) 
			{
				if ( __config.conf_flags & CONF_DISMOUNT_LOGOFF ) 
				{
					dc_unmount_all( );
				}
				if ( __config.conf_flags & CONF_WIPEPAS_LOGOFF ) 
				{
					dc_clean_pass_cache( );
				}
			}
		}
		break;

		case WM_SYSCOLORCHANGE :
		{
			COLORREF cl_light = _cl( COLOR_BTNFACE, LGHT_CLR );
			COLORREF cl_button = GetSysColor( COLOR_BTNFACE );

			int k;
			for ( k = 0; k < array_num(__lists); k++ )
			{
				if ( ( __lists[k] != HWND_NULL ) && ( __lists[k] != NULL ) )
				{
					ListView_SetBkColor( __lists[k], cl_button );
					ListView_SetTextBkColor( __lists[k], cl_button );
					ListView_SetExtendedListViewStyle( __lists[k], LVS_EX_FULLROWSELECT );

					if ( !IsWindowEnabled( __lists[k] ) )
					{
						// EnableWindow( __lists[k], TRUE );
						// EnableWindow( __lists[k], FALSE );
					}
				}
			}
			TreeView_SetBkColor( GetDlgItem(hwnd, IDC_TREE), cl_light );

			ListView_SetBkColor( __lists[HMAIN_DRIVES], cl_light );
			ListView_SetTextBkColor( __lists[HMAIN_DRIVES], cl_light );

			ListView_SetExtendedListViewStyle( __lists[HMAIN_DRIVES], LVS_EX_FULLROWSELECT );
			ListView_SetImageList( __lists[HMAIN_DRIVES], __dsk_img, LVSIL_SMALL );

		}
		break;

		case WM_APP + WM_APP_TRAY :
		{
			switch ( lparam ) 
			{
			case WM_LBUTTONDOWN : 
			{
				BOOL show = !IsWindowVisible(hwnd);				
				ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE);

				if ( show )
				{
					SetForegroundWindow(hwnd);
				}
			}
			break;

			case WM_RBUTTONDOWN : 
			{
				POINT pt; int item;
				HMENU menu = CreatePopupMenu( );				

				AppendMenu( menu, MF_STRING, ID_VOLUMES_UNMOUNTALL, IDS_UNMOUNTALL );
				AppendMenu( menu, MF_STRING, ID_VOLUMES_MOUNTALL, IDS_MOUNTALL );
				AppendMenu( menu, MF_SEPARATOR, 0, NULL );

				AppendMenu( menu, MF_STRING, ID_TOOLS_SETTINGS, IDS_SETTINGS );
				AppendMenu( menu, MF_STRING, ID_HELP_ABOUT, IDS_ABOUT );
				AppendMenu( menu, MF_SEPARATOR, 0, NULL );
				AppendMenu( menu, MF_STRING, ID_EXIT, IDS_EXIT );

				GetCursorPos(&pt);
				SetForegroundWindow( hwnd );

				item = TrackPopupMenu ( menu,
					TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
					pt.x, pt.y, 0, hwnd,
					NULL
				);

				DestroyMenu( menu );

				switch (item) {

				case ID_VOLUMES_UNMOUNTALL : _menu_unmountall( ); break;
				case ID_VOLUMES_MOUNTALL :   _menu_mountall( ); break;

				case ID_HELP_ABOUT :         _dlg_about( HWND_DESKTOP ); break;
				case ID_TOOLS_SETTINGS :     _dlg_options( __dlg ); break;

				case ID_EXIT : 
				{
					SendMessage(hwnd, WM_CLOSE, 0, 1);
				}
				break;
				}
			}
			break;
			}
		}
		break;

		default:
		{
			int rlt = _draw_proc( message, lparam );
			if (rlt != -1) 
			{
				return rlt;
			}
		}
	}	
	return 0L; 

}
Exemplo n.º 22
0
unsigned int
heap_getsize(struct heap* h) {
    assert(h != NULL);
    ASSERT_HEAP(h);
    return array_num(h->vals);
}
Exemplo n.º 23
0
int
heap_isempty(struct heap* h) {
    assert(h != NULL);
    ASSERT_HEAP(h);
    return (array_num(h->vals) == 0);
}
Exemplo n.º 24
0
void
heap_assertvalid(struct heap* h) {
    assert(h != NULL);
    ASSERT_HEAP(h);
    assert_heap_property(h->vals, 0, array_num(h->vals), h->comparator);
}
int getSize(struct fdManager * manager){
	return array_num(manager->fdm_descriptors);
} 
Exemplo n.º 26
0
int test_aes256()
{
	char       tmp[16];
	aes256_key skey;
	int        i;
#ifndef SMALL_CODE	
	u32        old_p;
#endif	

#ifdef SMALL_CODE
	/* initialize AES tables */
	aes256_gentab();
#else
	/* allow execute code from key buffer */
	if (VirtualProtect(&skey, sizeof(skey), PAGE_EXECUTE_READWRITE, &old_p) == 0) {
		return 0;
	}
#endif
	/* test basic assembler inmpementation */
	for (i = 0; i < array_num(aes256_vectors); i++) 
	{
#ifdef SMALL_CODE
		aes256_set_key(aes256_vectors[i].key, &skey);
		aes256_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#else
		aes256_asm_set_key(aes256_vectors[i].key, &skey);
		aes256_asm_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#endif
		if (memcmp(aes256_vectors[i].ciphertext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}
#ifdef SMALL_CODE
		aes256_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#else
		aes256_asm_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#endif
		if (memcmp(aes256_vectors[i].plaintext, tmp, sizeof(tmp)) != 0) {
			return 0;
		}
#if !defined(SMALL_CODE) || !defined(_M_X64)
		/* test AES with VIA Padlock API */
		if (aes256_padlock_available() != 0)
		{
#ifdef SMALL_CODE
			aes256_padlock_encrypt(aes256_vectors[i].plaintext, tmp, &skey);
#else
			aes256_padlock_encrypt(aes256_vectors[i].plaintext, tmp, 1, &skey);
#endif
			if (memcmp(aes256_vectors[i].ciphertext, tmp, sizeof(tmp)) != 0) {
				return 0;
			}
#ifdef SMALL_CODE
			aes256_padlock_decrypt(aes256_vectors[i].ciphertext, tmp, &skey);
#else
			aes256_padlock_decrypt(aes256_vectors[i].ciphertext, tmp, 1, &skey);
#endif
			if (memcmp(aes256_vectors[i].plaintext, tmp, sizeof(tmp)) != 0) {
				return 0;
			}
		}
#endif
	}
	return 1;
}
Exemplo n.º 27
0
static
void
testa(struct array *a)
{
	int testarray[TESTSIZE];
	int i, j, n, r, *p;

	for (i=0; i<TESTSIZE; i++) {
		testarray[i]=i;
	}

	n = array_num(a);
	KASSERT(n==0);

	for (i=0; i<TESTSIZE; i++) {
		r = array_add(a, &testarray[i], NULL);
		KASSERT(r==0);
		n = array_num(a);
		KASSERT(n==i+1);
	}
	n = array_num(a);
	KASSERT(n==TESTSIZE);

	for (i=0; i<TESTSIZE; i++) {
		p = array_get(a, i);
		KASSERT(*p == i);
	}
	n = array_num(a);
	KASSERT(n==TESTSIZE);

	for (j=0; j<TESTSIZE*4; j++) {
		i = random()%TESTSIZE;
		p = array_get(a, i);
		KASSERT(*p == i);
	}
	n = array_num(a);
	KASSERT(n==TESTSIZE);

	for (i=0; i<TESTSIZE; i++) {
		array_set(a, i, &testarray[TESTSIZE-i-1]);
	}

	for (i=0; i<TESTSIZE; i++) {
		p = array_get(a, i);
		KASSERT(*p == TESTSIZE-i-1);
	}

	r = array_setsize(a, TESTSIZE/2);
	KASSERT(r==0);

	for (i=0; i<TESTSIZE/2; i++) {
		p = array_get(a, i);
		KASSERT(*p == TESTSIZE-i-1);
	}

	array_remove(a, 1);

	for (i=1; i<TESTSIZE/2 - 1; i++) {
		p = array_get(a, i);
		KASSERT(*p == TESTSIZE-i-2);
	}
	p = array_get(a, 0);
	KASSERT(*p == TESTSIZE-1);

	array_setsize(a, 2);
	p = array_get(a, 0);
	KASSERT(*p == TESTSIZE-1);
	p = array_get(a, 1);
	KASSERT(*p == TESTSIZE-3);

	array_set(a, 1, NULL);
	array_setsize(a, 2);
	p = array_get(a, 0);
	KASSERT(*p == TESTSIZE-1);
	p = array_get(a, 1);
	KASSERT(p==NULL);

	array_setsize(a, TESTSIZE*10);
	p = array_get(a, 0);
	KASSERT(*p == TESTSIZE-1);
	p = array_get(a, 1);
	KASSERT(p==NULL);
}
Exemplo n.º 28
0
INT_PTR CALLBACK
_about_dlg_proc(
		HWND	hwnd,
		UINT	message,
		WPARAM	wparam,
		LPARAM	lparam
	)
{
	_ctl_init ctl_links[ ] = 
	{
		{ DC_HOMEPAGE,  IDC_ABOUT_URL1, 0 },
		{ DC_FORUMPAGE, IDC_ABOUT_URL2, 0 }
	};
	static HICON h_icon;

	switch ( message )
	{
		case WM_DESTROY :
		{
			DestroyIcon(h_icon);
			return 0L;
		}
		break;			

		case WM_CLOSE : 
		{
			EndDialog(hwnd, 0);
			return 0L;
		}
		break;

		case WM_COMMAND : 
		{
			int id   = LOWORD(wparam);
			int code = HIWORD(wparam);
			int k;

			if ( code == EN_SETFOCUS )
			{
				SendMessage( (HWND)lparam, EM_SETSEL, -1, 0 );
			}

			if ( id == IDCANCEL || id == IDOK )
			{
				EndDialog(hwnd, 0);
			}
			for ( k = 0; k < array_num(ctl_links); k++ )
			{
				if ( id == ctl_links[k].id )
				{
					__execute(ctl_links[k].display);
				}
			}
		}
		break;

		case WM_SHOWWINDOW :
		{
			SetFocus( GetDlgItem(hwnd, IDC_EDIT_NOTICE) );
			SendMessage( GetDlgItem(hwnd, IDC_EDIT_NOTICE), EM_SETSEL, -1, 0 );
		}
		break;

		case WM_INITDIALOG : 
		{
			HWND    h_notice = GetDlgItem(hwnd, IDC_EDIT_NOTICE);
			wchar_t s_display[MAX_PATH];
			BYTE   *res;
			int     size, id_icon;
			int     k = 0;

			res = _extract_rsrc( IDI_ICON_TRAY, RT_GROUP_ICON, &size );

			id_icon = LookupIconIdFromDirectoryEx( res, TRUE, 48, 48, 0 );
			res = _extract_rsrc( id_icon, RT_ICON, &size );
 
			h_icon = CreateIconFromResourceEx( res, size, TRUE, 0x00030000, 48, 48, 0 );
			SendMessage( GetDlgItem(hwnd, IDC_ICON_MAIN), STM_SETICON, (WPARAM)h_icon, 0 );
			{
				HWND h_title = GetDlgItem( hwnd, IDC_ABOUT1 );

				_snwprintf(
					s_display, sizeof_w(s_display), L"%s %S", DC_NAME, DC_FILE_VER
					);

				SetWindowText( h_title, s_display );
				SetWindowText( h_notice,
					L"This program is free software: you can redistribute "
					L"it under the terms of the GNU General Public License "
					L"version 3 as published by the Free Software Foundation.\r\n\r\n"
					L"Contacts:\r\n"
					L"[email protected] (PGP key ID 0xC48251EB4F8E4E6E)\r\n\r\n"
					L"Special thanks to:\r\n"
					L"Aleksey Bragin and ReactOS Foundation\r\n\r\n"
					L"Portions of this software:\r\n"
					L"Copyright \xa9 1998, 2001, 2002 Brian Palmer\r\n"
					L"Copyright \xa9 2003, Dr Brian Gladman, Worcester, UK\r\n"
					L"Copyright \xa9 2006, Rik Snel <*****@*****.**>\r\n"
					L"Copyright \xa9 Vincent Rijmen <*****@*****.**>\r\n"
					L"Copyright \xa9 Antoon Bosselaers <*****@*****.**>\r\n"
					L"Copyright \xa9 Paulo Barreto <*****@*****.**>\r\n"
					L"Copyright \xa9 Tom St Denis <*****@*****.**>\r\n"
					L"Copyright \xa9 Juergen Schmied and Jon Griffiths\r\n"
					L"Copyright \xa9 Lynn McGuire\r\n"
					L"Copyright \xa9 Matthew Skala <*****@*****.**>\r\n"
					L"Copyright \xa9 Werner Koch\r\n"
					L"Copyright \xa9 Dag Arne Osvik <*****@*****.**>\r\n"
					L"Copyright \xa9 Herbert Valerio Riedel <*****@*****.**>\r\n"
					L"Copyright \xa9 Wei Dai\r\n"
					L"Copyright \xa9 Ruben Jesus Garcia Hernandez <*****@*****.**>\r\n"
					L"Copyright \xa9 Serge Trusov <*****@*****.**>"
				);

				SendMessage( h_title, WM_SETFONT, (WPARAM)__font_bold, 0 );
				for ( k = 0; k < array_num(ctl_links); k++ )
				{
					HWND h_ctl = GetDlgItem(hwnd, ctl_links[k].id);

					SetWindowLongPtr( h_ctl, GWL_USERDATA, (LONG_PTR)GetWindowLongPtr( h_ctl, GWL_WNDPROC ) );
					SetWindowLongPtr( h_ctl, GWL_WNDPROC, (LONG_PTR)_link_proc );

					SetWindowText( h_ctl, ctl_links[k].display );
					SendMessage( h_ctl, WM_SETFONT, (WPARAM)__font_link, 0 );
					{
						WINDOWINFO pwi;
						SIZE       size;
						HDC        h_dc = GetDC( h_ctl );

						SelectObject( h_dc, __font_link );
						GetTextExtentPoint32( h_dc, ctl_links[k].display, d32(wcslen(ctl_links[k].display)), &size );

						GetWindowInfo( h_ctl, &pwi );
						ScreenToClient( hwnd, pv(&pwi.rcClient) );

						MoveWindow( h_ctl, pwi.rcClient.left, pwi.rcClient.top, size.cx, size.cy, TRUE );
						ReleaseDC( h_ctl, h_dc );
					}
				}
				{
					dc_conf conf;
					if ( dc_get_conf_flags(&conf) == ST_OK )
					{
						wchar_t *s_using = L"Not supported";
						wchar_t *s_inset = L"Not supported";

						if ( conf.load_flags & DST_HW_CRYPTO )
						{
							s_using = (
								conf.conf_flags & CONF_HW_CRYPTO ? L"Enabled" : L"Disabled"
							);
							if ( conf.load_flags & DST_INTEL_NI ) s_inset = L"Intel® AES Instructions Set (AES-NI)";
							if ( conf.load_flags & DST_VIA_PADLOCK ) s_inset = L"The VIA PadLock Advanced Cryptography Engine (ACE)";
						}
						_snwprintf( s_display, sizeof_w(s_display), 
							L"Hardware Cryptography: %s\r\n"
							L"Instruction Set: %s",
							s_using, s_inset
						);
						SetWindowText( GetDlgItem(hwnd, IDC_EDIT_CIPHER_INFO), s_display );
						EnableWindow( GetDlgItem(hwnd, IDC_EDIT_CIPHER_INFO), conf.load_flags & DST_HW_CRYPTO );
					}
				}
			}
			SendMessage( h_notice, EM_SCROLLCARET, 0, 0 );
			SetForegroundWindow( hwnd );

			return 1L;
		}
		break;

		default:
		{
			int rlt = _draw_proc( message, lparam );
			if ( rlt != -1 )
			{
				return rlt;
			}
		}
	}
	return 0L;

}
Exemplo n.º 29
0
int
as_copy(struct addrspace *old, struct addrspace **ret)
{
	struct addrspace *newas;
	int i,j, errno, retval, offset, region_len;
	struct region *old_region, *new_region;
	void *buffer;
	struct pt_entry *old_entry, *new_entry;

	newas = as_create();
	if (newas==NULL) {
		return ENOMEM;
	}

	buffer = kmalloc(PAGE_SIZE);

	newas->heap_start = old->heap_start;
	newas->heap_end = old->heap_end;

	// Copy regions
	region_len = array_num(old->as_regions);
	for (i = 0; i < region_len; i++) {
		old_region = array_get(old->as_regions, i);
		new_region = kmalloc(sizeof(struct region));
		if (old_region == NULL || new_region == NULL) {
			goto err0;
		}

		new_region->base = old_region->base;
		new_region->size = old_region->size;
		new_region->permission = old_region->permission;

		errno = array_add(newas->as_regions, new_region, NULL);
		if (errno) {
			goto err0;
		}
	}

	// Copy page table
	for (i = 0; i < PT_LEVEL_SIZE; i++){
		if (old->pagetable[i] != NULL){
			newas->pagetable[i] = kmalloc(PT_LEVEL_SIZE * sizeof(struct pt_entry));
			memset(newas->pagetable[i], 0, PT_LEVEL_SIZE * sizeof(struct pt_entry));
			// For each page table entry
			// Lock the entire L2 pagetable
			lock_acquire(old->pt_locks[i]);
			for (j = 0; j < PT_LEVEL_SIZE; j++){
				// We're about to copy this page. Make sure it can't be written to
				vm_tlbflush((i << 22) & (j << 12));

				old_entry = &old->pagetable[i][j];
				new_entry = &newas->pagetable[i][j];

				// For every valid pagetable entry...
				if (old_entry->allocated){
					offset = bs_alloc_index();
					if (old_entry->in_memory){
						// Write it to disk if it's in memory
						retval = bs_write_page((void *) PADDR_TO_KVADDR(old_entry->p_addr), offset);
						KASSERT(retval == 0);
					} else {
						// Or copy it to the new disk spot if not
						retval = bs_read_page(buffer, old_entry->store_index);
						KASSERT(retval == 0);

						retval = bs_write_page(buffer, offset);
						KASSERT(retval == 0);
					}
					// Update entry
					// TODO: this will be caught by coremap
					new_entry->p_addr = 0;
					new_entry->store_index = offset;
					new_entry->in_memory = false;
					new_entry->allocated = true;
				}
			}
			lock_release(old->pt_locks[i]);
		}
	}
	kfree(buffer);

	*ret = newas;

	return 0;

	err0:
	for (i=0; i < (int)region_len; i++){
		new_region = (struct region *)array_get(newas->as_regions,i);
		if (new_region != NULL)
			kfree(new_region);
	}
	return ENOMEM;
}