Skip to content

Commit

Permalink
Jump to hive implementation (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
glachancecmaisonneuve authored Jan 13, 2025
1 parent 3f7b1e2 commit 0859e90
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
65 changes: 65 additions & 0 deletions RegExp/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,40 @@ LRESULT CMainFrame::OnTreeContextMenu(int, LPNMHDR hdr, BOOL&) {
//
hMenu.InsertMenu(0, MF_BYPOSITION, ID_KEY_JUMPTOHIVEFILE, L"Jump &Hive File...");
}

hMenu.AppendMenu(MF_SEPARATOR);
auto path = GetCurrentKeyPath();
auto currentHive = path.Mid(0, path.Find(L"\\", 0));
if (currentHive == L"HKEY_CURRENT_USER") {
auto destination = L"HKEY_LOCAL_MACHINE" + path.Mid(currentHive.GetLength());
auto key = Registry::OpenKey(destination, KEY_QUERY_VALUE);
if (key)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_LOCALMACHINE, L"Goto HKEY_LOCAL_MACHINE");
if (path.MakeUpper().Find(L"HKEY_CURRENT_USER\\SOFTWARE\\CLASSES") == 0)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_CLASSESROOT, L"Goto HKEY_CLASSES_ROOT");
}
else if (currentHive == L"HKEY_LOCAL_MACHINE") {
auto destination = L"HKEY_CURRENT_USER" + path.Mid(currentHive.GetLength());
auto key = Registry::OpenKey(destination, KEY_QUERY_VALUE);
if (key)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_CURRENTUSER, L"Goto HKEY_CURRENT_USER");
if (path.MakeUpper().Find(L"HKEY_LOCAL_MACHINE\\SOFTWARE\\CLASSES") == 0)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_CLASSESROOT, L"Goto HKEY_CLASSES_ROOT");
}
else if (currentHive == L"HKEY_CLASSES_ROOT") {
auto destination = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\CLASSES" + path.Mid(currentHive.GetLength());
auto key = Registry::OpenKey(destination, KEY_QUERY_VALUE);
if (key)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_LOCALMACHINE, L"Goto HKEY_LOCAL_MACHINE");
destination = L"HKEY_CURRENT_USER\\SOFTWARE\\CLASSES" + path.Mid(currentHive.GetLength());
key = Registry::OpenKey(destination, KEY_QUERY_VALUE);
if (key)
hMenu.AppendMenu(MF_STRING, ID_GOTOHIVE_CURRENTUSER, L"Goto HKEY_CURRENT_USER");
}
auto lastMenuItem = hMenu.GetMenuItemID(hMenu.GetMenuItemCount()-1);
if (lastMenuItem == 0)
hMenu.DeleteMenu(hMenu.GetMenuItemCount()-1, MF_BYPOSITION);

ShowContextMenu(hMenu, 0, pt2.x, pt2.y);
}
return 0;
Expand Down Expand Up @@ -2723,3 +2757,34 @@ void CMainFrame::UpdateList(bool newLocation) {
m_List.RedrawItems(m_List.GetTopIndex(), m_List.GetTopIndex() + m_List.GetCountPerPage());
}

LRESULT CMainFrame::OnGotoHive(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
auto path = GetCurrentKeyPath();
CString currentHive = path.Mid(0, path.Find(L"\\", 0));
CString destinationHive = L"";

if (wID == ID_GOTOHIVE_CURRENTUSER) {
destinationHive = L"HKEY_CURRENT_USER";
}
else if (wID == ID_GOTOHIVE_LOCALMACHINE) {
destinationHive = L"HKEY_LOCAL_MACHINE";
}
else {
ATLASSERT(wID == ID_GOTOHIVE_CLASSESROOT);
destinationHive = L"HKEY_CLASSES_ROOT";
}

if (currentHive == L"HKEY_CLASSES_ROOT" && (destinationHive == L"HKEY_CURRENT_USER" || destinationHive == L"HKEY_LOCAL_MACHINE")) {
destinationHive += L"\\SOFTWARE\\CLASSES";
}

if (destinationHive == L"HKEY_CLASSES_ROOT" && (currentHive == L"HKEY_CURRENT_USER" || currentHive == L"HKEY_LOCAL_MACHINE")) {
currentHive += L"\\SOFTWARE\\CLASSES";
}

path = destinationHive + path.Mid(currentHive.GetLength());
if (currentHive != destinationHive) {
GotoKey(path, false);
}

return 0;
}
4 changes: 4 additions & 0 deletions RegExp/MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class CMainFrame :
COMMAND_ID_HANDLER(ID_KEY_ADDBOOKMARK, OnAddBookmark)
COMMAND_ID_HANDLER(ID_DELETE_BOOKMARK, OnDeleteBookmark)
COMMAND_ID_HANDLER(ID_LOCATIONS_MANAGE, OnManageLocations)
COMMAND_ID_HANDLER(ID_GOTOHIVE_CURRENTUSER, OnGotoHive)
COMMAND_ID_HANDLER(ID_GOTOHIVE_LOCALMACHINE, OnGotoHive)
COMMAND_ID_HANDLER(ID_GOTOHIVE_CLASSESROOT, OnGotoHive)
MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
Expand Down Expand Up @@ -295,6 +298,7 @@ class CMainFrame :
LRESULT OnDeleteBookmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnManageLocations(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnViewSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnGotoHive(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

void ConnectRemoteRegistry(CString hostname);
void InitCommandBar();
Expand Down
5 changes: 4 additions & 1 deletion RegExp/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@
#define ID_KEY_ADDBOOKMARK 32882
#define ID_DELETE_BOOKMARK 32883
#define ID_VIEW_SELECTALL 32887
#define ID_GOTOHIVE_CURRENTUSER 32888
#define ID_GOTOHIVE_LOCALMACHINE 32889
#define ID_GOTOHIVE_CLASSESROOT 32890

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 182
#define _APS_NEXT_COMMAND_VALUE 32890
#define _APS_NEXT_COMMAND_VALUE 32891
#define _APS_NEXT_CONTROL_VALUE 1060
#define _APS_NEXT_SYMED_VALUE 115
#endif
Expand Down

0 comments on commit 0859e90

Please sign in to comment.