https://bugs.winehq.org/show_bug.cgi?id=46956
Bug ID: 46956 Summary: ReplaceFile cannot replace the current executable Product: Wine Version: 1.6.2 Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: kernel32 Assignee: wine-bugs@winehq.org Reporter: shaggie76@hotmail.com Distribution: ---
Created attachment 64085 --> https://bugs.winehq.org/attachment.cgi?id=64085 A simple VS2017 console project that you can compile to test this.
The ReplaceFile API can be used to update the currently running exe file; this does not work with WINE.
This bug prevents the Warframe launcher from working properly.
A simple program that demonstrates this is:
#include <windows.h> #include <tchar.h>
int main(int argc, const char* argv[]) { TCHAR exePath[MAX_PATH]; TCHAR tmpPath[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), exePath, MAX_PATH); _tcscpy_s(tmpPath, MAX_PATH, exePath); _tcscat_s(tmpPath, MAX_PATH, TEXT(".tmp"));
if(!CopyFile(exePath, tmpPath, FALSE)) { _tprintf(TEXT("CopyFile(%s, %s, FALSE) failed [0x%08X]\n"), exePath, tmpPath, GetLastError()); return(1); }
/* this has worked from at least as far back as WinXP and continues to work on Win10 */ if(!ReplaceFile(exePath, tmpPath, NULL, 0, NULL, NULL)) { _tprintf(TEXT("ReplaceFile(%s, %s, NULL, 0, NULL, NULL) failed [0x%08X]\n"), exePath, tmpPath, GetLastError()); return(1); }
/* A proper test would check that the file was actually updated but this is sufficient to demonstrate the bug */ _tprintf(TEXT("No errors!\n"));
return(0); }
Under WINE this prints:
ReplaceFile(Z:\home\glen\WineReplaceFile.exe, Z:\home\glen\WineReplaceFile.exe.tmp, NULL, 0, NULL, NULL) failed [0x00000497]
Under real WinXP to Win10 this prints:
No errors!
https://bugs.winehq.org/show_bug.cgi?id=46956
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEEDINFO
--- Comment #1 from Austin English austinenglish@gmail.com --- Please retest in 4.x, 1.6.2 hasn't been supported for years.
https://bugs.winehq.org/show_bug.cgi?id=46956
--- Comment #2 from Gijs Vermeulen gijsvrm@gmail.com --- This looks like a dupe of bug 33845, which was just STAGED with https://github.com/wine-staging/wine-staging/commit/8b930aea2fe08d845dc98600...
https://bugs.winehq.org/show_bug.cgi?id=46956
--- Comment #3 from Glen Miner shaggie76@hotmail.com --- I just checked in 4.0 and it's still there.
I did search for other reports involving ReplaceFile but found none; I doubt Warframe is the only one program using this technique.
Feel free to close as dup; I'm glad it's being fixed.
https://bugs.winehq.org/show_bug.cgi?id=46956
--- Comment #4 from Glen Miner shaggie76@hotmail.com --- I just checked in wine-4.5 (Staging) from the Ubuntu repo and the test still fails; I'm guessing it hasn't been built yet with that fix.
https://bugs.winehq.org/show_bug.cgi?id=46956
--- Comment #5 from Glen Miner shaggie76@hotmail.com --- I'm also embarrassed to say that when I made the quick test project I forgot to fix the x64 targets which I discovered are the default when you open the SLN on a new machine. Sorry about that; remove PCH settings, set runtime to static to fix.
https://bugs.winehq.org/show_bug.cgi?id=46956
--- Comment #6 from Glen Miner shaggie76@hotmail.com --- I went looking to see if I could hack around this problem by emulating what the patched ReplaceFile does; I can get close but in the end I'm blocked because the call to rename() is subverted: when WINE calls it libc answers; when I call it dlls/msvcrt/file.c answers (and fails: Permission denied).
If there was a way for me to call the 'real' rename() I'd be willing to try but as it stands I've spent far, far more time trying to work around this problem as it is.
I'm going to just hack our launcher to detect this failure and direct people here. I'm not willing to modify how the launcher works at a fundamental level because screwing that up could break millions of installs and it isn't worth the risk.
https://bugs.winehq.org/show_bug.cgi?id=46956
Gijs Vermeulen gijsvrm@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEEDINFO |RESOLVED Resolution|--- |DUPLICATE
--- Comment #7 from Gijs Vermeulen gijsvrm@gmail.com --- (In reply to Glen Miner from comment #6)
-snip-
Wine 4.6 includes a fix for bug 33845, so marking as a duplicate. If you are still able to reproduce your issue, please reopen this bug.
*** This bug has been marked as a duplicate of bug 33845 ***
https://bugs.winehq.org/show_bug.cgi?id=46956
Alistair Leslie-Hughes leslie_alistair@hotmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #8 from Alistair Leslie-Hughes leslie_alistair@hotmail.com --- Closing Duplicate.