Skip to content

Commit

Permalink
AppExec: Registry ACLs automatic conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Feb 7, 2021
1 parent d457e31 commit b818e40
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
43 changes: 35 additions & 8 deletions AppExec/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ INT_PTR WINAPI App::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
return FALSE;
}

WCHAR placeholderText[] = L"Registry ACLs only support starts With: \"Registry::CLASSES_ROOT\", "
L"\"Registry::CURRENT_USER\", \"Registry::MACHINE\", and \"Registry::USERS\".";

bool App::Initialize(HWND window) {
hWnd = window;
title.Initialize(hWnd);
Expand Down Expand Up @@ -79,11 +82,16 @@ bool App::Initialize(HWND window) {
appx.UpdateName(L"Privexec.AppContainer.Launcher");
::SetFocus(cmd.hInput);
trace.hWindow = GetDlgItem(hWnd, IDE_APPEXEC_INFO);

// SetWindowLongPtr(trace.hInfo, GWL_EXSTYLE, 0);

InitializeCapabilities();

hTip = CreateWindowEx(0, TOOLTIPS_CLASS, 0, WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, hWnd, NULL, hInst, nullptr);
TOOLINFO toolInfo = {0};
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)appx.hAcl;
toolInfo.lpszText = placeholderText;
::SendMessageW(hTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return true;
}

Expand Down Expand Up @@ -162,15 +170,34 @@ std::vector<std::wstring_view> NewlineTokenize(std::wstring_view sv) {
return output;
}

std::optional<std::wstring> MakeRegistryKey(std::wstring_view path) {
std::wstring_view makeSubRegistryKey(std::wstring_view path) {
constexpr std::wstring_view prefix = {L"Registry::"};
if (bela::StartsWithIgnoreCase(path, prefix)) {
if (path.size() > prefix.size() && bela::IsPathSeparator(path[prefix.size()])) {
return std::make_optional<std::wstring>(path.substr(prefix.size() + 1));
return path.substr(prefix.size() + 1);
}
return std::make_optional<std::wstring>(path.substr(prefix.size()));
return path.substr(prefix.size());
}
return L"";
}

std::optional<std::wstring> MakeRegistryKey(std::wstring_view path) {
auto s = makeSubRegistryKey(path);
if (s.empty()) {
return std::nullopt;
}
auto sv = bela::SplitPath(s);
if (sv.empty()) {
return std::nullopt;
}
constexpr std::wstring_view localPrefix = L"LOCAL_";
constexpr std::wstring_view localHKeyPrefix = L"HKEY_LOCAL_";
if (bela::StartsWithIgnoreCase(sv[0], localPrefix)) {
sv[0].remove_prefix(localPrefix.size());
} else if (bela::StartsWithIgnoreCase(sv[0], localPrefix)) {
sv[0].remove_prefix(localHKeyPrefix.size());
}
return std::nullopt;
return std::make_optional<std::wstring>(bela::StrJoin(sv, L"\\"));
}

bool App::AppLookupAcl(std::vector<std::wstring> &fsdir, std::vector<std::wstring> &registries) {
Expand Down
1 change: 1 addition & 0 deletions AppExec/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class App {
Appx appx;
AppTrace trace;
AppSettings as;
HWND hTip{nullptr};
HBRUSH hbrBkgnd{nullptr};
};
} // namespace priv
Expand Down
4 changes: 4 additions & 0 deletions AppExec/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ int nCmdShow) {
priv::dotcom_global_initializer di;
priv::App app;
// INITCOMMONCONTROLSEX iccex;
// iccex.dwICC = ICC_WIN95_CLASSES;
// iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
// InitCommonControlsEx(&iccex);
return app.run(hInstance);
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ endif()
#
set(PRIVEXEC_VERSION_MAJOR 4)
set(PRIVEXEC_VERSION_MINOR 4)
set(PRIVEXEC_VERSION_PATCH 0)
set(PRIVEXEC_VERSION_PATCH 1)
set(PACKAGE_VERSION "${PRIVEXEC_VERSION_MAJOR}.${PRIVEXEC_VERSION_MINOR}.${PRIVEXEC_VERSION_PATCH}")

string(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" COMPILER_ARCH_ID)
Expand Down

0 comments on commit b818e40

Please sign in to comment.