Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notepad++ x86 on 64Bit Windows can't save files in C:\Windows\Sysnative\ #11196

Closed
dodmi opened this issue Feb 12, 2022 · 14 comments
Closed

Notepad++ x86 on 64Bit Windows can't save files in C:\Windows\Sysnative\ #11196

dodmi opened this issue Feb 12, 2022 · 14 comments
Assignees

Comments

@dodmi
Copy link

dodmi commented Feb 12, 2022

-- Nothing to see here, anymore --

@mere-human
Copy link
Contributor

This file is probably protected and requires administrator rights in order to edit it.
I tried a similar command line:
-nosession -multiInst -noPlugin C:\Windows\System32\drivers\etc\hosts
And I got this message:
image
After pressing Yes I was able to modify and save the file.
Did you see a similar message?

@xomx
Copy link
Contributor

xomx commented Feb 16, 2022

@mere-human

From the @dodmi report is clear (e.g. look at the N++ screenshot taken - there is the [Administrator] visible), that the N++ has been already elevated before by launching from the elevated cmd. So there should not be the "Save failed - Do you want ... Administrator mode?" msgbox visible.

@dodmi

I have tried exactly your steps but with the current 8.3.1 x86 portable. And I was able to save that file. So there should be something else in your way.

But - on another PC I have the ZoneAlarm firewall installed and it failed to do so. When I looked at the ZoneAlarm setting, I have found an advanced setting "Lock host file" checked. After I unchecked that, I have started to be able to save ok. So maybe you have a similar SW installed on your computer(?). Maybe an antivirus solution(?).

Edited:
My messagebox, in the case of the ZoneAlarm guarding that file, was (Ctrl+C in the messagebox):

Save failed
Please check whether if this file is opened in another program
OK

When I select 'Deutsch' N++ localization, it becames exactly the message as in your report:

Speichern fehlgeschlagen!
Datei konnte von Notepad++ nicht gespeichert werden.
Bitte überprüfen Sie, ob die Datei in einem anderen Programm geöffnet ist.
OK

@xomx
Copy link
Contributor

xomx commented Feb 16, 2022

@dodmi

Ok, now I am able to reproduce your issue reported.
I forgot to use your "Sysnative" substitute for the x64 "System32".
When I used "PathToNPP\notepad++.exe -noPlugin C:\Windows\System32\drivers\etc\hosts", the saving worked ok.

Edited:
Weird, the WIN32 API CreateFile in N++ cannot open such alias ("C:\Windows\Sysnative\drivers\etc\hosts") and returns ERROR_PATH_NOT_FOUND instead in the ".\PowerEditor\src\MISC\Common\FileInterface.cpp" -> Win32_IO_File::Win32_IO_File(const wchar_t *fname).

@xomx
Copy link
Contributor

xomx commented Feb 16, 2022

I have found the culprit here - it is the default using of the flag FILE_FLAG_POSIX_SEMANTICS in the ".\PowerEditor\src\MISC\Common\FileInterface.h".

Without this flag the CreateFile call in the described situation succeeds, so such writing is then possible.

Contrary to the N++, the standard Windows Notepad works ok in such situation, you can try that by:
"C:\Windows\SysWOW64\notepad.exe C:\Windows\Sysnative\drivers\etc\hosts"
then modify the file & save.

@xomx
Copy link
Contributor

xomx commented Feb 16, 2022

@dodmi

this was/is also working in Notepad++ prior to version 8.1.6

Yes, in the version 8.1.6 has been exchanged the original POSIX IO (fopen/fwrite) for the WIN32 API one (CreateFile/WriteFile) for the file saving. For this issue is problematic only the use of the 'case sensitive file access flag' FILE_FLAG_POSIX_SEMANTICS.

To tell the truth - I do not fully understand yet, why this 'case sensitive' flag causes this fail of the CreateFile API. One explanation could be that the Windows OS inherent substitute for the "Sysnative" is e.g. "SYSTEM32" instead of the real "System32" used on the disk ("at least that is used on my PC ... "C:\Windows\System32").

Edited:
I should add that the 32-bit N++ probably can open such file ("C:\Windows\Sysnative\drivers\etc\hosts"), just because of it still uses the POSIX fopen/fread for the file loading.

@pnedev
Is that FILE_FLAG_POSIX_SEMANTICS really needed?
Is it equivalent to the previously used POSIX fopen-way? (I suppose that it is relevant when accessing a *NIX file systems, but was something like that there before with the fopen-way?)

@pnedev
Copy link
Contributor

pnedev commented Feb 17, 2022

Hi @xomx ,
Very good analysis, perhaps the system indeed replaces "Sysnative" with "SYSTEM32" and the new case sensitivity flag is problematic in that case.

The FILE_FLAG_POSIX_SEMANTICS is not needed actually - it is not equivalent with fopen in any way and is additional option in the Win32 API. I added it as a personal preference (because I'm mainly working on Linux and because I thought that having case sensitive file naming in the new API can't hurt the existing functionality and perhaps could even help in cases with mapped UNIX like drives).
So this flag is new and can be safely removed to fix this issue - the file saving function then will behave as in pre-8.1.6 Notepad++ versions.

@xomx
Copy link
Contributor

xomx commented Feb 17, 2022

@pnedev
Thanks for your quick confirmation.

So I am going to do a PR for it to others can also test & confirm my findings.

But the final decision will be up to @donho and I know that he will not be happy from any change in this WIN32 IO area...

@pnedev
Copy link
Contributor

pnedev commented Feb 17, 2022

Thanks @xomx .

But the final decision will be up to @donho and I know that he will not be happy from any change in this WIN32 IO area...

I guess that Don will not have problems merging your PR because we discussed that flag before and he was asking me about the justification of FILE_FLAG_POSIX_SEMANTICS flag as well. We decided back then that it will not be problematic and it will be safe to leave it as an enhancement.

@xomx
Copy link
Contributor

xomx commented Feb 17, 2022

@dodmi
Could you please download & re-test the patched Notepad++.Win32.Release.exe artifact:
https://ci.appveyor.com/project/donho/notepad-plus-plus/builds/42608795/job/8km2iajucog6fkma/artifacts

@donho
Copy link
Member

donho commented Feb 17, 2022

But the final decision will be up to @donho and I know that he will not be happy from any change in this WIN32 IO area..

These codes are contributed by @pnedev , so if he feel it's save to remove FILE_FLAG_POSIX_SEMANTICS flag, I have no problem with it.

@donho
Copy link
Member

donho commented Feb 17, 2022

@xomx

I forgot to use your "Sysnative" substitute for the x64 "System32".

How can I do the same?

@xomx
Copy link
Contributor

xomx commented Feb 18, 2022

@donho

Just use it like:

  • start the 32-bit cmd (goto "C:\Windows\SysWOW64" and run the "cmd.exe" there)
  • in the cmd-window enter the "C:\Windows\System32\notepad.exe" (e.g. Ctrl+C on the text here & then right-click in the cmd-window & 'Paste')
  • check in a task manager that you are running the 32-bit version of the notepad.exe (though you have used the 64-bit path "C:\Windows\System32")
  • close the opened 32-bit Notepad
  • in the same cmd-window enter the "C:\Windows\Sysnative\notepad.exe"
  • check in a task manager that now you are running the 64-bit notepad.exe

A 64-bit Windows OS internal 'shim' translates transparently this "Sysnative" string to its 64-bit equivalent (or better - it redirects such 32-bit app request to the 64-bit "C:\Windows\System32" counterpart).
This is the easiest way for 32-bit apps, how to handle those 32/64 redirections without additional code-changes.

@donho
Copy link
Member

donho commented Feb 18, 2022

@xomx
Thank you for the explanation.So Sysnative is only visible for x86 appz, isn't it?

@donho donho closed this as completed in b233c0c Feb 18, 2022
@xomx
Copy link
Contributor

xomx commented Feb 18, 2022

@donho

So Sysnative is only visible for x86 appz, isn't it?

Exactly.
The WOW64 x86 emulator handles that. For a native x64-app is the "C:\Windows\Sysnative" an invalid path.

@dodmi dodmi changed the title Notepad++ x86 on 64Bit Windows can't save files in C:\Windows\Sysnative\... --- Jun 21, 2023
@dodmi dodmi changed the title --- -- Nothing to see here, anymore -- Jun 21, 2023
@donho donho changed the title -- Nothing to see here, anymore -- Notepad++ x86 on 64Bit Windows can't save files in C:\Windows\Sysnative\ Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants