Bug fixes and new checks in ThreadHideFromDebugger. #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously we were using BOOL for the hidden thread flag, but that's typedef int which is 4 bytes. This query call expects a 1-byte bool instead, so the NtQueryInformationThread call would always fail with a length mismatch. Due to the logic in the function, this resulted in silently returning no detection.
One important detail of note is that because bool is a single byte local variable, it is free to be allocated anywhere and isn't necessarily aligned. This commit introduces an AlignedBool struct that uses the alignas keyword to get around this issue.
Three new checks are added in this commit:
The first check detects if a length mismatch status is returned for legitimate calls, which might happen if someone writes a buggy hook that incorrectly assumes a BOOL is passed rather than a bool.
The second check detects if a length mismatch status is not returned when a BOOL is passed, which is likely to happen if someone writes a buggy hook that doesn't check the input length properly.
The third check detects if misaligned ThreadInformation pointers are properly rejected. This is not something a hook is likely to properly check for, so it's a good way to catch them out.
This resolves #230.