7 PVOID ObjectAttributes, HANDLE ProcessHandle, PVOID StartRoutine, PVOID Argument,
8 ULONG CreateFlags, SIZE_T ZeroBits, SIZE_T StackSize, SIZE_T MaximumStackSize, PVOID AttributeList);
10#define THREAD_CREATE_FLAGS_CREATE_SUSPENDED 0x1
14static LPTHREAD_START_ROUTINE RemoteStart() {
15 return (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA(
"kernel32.dll"),
"ExitThread");
18static DWORD WINAPI ReturnImmediately(LPVOID) {
23static void Join(HANDLE thread) {
25 WaitForSingleObject(thread, INFINITE);
30static const std::vector<HookTestCase> g_Cases = {
32 "Suspended thread created in remote process",
34 HANDLE thread = CreateRemoteThread(context.RemoteProcess(), NULL, 0, RemoteStart(), NULL, CREATE_SUSPENDED, NULL);
39 {
"NtCreateThreadEx: thread created in a remote process, start *, flags 0x1" },
42 "Suspended thread created in remote process through ntdll",
51 {
"NtCreateThreadEx: thread created in a remote process, start *, flags 0x1" },
54 "Thread created in current process is not reported",
56 Join(CreateThread(NULL, 0, ReturnImmediately, NULL, 0, NULL));
61 "Thread created through a real handle to self is not reported",
63 HANDLE self = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
64 Join(CreateRemoteThread(self, NULL, 0, ReturnImmediately, NULL, 0, NULL));
74 "Failed remote thread creation is not reported",
76 HANDLE thread = CreateRemoteThread((HANDLE)(ULONG_PTR)0x7FFC, NULL, 0, RemoteStart(), NULL, CREATE_SUSPENDED, NULL);
85int main(
int argc,
char** argv) {
86 return RunHookTests(argc, argv,
"NtCreateThreadEx", g_Cases);
NTSTATUS(NTAPI * NtCreateThreadEx_t)(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, PVOID ObjectAttributes, HANDLE ProcessHandle, PVOID StartRoutine, PVOID Argument, ULONG CreateFlags, SIZE_T ZeroBits, SIZE_T StackSize, SIZE_T MaximumStackSize, PVOID AttributeList)
#define THREAD_CREATE_FLAGS_CREATE_SUSPENDED
int main()
Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this...
Resources shared by the cases of one test run, created in the child process. The remote processes are...
T NtdllFunction(const char *name)
Looks up an ntdll export. Calls through the result go through the hooks, because the hooks patch the ...
int RunHookTests(int argc, char **argv, const char *apiName, const std::vector< HookTestCase > &cases)
Runs the cases and prints a PASS/FAIL line for each. Call from main.