PPH_STRING PhGetListBoxString( _In_ HWND hwnd, _In_ INT Index ) { PPH_STRING string; ULONG length; if (Index == -1) { Index = ListBox_GetCurSel(hwnd); if (Index == -1) return NULL; } length = ListBox_GetTextLen(hwnd, Index); if (length == LB_ERR) return NULL; if (length == 0) return PhReferenceEmptyString(); string = PhCreateStringEx(NULL, length * 2); if (ListBox_GetText(hwnd, Index, string->Buffer) != LB_ERR) { return string; } else { PhDereferenceObject(string); return NULL; } }
PPH_STRING DiskDriveQueryGeometry( _In_ HANDLE DeviceHandle ) { IO_STATUS_BLOCK isb; DISK_GEOMETRY result; memset(&result, 0, sizeof(DISK_GEOMETRY)); if (NT_SUCCESS(NtDeviceIoControlFile( DeviceHandle, NULL, NULL, NULL, &isb, IOCTL_DISK_GET_DRIVE_GEOMETRY, // https://msdn.microsoft.com/en-us/library/aa365169.aspx NULL, 0, &result, sizeof(result) ))) { // TODO: This doesn't return total capacity like Task Manager. return PhFormatSize(result.Cylinders.QuadPart * result.TracksPerCylinder * result.SectorsPerTrack * result.BytesPerSector, -1); } return PhReferenceEmptyString(); }
static PPH_STRING NetworkAdapterQueryLinkSpeed( _In_ HANDLE DeviceHandle ) { NDIS_OID opcode; IO_STATUS_BLOCK isb; NDIS_CO_LINK_SPEED result; // https://msdn.microsoft.com/en-us/library/windows/hardware/ff569593.aspx opcode = OID_GEN_LINK_SPEED; // OID_GEN_CO_LINK_SPEED memset(&result, 0, sizeof(NDIS_CO_LINK_SPEED)); if (NT_SUCCESS(NtDeviceIoControlFile( DeviceHandle, NULL, NULL, NULL, &isb, IOCTL_NDIS_QUERY_GLOBAL_STATS, &opcode, sizeof(NDIS_OID), &result, sizeof(result) ))) { return PhFormatSize(UInt32x32To64(result.Outbound, NDIS_UNIT_OF_MEASUREMENT) / BITS_IN_ONE_BYTE, -1); } return PhReferenceEmptyString(); }
PPH_STRING PhFormatLogEntry( _In_ PPH_LOG_ENTRY Entry ) { switch (Entry->Type) { case PH_LOG_ENTRY_PROCESS_CREATE: return PhFormatString( L"Process created: %s (%u) started by %s (%u)", Entry->Process.Name->Buffer, (ULONG)Entry->Process.ProcessId, PhGetStringOrDefault(Entry->Process.ParentName, L"Unknown Process"), (ULONG)Entry->Process.ParentProcessId ); case PH_LOG_ENTRY_PROCESS_DELETE: return PhFormatString(L"Process terminated: %s (%u)", Entry->Process.Name->Buffer, (ULONG)Entry->Process.ProcessId); case PH_LOG_ENTRY_SERVICE_CREATE: return PhFormatString(L"Service created: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_SERVICE_DELETE: return PhFormatString(L"Service deleted: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_SERVICE_START: return PhFormatString(L"Service started: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_SERVICE_STOP: return PhFormatString(L"Service stopped: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_SERVICE_CONTINUE: return PhFormatString(L"Service continued: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_SERVICE_PAUSE: return PhFormatString(L"Service paused: %s (%s)", Entry->Service.Name->Buffer, Entry->Service.DisplayName->Buffer); case PH_LOG_ENTRY_MESSAGE: PhReferenceObject(Entry->Message); return Entry->Message; default: return PhReferenceEmptyString(); } }
static PPH_STRING PhpGetStringForSelectedLogEntries( __in BOOLEAN All ) { PH_STRING_BUILDER stringBuilder; ULONG i; if (ListViewCount == 0) return PhReferenceEmptyString(); PhInitializeStringBuilder(&stringBuilder, 0x100); i = ListViewCount - 1; while (TRUE) { PPH_LOG_ENTRY entry; SYSTEMTIME systemTime; PPH_STRING temp; if (!All) { // The list view displays the items in reverse order... if (!(ListView_GetItemState(ListViewHandle, ListViewCount - i - 1, LVIS_SELECTED) & LVIS_SELECTED)) { goto ContinueLoop; } } entry = PhGetItemCircularBuffer_PVOID(&PhLogBuffer, i); if (!entry) goto ContinueLoop; PhLargeIntegerToLocalSystemTime(&systemTime, &entry->Time); temp = PhFormatDateTime(&systemTime); PhAppendStringBuilder(&stringBuilder, temp); PhDereferenceObject(temp); PhAppendStringBuilder2(&stringBuilder, L": "); temp = PhFormatLogEntry(entry); PhAppendStringBuilder(&stringBuilder, temp); PhDereferenceObject(temp); PhAppendStringBuilder2(&stringBuilder, L"\r\n"); ContinueLoop: if (i == 0) break; i--; } return PhFinalStringBuilderString(&stringBuilder); }
PPH_STRING PhGetOpaqueXmlNodeText( _In_ mxml_node_t *xmlNode ) { if (xmlNode && xmlNode->child && xmlNode->child->type == MXML_OPAQUE && xmlNode->child->value.opaque) { return PhConvertUtf8ToUtf16(xmlNode->child->value.opaque); } return PhReferenceEmptyString(); }
static PPH_STRING PhGetOpaqueXmlNodeText( __in mxml_node_t *xmlNode ) { if (xmlNode && xmlNode->child && xmlNode->child->type == MXML_OPAQUE && xmlNode->child->value.opaque) { return PhCreateStringFromAnsi(xmlNode->child->value.opaque); } return PhReferenceEmptyString(); }
static PPH_STRING PhpSettingToString( _In_ PH_SETTING_TYPE Type, _In_ PPH_SETTING Setting ) { switch (Type) { case StringSettingType: { if (!Setting->u.Pointer) return PhReferenceEmptyString(); PhReferenceObject(Setting->u.Pointer); return (PPH_STRING)Setting->u.Pointer; } case IntegerSettingType: { return PhFormatString(L"%x", Setting->u.Integer); } case IntegerPairSettingType: { PPH_INTEGER_PAIR integerPair = &Setting->u.IntegerPair; return PhFormatString(L"%d,%d", integerPair->X, integerPair->Y); } case ScalableIntegerPairSettingType: { PPH_SCALABLE_INTEGER_PAIR scalableIntegerPair = Setting->u.Pointer; if (!scalableIntegerPair) return PhReferenceEmptyString(); return PhFormatString(L"@%u|%d,%d", scalableIntegerPair->Scale, scalableIntegerPair->X, scalableIntegerPair->Y); } } return PhReferenceEmptyString(); }
PPH_STRING EtpGetGpuNameString( VOID ) { PPH_STRING description; if (EtGetGpuAdapterCount() == 1) { description = EtGetGpuAdapterDescription(0); if (!description) description = PhReferenceEmptyString(); } else if (EtGetGpuAdapterCount() > 1) { description = PhCreateString(L"Multiple GPUs"); } else { description = PhReferenceEmptyString(); } return description; }
_May_raise_ PPH_STRING PhGetStringSetting( _In_ PWSTR Name ) { PPH_SETTING setting; PH_STRINGREF name; PPH_STRING value; PhInitializeStringRef(&name, Name); PhAcquireQueuedLockShared(&PhSettingsLock); setting = PhpLookupSetting(&name); if (setting && setting->Type == StringSettingType) { if (setting->u.Pointer) { PhSetReference(&value, setting->u.Pointer); } else { // Set to NULL, create an empty string // outside of the lock. value = NULL; } } else { setting = NULL; } PhReleaseQueuedLockShared(&PhSettingsLock); if (!setting) PhRaiseStatus(STATUS_NOT_FOUND); if (!value) value = PhReferenceEmptyString(); return value; }
PDB_OBJECT CreateDbObject( _In_ ULONG Tag, _In_ PPH_STRINGREF Name, _In_opt_ PPH_STRING Comment ) { PDB_OBJECT object; BOOLEAN added; PDB_OBJECT *realObject; object = PhAllocate(sizeof(DB_OBJECT)); memset(object, 0, sizeof(DB_OBJECT)); object->Tag = Tag; object->Key = *Name; object->BackColor = ULONG_MAX; realObject = PhAddEntryHashtableEx(ObjectDb, &object, &added); if (added) { object->Name = PhCreateStringEx(Name->Buffer, Name->Length); object->Key = object->Name->sr; if (Comment) PhSetReference(&object->Comment, Comment); else object->Comment = PhReferenceEmptyString(); } else { PhFree(object); object = *realObject; if (Comment) PhSwapReference(&object->Comment, Comment); } return object; }
VOID WepFillWindowInfo( _In_ PWE_WINDOW_NODE Node ) { HWND hwnd; ULONG threadId; ULONG processId; hwnd = Node->WindowHandle; GetClassName(hwnd, Node->WindowClass, sizeof(Node->WindowClass) / sizeof(WCHAR)); Node->WindowText = PhGetWindowText(hwnd); if (!Node->WindowText) Node->WindowText = PhReferenceEmptyString(); threadId = GetWindowThreadProcessId(hwnd, &processId); Node->ClientId.UniqueProcess = UlongToHandle(processId); Node->ClientId.UniqueThread = UlongToHandle(threadId); Node->WindowVisible = !!IsWindowVisible(hwnd); Node->HasChildren = !!FindWindowEx(hwnd, NULL, NULL, NULL); }
VOID RebarLoadSettings( VOID ) { if (ToolStatusConfig.ToolBarEnabled && !ToolBarImageList) { ToolBarImageSize.cx = GetSystemMetrics(SM_CXSMICON); ToolBarImageSize.cy = GetSystemMetrics(SM_CYSMICON); ToolBarImageList = ImageList_Create(ToolBarImageSize.cx, ToolBarImageSize.cy, ILC_COLOR32, 0, 0); HFONT newFont; if (newFont = ToolStatusGetTreeWindowFont()) { if (ToolStatusWindowFont) DeleteObject(ToolStatusWindowFont); ToolStatusWindowFont = newFont; } } if (ToolStatusConfig.ToolBarEnabled && !RebarHandle) { RebarHandle = CreateWindowEx( WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NODIVIDER | CCS_TOP | RBS_VARHEIGHT | RBS_AUTOSIZE, // CCS_NOPARENTALIGN CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); ToolBarHandle = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NOPARENTALIGN | CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, RebarHandle, NULL, NULL, NULL ); // Set the rebar info with no imagelist. SendMessage(RebarHandle, RB_SETBARINFO, 0, (LPARAM)&(REBARINFO){ sizeof(REBARINFO) }); // Set the toolbar struct size. SendMessage(ToolBarHandle, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); // Set the toolbar extended toolbar styles. SendMessage(ToolBarHandle, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS | TBSTYLE_EX_HIDECLIPPEDBUTTONS); // Configure the toolbar imagelist. SendMessage(ToolBarHandle, TB_SETIMAGELIST, 0, (LPARAM)ToolBarImageList); // Add the buttons to the toolbar. ToolbarLoadButtonSettings(); SendMessage(ToolBarHandle, WM_SETFONT, (WPARAM)ToolStatusWindowFont, FALSE); // Resize the toolbar. SendMessage(ToolBarHandle, TB_AUTOSIZE, 0, 0); // Inset the toolbar into the rebar control. ULONG toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0); RebarBandInsert(REBAR_BAND_ID_TOOLBAR, ToolBarHandle, LOWORD(toolbarButtonSize), HIWORD(toolbarButtonSize)); } if (ToolStatusConfig.SearchBoxEnabled && !SearchboxHandle) { SearchboxText = PhReferenceEmptyString(); ProcessTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportProcessTreeList(), ProcessTreeFilterCallback, NULL); ServiceTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportServiceTreeList(), ServiceTreeFilterCallback, NULL); NetworkTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportNetworkTreeList(), NetworkTreeFilterCallback, NULL); if (SearchboxHandle = CreateWindowEx( WS_EX_CLIENTEDGE, WC_EDIT, NULL, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | ES_LEFT | ES_AUTOHSCROLL | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, RebarHandle, NULL, NULL, NULL )) { PhCreateSearchControl(RebarHandle, SearchboxHandle, L"Search Processes (Ctrl+K)"); } } if (ToolStatusConfig.StatusBarEnabled && !StatusBarHandle) { StatusBarHandle = CreateWindowEx( 0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); if (StatusBarHandle && PhGetIntegerSetting(L"EnableThemeSupport")) { PhInitializeWindowThemeStatusBar(StatusBarHandle); } } // Hide or show controls (Note: don't unload or remove at runtime). if (ToolStatusConfig.ToolBarEnabled) { if (RebarHandle && !IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_SHOW); } else { if (RebarHandle && IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_HIDE); } if (ToolStatusConfig.SearchBoxEnabled && RebarHandle && SearchboxHandle) { UINT height = (UINT)SendMessage(RebarHandle, RB_GETROWHEIGHT, 0, 0); // Add the Searchbox band into the rebar control. if (!RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandInsert(REBAR_BAND_ID_SEARCHBOX, SearchboxHandle, PH_SCALE_DPI(180), height); if (!IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_SHOW); if (SearchBoxDisplayMode == SEARCHBOX_DISPLAY_MODE_HIDEINACTIVE) { if (RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandRemove(REBAR_BAND_ID_SEARCHBOX); } } else { // Remove the Searchbox band from the rebar control. if (RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandRemove(REBAR_BAND_ID_SEARCHBOX); if (SearchboxHandle) { // Clear search text and reset search filters. SetFocus(SearchboxHandle); Static_SetText(SearchboxHandle, L""); if (IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_HIDE); } } if (ToolStatusConfig.StatusBarEnabled) { if (StatusBarHandle && !IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_SHOW); } else { if (StatusBarHandle && IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_HIDE); } }
INT WINAPI wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR lpCmdLine, _In_ INT nCmdShow ) { LONG result; #ifdef DEBUG PHP_BASE_THREAD_DBG dbg; #endif CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); #ifndef DEBUG SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); #endif PhInstanceHandle = (HINSTANCE)NtCurrentPeb()->ImageBaseAddress; if (!NT_SUCCESS(PhInitializePhLib())) return 1; if (!PhInitializeAppSystem()) return 1; PhInitializeCommonControls(); if (PhCurrentTokenQueryHandle) { PTOKEN_USER tokenUser; if (NT_SUCCESS(PhGetTokenUser(PhCurrentTokenQueryHandle, &tokenUser))) { PhCurrentUserName = PhGetSidFullName(tokenUser->User.Sid, TRUE, NULL); PhFree(tokenUser); } } PhLocalSystemName = PhGetSidFullName(&PhSeLocalSystemSid, TRUE, NULL); // There has been a report of the above call failing. if (!PhLocalSystemName) PhLocalSystemName = PhCreateString(L"NT AUTHORITY\\SYSTEM"); PhApplicationFileName = PhGetApplicationFileName(); PhApplicationDirectory = PhGetApplicationDirectory(); // Just in case if (!PhApplicationFileName) PhApplicationFileName = PhCreateString(L"ProcessHacker.exe"); if (!PhApplicationDirectory) PhApplicationDirectory = PhReferenceEmptyString(); PhpProcessStartupParameters(); PhSettingsInitialization(); PhpEnablePrivileges(); if (PhStartupParameters.RunAsServiceMode) { RtlExitUserProcess(PhRunAsServiceStart(PhStartupParameters.RunAsServiceMode)); } PhpInitializeSettings(); // Activate a previous instance if required. if (PhGetIntegerSetting(L"AllowOnlyOneInstance") && !PhStartupParameters.NewInstance && !PhStartupParameters.ShowOptions && !PhStartupParameters.CommandMode && !PhStartupParameters.PhSvc) { PhActivatePreviousInstance(); } if (PhGetIntegerSetting(L"EnableKph") && !PhStartupParameters.NoKph && !PhIsExecutingInWow64()) PhInitializeKph(); if (PhStartupParameters.CommandMode && PhStartupParameters.CommandType && PhStartupParameters.CommandAction) { NTSTATUS status; status = PhCommandModeStart(); if (!NT_SUCCESS(status) && !PhStartupParameters.Silent) { PhShowStatus(NULL, L"Unable to execute the command", status, 0); } RtlExitUserProcess(status); } #ifdef DEBUG dbg.ClientId = NtCurrentTeb()->ClientId; dbg.StartAddress = wWinMain; dbg.Parameter = NULL; InsertTailList(&PhDbgThreadListHead, &dbg.ListEntry); TlsSetValue(PhDbgThreadDbgTlsIndex, &dbg); #endif PhInitializeAutoPool(&BaseAutoPool); PhEmInitialization(); PhGuiSupportInitialization(); PhTreeNewInitialization(); PhGraphControlInitialization(); PhHexEditInitialization(); PhColorBoxInitialization(); PhSmallIconSize.X = GetSystemMetrics(SM_CXSMICON); PhSmallIconSize.Y = GetSystemMetrics(SM_CYSMICON); PhLargeIconSize.X = GetSystemMetrics(SM_CXICON); PhLargeIconSize.Y = GetSystemMetrics(SM_CYICON); if (PhStartupParameters.ShowOptions) { // Elevated options dialog for changing the value of Replace Task Manager with Process Hacker. PhShowOptionsDialog(PhStartupParameters.WindowHandle); RtlExitUserProcess(STATUS_SUCCESS); } #ifndef DEBUG if (PhIsExecutingInWow64() && !PhStartupParameters.PhSvc) { PhShowWarning( NULL, L"You are attempting to run the 32-bit version of Process Hacker on 64-bit Windows. " L"Most features will not work correctly.\n\n" L"Please run the 64-bit version of Process Hacker instead." ); } #endif PhPluginsEnabled = PhGetIntegerSetting(L"EnablePlugins") && !PhStartupParameters.NoPlugins; if (PhPluginsEnabled) { PhPluginsInitialization(); PhLoadPlugins(); } if (PhStartupParameters.PhSvc) { MSG message; // Turn the feedback cursor off. PostMessage(NULL, WM_NULL, 0, 0); GetMessage(&message, NULL, 0, 0); RtlExitUserProcess(PhSvcMain(NULL, NULL, NULL)); } // Create a mutant for the installer. { HANDLE mutantHandle; OBJECT_ATTRIBUTES oa; UNICODE_STRING mutantName; RtlInitUnicodeString(&mutantName, L"\\BaseNamedObjects\\ProcessHacker2Mutant"); InitializeObjectAttributes( &oa, &mutantName, 0, NULL, NULL ); NtCreateMutant(&mutantHandle, MUTANT_ALL_ACCESS, &oa, FALSE); } // Set priority. { PROCESS_PRIORITY_CLASS priorityClass; priorityClass.Foreground = FALSE; priorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_HIGH; if (PhStartupParameters.PriorityClass != 0) priorityClass.PriorityClass = (UCHAR)PhStartupParameters.PriorityClass; NtSetInformationProcess(NtCurrentProcess(), ProcessPriorityClass, &priorityClass, sizeof(PROCESS_PRIORITY_CLASS)); } if (!PhMainWndInitialization(nCmdShow)) { PhShowError(NULL, L"Unable to initialize the main window."); return 1; } PhDrainAutoPool(&BaseAutoPool); result = PhMainMessageLoop(); RtlExitUserProcess(result); }
PPH_LIST PhGetGenericTreeNewLines( __in HWND TreeNewHandle, __in ULONG Mode ) { PH_AUTO_POOL autoPool; PPH_LIST lines; ULONG rows; ULONG columns; ULONG numberOfNodes; PULONG displayToId; PWSTR *displayToText; PPH_STRING **table; ULONG i; ULONG j; PhInitializeAutoPool(&autoPool); numberOfNodes = TreeNew_GetFlatNodeCount(TreeNewHandle); rows = numberOfNodes + 1; PhMapDisplayIndexTreeNew(TreeNewHandle, &displayToId, &displayToText, &columns); PhaCreateTextTable(&table, rows, columns); for (i = 0; i < columns; i++) table[0][i] = PhaCreateString(displayToText[i]); for (i = 0; i < numberOfNodes; i++) { PPH_TREENEW_NODE node; node = TreeNew_GetFlatNode(TreeNewHandle, i); if (node) { for (j = 0; j < columns; j++) { PH_TREENEW_GET_CELL_TEXT getCellText; getCellText.Node = node; getCellText.Id = displayToId[j]; PhInitializeEmptyStringRef(&getCellText.Text); TreeNew_GetCellText(TreeNewHandle, &getCellText); table[i + 1][j] = PhaCreateStringEx(getCellText.Text.Buffer, getCellText.Text.Length); } } else { for (j = 0; j < columns; j++) { table[i + 1][j] = PHA_DEREFERENCE(PhReferenceEmptyString()); } } } PhFree(displayToText); PhFree(displayToId); lines = PhaFormatTextTable(table, rows, columns, Mode); PhDeleteAutoPool(&autoPool); return lines; }
ULONG PhGetWindowTextEx( _In_ HWND hwnd, _In_ ULONG Flags, _Out_opt_ PPH_STRING *Text ) { PPH_STRING string; ULONG length; if (Flags & PH_GET_WINDOW_TEXT_INTERNAL) { if (Flags & PH_GET_WINDOW_TEXT_LENGTH_ONLY) { WCHAR buffer[32]; length = InternalGetWindowText(hwnd, buffer, sizeof(buffer) / sizeof(WCHAR)); } else { // TODO: Resize the buffer until we get the entire thing. string = PhCreateStringEx(NULL, 256 * sizeof(WCHAR)); length = InternalGetWindowText(hwnd, string->Buffer, (ULONG)string->Length / sizeof(WCHAR) + 1); string->Length = length * sizeof(WCHAR); if (Text) *Text = string; else PhDereferenceObject(string); } return length; } else { length = GetWindowTextLength(hwnd); if (length == 0 || (Flags & PH_GET_WINDOW_TEXT_LENGTH_ONLY)) { if (Text) *Text = PhReferenceEmptyString(); return length; } string = PhCreateStringEx(NULL, length * sizeof(WCHAR)); if (GetWindowText(hwnd, string->Buffer, (ULONG)string->Length / sizeof(WCHAR) + 1)) { if (Text) *Text = string; else PhDereferenceObject(string); return length; } else { if (Text) *Text = PhReferenceEmptyString(); PhDereferenceObject(string); return 0; } } }
VOID RebarLoadSettings( VOID ) { // Initialize the Toolbar Imagelist. if (ToolStatusConfig.ToolBarEnabled && !ToolBarImageList) { ToolBarImageList = ImageList_Create( GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 0, 0 ); } // Initialize the Rebar and Toolbar controls. if (ToolStatusConfig.ToolBarEnabled && !RebarHandle) { REBARINFO rebarInfo = { sizeof(REBARINFO) }; ULONG toolbarButtonSize; // Create the ReBar window. RebarHandle = CreateWindowEx( WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NODIVIDER | CCS_TOP | RBS_VARHEIGHT | RBS_AUTOSIZE, // CCS_NOPARENTALIGN | RBS_FIXEDORDER CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); // Set the toolbar info with no imagelist. SendMessage(RebarHandle, RB_SETBARINFO, 0, (LPARAM)&rebarInfo); // Create the ToolBar window. ToolBarHandle = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE, // TBSTYLE_CUSTOMERASE TBSTYLE_ALTDRAG CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, RebarHandle, NULL, NULL, NULL ); // Set the toolbar struct size. SendMessage(ToolBarHandle, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); // Set the toolbar extended toolbar styles. SendMessage(ToolBarHandle, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS | TBSTYLE_EX_HIDECLIPPEDBUTTONS); // Configure the toolbar imagelist. SendMessage(ToolBarHandle, TB_SETIMAGELIST, 0, (LPARAM)ToolBarImageList); // Add the buttons to the toolbar. ToolbarLoadButtonSettings(); // Query the toolbar width and height. //SendMessage(ToolBarHandle, TB_GETMAXSIZE, 0, (LPARAM)&toolbarSize); toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0); // Enable theming switch (ToolBarTheme) { case TOOLBAR_THEME_BLACK: { SendMessage(RebarHandle, RB_SETWINDOWTHEME, 0, (LPARAM)L"Media"); //Media/Communications/BrowserTabBar/Help SendMessage(ToolBarHandle, TB_SETWINDOWTHEME, 0, (LPARAM)L"Media"); //Media/Communications/BrowserTabBar/Help } break; case TOOLBAR_THEME_BLUE: { SendMessage(RebarHandle, RB_SETWINDOWTHEME, 0, (LPARAM)L"Communications"); SendMessage(ToolBarHandle, TB_SETWINDOWTHEME, 0, (LPARAM)L"Communications"); } break; } // Inset the toolbar into the rebar control. RebarBandInsert(REBAR_BAND_ID_TOOLBAR, ToolBarHandle, LOWORD(toolbarButtonSize), HIWORD(toolbarButtonSize)); } // Initialize the Searchbox and TreeNewFilters. if (ToolStatusConfig.SearchBoxEnabled && !SearchboxHandle) { SearchboxText = PhReferenceEmptyString(); ProcessTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportProcessTreeList(), (PPH_TN_FILTER_FUNCTION)ProcessTreeFilterCallback, NULL); ServiceTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportServiceTreeList(), (PPH_TN_FILTER_FUNCTION)ServiceTreeFilterCallback, NULL); NetworkTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportNetworkTreeList(), (PPH_TN_FILTER_FUNCTION)NetworkTreeFilterCallback, NULL); // Create the Searchbox control. SearchboxHandle = CreateSearchControl(ID_SEARCH_CLEAR); } // Initialize the Statusbar control. if (ToolStatusConfig.StatusBarEnabled && !StatusBarHandle) { // Create the StatusBar window. StatusBarHandle = CreateWindowEx( 0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); } // Hide or show controls (Note: don't unload or remove at runtime). if (ToolStatusConfig.ToolBarEnabled) { if (RebarHandle && !IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_SHOW); } else { if (RebarHandle && IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_HIDE); } if (ToolStatusConfig.SearchBoxEnabled && RebarHandle && SearchboxHandle) { UINT height = (UINT)SendMessage(RebarHandle, RB_GETROWHEIGHT, 0, 0); // Add the Searchbox band into the rebar control. if (!RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandInsert(REBAR_BAND_ID_SEARCHBOX, SearchboxHandle, PhMultiplyDivide(180, PhGlobalDpi, 96), height - 2); if (!IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_SHOW); if (SearchBoxDisplayMode == SEARCHBOX_DISPLAY_MODE_HIDEINACTIVE) { if (RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandRemove(REBAR_BAND_ID_SEARCHBOX); } } else { // Remove the Searchbox band from the rebar control. if (RebarBandExists(REBAR_BAND_ID_SEARCHBOX)) RebarBandRemove(REBAR_BAND_ID_SEARCHBOX); if (SearchboxHandle) { // Clear search text and reset search filters. SetFocus(SearchboxHandle); Static_SetText(SearchboxHandle, L""); if (IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_HIDE); } } if (ToolStatusConfig.StatusBarEnabled) { if (StatusBarHandle && !IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_SHOW); } else { if (StatusBarHandle && IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_HIDE); } ToolbarCreateGraphs(); }
/** * Gets information for a handle. * * \param ProcessHandle A handle to the process in which the * handle resides. * \param Handle The handle value. * \param ObjectTypeNumber The object type number of the handle. * You can specify -1 for this parameter if the object type number * is not known. * \param Flags Reserved. * \param SubStatus A variable which receives the NTSTATUS value of * the last component that fails. If all operations succeed, the * value will be STATUS_SUCCESS. If the function returns an error * status, this variable is not set. * \param BasicInformation A variable which receives basic * information about the object. * \param TypeName A variable which receives the object type name. * \param ObjectName A variable which receives the object name. * \param BestObjectName A variable which receives the formatted * object name. * \param ExtraInformation Reserved. * * \retval STATUS_INVALID_HANDLE The handle specified in * \c ProcessHandle or \c Handle is invalid. * \retval STATUS_INVALID_PARAMETER_3 The value specified in * \c ObjectTypeNumber is invalid. * * \remarks If \a BasicInformation or \a TypeName are specified, * the function will fail if either cannot be queried. \a ObjectName, * \a BestObjectName and \a ExtraInformation will return NULL if they * cannot be queried. */ NTSTATUS PhGetHandleInformationEx( __in HANDLE ProcessHandle, __in HANDLE Handle, __in ULONG ObjectTypeNumber, __reserved ULONG Flags, __out_opt PNTSTATUS SubStatus, __out_opt POBJECT_BASIC_INFORMATION BasicInformation, __out_opt PPH_STRING *TypeName, __out_opt PPH_STRING *ObjectName, __out_opt PPH_STRING *BestObjectName, __reserved PVOID *ExtraInformation ) { NTSTATUS status = STATUS_SUCCESS; NTSTATUS subStatus = STATUS_SUCCESS; HANDLE dupHandle = NULL; PPH_STRING typeName = NULL; PPH_STRING objectName = NULL; PPH_STRING bestObjectName = NULL; if (Handle == NULL || Handle == NtCurrentProcess() || Handle == NtCurrentThread()) return STATUS_INVALID_HANDLE; if (ObjectTypeNumber != -1 && ObjectTypeNumber >= MAX_OBJECT_TYPE_NUMBER) return STATUS_INVALID_PARAMETER_3; // Duplicate the handle if we're not using KPH. if (!KphIsConnected()) { // However, we obviously don't need to duplicate it // if the handle is in the current process. if (ProcessHandle != NtCurrentProcess()) { status = NtDuplicateObject( ProcessHandle, Handle, NtCurrentProcess(), &dupHandle, 0, 0, 0 ); if (!NT_SUCCESS(status)) return status; } else { dupHandle = Handle; } } // Get basic information. if (BasicInformation) { status = PhpGetObjectBasicInformation( ProcessHandle, KphIsConnected() ? Handle : dupHandle, BasicInformation ); if (!NT_SUCCESS(status)) goto CleanupExit; } // Exit early if we don't need to get any other information. if (!TypeName && !ObjectName && !BestObjectName) goto CleanupExit; // Get the type name. status = PhpGetObjectTypeName( ProcessHandle, KphIsConnected() ? Handle : dupHandle, ObjectTypeNumber, &typeName ); if (!NT_SUCCESS(status)) goto CleanupExit; // Exit early if we don't need to get the object name. if (!ObjectName && !BestObjectName) goto CleanupExit; // Get the object name. // If we're dealing with a file handle we must take // special precautions so we don't hang. if (PhEqualString2(typeName, L"File", TRUE) && !KphIsConnected()) { // 0: Query normally. // 1: Hack. // 2: Fail. ULONG hackLevel = 1; // We can't use the hack on XP because hanging threads // can't even be terminated! if (WindowsVersion <= WINDOWS_XP) hackLevel = 2; if (hackLevel == 0) { status = PhpGetObjectName( ProcessHandle, KphIsConnected() ? Handle : dupHandle, &objectName ); } else if (hackLevel == 1) { POBJECT_NAME_INFORMATION buffer; buffer = PhAllocate(0x800); status = PhQueryObjectNameHack( dupHandle, buffer, 0x800, NULL ); if (NT_SUCCESS(status)) objectName = PhCreateStringEx(buffer->Name.Buffer, buffer->Name.Length); PhFree(buffer); } else { // Pretend the file object has no name. objectName = PhReferenceEmptyString(); status = STATUS_SUCCESS; } } else { // Query the object normally. status = PhpGetObjectName( ProcessHandle, KphIsConnected() ? Handle : dupHandle, &objectName ); } if (!NT_SUCCESS(status)) { subStatus = status; status = STATUS_SUCCESS; goto CleanupExit; } // Exit early if we don't need to get the best object name. if (!BestObjectName) goto CleanupExit; status = PhpGetBestObjectName( ProcessHandle, Handle, objectName, typeName, &bestObjectName ); if (!NT_SUCCESS(status)) { subStatus = status; status = STATUS_SUCCESS; goto CleanupExit; } CleanupExit: if (NT_SUCCESS(status)) { if (SubStatus) { *SubStatus = subStatus; } if (TypeName && typeName) { *TypeName = typeName; PhReferenceObject(typeName); } if (ObjectName && objectName) { *ObjectName = objectName; PhReferenceObject(objectName); } if (BestObjectName && bestObjectName) { *BestObjectName = bestObjectName; PhReferenceObject(bestObjectName); } } if (dupHandle && ProcessHandle != NtCurrentProcess()) NtClose(dupHandle); if (typeName) PhDereferenceObject(typeName); if (objectName) PhDereferenceObject(objectName); if (bestObjectName) PhDereferenceObject(bestObjectName); return status; }
BOOLEAN NTAPI PhpCommandLineOptionCallback( _In_opt_ PPH_COMMAND_LINE_OPTION Option, _In_opt_ PPH_STRING Value, _In_opt_ PVOID Context ) { ULONG64 integer; if (Option) { switch (Option->Id) { case PH_ARG_SETTINGS: PhSwapReference(&PhStartupParameters.SettingsFileName, Value); break; case PH_ARG_NOSETTINGS: PhStartupParameters.NoSettings = TRUE; break; case PH_ARG_SHOWVISIBLE: PhStartupParameters.ShowVisible = TRUE; break; case PH_ARG_SHOWHIDDEN: PhStartupParameters.ShowHidden = TRUE; break; case PH_ARG_COMMANDMODE: PhStartupParameters.CommandMode = TRUE; break; case PH_ARG_COMMANDTYPE: PhSwapReference(&PhStartupParameters.CommandType, Value); break; case PH_ARG_COMMANDOBJECT: PhSwapReference(&PhStartupParameters.CommandObject, Value); break; case PH_ARG_COMMANDACTION: PhSwapReference(&PhStartupParameters.CommandAction, Value); break; case PH_ARG_COMMANDVALUE: PhSwapReference(&PhStartupParameters.CommandValue, Value); break; case PH_ARG_RUNASSERVICEMODE: PhSwapReference(&PhStartupParameters.RunAsServiceMode, Value); break; case PH_ARG_NOKPH: PhStartupParameters.NoKph = TRUE; break; case PH_ARG_INSTALLKPH: PhStartupParameters.InstallKph = TRUE; break; case PH_ARG_UNINSTALLKPH: PhStartupParameters.UninstallKph = TRUE; break; case PH_ARG_DEBUG: PhStartupParameters.Debug = TRUE; break; case PH_ARG_HWND: if (PhStringToInteger64(&Value->sr, 16, &integer)) PhStartupParameters.WindowHandle = (HWND)(ULONG_PTR)integer; break; case PH_ARG_POINT: { PH_STRINGREF xString; PH_STRINGREF yString; if (PhSplitStringRefAtChar(&Value->sr, ',', &xString, &yString)) { LONG64 x; LONG64 y; if (PhStringToInteger64(&xString, 10, &x) && PhStringToInteger64(&yString, 10, &y)) { PhStartupParameters.Point.x = (LONG)x; PhStartupParameters.Point.y = (LONG)y; } } } break; case PH_ARG_SHOWOPTIONS: PhStartupParameters.ShowOptions = TRUE; break; case PH_ARG_PHSVC: PhStartupParameters.PhSvc = TRUE; break; case PH_ARG_NOPLUGINS: PhStartupParameters.NoPlugins = TRUE; break; case PH_ARG_NEWINSTANCE: PhStartupParameters.NewInstance = TRUE; break; case PH_ARG_ELEVATE: PhStartupParameters.Elevate = TRUE; break; case PH_ARG_SILENT: PhStartupParameters.Silent = TRUE; break; case PH_ARG_HELP: PhStartupParameters.Help = TRUE; break; case PH_ARG_SELECTPID: if (PhStringToInteger64(&Value->sr, 0, &integer)) PhStartupParameters.SelectPid = (ULONG)integer; break; case PH_ARG_PRIORITY: if (PhEqualString2(Value, L"r", TRUE)) PhStartupParameters.PriorityClass = PROCESS_PRIORITY_CLASS_REALTIME; else if (PhEqualString2(Value, L"h", TRUE)) PhStartupParameters.PriorityClass = PROCESS_PRIORITY_CLASS_HIGH; else if (PhEqualString2(Value, L"n", TRUE)) PhStartupParameters.PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL; else if (PhEqualString2(Value, L"l", TRUE)) PhStartupParameters.PriorityClass = PROCESS_PRIORITY_CLASS_IDLE; break; case PH_ARG_PLUGIN: if (!PhStartupParameters.PluginParameters) PhStartupParameters.PluginParameters = PhCreateList(3); PhAddItemList(PhStartupParameters.PluginParameters, PhReferenceObject(Value)); break; case PH_ARG_SELECTTAB: PhSwapReference(&PhStartupParameters.SelectTab, Value); break; case PH_ARG_SYSINFO: PhSwapReference(&PhStartupParameters.SysInfo, Value ? Value : PhReferenceEmptyString()); break; } } else { PPH_STRING upperValue; upperValue = PhDuplicateString(Value); _wcsupr(upperValue->Buffer); if (PhFindStringInString(upperValue, 0, L"TASKMGR.EXE") != -1) { // User probably has Process Hacker replacing Task Manager. Force // the main window to start visible. PhStartupParameters.ShowVisible = TRUE; } PhDereferenceObject(upperValue); } return TRUE; }
PPH_STRING PhCmSaveSettingsEx( _In_ HWND TreeNewHandle, _In_opt_ PPH_CM_MANAGER Manager, _In_ ULONG Flags, _Out_opt_ PPH_STRING *SortSettings ) { PH_STRING_BUILDER stringBuilder; ULONG i = 0; ULONG count = 0; ULONG total; ULONG increment; PH_TREENEW_COLUMN column; total = TreeNew_GetColumnCount(TreeNewHandle); if (TreeNew_GetFixedColumn(TreeNewHandle)) increment = 1; // the first normal column should have a display index that starts with 1, for compatibility else increment = 0; PhInitializeStringBuilder(&stringBuilder, 100); while (count < total) { if (TreeNew_GetColumn(TreeNewHandle, i, &column)) { if (!(Flags & PH_CM_COLUMN_WIDTHS_ONLY)) { if (column.Visible) { if (!Manager || i < Manager->MinId) { PhAppendFormatStringBuilder( &stringBuilder, L"%u,%u,%u|", i, column.Fixed ? 0 : column.DisplayIndex + increment, column.Width ); } else { PPH_CM_COLUMN cmColumn; cmColumn = column.Context; PhAppendFormatStringBuilder( &stringBuilder, L"+%s+%u,%u,%u|", cmColumn->Plugin->Name.Buffer, cmColumn->SubId, column.DisplayIndex + increment, column.Width ); } } } else { if (!Manager || i < Manager->MinId) { PhAppendFormatStringBuilder( &stringBuilder, L"%u,,%u|", i, column.Width ); } else { PPH_CM_COLUMN cmColumn; cmColumn = column.Context; PhAppendFormatStringBuilder( &stringBuilder, L"+%s+%u,,%u|", cmColumn->Plugin->Name.Buffer, cmColumn->SubId, column.Width ); } } count++; } i++; } if (stringBuilder.String->Length != 0) PhRemoveEndStringBuilder(&stringBuilder, 1); if (SortSettings) { ULONG sortColumn; PH_SORT_ORDER sortOrder; if (TreeNew_GetSort(TreeNewHandle, &sortColumn, &sortOrder)) { if (sortOrder != NoSortOrder) { if (!Manager || sortColumn < Manager->MinId) { *SortSettings = PhFormatString(L"%u,%u", sortColumn, sortOrder); } else { PH_TREENEW_COLUMN column; PPH_CM_COLUMN cmColumn; if (TreeNew_GetColumn(TreeNewHandle, sortColumn, &column)) { cmColumn = column.Context; *SortSettings = PhFormatString(L"+%s+%u,%u", cmColumn->Plugin->Name.Buffer, cmColumn->SubId, sortOrder); } else { *SortSettings = PhReferenceEmptyString(); } } } else { *SortSettings = PhCreateString(L"0,0"); } } else { *SortSettings = PhReferenceEmptyString(); } } return PhFinalStringBuilderString(&stringBuilder); }
static VOID RebarLoadSettings( VOID ) { // Initialize the Toolbar Imagelist. if (EnableToolBar && !ToolBarImageList) { HBITMAP iconBitmap = NULL; // Create the toolbar imagelist ToolBarImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0); // Set the number of images ImageList_SetImageCount(ToolBarImageList, 8); // Add the images to the imagelist if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_ARROW_REFRESH))) { ImageList_Replace(ToolBarImageList, 0, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 0, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_ARROW_REFRESH_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_COG_EDIT))) { ImageList_Replace(ToolBarImageList, 1, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 1, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_COG_EDIT_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_FIND))) { ImageList_Replace(ToolBarImageList, 2, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 2, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_FIND_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_CHART_LINE))) { ImageList_Replace(ToolBarImageList, 3, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 3, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_CHART_LINE_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_APPLICATION))) { ImageList_Replace(ToolBarImageList, 4, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 4, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_APPLICATION_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_APPLICATION_GO))) { ImageList_Replace(ToolBarImageList, 5, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 5, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_APPLICATION_GO_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_CROSS))) { ImageList_Replace(ToolBarImageList, 6, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 6, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_CROSS_BMP)); } if (iconBitmap = LoadImageFromResources(16, 16, MAKEINTRESOURCE(IDB_APPLICATION_GET))) { ImageList_Replace(ToolBarImageList, 7, iconBitmap, NULL); DeleteObject(iconBitmap); } else { PhSetImageListBitmap(ToolBarImageList, 7, PluginInstance->DllBase, MAKEINTRESOURCE(IDB_APPLICATION_GET_BMP)); } } // Initialize the Rebar and Toolbar controls. if (EnableToolBar && !RebarHandle) { REBARINFO rebarInfo = { sizeof(REBARINFO) }; ULONG toolbarButtonSize; // Create the ReBar window. RebarHandle = CreateWindowEx( WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NODIVIDER | CCS_TOP | RBS_VARHEIGHT | RBS_AUTOSIZE, // CCS_NOPARENTALIGN | RBS_FIXEDORDER CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); // Set the toolbar info with no imagelist. SendMessage(RebarHandle, RB_SETBARINFO, 0, (LPARAM)&rebarInfo); // Create the ToolBar window. ToolBarHandle = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER | CCS_ADJUSTABLE | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE, // TBSTYLE_ALTDRAG CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, RebarHandle, NULL, NULL, NULL ); // Manually add button strings via TB_ADDSTRING. // NOTE: The Toolbar will sometimes decide to free strings hard-coded via (INT_PTR)L"String" // in the ToolbarButtons array causing random crashes unless we manually add the strings // into the Toolbar string pool (this bug only affects 64bit Windows)... WTF??? ToolbarButtons[0].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Refresh"); ToolbarButtons[1].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Options"); ToolbarButtons[3].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Find Handles or DLLs"); ToolbarButtons[4].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"System Information"); ToolbarButtons[6].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Find Window"); ToolbarButtons[7].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Find Window and Thread"); ToolbarButtons[8].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Find Window and Kill"); ToolbarButtons[9].iString = SendMessage(ToolBarHandle, TB_ADDSTRING, 0, (LPARAM)L"Always on Top"); // Set the toolbar struct size. SendMessage(ToolBarHandle, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); // Set the toolbar extended toolbar styles. SendMessage(ToolBarHandle, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_MIXEDBUTTONS | TBSTYLE_EX_HIDECLIPPEDBUTTONS); // Configure the toolbar imagelist. SendMessage(ToolBarHandle, TB_SETIMAGELIST, 0, (LPARAM)ToolBarImageList); // Add the buttons to the toolbar (also specifying the default number of items to display). SendMessage(ToolBarHandle, TB_ADDBUTTONS, MAX_DEFAULT_TOOLBAR_ITEMS, (LPARAM)ToolbarButtons); // Restore the toolbar settings (Note: This will invoke the TBN_ENDADJUST notification). SendMessage(ToolBarHandle, TB_SAVERESTORE, FALSE, (LPARAM)&ToolbarSaveParams); // Query the toolbar button width/height. toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0); // Enable theming: //SendMessage(RebarHandle, RB_SETWINDOWTHEME, 0, (LPARAM)L"Media"); //Media/Communications/BrowserTabBar/Help //SendMessage(ToolBarHandle, TB_SETWINDOWTHEME, 0, (LPARAM)L"Media"); //Media/Communications/BrowserTabBar/Help // Inset the toolbar into the rebar control. RebarBandInsert(BandID_ToolBar, ToolBarHandle, HIWORD(toolbarButtonSize), LOWORD(toolbarButtonSize)); ToolbarInitialized = TRUE; } // Initialize the Searchbox and TreeNewFilters. if (EnableSearchBox && !SearchboxHandle) { SearchboxText = PhReferenceEmptyString(); ProcessTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportProcessTreeList(), (PPH_TN_FILTER_FUNCTION)ProcessTreeFilterCallback, NULL); ServiceTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportServiceTreeList(), (PPH_TN_FILTER_FUNCTION)ServiceTreeFilterCallback, NULL); NetworkTreeFilterEntry = PhAddTreeNewFilter(PhGetFilterSupportNetworkTreeList(), (PPH_TN_FILTER_FUNCTION)NetworkTreeFilterCallback, NULL); // Create the Searchbox control. SearchboxHandle = CreateSearchControl(ID_SEARCH_CLEAR); } // Initialize the Statusbar control. if (EnableStatusBar && !StatusBarHandle) { // Create the StatusBar window. StatusBarHandle = CreateWindowEx( 0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP | SBARS_TOOLTIPS, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, PhMainWndHandle, NULL, NULL, NULL ); } // Hide or show controls (Note: don't unload or remove at runtime). if (EnableToolBar) { if (RebarHandle && !IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_SHOW); } else { if (RebarHandle && IsWindowVisible(RebarHandle)) ShowWindow(RebarHandle, SW_HIDE); } if (EnableSearchBox) { // Add the Searchbox band into the rebar control. if (!RebarBandExists(BandID_SearchBox)) RebarBandInsert(BandID_SearchBox, SearchboxHandle, 20, 180); if (SearchboxHandle && !IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_SHOW); } else { // Remove the Searchbox band from the rebar control. if (RebarBandExists(BandID_SearchBox)) RebarBandRemove(BandID_SearchBox); if (SearchboxHandle) { // Clear search text and reset search filters. SetFocus(SearchboxHandle); Static_SetText(SearchboxHandle, L""); if (IsWindowVisible(SearchboxHandle)) ShowWindow(SearchboxHandle, SW_HIDE); } } // TODO: Fix above code... if (SearchBoxDisplayMode == SearchBoxDisplayHideInactive) { if (RebarBandExists(BandID_SearchBox)) RebarBandRemove(BandID_SearchBox); } else { if (!RebarBandExists(BandID_SearchBox)) RebarBandInsert(BandID_SearchBox, SearchboxHandle, 20, 180); } if (EnableStatusBar) { if (StatusBarHandle && !IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_SHOW); } else { if (StatusBarHandle && IsWindowVisible(StatusBarHandle)) ShowWindow(StatusBarHandle, SW_HIDE); } }