Skip to content

Commit

Permalink
Fixed the portable version loading configuration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Apr 3, 2023
1 parent fff1db1 commit 8e9da8e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files.associations": {
"*.manifest": "xml",
"*.env": "jsonc",
"*.manifest": "xml",
"*.ipp": "cpp",
"vector": "cpp",
"xstring": "cpp",
Expand Down Expand Up @@ -84,6 +84,9 @@
"span": "cpp",
"stop_token": "cpp",
"format": "cpp",
"source_location": "cpp"
"source_location": "cpp",
"any": "cpp",
"codecvt": "cpp",
"ranges": "cpp"
}
}
4 changes: 2 additions & 2 deletions AppExec/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace priv {
bool AppInitializeSettings(AppSettings &as) {
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\AppExec.json");
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\AppExec.json)");
FD fd;
if (_wfopen_s(&fd.fd, file.data(), L"rb") != 0) {
return false;
Expand All @@ -29,7 +29,7 @@ bool AppInitializeSettings(AppSettings &as) {
}

bool AppApplySettings(const AppSettings &as) {
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\AppExec.json");
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\AppExec.json)");
std::filesystem::path p(file);
auto parent = p.parent_path();
std::error_code e;
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ endif()

#
set(PRIVEXEC_VERSION_MAJOR 5)
set(PRIVEXEC_VERSION_MINOR 0)
set(PRIVEXEC_VERSION_PATCH 4)
set(PRIVEXEC_VERSION_MINOR 1)
set(PRIVEXEC_VERSION_PATCH 0)
set(PACKAGE_VERSION "${PRIVEXEC_VERSION_MAJOR}.${PRIVEXEC_VERSION_MINOR}.${PRIVEXEC_VERSION_PATCH}")

string(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" COMPILER_ARCH_ID)
Expand Down
15 changes: 11 additions & 4 deletions Privexec/alias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ struct alias_item_t {
};
bool AppAliasInitializeBuilt(std::wstring_view file) {
constexpr alias_item_t items[] = {
{"windbg", "Windows Debugger", "\"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\windbg.exe\""}, //
{"edit-hosts", "Edit Hosts", "Notepad %windir%\\System32\\Drivers\\etc\\hosts"}, //
{"edit-hosts", "Edit Hosts", "Notepad %windir%\\System32\\Drivers\\etc\\hosts"}, //
};
try {
nlohmann::json j;
Expand All @@ -33,6 +32,14 @@ bool AppAliasInitializeBuilt(std::wstring_view file) {
}
j["alias"] = alias;
bela::error_code ec;
std::filesystem::path p(file);
auto parent = p.parent_path();
if (std::error_code e; !std::filesystem::exists(parent, e)) {
if (!std::filesystem::create_directories(parent, e)) {
ec = bela::make_error_code_from_std(e);
return false;
}
}
if (!bela::io::AtomicWriteText(file, bela::io::as_bytes<char>(j.dump(4)), ec)) {
return false;
}
Expand All @@ -45,11 +52,11 @@ bool AppAliasInitializeBuilt(std::wstring_view file) {

std::wstring AppAliasFile() {
//
return PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
return PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
}

bool AppAliasInitialize(HWND hbox, priv::alias_t &alias) {
auto file = PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
auto file = PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
if (!bela::PathExists(file)) {
if (!AppAliasInitializeBuilt(file)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion Privexec/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool App::Initialize(HWND window) {
box.Append((int)wsudo::exec::privilege_t::elevated, L"Administrator", true);
}
HMENU hSystemMenu = ::GetSystemMenu(hWnd, FALSE);
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_EDIT_ALIASFILE, L"Open Privexec.json");
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_EDIT_ALIASFILE, L"Edit Privexec.json");
InsertMenuW(hSystemMenu, SC_CLOSE, MF_ENABLED, IDM_PRIVEXEC_ABOUT, L"About Privexec\tAlt+F1");
cmd.hInput = GetDlgItem(hWnd, IDC_COMMAND_COMBOX);
cmd.hButton = GetDlgItem(hWnd, IDB_COMMAND_TARGET);
Expand Down
10 changes: 8 additions & 2 deletions include/vfsenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ class PathSearcher {
PathSearcher() {
bela::error_code ec;
if (!vfsInitialize(ec)) {
etc = std::filesystem::path{L"."};
if (auto e = bela::ExecutableFinalPathParent(ec); e) {
basePath = std::filesystem::path{*e};
appdata = basePath / L"appdata";
etc = basePath / L"etc";
return;
}
basePath = std::filesystem::path{L"."};
appdata = std::filesystem::path{L"."};
appdata = basePath / L"appdata";
etc = basePath / L"etc";
}
}

Expand Down
4 changes: 2 additions & 2 deletions wsudo/alias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ wsudo::AliasEngine::~AliasEngine() {
}

bool wsudo::AliasEngine::Initialize(bool verbose) {
auto file = priv::PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
auto file = priv::PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
DbgPrint(L"use %s", file);
priv::FD fd;
if (auto en = _wfopen_s(&fd.fd, file.data(), L"rb"); en != 0) {
Expand Down Expand Up @@ -49,7 +49,7 @@ std::optional<std::wstring> wsudo::AliasEngine::Target(std::wstring_view al) {
}

bool wsudo::AliasEngine::Apply() {
auto file = priv::PathSearcher::Instance().JoinAppData(L"Privexec\\Privexec.json");
auto file = priv::PathSearcher::Instance().JoinAppData(LR"(Privexec\Privexec.json)");
DbgPrint(L"use %s", file);
std::filesystem::path p(file);
auto parent = p.parent_path();
Expand Down

0 comments on commit 8e9da8e

Please sign in to comment.