WinScopedDisableWow64Redirection::~WinScopedDisableWow64Redirection() { if(!wutil_IsWow64()) return; const BOOL ok = pWow64RevertWow64FsRedirection(m_wasRedirectionEnabled); WARN_IF_FALSE(ok); }
BOOL TWow64RevertWow64FsRedirection(void *oldval) { static BOOL once = FALSE; static BOOL (WINAPI *pWow64RevertWow64FsRedirection)(void *); if (!once) { pWow64RevertWow64FsRedirection = (BOOL (WINAPI *)(void *)) GetProcAddress(::GetModuleHandle("kernel32"), "Wow64RevertWow64FsRedirection"); once = TRUE; } return pWow64RevertWow64FsRedirection ? pWow64RevertWow64FsRedirection(oldval) : FALSE; }
static void test_autocreation(void) { HKEY key, eventkey; DWORD type, size; LONG ret; int i; char *p; char sources[sizeof(eventsources)]; char sysdir[MAX_PATH]; void *redir = 0; RegOpenKeyA(HKEY_LOCAL_MACHINE, eventlogsvc, &key); RegOpenKeyA(key, eventlogname, &eventkey); size = sizeof(sources); sources[0] = 0; ret = RegQueryValueExA(eventkey, "Sources", NULL, &type, (LPBYTE)sources, &size); if (ret == ERROR_SUCCESS) { char sources_verify[sizeof(eventsources)]; ok(type == REG_MULTI_SZ, "Expected a REG_MULTI_SZ, got %d\n", type); /* Build the expected string */ memset(sources_verify, 0, sizeof(sources_verify)); p = sources_verify; for (i = sizeof(eventsources)/sizeof(eventsources[0]); i > 0; i--) { lstrcpyA(p, eventsources[i - 1]); p += (lstrlenA(eventsources[i - 1]) + 1); } lstrcpyA(p, eventlogname); ok(!memcmp(sources, sources_verify, size), "Expected a correct 'Sources' value (size : %d)\n", size); } RegCloseKey(eventkey); RegCloseKey(key); /* The directory that holds the eventlog files could be redirected */ if (pWow64DisableWow64FsRedirection) pWow64DisableWow64FsRedirection(&redir); /* On Windows we also automatically get an eventlog file */ GetSystemDirectoryA(sysdir, sizeof(sysdir)); /* NT4 - W2K3 */ lstrcpyA(eventlogfile, sysdir); lstrcatA(eventlogfile, "\\config\\"); lstrcatA(eventlogfile, eventlogname); lstrcatA(eventlogfile, ".evt"); if (GetFileAttributesA(eventlogfile) == INVALID_FILE_ATTRIBUTES) { /* Vista+ */ lstrcpyA(eventlogfile, sysdir); lstrcatA(eventlogfile, "\\winevt\\Logs\\"); lstrcatA(eventlogfile, eventlogname); lstrcatA(eventlogfile, ".evtx"); } todo_wine ok(GetFileAttributesA(eventlogfile) != INVALID_FILE_ATTRIBUTES, "Expected an eventlog file\n"); if (pWow64RevertWow64FsRedirection) pWow64RevertWow64FsRedirection(redir); }
bool File::CWow64RedirDisable::Revert() { if( pWow64RevertWow64FsRedirection == NULL ) return false; return pWow64RevertWow64FsRedirection(m_OldValue) != FALSE; }
void CPutFile::CheckFile(wstring name, wstring path, bool replace) { HMODULE hKernel32 = ::LoadLibrary(_T("Kernel32.dll")); PVOID OldValue; BOOL bRet = FALSE; if(CGetOSInfo::getInstance()->isX64()) { Wow64DisableWow64FsRedirectionFun pWow64DisableWow64FsRedirection = NULL; if (hKernel32) { pWow64DisableWow64FsRedirection = (Wow64DisableWow64FsRedirectionFun)::GetProcAddress(hKernel32, "Wow64DisableWow64FsRedirection"); } if(pWow64DisableWow64FsRedirection != NULL) bRet = pWow64DisableWow64FsRedirection(&OldValue); } wstring fullPath; fullPath = path + L"\\" + name; WCHAR expName[MAX_PATH] ={0}; ExpandEnvironmentStringsW(fullPath.c_str(), expName, MAX_PATH); if(::PathFileExistsW(expName) == FALSE)// 判断文件是否存在 { CRecordProgram::GetInstance ()->RecordCommonInfo(L"PutFile", 1001, CRecordProgram::GetInstance ()->GetRecordInfo(L"%s文件不存在", expName)); wstring file = CResourceManager::_()->GetFilePath(m_pWebsiteData->GetWebsiteType(), m_pWebsiteData->GetID(), name.c_str()); ::CopyFileW(file.c_str(), expName , TRUE); DWORD re = ::GetLastError(); CRecordProgram::GetInstance ()->RecordCommonInfo(L"PutFile", 1001, CRecordProgram::GetInstance ()->GetRecordInfo(L"替换%s文件结果:%d", file.c_str(),re)); if(re == ERROR_ACCESS_DENIED) { CRecordProgram::GetInstance ()->RecordCommonInfo(L"PutFile", 1001, CRecordProgram::GetInstance ()->GetRecordInfo(L"%s文件放入失败", file.c_str())); USES_CONVERSION; string appid; if(m_pWebsiteData) { USES_CONVERSION; appid = CFavBankOperator::GetBankIDOrBankName(W2A(m_pWebsiteData->GetID()),false); CWebsiteData::StartUAC(A2W(appid.c_str())); } } } else { if(replace == true)//强制替换 { DWORD oLength = 0, nLength = 0; HANDLE hFile = CreateFileW(expName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile != INVALID_HANDLE_VALUE) { oLength = GetFileSize(hFile, NULL); CloseHandle(hFile); } CRecordProgram::GetInstance ()->RecordCommonInfo(L"PutFile", 1001, CRecordProgram::GetInstance ()->GetRecordInfo(L"%s文件已经存在", expName)); wstring file = CResourceManager::_()->GetFilePath(m_pWebsiteData->GetWebsiteType(), m_pWebsiteData->GetID(), name.c_str()); hFile = CreateFileW(file.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile != INVALID_HANDLE_VALUE) { nLength = GetFileSize(hFile, NULL); CloseHandle(hFile); } if((oLength != 0) && (oLength != nLength)) { ::CopyFileW(file.c_str(), expName , FALSE);// DWORD re = ::GetLastError(); CRecordProgram::GetInstance ()->RecordCommonInfo(L"PutFile", 1001, CRecordProgram::GetInstance ()->GetRecordInfo(L"替换%s文件结果:%d", file.c_str(),re)); if(re == ERROR_ACCESS_DENIED) { USES_CONVERSION; string appid; if(m_pWebsiteData) { appid = CFavBankOperator::GetBankIDOrBankName(W2A(m_pWebsiteData->GetID()),false); CWebsiteData::StartUAC(A2W(appid.c_str())); } } } } } if(CGetOSInfo::getInstance()->isX64()) if(bRet == TRUE) { Wow64RevertWow64FsRedirectionFun pWow64RevertWow64FsRedirection = NULL; if (hKernel32) { pWow64RevertWow64FsRedirection = (Wow64RevertWow64FsRedirectionFun)::GetProcAddress(hKernel32, "Wow64RevertWow64FsRedirection"); } if(pWow64RevertWow64FsRedirection != NULL) pWow64RevertWow64FsRedirection(OldValue); } return; }