regsvr32: Restart the correct version for all supported architectures.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-04-29 17:09:06 +02:00
parent 9b0a8f5f49
commit 20984f2e1f
2 changed files with 20 additions and 33 deletions

View File

@ -1,5 +1,5 @@
MODULE = regsvr32.exe MODULE = regsvr32.exe
IMPORTS = ole32 user32 IMPORTS = ole32 user32 kernelbase
EXTRADLLFLAGS = -mwindows -municode -mno-cygwin EXTRADLLFLAGS = -mwindows -municode -mno-cygwin

View File

@ -112,46 +112,39 @@ static LPCWSTR find_arg_start(LPCWSTR cmdline)
return s; return s;
} }
static void reexec_self(void) static void reexec_self( WORD machine )
{ {
/* restart current process as 32-bit or 64-bit with same command line */ WCHAR app[MAX_PATH];
#ifndef _WIN64
BOOL wow64;
#endif
WCHAR systemdir[MAX_PATH];
LPCWSTR args; LPCWSTR args;
WCHAR *cmdline; WCHAR *cmdline;
ULONG i, machines[8];
HANDLE process = 0;
STARTUPINFOW si = {0}; STARTUPINFOW si = {0};
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
void *cookie;
#ifdef _WIN64 NtQuerySystemInformationEx( SystemSupportedProcessorArchitectures, &process, sizeof(process),
TRACE("restarting as 32-bit\n"); machines, sizeof(machines), NULL );
GetSystemWow64DirectoryW(systemdir, MAX_PATH); for (i = 0; machines[i]; i++) if (LOWORD(machines[i]) == machine) break;
#else if (!machines[i]) return;
TRACE("restarting as 64-bit\n"); if (HIWORD(machines[i]) & 4 /* native machine */) machine = IMAGE_FILE_MACHINE_TARGET_HOST;
if (!GetSystemWow64Directory2W( app, MAX_PATH, machine )) return;
wcscat( app, L"\\regsvr32.exe" );
if (!IsWow64Process(GetCurrentProcess(), &wow64) || !wow64) TRACE( "restarting as %s\n", debugstr_w(app) );
{
TRACE("not running in wow64, can't restart as 64-bit\n");
return;
}
GetWindowsDirectoryW(systemdir, MAX_PATH);
wcscat(systemdir, L"\\SysNative");
#endif
args = find_arg_start(GetCommandLineW()); args = find_arg_start(GetCommandLineW());
cmdline = HeapAlloc(GetProcessHeap(), 0, cmdline = HeapAlloc(GetProcessHeap(), 0,
(wcslen(systemdir)+wcslen(L"\\regsvr32.exe")+wcslen(args)+1)*sizeof(WCHAR)); (wcslen(app)+wcslen(args)+1)*sizeof(WCHAR));
wcscpy(cmdline, systemdir); wcscpy(cmdline, app);
wcscat(cmdline, L"\\regsvr32.exe");
wcscat(cmdline, args); wcscat(cmdline, args);
si.cb = sizeof(si); si.cb = sizeof(si);
if (CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) Wow64DisableWow64FsRedirection(&cookie);
if (CreateProcessW(app, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{ {
DWORD exit_code; DWORD exit_code;
WaitForSingleObject(pi.hProcess, INFINITE); WaitForSingleObject(pi.hProcess, INFINITE);
@ -162,16 +155,10 @@ static void reexec_self(void)
{ {
WINE_TRACE("failed to restart, err=%d\n", GetLastError()); WINE_TRACE("failed to restart, err=%d\n", GetLastError());
} }
Wow64RevertWow64FsRedirection(cookie);
HeapFree(GetProcessHeap(), 0, cmdline); HeapFree(GetProcessHeap(), 0, cmdline);
} }
#ifdef _WIN64
# define ALT_MACHINE IMAGE_FILE_MACHINE_I386
#else
# define ALT_MACHINE IMAGE_FILE_MACHINE_AMD64
#endif
/** /**
* Loads procedure. * Loads procedure.
* *
@ -193,7 +180,7 @@ static VOID *LoadProc(const WCHAR* strDll, const char* procName, HMODULE* DllHan
(module = LoadLibraryExW(strDll, 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE))) (module = LoadLibraryExW(strDll, 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE)))
{ {
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( (HMODULE)((ULONG_PTR)module & ~3) ); IMAGE_NT_HEADERS *nt = RtlImageNtHeader( (HMODULE)((ULONG_PTR)module & ~3) );
if (nt->FileHeader.Machine == ALT_MACHINE) reexec_self(); reexec_self( nt->FileHeader.Machine );
} }
output_write(STRING_DLL_LOAD_FAILED, strDll); output_write(STRING_DLL_LOAD_FAILED, strDll);
ExitProcess(LOADLIBRARY_FAILED); ExitProcess(LOADLIBRARY_FAILED);