Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ur src-0.2.2.235/vfs.cc src/vfs.cc
- --- src-0.2.2.235/vfs.cc 2005-03-13 05:08:43.000000000 +0900
- +++ src/vfs.cc 2012-02-28 22:57:25.498409200 +0900
- @@ -2,6 +2,210 @@
- #include "dyn-handle.h"
- #include "vwin32.h"
- +class WINWOW64
- +{
- +public:
- + enum file_path_mode {wow64, native};
- +
- +protected:
- + typedef BOOL (WINAPI *ISWOW64PROCESS)(HANDLE, PBOOL);
- + typedef BOOL (WINAPI *WOW64DISABLEWOW64FSREDIRECTION)(PVOID *);
- + typedef BOOL (WINAPI *WOW64REVERTWOW64FSREDIRECTION)(PVOID *);
- +
- + static const ISWOW64PROCESS fnIsWow64Process;
- + static const WOW64DISABLEWOW64FSREDIRECTION fnWow64DisableWow64FsRedirection;
- + static const WOW64REVERTWOW64FSREDIRECTION fnWow64RevertWow64FsRedirection;
- + static BOOL b_wow64;
- + static file_path_mode filePathMode;
- +
- +public:
- + static BOOL WINAPI IsWow64Process (HANDLE hProcess, PBOOL Wow64Process);
- + static BOOL WINAPI Wow64DisableWow64FsRedirection (PVOID *OldValue);
- + static BOOL WINAPI Wow64RevertWow64FsRedirection (PVOID *OldValue);
- + static BOOL IsWow64 ();
- + static BOOL IsSpecialRedirectionPath (const char *path, WIN32_FIND_DATA &fd);
- + static void SetFilePathMode (file_path_mode m);
- + static file_path_mode GetFilePathMode ();
- +};
- +
- +const WINWOW64::ISWOW64PROCESS WINWOW64::fnIsWow64Process =
- + (WINWOW64::ISWOW64PROCESS)GetProcAddress (GetModuleHandle ("KERNEL32"),
- + "IsWow64Process");
- +
- +const WINWOW64::WOW64DISABLEWOW64FSREDIRECTION WINWOW64::fnWow64DisableWow64FsRedirection =
- + (WINWOW64::WOW64DISABLEWOW64FSREDIRECTION)GetProcAddress (GetModuleHandle ("KERNEL32"),
- + "Wow64DisableWow64FsRedirection");
- +
- +const WINWOW64::WOW64REVERTWOW64FSREDIRECTION WINWOW64::fnWow64RevertWow64FsRedirection =
- + (WINWOW64::WOW64REVERTWOW64FSREDIRECTION)GetProcAddress (GetModuleHandle ("KERNEL32"),
- + "Wow64RevertWow64FsRedirection");
- +
- +BOOL WINWOW64::b_wow64 = -1;
- +WINWOW64::file_path_mode WINWOW64::filePathMode = WINWOW64::wow64;
- +
- +BOOL WINAPI
- +WINWOW64::IsWow64Process (HANDLE hProcess, PBOOL Wow64Process)
- +{
- + BOOL r = FALSE;
- + if (Wow64Process)
- + {
- + *Wow64Process = FALSE;
- + }
- + if (fnIsWow64Process)
- + {
- + r = fnIsWow64Process (hProcess, Wow64Process);
- + }
- + return r;
- +}
- +
- +BOOL WINAPI
- +WINWOW64::Wow64DisableWow64FsRedirection (PVOID *OldValue)
- +{
- + BOOL r = FALSE;
- + if (OldValue)
- + {
- + *OldValue = NULL;
- + }
- + if (fnWow64DisableWow64FsRedirection)
- + {
- + r = fnWow64DisableWow64FsRedirection (OldValue);
- + }
- + return r;
- +}
- +
- +BOOL WINAPI
- +WINWOW64::Wow64RevertWow64FsRedirection (PVOID *OldValue)
- +{
- + BOOL r = FALSE;
- + if (OldValue)
- + {
- + *OldValue = NULL;
- + }
- + if (fnWow64RevertWow64FsRedirection)
- + {
- + r = fnWow64RevertWow64FsRedirection (OldValue);
- + }
- + return r;
- +}
- +
- +BOOL
- +WINWOW64::IsWow64 ()
- +{
- + if (b_wow64 < 0)
- + {
- + IsWow64Process (GetCurrentProcess (), &b_wow64);
- + }
- + return b_wow64;
- +}
- +
- +void
- +WINWOW64::SetFilePathMode (file_path_mode m)
- +{
- + filePathMode = m;
- +}
- +
- +WINWOW64::file_path_mode
- +WINWOW64::GetFilePathMode ()
- +{
- + return filePathMode;
- +}
- +
- +BOOL
- +WINWOW64::IsSpecialRedirectionPath (const char *path, WIN32_FIND_DATA &fd)
- +{
- + BOOL r = FALSE;
- + if (WINWOW64::IsWow64 ())
- + {
- + struct WoW64SpecialRedirectionPath
- + {
- + const char* name;
- + const char* expStr;
- + char path[MAX_PATH+1];
- + WIN32_FIND_DATA fd;
- + };
- + // See : http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx
- + static WoW64SpecialRedirectionPath srp[] =
- + {
- + { "Sysnative", "%windir%\\Sysnative" },
- + { "catroot", "%windir%\\System32\\catroot" },
- + { "catroot2", "%windir%\\System32\\catroot2" },
- + { "driverstore", "%windir%\\System32\\driverstore" },
- + { "etc", "%windir%\\System32\\drivers\\etc" },
- + { "logfiles", "%windir%\\System32\\logfiles" },
- + { "spool", "%windir%\\System32\\spool" },
- + };
- +
- + if(srp[0].path[0] == 0)
- + {
- + PVOID OldValue;
- + WINWOW64::Wow64DisableWow64FsRedirection (&OldValue);
- + WIN32_FIND_DATA tfd = { 0 };
- + {
- + char path[MAX_PATH+1];
- + ExpandEnvironmentStrings ("%windir%\\System32", path, _countof (path));
- + HANDLE h = FindFirstFile (path, &tfd);
- + FindClose (h);
- + }
- +
- + for(int i = 0; i < _countof (srp); i++)
- + {
- + WoW64SpecialRedirectionPath &s = srp[i];
- + ExpandEnvironmentStrings (s.expStr, s.path, _countof (s.path));
- + s.fd = tfd;
- + strcpy (s.fd.cFileName, s.name);
- + }
- + WINWOW64::Wow64RevertWow64FsRedirection (&OldValue);
- + }
- +
- + char t[MAX_PATH+1];
- + strcpy (t, path);
- + for(char* p = t; *p != 0; p++)
- + {
- + if(*p == '/')
- + {
- + *p = '\\';
- + }
- + }
- +
- + for(int i = 0; i < _countof(srp); i++)
- + {
- + const WoW64SpecialRedirectionPath &s = srp[i];
- + if(_stricmp (t, s.path) == 0)
- + {
- + fd = s.fd;
- + r = TRUE;
- + break;
- + }
- + }
- + }
- + return r;
- +}
- +
- +class DisableWow64FsRedirection
- +{
- + PVOID OldValue;
- +public:
- + DisableWow64FsRedirection ();
- + ~DisableWow64FsRedirection ();
- +};
- +
- +DisableWow64FsRedirection::DisableWow64FsRedirection ()
- + : OldValue (NULL)
- +{
- + if (WINWOW64::IsWow64 () && WINWOW64::GetFilePathMode () == WINWOW64::native)
- + {
- + WINWOW64::Wow64DisableWow64FsRedirection (&OldValue);
- + }
- +}
- +
- +DisableWow64FsRedirection::~DisableWow64FsRedirection ()
- +{
- + if (WINWOW64::IsWow64 () && WINWOW64::GetFilePathMode () == WINWOW64::native)
- + {
- + WINWOW64::Wow64RevertWow64FsRedirection (&OldValue);
- + }
- +}
- +
- class NetPassDlg
- {
- HWND hwnd;
- @@ -227,6 +431,7 @@
- BOOL WINAPI
- WINFS::CreateDirectory (LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (BOOL, FALSE, lpPathName, CreateDirectory (lpPathName, lpSecurityAttributes));
- }
- @@ -235,6 +440,7 @@
- LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
- DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- HANDLE r = ::CreateFile (lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
- dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
- if (r != INVALID_HANDLE_VALUE)
- @@ -259,12 +465,14 @@
- BOOL WINAPI
- WINFS::DeleteFile (LPCSTR lpFileName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (BOOL, FALSE, lpFileName, DeleteFile (lpFileName));
- }
- HANDLE WINAPI
- WINFS::FindFirstFile (LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (HANDLE, INVALID_HANDLE_VALUE, lpFileName,
- FindFirstFile (lpFileName, lpFindFileData));
- }
- @@ -272,6 +480,7 @@
- BOOL WINAPI
- WINFS::FindNextFile (HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- *lpFindFileData->cFileName = 0;
- return (::FindNextFile (hFindFile, lpFindFileData)
- || (GetLastError () == ERROR_MORE_DATA
- @@ -283,6 +492,7 @@
- LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
- LPDWORD lpTotalNumberOfClusters)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- char buf[PATH_MAX + 1];
- if (!lpRootPathName)
- {
- @@ -323,6 +533,7 @@
- LPDWORD lpBytesPerSector, LPDWORD lpNumberOfFreeClusters,
- LPDWORD lpTotalNumberOfClusters)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- BOOL r = ::GetDiskFreeSpace (lpRootPathName, lpSectorsPerCluster, lpBytesPerSector,
- lpNumberOfFreeClusters, lpTotalNumberOfClusters);
- if (!r)
- @@ -374,12 +585,14 @@
- DWORD WINAPI
- WINFS::internal_GetFileAttributes (LPCSTR lpFileName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (DWORD, -1, lpFileName, GetFileAttributes (lpFileName));
- }
- DWORD WINAPI
- WINFS::GetFileAttributes (LPCSTR lpFileName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- DWORD attr = internal_GetFileAttributes (lpFileName);
- if (attr == DWORD (-1) && GetLastError () != ERROR_INVALID_NAME)
- {
- @@ -393,6 +606,7 @@
- UINT WINAPI
- WINFS::GetTempFileName (LPCSTR lpPathName, LPCSTR lpPrefixString, UINT uUnique, LPSTR lpTempFileName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (UINT, 0, lpPathName,
- GetTempFileName (lpPathName, lpPrefixString, uUnique, lpTempFileName));
- }
- @@ -403,6 +617,7 @@
- LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags,
- LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (BOOL, FALSE, lpRootPathName,
- GetVolumeInformation (lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize,
- lpVolumeSerialNumber, lpMaximumComponentLength,
- @@ -418,6 +633,7 @@
- static BOOL
- move_file (LPCSTR lpExistingFileName, LPCSTR lpNewFileName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL2 (BOOL, FALSE, lpExistingFileName, lpNewFileName,
- MoveFile (lpExistingFileName, lpNewFileName));
- }
- @@ -438,12 +654,14 @@
- BOOL WINAPI
- WINFS::RemoveDirectory (LPCSTR lpPathName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (BOOL, FALSE, lpPathName, RemoveDirectory (lpPathName));
- }
- BOOL WINAPI
- WINFS::SetFileAttributes (LPCSTR lpFileName, DWORD dwFileAttributes)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_CALL1 (BOOL, FALSE, lpFileName,
- SetFileAttributes (lpFileName, dwFileAttributes));
- }
- @@ -452,6 +670,7 @@
- WINFS::internal_GetFullPathName (LPCSTR lpFileName, DWORD nBufferLength,
- LPSTR lpBuffer, LPSTR *lpFilePart)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_MAPSL (lpFileName);
- WINFS_CALL1 (DWORD, 0, lpFileName,
- GetFullPathName (lpFileName, nBufferLength, lpBuffer, lpFilePart));
- @@ -460,6 +679,7 @@
- BOOL WINAPI
- WINFS::SetCurrentDirectory (LPCSTR lpPathName)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- WINFS_MAPSL (lpPathName);
- WINFS_CALL1 (BOOL, FALSE, lpPathName, SetCurrentDirectory (lpPathName));
- }
- @@ -467,6 +687,7 @@
- DWORD WINAPI
- WINFS::GetFullPathName (LPCSTR path, DWORD size, LPSTR buf, LPSTR *name)
- {
- + DisableWow64FsRedirection disableWow64FsRedirection;
- DWORD l = internal_GetFullPathName (path, size, buf, name);
- if (!l || l >= size)
- return l;
- @@ -499,9 +720,19 @@
- int WINAPI
- WINFS::get_file_data (const char *path, WIN32_FIND_DATA &fd)
- {
- - HANDLE h = FindFirstFile (path, &fd);
- - if (h == INVALID_HANDLE_VALUE)
- - return 0;
- - FindClose (h);
- - return 1;
- + int r = 0;
- + if (WINWOW64::IsSpecialRedirectionPath (path, fd))
- + {
- + r = 1;
- + }
- + else
- + {
- + HANDLE h = FindFirstFile (path, &fd);
- + if (h != INVALID_HANDLE_VALUE)
- + {
- + r = 1;
- + FindClose(h);
- + }
- + }
- + return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement