/** * Finds a child menu item. * * \param Item The parent menu item. * \param Flags A combination of the following: * \li \c PH_EMENU_FIND_DESCEND Searches recursively within child menu items. * \li \c PH_EMENU_FIND_STARTSWITH Performs a partial text search instead of an exact search. * \li \c PH_EMENU_FIND_LITERAL Performs a literal search instead of ignoring prefix characters * (ampersands). * \param Text The text of the menu item to find. If NULL, the text is ignored. * \param Id The identifier of the menu item to find. If 0, the identifier is ignored. * * \return The found menu item, or NULL if the menu item could not be found. */ PPH_EMENU_ITEM PhFindEMenuItem( _In_ PPH_EMENU_ITEM Item, _In_ ULONG Flags, _In_opt_ PWSTR Text, _In_opt_ ULONG Id ) { return PhFindEMenuItemEx(Item, Flags, Text, Id, NULL, NULL); }
VOID PhInsertHandleObjectPropertiesEMenuItems( _In_ struct _PH_EMENU_ITEM *Menu, _In_ ULONG InsertBeforeId, _In_ BOOLEAN EnableShortcut, _In_ PPH_HANDLE_ITEM_INFO Info ) { PPH_EMENU_ITEM parentItem; ULONG indexInParent; if (!PhFindEMenuItemEx(Menu, 0, NULL, InsertBeforeId, &parentItem, &indexInParent)) return; if (PhIsNullOrEmptyString(Info->TypeName)) return; if (PhEqualString2(Info->TypeName, L"File", TRUE) || PhEqualString2(Info->TypeName, L"DLL", TRUE) || PhEqualString2(Info->TypeName, L"Mapped file", TRUE) || PhEqualString2(Info->TypeName, L"Mapped image", TRUE)) { if (PhEqualString2(Info->TypeName, L"File", TRUE)) PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES2, L"File propert&ies", NULL, NULL), indexInParent); PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &file location", EnableShortcut), NULL, NULL), indexInParent); } else if (PhEqualString2(Info->TypeName, L"Key", TRUE)) { PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &key", EnableShortcut), NULL, NULL), indexInParent); } else if (PhEqualString2(Info->TypeName, L"Process", TRUE)) { PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Process propert&ies", EnableShortcut), NULL, NULL), indexInParent); } else if (PhEqualString2(Info->TypeName, L"Section", TRUE)) { PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Read/Write &memory", EnableShortcut), NULL, NULL), indexInParent); } else if (PhEqualString2(Info->TypeName, L"Thread", TRUE)) { PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Go to t&hread", EnableShortcut), NULL, NULL), indexInParent); } }
/** * Finds a child menu item. * * \param Item The parent menu item. * \param Flags A combination of the following: * \li \c PH_EMENU_FIND_DESCEND Searches recursively within child menu items. * \li \c PH_EMENU_FIND_STARTSWITH Performs a partial text search instead of an exact search. * \li \c PH_EMENU_FIND_LITERAL Performs a literal search instead of ignoring prefix characters * (ampersands). * \param Text The text of the menu item to find. If NULL, the text is ignored. * \param Id The identifier of the menu item to find. If 0, the identifier is ignored. * \param FoundParent A variable which receives the parent of the found menu item. * \param FoundIndex A variable which receives the index of the found menu item. * * \return The found menu item, or NULL if the menu item could not be found. */ PPH_EMENU_ITEM PhFindEMenuItemEx( _In_ PPH_EMENU_ITEM Item, _In_ ULONG Flags, _In_opt_ PWSTR Text, _In_opt_ ULONG Id, _Out_opt_ PPH_EMENU_ITEM *FoundParent, _Out_opt_ PULONG FoundIndex ) { PH_STRINGREF searchText; ULONG i; PPH_EMENU_ITEM item; if (!Item->Items) return NULL; if (Text && (Flags & PH_EMENU_FIND_LITERAL)) PhInitializeStringRef(&searchText, Text); for (i = 0; i < Item->Items->Count; i++) { item = Item->Items->Items[i]; if (Text) { if (Flags & PH_EMENU_FIND_LITERAL) { PH_STRINGREF text; PhInitializeStringRef(&text, item->Text); if (Flags & PH_EMENU_FIND_STARTSWITH) { if (PhStartsWithStringRef(&text, &searchText, TRUE)) goto FoundItemHere; } else { if (PhEqualStringRef(&text, &searchText, TRUE)) goto FoundItemHere; } } else { if (PhCompareUnicodeStringZIgnoreMenuPrefix(Text, item->Text, TRUE, !!(Flags & PH_EMENU_FIND_STARTSWITH)) == 0) goto FoundItemHere; } } if (Id && item->Id == Id) goto FoundItemHere; if (Flags & PH_EMENU_FIND_DESCEND) { PPH_EMENU_ITEM foundItem; PPH_EMENU_ITEM foundParent; ULONG foundIndex; foundItem = PhFindEMenuItemEx(item, Flags, Text, Id, &foundParent, &foundIndex); if (foundItem) { if (FoundParent) *FoundParent = foundParent; if (FoundIndex) *FoundIndex = foundIndex; return foundItem; } } } return NULL; FoundItemHere: if (FoundParent) *FoundParent = Item; if (FoundIndex) *FoundIndex = i; return item; }