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

kernelbase: Fix return on failed VirtualQueryEx #262

Closed
wants to merge 1 commit into from

Conversation

nulleve
Copy link

@nulleve nulleve commented Nov 3, 2024

Issues mentioned in #8208;

Returning specific booleans such as FALSE, TRUE causes WriteProcessMemory to break, noticeably with Dark and Darker's anti-cheat "TavernWorker".

This patch returns the NTSTATUS of NtWriteVirtualMemory as solely handled previously, however now only in cases where VirtualQueryEx responds with an error.

@@ -613,7 +613,7 @@ BOOL WINAPI DECLSPEC_HOTPATCH WriteProcessMemory( HANDLE process, void *addr, co
if (!VirtualQueryEx( process, addr, &info, sizeof(info) ))
{
close_cross_process_connection( list );
return FALSE;
return set_ntstatus( NtWriteVirtualMemory( process, addr, buffer, size, bytes_written ));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right. If you want to have the last error set, you'll need to use NtQueryVirtualMemory() and use status from that. Note that set_ntstatus() will still return either 0 or 1.

Also, since part is not specific to proton, please submit the fix together with some tests replicating failure you see, at https://gitlab.winehq.org/wine/wine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, I saw the commits in this repo without checking if it was in wine's repo sorry about that. I attempted to use NtQueryVirtualMemory however I'm not familiar with windows internals (let alone their kernel), so while it compiles/runs it doesn't produce the same working effect as NtWriteVirtualMemory (TavernWorker in Dark and Darker still fails to run) and I don't have insight as to why to be honest.

Thank you for the insight and help, I'll try and send this over to wine's repo and see if someone is able to resolve this.

@nulleve nulleve closed this Nov 3, 2024
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 this pull request may close these issues.

2 participants