summaryrefslogtreecommitdiff
path: root/src/envfs.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2021-02-22 18:28:07 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2021-02-22 18:28:07 -0500
commitd22d77d921e9915b3209e1a447d628c0f2d01baa (patch)
treecf3b7e0512534d59ba42f3284ae5d88f4ebaf484 /src/envfs.cpp
parent708402106743427fd1f4d40d83dd67da9add9a92 (diff)
handle network shares for NtOpenFile()
changed error messages to use formatNtMessage(), which handles NTSTATUS errors
Diffstat (limited to 'src/envfs.cpp')
-rw-r--r--src/envfs.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/envfs.cpp b/src/envfs.cpp
index 9317eb70..dfea6598 100644
--- a/src/envfs.cpp
+++ b/src/envfs.cpp
@@ -232,8 +232,8 @@ void forEachEntryImpl(
if (status < 0) {
log::error(
- "NtOpenFile() failed for '{}', {}",
- toString(poa), formatSystemMessage(status));
+ "failed to open directory '{}': {}",
+ toString(poa), formatNtMessage(status));
return;
}
@@ -264,8 +264,9 @@ void forEachEntryImpl(
break;
} else if (status < 0) {
log::error(
- "NtQueryDirectoryFile() failed for '{}', {}",
- toString(poa), formatSystemMessage(status));
+ "failed to read directory '{}': {}",
+ toString(poa), formatNtMessage(status));
+
break;
}
@@ -321,6 +322,23 @@ void forEachEntryImpl(
}
}
+std::wstring makeNtPath(const std::wstring& path)
+{
+ constexpr const wchar_t* nt_prefix = L"\\??\\";
+ constexpr const wchar_t* nt_unc_prefix = L"\\??\\UNC\\";
+ constexpr const wchar_t* share_prefix = L"\\\\";
+
+ if (path.starts_with(nt_prefix)) {
+ // already an nt path
+ return path;
+ } else if (path.starts_with(share_prefix)) {
+ // network shared need \??\UNC\ as a prefix
+ return nt_unc_prefix + path.substr(2);
+ } else {
+ // prepend the \??\ prefix
+ return nt_prefix + path;
+ }
+}
void DirectoryWalker::forEachEntry(
const std::wstring& path, void* cx,
@@ -335,7 +353,7 @@ void DirectoryWalker::forEachEntry(
NtClose = (NtClose_type)::GetProcAddress(m.get(), "NtClose");
}
- const std::wstring ntpath = std::wstring(L"\\??\\") + path;
+ const std::wstring ntpath = makeNtPath(path);
UNICODE_STRING ObjectName = {};
ObjectName.Buffer = const_cast<wchar_t*>(ntpath.c_str());