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.
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.