64位进程如何具有32位文件系统和注册表视图?

时间:2010-09-16 05:51:53

标签: winapi 64-bit syswow64

为了向后兼容,我的64进程需要查看文件系统和注册表的32位视图。

我知道如何使32位进程看到文件系统和注册表的64位视图(使用Wow64DisableWow64FsRedirection和Wow64RevertWow64FsRedirection)

但是如何使64位进程具有文件系统和注册表的32位视图?

4 个答案:

答案 0 :(得分:4)

您需要明确查看“WOW64”键/目录。实际上没有“64位”注册表,只有“注册表”和Wow64重定向内容只是将32位进程重定向到不同的子项。因此,当一个32位进程要求“HKLM \ Software \ foo”时,注册表API实际上会说,“等等,你是32位所以我打算假装你要求'HKLM \ Software \ Wow6432Node \ foo'而不是“。

因此,考虑到这一点,在“32位”注册表中无法使用64位进程,因为没有“32位注册表”这样的东西。相反,您只需要执行Wow64重定向逻辑自动执行的操作。

修改

对于注册表,实际上您可以在various method calls中指定KEY_WOW64_32KEY密钥。

对于文件系统,您可以尝试Wow64EnableWow64FsRedirection,但我不确定它是否可行...

答案 1 :(得分:0)

如果要查看32位注册表,可以按照here所述使用KEY_WOW64_32KEY

如果要访问SysWOW64目录,可以按照here所述使用GetSystemWow64Directory

答案 2 :(得分:0)

KEY_WOW64_32KEY适用于64位和32位进程。

从实验来看,Wow64EnableWow64FsRedirection / Wow64DisableWow64FsRedirection似乎不能在64位进程中工作 - 而且名称表明它似乎只能在WOW64进程中工作。

因此,为了从64位进程获得文件系统的32位“视图”,需要更改路径以指向正确的位置

这真的很难看,但这是一个如何根据Microsoft执行文件系统重定向的c ++代码示例。需要提升。

#include"boost/filesystem.hpp"
#include"wstring"
#include"shfolder.h"
#include"Shlobj.h"
bool redirectPathRoot( boost::filesystem::wpath pathFromRoot, boost::filesystem::wpath pathToRoot, boost::filesystem::wpath & pathToRedirect )
{
bool bPathWasRedirected = false;
boost::filesystem::wpath theNewPath;
boost::filesystem::wpath::iterator iPathToRedirect = pathToRedirect.begin();
boost::filesystem::wpath::iterator iFromRoot = pathFromRoot.begin();
bool bMatch = true;
while( iPathToRedirect != pathToRedirect.end() && iFromRoot != pathFromRoot.end() && bMatch )
{
    //
    // see if the root of the path we are checking matches 
    //
    bMatch = ( std::wstring(*iPathToRedirect++) == std::wstring(*iFromRoot++) );
}
if( bMatch && iFromRoot == pathFromRoot.end() )
{
    theNewPath = pathToRoot;
    //
    // these guys need to be redirected
    //
    while( iPathToRedirect != pathToRedirect.end() )
    {
        theNewPath /= *iPathToRedirect++;
    }
    bPathWasRedirected = true;
    pathToRedirect = theNewPath;
}
return bPathWasRedirected;
}
std::wstring adjustPathFor32BitOn64BitProcess( LPCWSTR thePath )
{
std::wstring strPath(thePath);
boost::to_lower(strPath);
//
// default to the original path
//
boost::filesystem::wpath theNewPath(strPath.c_str());
theNewPath.normalize();
//
// init the supplied path
//
boost::filesystem::wpath pathToCheck( strPath.c_str() );
pathToCheck.normalize();
//
// get the path for the 32 bit folder on a 64 bit system
//
wchar_t strTemp[MAX_PATH] = L"\0";
GetSystemWow64Directory( strTemp, MAX_PATH );
std::wstring strSysWow64 = strTemp;
boost::to_lower( strSysWow64 );
boost::filesystem::wpath pathSysWow64( strSysWow64.c_str() );
pathSysWow64.normalize();

//
// get the path for the system directory
//
GetSystemDirectory( strTemp, MAX_PATH );
std::wstring strSys = strTemp;
boost::to_lower( strSys );
boost::filesystem::wpath pathSys( strSys.c_str() );
pathSys.normalize();

//
// get the path for the Program Files directory
//
SHGetFolderPath( NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_DEFAULT, strTemp);
std::wstring strPrograms = strTemp;
boost::to_lower( strPrograms );
boost::filesystem::wpath pathPrograms( strPrograms.c_str() );
pathPrograms.normalize();

//
// get the path for the Program Files x86 directory
//
SHGetFolderPath( NULL, CSIDL_PROGRAM_FILESX86, NULL, SHGFP_TYPE_DEFAULT, strTemp);
std::wstring strProgramsX86 = strTemp;
boost::to_lower( strProgramsX86 );
boost::filesystem::wpath pathProgramsX86( strProgramsX86.c_str() );
pathProgramsX86.normalize();

//
// get the path for the Windows\lastgood\system32 directory
//
SHGetFolderPath( NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_DEFAULT, strTemp);
std::wstring strWindows = strTemp;
boost::to_lower( strWindows );
boost::filesystem::wpath pathWindows( strWindows.c_str() );
pathWindows.normalize();

boost::filesystem::wpath pathWindowsLastGoodSystem32( strWindows.c_str() );
pathWindowsLastGoodSystem32 /= L"lastgood";
pathWindowsLastGoodSystem32 /= L"system32";
pathWindowsLastGoodSystem32.normalize();

boost::filesystem::wpath pathWindowsLastGoodSysWOW64( strWindows.c_str() );
pathWindowsLastGoodSysWOW64 /= L"lastgood";
pathWindowsLastGoodSysWOW64 /= L"syswow64";
pathWindowsLastGoodSysWOW64.normalize();


//
// finally, regedit...
//
boost::filesystem::wpath pathRegedit( strWindows.c_str() );
pathRegedit /= L"regedit.exe";
pathRegedit.normalize();

boost::filesystem::wpath pathRegeditSysWOW64( pathSysWow64 );
pathRegeditSysWOW64 /= L"regedit.exe";
pathRegeditSysWOW64.normalize();

//
// now see if the supplied path matches system directoy
//
boost::filesystem::wpath::iterator iPathToCheck = pathToCheck.begin();
boost::filesystem::wpath::iterator iSys = pathSys.begin();
bool bMatch = true;
while( iPathToCheck != pathToCheck.end() && iSys != pathSys.end() && bMatch )
{
    //
    // see if the beginning of the path we are checking matches the system path
    //
    bMatch = ( std::wstring(*iPathToCheck++) == std::wstring(*iSys++) );
}
if( bMatch && iSys == pathSys.end() )
{
    //
    // the supplied path matches at least as far as the system dir...
    //
    if( iPathToCheck == pathToCheck.end() )
    {
        //
        // ...actually its an exact match, so redirect it
        //
        theNewPath = pathSysWow64;
    }
    else
    {
        //
        // ...however, there are a few exceptions....
        //
        boost::filesystem::wpath::iterator iTemp = iPathToCheck;
        if( 
                !(
                    std::wstring(*iTemp) == L"drivers" && 
                    ( 
                        (++iTemp) != pathToCheck.end()  && 
                        std::wstring(*(iTemp)) == L"etc" 
                        )
                    ) 
                &&
                (std::wstring(*iPathToCheck) != L"catroot") &&
                (std::wstring(*iPathToCheck) != L"catroot2") &&
                (std::wstring(*iPathToCheck) != L"logfiles") &&
                (std::wstring(*iPathToCheck) != L"spool")
                )
        {
            //
            // all but the above dirs should be redirected
            //
            theNewPath = pathSysWow64;
            while( iPathToCheck != pathToCheck.end() )
            {
                theNewPath /= *iPathToCheck++;
            }
        }
    }
}
else
{
    //
    // didn't match the system dir... see if it matches the Program Files dir
    //
    if(!redirectPathRoot(  pathPrograms, pathProgramsX86, theNewPath ))
    {
        //
        // now try %windir%/lastgood/system32
        //
        if(!redirectPathRoot(  pathWindowsLastGoodSystem32, pathWindowsLastGoodSysWOW64, theNewPath ))
        {
            //
            // finally, regedit
            //
            redirectPathRoot(  pathRegedit, pathRegeditSysWOW64, theNewPath );
        }
    }

}
return theNewPath.file_string();}

答案 3 :(得分:0)

派对迟到了,但是你能不能创建一个32位的小型32位进程吗?然后,WOW64的所有内置优点都将起作用。

不确定您的开发语言/运行时是什么样的,因此无法就进程间通信的内容提供进一步的建议。