Ejemplo n.º 1
0
/*
* propCreateDialog
*
* Purpose:
*
* Initialize and create PropertySheet Window 
*
* Sets custom Window Procedure for PropertySheet
*
*/
VOID propCreateDialog(
	_In_ HWND hwndParent,
	_In_ LPWSTR lpObjectName,
	_In_ LPCWSTR lpObjectType,
	_In_opt_ LPWSTR lpDescription
	)
{
	INT					nPages;
	HWND				hwndDlg;
	PROP_OBJECT_INFO	*propContext = NULL;
	HPROPSHEETPAGE		SecurityPage;
	PROPSHEETPAGE		Page;
	PROPSHEETHEADER		PropHeader;
	WCHAR				szCaption[MAX_PATH * 2];

	if ((hwndParent == NULL) ||
		(lpObjectName == NULL) ||
		(lpObjectType == NULL)) 
	{
		return;
	}

	//
	//allocate context variable, copy name, type, object path
	//
	propContext = propContextCreate(lpObjectName, lpObjectType, CurrentObjectPath, lpDescription);
	if (propContext == NULL) {
		return;
	}

	//if worker available - wait on it
	if (g_kdctx.hDevice) {
		if (g_kdctx.hThreadWorker) {
			WaitForSingleObject(g_kdctx.hThreadWorker, INFINITE);
			CloseHandle(g_kdctx.hThreadWorker);
			g_kdctx.hThreadWorker = NULL;
		}
	}

	//remember previously focused window
	//except special types: desktop
	if (propContext->TypeIndex != TYPE_DESKTOP) {
		hPrevFocus = GetFocus();
	}

	//zero pages arrays
	nPages = 0;
	RtlSecureZeroMemory(psp, sizeof(psp));
	//
	// Properties: 
	// Basic->[Object]->[Process]->[Desktops]->[Registry]->Type->[Security]
	//

	//
	//Basic Info Page
	//
	RtlSecureZeroMemory(&Page, sizeof(Page));
	Page.dwSize = sizeof(PROPSHEETPAGE);
	Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
	Page.hInstance = g_hInstance;

	//select dialog for basic info
	switch (propContext->TypeIndex) {
	case TYPE_TIMER:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_TIMER);
		break;
	case TYPE_MUTANT:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_MUTANT);
		break;
	case TYPE_SEMAPHORE:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_SEMAPHORE);
		break;
	case TYPE_JOB:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_JOB);
		break;
	case TYPE_WINSTATION:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_WINSTATION);
		break;
	case TYPE_EVENT:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_EVENT);
		break;
	case TYPE_SYMLINK:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_SYMLINK);
		break;
	case TYPE_KEY:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_KEY);
		break;
	case TYPE_SECTION:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_SECTION);
		break;
	case TYPE_DRIVER:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_DRIVER);
		break;
	case TYPE_DEVICE:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_DEVICE);
		break;
	case TYPE_IOCOMPLETION:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_IOCOMPLETION);
		break;

	case TYPE_TYPE:
	default:
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_BASIC);
		break;
	}
	Page.pfnDlgProc = BasicPropDialogProc;
	Page.pszTitle = L"Basic";
	Page.lParam = (LPARAM)propContext;
	psp[nPages++] = CreatePropertySheetPage(&Page);

	//
	//Create Objects page for supported types
	//
	if (g_kdctx.hDevice != NULL) {
		switch (propContext->TypeIndex) {
		case TYPE_DIRECTORY:
		case TYPE_DRIVER:
		case TYPE_DEVICE:
		case TYPE_EVENT:
		case TYPE_MUTANT:
		case TYPE_SEMAPHORE:
		case TYPE_TIMER:
		case TYPE_IOCOMPLETION:
		case TYPE_TYPE:
			RtlSecureZeroMemory(&Page, sizeof(Page));
			Page.dwSize = sizeof(PROPSHEETPAGE);
			Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
			Page.hInstance = g_hInstance;
			Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_OBJECTDUMP);
			Page.pfnDlgProc = ObjectDumpDialogProc;
			Page.pszTitle = L"Object";
			Page.lParam = (LPARAM)propContext;
			psp[nPages++] = CreatePropertySheetPage(&Page);
			break;
		}
	}

	//
	//Create additional page(s), depending on object type
	//
	switch (propContext->TypeIndex) {
	case TYPE_DIRECTORY:
	case TYPE_PORT:
	case TYPE_FLTCOMM_PORT:
	case TYPE_FLTCONN_PORT:
	case TYPE_EVENT:
	case TYPE_MUTANT:
	case TYPE_SEMAPHORE:
	case TYPE_SECTION:
	case TYPE_SYMLINK:
	case TYPE_TIMER:
	case TYPE_JOB:
	case TYPE_WINSTATION:
	case TYPE_IOCOMPLETION:
		RtlSecureZeroMemory(&Page, sizeof(Page));
		Page.dwSize = sizeof(PROPSHEETPAGE);
		Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
		Page.hInstance = g_hInstance;
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_PROCESSLIST);
		Page.pfnDlgProc = ProcessListDialogProc;
		Page.pszTitle = L"Process";
		Page.lParam = (LPARAM)propContext;
		psp[nPages++] = CreatePropertySheetPage(&Page);

		//
		//Add desktop list for selected desktop, located here because of sheets order
		//
		if (propContext->TypeIndex == TYPE_WINSTATION) {
			RtlSecureZeroMemory(&Page, sizeof(Page));
			Page.dwSize = sizeof(PROPSHEETPAGE);
			Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
			Page.hInstance = g_hInstance;
			Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_DESKTOPS);
			Page.pfnDlgProc = DesktopListDialogProc;
			Page.pszTitle = L"Desktops";
			Page.lParam = (LPARAM)propContext;
			psp[nPages++] = CreatePropertySheetPage(&Page);
		}

		break;
	case TYPE_DRIVER:
		//
		//Add registry page
		//
		RtlSecureZeroMemory(&Page, sizeof(Page));
		Page.dwSize = sizeof(PROPSHEETPAGE);
		Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
		Page.hInstance = g_hInstance;
		Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_SERVICE);
		Page.pfnDlgProc = DriverRegistryDialogProc;
		Page.pszTitle = L"Registry";
		Page.lParam = (LPARAM)propContext;
		psp[nPages++] = CreatePropertySheetPage(&Page);
		break;
	}

	//
	//Type Info Page
	//
	RtlSecureZeroMemory(&Page, sizeof(Page));
	Page.dwSize = sizeof(PROPSHEETPAGE);
	Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
	Page.hInstance = g_hInstance;
	Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_TYPE);
	Page.pfnDlgProc = TypePropDialogProc;
	Page.pszTitle = L"Type";
	Page.lParam = (LPARAM)propContext;
	psp[nPages++] = CreatePropertySheetPage(&Page);

	//
	//Create Security Dialog if available
	//
	SecurityPage = propSecurityCreatePage(
		propContext, //Context
		(POPENOBJECTMETHOD)&propOpenCurrentObject, //OpenObjectMethod
		NULL, //CloseObjectMethod, use default
		SI_EDIT_AUDITS | SI_EDIT_OWNER | SI_EDIT_PERMS | //psiFlags
		SI_ADVANCED | SI_NO_ACL_PROTECT | SI_NO_TREE_APPLY |
		SI_PAGE_TITLE
		);
	if (SecurityPage != NULL) {
		psp[nPages++] = SecurityPage;
	}

	//
	//Finally create property sheet
	//
	if (propContext->IsType) {
		_strncpy(szCaption, MAX_PATH, lpObjectName, _strlen(lpObjectName));
	}
	else {
		_strncpy(szCaption, MAX_PATH, lpObjectType, _strlen(lpObjectType));
	}

	_strcat(szCaption, L" Properties");
	RtlSecureZeroMemory(&PropHeader, sizeof(PropHeader));
	PropHeader.dwSize = sizeof(PropHeader);
	PropHeader.phpage = psp;
	PropHeader.nPages = nPages;
	PropHeader.dwFlags = PSH_DEFAULT | PSH_NOCONTEXTHELP | PSH_MODELESS;
	PropHeader.nStartPage = 0;
	PropHeader.hwndParent = hwndParent;
	PropHeader.hInstance = g_hInstance;
	PropHeader.pszCaption = szCaption;

	hwndDlg = (HWND)PropertySheet(&PropHeader);

	//remove class icon if any
	SetClassLongPtr(hwndDlg, GCLP_HICON, (LONG_PTR)NULL);

	if (propContext->TypeIndex == TYPE_DESKTOP) {
		g_SubPropWindow = hwndDlg;
	}
	else {
		g_PropWindow = hwndDlg;
	}
	if (hwndDlg) {
		SetProp(hwndDlg, T_PROPCONTEXT, (HANDLE)propContext);
		PropSheetOriginalWndProc = (WNDPROC)GetWindowLongPtr(hwndDlg, GWLP_WNDPROC);
		if (PropSheetOriginalWndProc) {
			SetWindowLongPtr(hwndDlg, GWLP_WNDPROC, (LONG_PTR)&PropSheetCustomWndProc);
		}
		supCenterWindow(hwndDlg);
	}
}
Ejemplo n.º 2
0
/*
* PipeDlgShowProperties
*
* Purpose:
*
* Show properties dialog for selected pipe.
* Because of Pipe special case we cannot use propCreateDialog.
*
*/
VOID PipeDlgShowProperties(
    _In_ INT iItem
)
{
    INT                 nPages = 0;
    PROP_OBJECT_INFO   *Context;
    HPROPSHEETPAGE      SecurityPage = NULL;
    PROPSHEETPAGE       Page;
    PROPSHEETHEADER     PropHeader;
    WCHAR               szCaption[MAX_PATH];

    Context = propContextCreate(NULL, NULL, NULL, NULL);
    if (Context == NULL) {
        return;
    }

    Context->lpObjectName = supGetItemText(PipeDlgContext.ListView, iItem, 0, NULL);
    Context->lpCurrentObjectPath = PipeCreateFullName(Context->lpObjectName);

    //
    //Create Pipe Page
    //
    RtlSecureZeroMemory(&Page, sizeof(Page));
    Page.dwSize = sizeof(PROPSHEETPAGE);
    Page.dwFlags = PSP_DEFAULT | PSP_USETITLE;
    Page.hInstance = g_hInstance;
    Page.pszTemplate = MAKEINTRESOURCE(IDD_PROP_PIPE);
    Page.pfnDlgProc = PipeTypeDialogProc;
    Page.pszTitle = TEXT("Pipe");
    Page.lParam = (LPARAM)Context;
    epsp[nPages++] = CreatePropertySheetPage(&Page);

    //
    //Create Security Dialog if available
    //
    SecurityPage = propSecurityCreatePage(
        Context,
        (POPENOBJECTMETHOD)&PipeOpenObjectMethod,
        NULL, //use default close method
        SI_EDIT_AUDITS | SI_EDIT_OWNER | SI_EDIT_PERMS |
        SI_ADVANCED | SI_NO_ACL_PROTECT | SI_NO_TREE_APPLY |
        SI_PAGE_TITLE
    );
    if (SecurityPage != NULL) {
        epsp[nPages++] = SecurityPage;
    }

    //
    //Create property sheet
    //
    _strcpy(szCaption, TEXT("Pipe Properties"));
    RtlSecureZeroMemory(&PropHeader, sizeof(PropHeader));
    PropHeader.dwSize = sizeof(PropHeader);
    PropHeader.phpage = epsp;
    PropHeader.nPages = nPages;
    PropHeader.dwFlags = PSH_DEFAULT | PSH_NOCONTEXTHELP;
    PropHeader.nStartPage = 0;
    PropHeader.hwndParent = PipeDlgContext.hwndDlg;
    PropHeader.hInstance = g_hInstance;
    PropHeader.pszCaption = szCaption;

    PropertySheet(&PropHeader);
    propContextDestroy(Context);
}