Hollowing/main.c
#include "common.h"

int main() {

	HANDLE	hNewThread	= NULL;
	HANDLE	hThread		= NULL;
	DWORD	dwThreadId	= 0;

	// Duplicate the pseudo-handle to get a real handle with the same access rights
	// https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle
	if (!DuplicateHandle(NtCurrentProcess(), NtCurrentThread(), NtCurrentProcess(), &hThread, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
		errorWin32("DuplicateHandle - Failed to duplicate handle");
		return EXIT_FAILURE;
	}
	info("Duplicated thread handle");

	// Create a new thread and execute RunIt
	// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread
	info("CreateThread - Creating thread executing RunIt()");
	hNewThread = CreateThread(
		NULL,							// Optional can be null
		0,								// Use default size
		(LPTHREAD_START_ROUTINE)RunIt,	// Start a new threat and execute RunIt
		&hThread,						// Pass the thread handle to the newly created thread
		0,								// Run immediatly
		&dwThreadId						// Save the thread id
	);
	okay("CreateThread - Thread with id %d created", dwThreadId);

	// Wait forever for the thread to execute
	if (hNewThread) {
		WaitForSingleObject(hNewThread, INFINITE);
	}

	// CLEANUP

	// Close handles
	if (hNewThread) {
		CloseHandle(hNewThread);
	}
	if (hThread) {
		CloseHandle(hThread);
	}

	return EXIT_SUCCESS;

}