Created
December 23, 2023 20:51
-
-
Save blair1922/1cd701016754cbc7b678e38cda20766b to your computer and use it in GitHub Desktop.
Usermode->Kernel communication using Events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ntifs.h> | |
const wchar_t* EVENT_NAME = L"Global\\EventMeme"; | |
extern "C" | |
NTSTATUS | |
DriverEntry( | |
_In_ PDRIVER_OBJECT DriverObject, | |
_In_ PUNICODE_STRING RegistryPath | |
) | |
{ | |
UNREFERENCED_PARAMETER(RegistryPath); | |
HANDLE hEvent = OpenEvent(SYNCHRONIZE, FALSE, EVENT_NAME); | |
if (hEvent == nullptr) { | |
KdPrint(("Error opening event: %lu\n", GetLastError())); | |
return STATUS_UNSUCCESSFUL; | |
} | |
KdPrint(("Waiting for the event...\n")); | |
if (WaitForSingleObject(hEvent, INFINITE) != WAIT_OBJECT_0) { | |
KdPrint(("Error waiting for event: %lu\n", GetLastError())); | |
} else { | |
KdPrint(("Event signaled!\n")); | |
} | |
CloseHandle(hEvent); | |
return STATUS_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
// Example named event name | |
const wchar_t* EVENT_NAME = L"Global\\EventMeme"; | |
int main() { | |
HANDLE hEvent = CreateEvent(nullptr, FALSE, FALSE, EVENT_NAME); | |
if (hEvent == nullptr) { | |
std::cerr << "Error creating event: " << GetLastError() << std::endl; | |
return 1; | |
} | |
//do whatever | |
SetEvent(hEvent); | |
CloseHandle(hEvent); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment