Sto lavorando alla segnalazione di alcune informazioni ricavate dalle API di sistema native. (So che questo è male .... ma sto ricevendo informazioni che non posso ottenere altrimenti, e ho poco problemi con dover aggiornare la mia app se/quando arriva il momento.)Come posso convertire un nome di percorso nativo (NT) in un nome di percorso Win32?
Il nativo L'API restituisce i nomi di percorso nativi, come visto da ob
, ovvero \SystemRoot\System32\Ntoskrnl.exe
o \??\C:\Program Files\VMWare Workstation\vstor-ws60.sys
.
posso sostituire i prefissi comuni, vale a dire
std::wstring NtPathToWin32Path(std::wstring ntPath)
{
if (boost::starts_with(ntPath, L"\\\\?\\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 4);
return ntPath;
}
if (boost::starts_with(ntPath, L"\\??\\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 4);
}
if (boost::starts_with(ntPath, L"\\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 1);
}
if (boost::istarts_with(ntPath, L"globalroot\\"))
{
ntPath.erase(ntPath.begin(), ntPath.begin() + 11);
}
if (boost::istarts_with(ntPath, L"systemroot"))
{
ntPath.replace(ntPath.begin(), ntPath.begin() + 10, GetWindowsPath());
}
if (boost::istarts_with(ntPath, L"windows"))
{
ntPath.replace(ntPath.begin(), ntPath.begin() + 7, GetWindowsPath());
}
return ntPath;
}
TEST(Win32Path, NtPathDoubleQuestions)
{
ASSERT_EQ(L"C:\\Example", NtPathToWin32Path(L"\\??\\C:\\Example"));
}
TEST(Win32Path, NtPathUncBegin)
{
ASSERT_EQ(L"C:\\Example", NtPathToWin32Path(L"\\\\?\\C:\\Example"));
}
TEST(Win32Path, NtPathWindowsStart)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\\World"), NtPathToWin32Path(L"\\Windows\\Hello\\World"));
}
TEST(Win32Path, NtPathSystemrootStart)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\\World"), NtPathToWin32Path(L"\\SystemRoot\\Hello\\World"));
}
TEST(Win32Path, NtPathGlobalRootSystemRoot)
{
ASSERT_EQ(GetCombinedPath(GetWindowsPath(), L"Hello\\World"), NtPathToWin32Path(L"\\globalroot\\SystemRoot\\Hello\\World"));
}
ma sarei fortemente sorpreso se non c'è qualche API, nativo o meno, che permette di convertire questi in nomi di percorso Win32. Esiste una tale API?
Condivide la funzione API di shell 'PathCanonicalize' fare il trucco? http://msdn.microsoft.com/en-us/library/bb773569%28v=vs.85%29.aspx – Praetorian
@Praetorian: No, PathCanonicalize accetta i percorsi Win32. Sto cercando di ottenere un percorso Win32. –
Non conosco nessuna di queste funzioni, e non è sempre possibile: NT può usare percorsi che Win32 non può affatto. Buona fortuna comunque ... – ephemient