// ==========================================================
// Definitions and Macros
// ==========================================================
#define TARGET_PROCESS_NAME L"notepad.exe" // Replace with your target process name
#define MY_WNF_STATE_NAME 0x41C64E6DA3BC1074ULL // Example WNF State Name (WNF_AUDC_CAPTURE)
// ==========================================================
// Global Function Pointers for WNF
// ==========================================================
// ==========================================================
// Function Definitions
// ==========================================================
// Get the offset for UserDirectoryTableBase based on Windows version
DWORD GetUserDirectoryTableBaseOffset()
{
RTL_OSVERSIONINFOW ver = { 0 };
RtlGetVersion(&ver);
switch (ver.dwBuildNumber)
{
case WINDOWS_1803:
case WINDOWS_1809:
return 0x0278;
case WINDOWS_1903:
case WINDOWS_1909:
return 0x0280;
case WINDOWS_2004:
case WINDOWS_20H2:
case WINDOWS_21H1:
case WINDOWS_22H2:
default:
return 0x0388;
}
}
// Translate a virtual address to a physical address using the provided directory table base
uint64_t TranslateLinearAddress(uint64_t directoryTableBase, uint64_t virtualAddress)
{
directoryTableBase &= PMASK; // Align directoryTableBase
// Base64 Decode a single character
UCHAR Base64DecodeChar(char c)
{
if (c >= 'A' && c <= 'Z') return c - 'A';
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
if (c >= '0' && c <= '9') return c - '0' + 52;
if (c == '+') return 62;
if (c == '/') return 63;
return 0xFF; // Invalid character
}
NTSTATUS status = STATUS_SUCCESS;
if (Buffer && BufferSize >= sizeof(INSTRUCTIONS))
{
PINSTRUCTIONS instructions = (PINSTRUCTIONS)Buffer;
if (instructions->read)
{
// Handle read request
SIZE_T bytesRead = 0;
BYTE readBuffer[1024] = { 0 };
status = ReadProcessMemoryInternal(
(HANDLE)(ULONGLONG)instructions->processId,
(PVOID)(ULONGLONG)instructions->address,
readBuffer,
(SIZE_T)instructions->size,
&bytesRead
);
if (NT_SUCCESS(status))
{
// Encode the read data to Base64
SIZE_T base64Size = ((bytesRead + 2) / 3) * 4;
if (base64Size + 1 > sizeof(instructions->data))
{
DbgPrint("[Driver] Read operation failed: Encoded data exceeds buffer size.\n");
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Read operation failed: Encoded data exceeds buffer size.",
(ULONG)strlen("Read operation failed: Encoded data exceeds buffer size.") + 1,
NULL,
NULL,
0
);
return status;
}
CHAR encodedData[4096] = { 0 };
SIZE_T encodedLength = 0;
status = EncodeBase64(readBuffer, bytesRead, encodedData, sizeof(encodedData), &encodedLength);
if (!NT_SUCCESS(status))
{
DbgPrint("[Driver] EncodeBase64 failed with status: 0x%X\n", status);
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Read operation failed: Base64 encode failed.",
(ULONG)strlen("Read operation failed: Base64 encode failed.") + 1,
NULL,
NULL,
0
);
return status;
}
// Prepare instructions to send back
RtlZeroMemory(instructions->data, sizeof(instructions->data));
RtlCopyMemory(instructions->data, encodedData, min(encodedLength, sizeof(instructions->data) - 1));
instructions->size = bytesRead;
// Publish the data back via WNF
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
instructions,
sizeof(INSTRUCTIONS),
NULL,
NULL,
0
);
if (NT_SUCCESS(status))
{
DbgPrint("[Driver] Read operation completed successfully. %zu bytes read, %zu bytes encoded.\n", bytesRead, encodedLength);
}
else
{
DbgPrint("[Driver] ExPublishWnfStateData failed with status: 0x%X\n", status);
}
}
else
{
// Handle read error
DbgPrint("[Driver] ReadProcessMemoryInternal failed with status: 0x%X\n", status);
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Read operation failed.",
(ULONG)strlen("Read operation failed.") + 1,
NULL,
NULL,
0
);
}
}
else if (instructions->write)
{
// Handle write request
SIZE_T bytesWritten = 0;
// Decode Base64 data
UCHAR decodedData[512] = { 0 };
SIZE_T decodedSize = 0;
status = DecodeBase64((CHAR)instructions->data, decodedData, sizeof(decodedData), &decodedSize);
if (!NT_SUCCESS(status))
{
DbgPrint("[Driver] DecodeBase64 failed with status: 0x%X\n", status);
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Write operation failed: Base64 decode failed.",
(ULONG)strlen("Write operation failed: Base64 decode failed.") + 1,
NULL,
NULL,
0
);
return status;
}
status = WriteProcessMemoryInternal(
(HANDLE)(ULONGLONG)instructions->processId,
(PVOID)(ULONGLONG)instructions->address,
decodedData,
decodedSize,
&bytesWritten
);
if (NT_SUCCESS(status) && bytesWritten == decodedSize)
{
// Prepare instruction to send back
instructions->size = bytesWritten;
// Publish the success message back via WNF
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
instructions,
sizeof(INSTRUCTIONS),
NULL,
NULL,
0
);
DbgPrint("[Driver] Write operation completed successfully. %zu bytes written to process %llu at address 0x%llX.\n",
bytesWritten, instructions->processId, instructions->address);
}
else
{
// Handle write error
DbgPrint("[Driver] WriteProcessMemoryInternal failed with status: 0x%X and bytes written: %zu\n", status, bytesWritten);
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Write operation failed.",
(ULONG)strlen("Write operation failed.") + 1,
NULL,
NULL,
0
);
}
}
else if (instructions->close)
{
// Handle close instruction
// Currently, no specific cleanup is required
DbgPrint("[Driver] Received close instruction.\n");
}
else if (instructions->reqBase)
{
// Handle base address request
PEPROCESS pProcess = NULL;
NTSTATUS statusLookup = PsLookupProcessByProcessId((HANDLE)(ULONGLONG)instructions->processId, &pProcess);
if (NT_SUCCESS(statusLookup))
{
PVOID baseAddress = PsGetProcessSectionBaseAddress(pProcess);
instructions->baseAddress = (UINT64)baseAddress;
ObDereferenceObject(pProcess);
// Publish the base address back via WNF
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
instructions,
sizeof(INSTRUCTIONS),
NULL,
NULL,
0
);
DbgPrint("[Driver] Base address of process %llu: %p\n", instructions->processId, baseAddress);
}
else
{
// Handle error
DbgPrint("[Driver] PsLookupProcessByProcessId failed with status: 0x%X\n", statusLookup);
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
"Base address request failed: PsLookupProcessByProcessId failed.",
(ULONG)strlen("Base address request failed: PsLookupProcessByProcessId failed.") + 1,
NULL,
NULL,
0
);
}
}
// Additional instruction handling can be added here
}
else if (Buffer && BufferSize > 0)
{
// Handle simple messages like "Hi"
CHAR receivedMessage = (CHAR)ExAllocatePoolWithTag(NonPagedPoolNx, BufferSize + 1, 'msgK');
if (!receivedMessage)
{
DbgPrint("[Driver] Failed to allocate memory for received message.\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory(receivedMessage, BufferSize + 1);
RtlCopyMemory(receivedMessage, Buffer, min(BufferSize, sizeof(receivedMessage) - 1));
DbgPrint("[Driver] Kernel received message: %s\n", receivedMessage);
if (strcmp(receivedMessage, "Hi") == 0)
{
// Send handshake response
const CHAR responseMessage = "Hello from kernel mode";
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
(PVOID)responseMessage,
(ULONG)strlen(responseMessage) + 1,
NULL,
NULL,
0
);
if (NT_SUCCESS(status))
{
DbgPrint("[Driver] Handshake response sent successfully.\n");
}
else
{
DbgPrint("[Driver] Failed to send handshake response with status: 0x%X\n", status);
}
}
ExFreePoolWithTag(receivedMessage, 'msgK');
}
else
{
// Handle unexpected or unsupported data
DbgPrint("[Driver] Received invalid or unsupported data.\n");
}
return status;
}
// ==========================================================
// WNF Subscription Function
// ==========================================================
// Subscribe to WNF state changes
NTSTATUS SubscribeToWNF()
{
if (!ExSubscribeWnfStateChange || !ExPublishWnfStateData || !ExUnsubscribeWnfStateChange)
{
DbgPrint("[Driver] WNF function pointers not initialized.\n");
return STATUS_UNSUCCESSFUL;
}
code
NTSTATUS status = ExSubscribeWnfStateChange(
g_WnfSubscription,
MY_WNF_STATE_NAME_VALUE,
0, // ChangeStamp (0 for all changes)
(PVOID)OnWnfCallback,
NULL, // CallbackContext
NULL, // TypeId
0, // SerializationGroup
0 // Unknown
);
if (NT_SUCCESS(status))
{
DbgPrint("[Driver] Successfully subscribed to WNF state changes.\n");
}
else
{
DbgPrint("[Driver] ExSubscribeWnfStateChange failed with status: 0x%X\n", status);
}
return status;
}
// ==========================================================
// Process Notification Callback
// ==========================================================
if (Create)
{
PEPROCESS pProcess = NULL;
NTSTATUS status = PsLookupProcessByProcessId(ProcessId, &pProcess);
if (NT_SUCCESS(status))
{
// Get process image file name
UNICODE_STRING uProcessImageName = { 0 };
status = SeLocateProcessImageName(pProcess, &uProcessImageName);
if (NT_SUCCESS(status))
{
// Extract file name from full path
PWSTR processName = wcsrchr(uProcessImageName.Buffer, L'\'); // Corrected backslash
if (processName)
{
processName++; // Move past the backslash
// Check if this is the target process
if (_wcsicmp(processName, TARGET_PROCESS_NAME) == 0)
{
// Perform memory operations here (if needed)
PVOID baseAddress = GetProcessBaseAddress(ProcessId);
if (baseAddress)
{
DbgPrint("[Driver] Target process '%ws' created with base address: %p\n", processName, baseAddress);
// Example: Read some memory from the process
BYTE buffer[256] = { 0 };
SIZE_T bytesRead = 0;
NTSTATUS ntStatus = ReadProcessMemoryInternal(
ProcessId,
baseAddress,
buffer,
sizeof(buffer),
&bytesRead
);
if (NT_SUCCESS(ntStatus))
{
DbgPrint("[Driver] Successfully read %zu bytes from '%ws'.\n", bytesRead, processName);
}
else
{
DbgPrint("[Driver] Failed to read memory of '%ws' with status: 0x%X\n", processName, ntStatus);
}
// Example: Write to process memory (commented out for safety)
/
BYTE writeData[256] = { / Your data here * / };
SIZE_T bytesWritten = 0;
ntStatus = WriteProcessMemoryInternal(
ProcessId,
baseAddress,
writeData,
sizeof(writeData),
&bytesWritten
);
if (NT_SUCCESS(ntStatus))
{
DbgPrint("[Driver] Successfully wrote %zu bytes to '%ws'.\n", bytesWritten, processName);
}
else
{
DbgPrint("[Driver] Failed to write memory of '%ws' with status: 0x%X\n", processName, ntStatus);
}
/
}
else
{
DbgPrint("[Driver] Failed to retrieve base address of process ID: %llu\n", ProcessId);
}
}
}
else
{
DbgPrint("[Driver] Failed to parse process name for PID: %llu\n", ProcessId);
}
// Free the allocated image name buffer
ExFreePoolWithTag(uProcessImageName.Buffer, 'imgN');
}
else
{
DbgPrint("[Driver] SeLocateProcessImageName failed with status: 0x%X for PID: %llu\n", status, ProcessId);
}
ObDereferenceObject(pProcess);
}
else
{
DbgPrint("[Driver] PsLookupProcessByProcessId failed with status: 0x%X for PID: %llu\n", status, ProcessId);
}
}
if (Create)
{
PEPROCESS pProcess = NULL;
NTSTATUS status = PsLookupProcessByProcessId(ProcessId, &pProcess);
if (NT_SUCCESS(status))
{
// Get process image file name
UNICODE_STRING uProcessImageName = { 0 };
status = SeLocateProcessImageName(pProcess, &uProcessImageName);
if (NT_SUCCESS(status))
{
// Extract file name from full path
PWSTR processName = wcsrchr(uProcessImageName.Buffer, L'\'); // Corrected backslash
if (processName)
{
processName++; // Move past the backslash
// Check if this is the target process
if (wcsicmp(processName, TARGET_PROCESS_NAME) == 0)
{
// Perform memory operations here (if needed)
PVOID baseAddress = GetProcessBaseAddress(ProcessId);
if (baseAddress)
{
DbgPrint("[Driver] Target process '%ws' created with base address: %p\n", processName, baseAddress);
// Example: Read some memory from the process
BYTE buffer[256] = { 0 };
SIZE_T bytesRead = 0;
NTSTATUS ntStatus = ReadProcessMemoryInternal(
(HANDLE)ProcessId,
baseAddress,
buffer,
sizeof(buffer),
&bytesRead
);
if (NT_SUCCESS(ntStatus))
{
DbgPrint("[Driver] Successfully read %zu bytes from '%ws'.\n", bytesRead, processName);
}
else
{
DbgPrint("[Driver] Failed to read memory of '%ws' with status: 0x%X\n", processName, ntStatus);
}
// Example: Write to process memory (commented out for safety)
/
BYTE writeData[256] = { / Your data here * / };
SIZE_T bytesWritten = 0;
ntStatus = WriteProcessMemoryInternal(
(HANDLE)ProcessId,
baseAddress,
writeData,
sizeof(writeData),
&bytesWritten
);
if (NT_SUCCESS(ntStatus))
{
DbgPrint("[Driver] Successfully wrote %zu bytes to '%ws'.\n", bytesWritten, processName);
}
else
{
DbgPrint("[Driver] Failed to write memory of '%ws' with status: 0x%X\n", processName, ntStatus);
}
/
}
else
{
DbgPrint("[Driver] Failed to retrieve base address of process ID: %llu\n", ProcessId);
}
}
}
else
{
DbgPrint("[Driver] Failed to parse process name for PID: %llu\n", ProcessId);
}
// Free the allocated image name buffer
ExFreePoolWithTag(uProcessImageName.Buffer, 'imgN');
}
else
{
DbgPrint("[Driver] SeLocateProcessImageName failed with status: 0x%X for PID: %llu\n", status, ProcessId);
}
ObDereferenceObject(pProcess);
}
else
{
DbgPrint("[Driver] PsLookupProcessByProcessId failed with status: 0x%X for PID: %llu\n", status, ProcessId);
}
}
NTSTATUS status;
// Resolve WNF functions
UNICODE_STRING routineName;
RtlInitUnicodeString(&routineName, L"ExSubscribeWnfStateChange");
ExSubscribeWnfStateChange = (EXSUBSCRIBEWNFSTATECHANGE)MmGetSystemRoutineAddress(&routineName);
if (!ExSubscribeWnfStateChange)
{
DbgPrint("[Driver] ExSubscribeWnfStateChange not found.\n");
return STATUS_UNSUCCESSFUL;
}
RtlInitUnicodeString(&routineName, L"ExPublishWnfStateData");
ExPublishWnfStateData = (EXPUBLISHWNFSTATEDATA*)MmGetSystemRoutineAddress(&routineName);
if (!ExPublishWnfStateData)
{
DbgPrint("[Driver] ExPublishWnfStateData not found.\n");
return STATUS_UNSUCCESSFUL;
}
RtlInitUnicodeString(&routineName, L"ExUnsubscribeWnfStateChange");
ExUnsubscribeWnfStateChange = (EXUNSUBSCRIBEWNFSTATECHANGE*)MmGetSystemRoutineAddress(&routineName);
if (!ExUnsubscribeWnfStateChange)
{
DbgPrint("[Driver] ExUnsubscribeWnfStateChange not found.\n");
return STATUS_UNSUCCESSFUL;
}
// Subscribe to WNF state changes
status = SubscribeToWNF();
if (!NT_SUCCESS(status))
{
DbgPrint("[Driver] Failed to subscribe to WNF state changes with status: 0x%X\n", status);
return status;
}
// Register the process creation notify routine
status = PsSetCreateProcessNotifyRoutine(ProcessNotifyCallback, FALSE);
if (!NT_SUCCESS(status))
{
DbgPrint("[Driver] PsSetCreateProcessNotifyRoutine failed with status: 0x%X\n", status);
// Unsubscribe from WNF before exiting
if (g_WnfSubscription && ExUnsubscribeWnfStateChange)
ExUnsubscribeWnfStateChange(g_WnfSubscription);
return status;
}
// Set the unload routine
DriverObject->DriverUnload = DriverUnloadRoutine;
// Send handshake message to user-mode
const CHAR* handshakeMessage = "Kernel driver loaded";
status = ExPublishWnfStateData(
MY_WNF_STATE_NAME_VALUE,
(PVOID)handshakeMessage,
(ULONG)strlen(handshakeMessage) + 1,
NULL,
NULL,
0
);
if (NT_SUCCESS(status))
{
DbgPrint("[Driver] Handshake message published successfully.\n");
}
else
{
DbgPrint("[Driver] Failed to publish handshake message with status: 0x%X\n", status);
}
DbgPrint("[Driver] Driver loaded successfully.\n");
return STATUS_SUCCESS;
}
Severity Code Description Project File Line Suppression State Details
Error (active) E0145 function "ExSubscribeWnfStateChange" may not be initialized KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 61
Error (active) E0145 function "ExPublishWnfStateData" may not be initialized KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 62
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 75
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 76
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 77
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 78
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 86
Error (active) E0020 identifier "DWORD" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 97
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 99
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 99
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 99
Error (active) E0020 identifier "DWORD" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 147
Error (active) E0020 identifier "DWORD" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 213
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 221
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 221
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 221
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 225
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 226
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 227
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 228
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 229
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 232
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 240
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 250
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 260
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 265
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 281
Error (active) E0020 identifier "uint64_t" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 316
Error (active) E0031 expression must have integral type KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 427
Error (active) E0031 expression must have integral type KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 432
Error (active) E0031 expression must have integral type KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 438
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 461
Error (active) E0142 expression must have pointer-to-object type but it has type "unsigned long long" KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 462
Error (active) E0142 expression must have pointer-to-object type but it has type "unsigned long long" KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 463
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 465
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 467
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 469
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 471
Error (active) E0142 expression must have pointer-to-object type but it has type "SIZE_T" (aka "unsigned long long") KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 478
Error (active) E0142 expression must have pointer-to-object type but it has type "unsigned long long" KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 482
Error (active) E0119 cast to type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is not allowed KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 546
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 548
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 552
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 555
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 556
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 558
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 566
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 598
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 599
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 600
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 605
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 635
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 643
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 659
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 660
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 669
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 674
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 682
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 682
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 698
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 704
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 708
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 712
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 718
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 725
Error (active) E0008 missing closing quote KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 852
Error (active) E0018 expected a ')' KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 853
Error (active) E0020 identifier "ntStatus" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 877
Error (active) E0020 identifier "bytesRead" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 879
Error (active) E0029 expected an expression KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 887
Error (active) E0020 identifier "baseAddress" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 892
Error (active) E0020 identifier "writeData" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 893
Error (active) E0029 expected an expression KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 906
Error (active) E0065 expected a ';' KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 907
Error (active) E0020 identifier "uProcessImageName" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 920
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 922
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 928
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 964
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 971
Error (active) E0137 expression must be a modifiable lvalue KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 986
Error (active) E0119 cast to type "EXSUBSCRIBEWNFSTATECHANGE" (aka "long (PVOID Subscription, ULONG64 StateName, ULONG ChangeStamp, PVOID Callback, PVOID CallbackContext, PVOID TypeId, ULONG SerializationGroup, ULONG Unknown)") is not allowed KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 986
Error (active) E0137 expression must be a modifiable lvalue KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 994
Error (active) E0119 cast to type "EXPUBLISHWNFSTATEDATA" (aka "long (ULONG64 StateName, PVOID Buffer, ULONG Length, PVOID TypeId, PVOID ExplicitScope, ULONG MatchingChangeStamp)") is not allowed KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 994
Error (active) E0119 cast to type "EXUNSUBSCRIBEWNFSTATECHANGE" (aka "long (PVOID Subscription)") is not allowed KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1002
Error (active) E0119 cast to type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is not allowed KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1116
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1118
Error (active) E0020 identifier "BYTE" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1122
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1125
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1126
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1128
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1136
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1168
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1169
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1170
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1175
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1205
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1213
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1229
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1230
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1239
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1244
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1252
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1252
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1268
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1275
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1279
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1283
Error (active) E0167 argument of type "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") is incompatible with parameter of type "PVOID" (aka "void *") KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1289
Error (active) E3364 operator -> or ->* applied to "PINSTRUCTIONS" (aka "struct INSTRUCTIONS") instead of to a pointer type KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1296
Error (active) E0020 identifier "in" is undefined KMDF Driver1 C:\Users\ruth\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1376
Error (active) E0018 expected a ')' KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1376
Error (active) E0020 identifier "Create" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1381
Error (active) E0008 missing closing quote KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1393
Error (active) E0018 expected a ')' KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1394
Error (active) E0020 identifier "ntStatus" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1418
Error (active) E0020 identifier "bytesRead" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1420
Error (active) E0029 expected an expression KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1428
Error (active) E0020 identifier "baseAddress" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1433
Error (active) E0020 identifier "writeData" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1434
Error (active) E0029 expected an expression KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1447
Error (active) E0065 expected a ';' KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1448
Error (active) E0020 identifier "uProcessImageName" is undefined KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1461
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1463
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1469
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1505
Error (active) E0169 expected a declaration KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1512
Error (active) E0137 expression must be a modifiable lvalue KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1527
Error (active) E0119 cast to type "EXSUBSCRIBEWNFSTATECHANGE" (aka "long (PVOID Subscription, ULONG64 StateName, ULONG ChangeStamp, PVOID Callback, PVOID CallbackContext, PVOID TypeId, ULONG SerializationGroup, ULONG Unknown)") is not allowed KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1527
Error (active) E0137 expression must be a modifiable lvalue KMDF Driver1 C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 1535
Warning VCR001 Function definition for 'ReadPhysicalAddress' not found. C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 95
Warning VCR001 Function definition for 'ReadVirtualMemory' not found. C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 102
Warning VCR001 Function definition for 'WriteVirtualMemory' not found. C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 103
Warning VCR001 Function definition for 'ReadProcessMemoryInternal' not found. C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 106
Warning VCR001 Function definition for 'EncodeBase64' not found. C:\Users\ruth_\source\repos\KMDF Driver1\KMDF Driver1\Driver.c 124
It seems you're encountering several compilation errors in your driver code, many of which are related to undefined identifiers and syntax issues. Below, I'll address the main problems and provide guidance on how to resolve them.
1. Undefined Types (BYTE, DWORD, uint64_t, etc.)
Problem:
You're using types like BYTE, DWORD, and uint64_t which are not defined in your driver code. This leads to errors like:
code
identifier "BYTE" is undefined
identifier "DWORD" is undefined
identifier "uint64_t" is undefined
Solution:
In Windows kernel-mode drivers, you should use the types defined in the Windows Driver Kit (WDK). Instead of BYTE, DWORD, and uint64_t, you should use:
BYTE → UCHAR
WORD → USHORT
DWORD → ULONG
QWORD or uint64_t → ULONG64 or ULONGLONG
Action:
Replace all instances of BYTE with UCHAR.
Replace all instances of WORD with USHORT.
Replace all instances of DWORD with ULONG.
Replace all instances of uint64_t and QWORD with ULONG64 or ULONGLONG.
Remove the line typedef unsigned __int64 QWORD; as it's no longer needed.
Example:
c
// Replace
typedef unsigned __int64 QWORD;
// With
typedef ULONGLONG QWORD; // If you still need QWORD
However, it's better to use ULONGLONG directly.
2. Incorrect Definition of Pointer Types
Problem:
Your definition of PINSTRUCTIONS is incorrect. You're defining it as a structure, not as a pointer to the structure. This causes errors like:
code
operator -> or ->* applied to "PINSTRUCTIONS" instead of to a pointer type
Solution:
You need to define PINSTRUCTIONS as a pointer to INSTRUCTIONS.
Action:
Modify the typedef for PINSTRUCTIONS to include the asterisk *.
Example:
c
typedef struct _INSTRUCTIONS {
// ... your structure members ...
} INSTRUCTIONS, *PINSTRUCTIONS;
3. Duplicate Function Definitions
Problem:
You have multiple definitions of functions like OnWnfCallback, SubscribeToWNF, and others. This leads to errors because you cannot have multiple definitions of the same function.
Solution:
Remove duplicate definitions and keep only one definition for each function.
Action:
Go through your code and locate duplicate function definitions.
Remove the duplicates, ensuring you keep the most complete and correct version of each function.
4. Mismatched Function Declarations and Definitions
Problem:
The function declarations (prototypes) and definitions have mismatched parameters or incorrect parameter types.
Solution:
Ensure that the function declarations match the definitions exactly in terms of parameter types and calling conventions.
There are several places in your code where comments are incorrectly used, causing syntax errors.
For example:
c
// Example: Write to process memory (commented out for safety)
/*
BYTE writeData[256] = { /* Your data here * / };
SIZE_T bytesWritten = 0;
// ... rest of the code ...
*/
The nested /* and */ within the commented block cause issues.
Solution:
Avoid nesting /* */ comments. Instead, use // for inner comments.
Action:
Correct the comment syntax.
Use // for single-line comments within a /* */ block, or restructure the comments.
Example:
c
/*
BYTE writeData[256] = { /* Your data here */ };
SIZE_T bytesWritten = 0;
// ... rest of the code ...
*/
Alternatively, you can do:
c
// Example: Write to process memory (commented out for safety)
// BYTE writeData[256] = { /* Your data here */ };
// SIZE_T bytesWritten = 0;
// ... rest of the code ...
6. Missing Includes for Standard Types
Problem:
Standard integer types like uint64_t are not defined because <stdint.h> is not included.
Solution:
Include the header <stdint.h>. However, in kernel-mode drivers, it's recommended to use WDK-provided types.
Action:
Replace uint64_t with UINT64 or ULONGLONG.
Example:
c
// Replace
uint64_t variableName;
// With
UINT64 variableName;
// or
ULONGLONG variableName;
7. Incorrect Usage of Strings and Character Literals
Problem:
You're assigning strings to CHAR variables and using single quotes for strings, which is incorrect.
Correct the definition of PINSTRUCTIONS to be a pointer (*PINSTRUCTIONS).
Remove duplicate function definitions.
Ensure function declarations and definitions match.
Fix comment syntax errors.
Correct variable declarations and ensure proper casting.
Review the code for any syntax errors due to typos or incorrect copy-pasting.
Additional Tips
Use Proper Headers: Ensure all necessary headers are included. For kernel-mode drivers, include headers like ntifs.h, ntddk.h, and others as needed.
Follow WDK Guidelines: Kernel-mode programming has specific requirements. Always refer to the WDK documentation for proper function usage and coding practices.
Testing and Debugging: After making changes, compile the code incrementally to identify and fix errors step by step.
Example Correction
Here's a snippet of your code with some corrections applied:
c
#include <ntifs.h>
#include <ntddk.h>
// ==========================================================
// Definitions and Macros
// ==========================================================
#define TARGET_PROCESS_NAME L"notepad.exe" // Replace with your target process name
#define MY_WNF_STATE_NAME 0x41C64E6DA3BC1074ULL // Example WNF State Name (WNF_AUDC_CAPTURE)
// Windows Build Numbers
#define WINDOWS_1803 17134
#define WINDOWS_1809 17763
#define WINDOWS_1903 18362
#define WINDOWS_1909 18363
#define WINDOWS_2004 19041
#define WINDOWS_20H2 19042
#define WINDOWS_21H1 19043
#define WINDOWS_22H2 19044
// Page size definitions
#define PAGE_OFFSET_SIZE 12
#define PAGE_SIZE 0x1000
#define PMASK (~0xFFFULL)
// ==========================================================
// Function Pointer Types for WNF (Undocumented APIs)
// ==========================================================
typedef NTSTATUS(EXSUBSCRIBEWNFSTATECHANGE)(
PVOID Subscription,
ULONG64 StateName,
ULONG ChangeStamp,
PVOID Callback,
PVOID CallbackContext,
PVOID TypeId,
ULONG SerializationGroup,
ULONG Unknown
);
typedef NTSTATUS(EXPUBLISHWNFSTATEDATA)(
ULONG64 StateName,
PVOID Buffer,
ULONG Length,
PVOID TypeId,
PVOID ExplicitScope,
ULONG MatchingChangeStamp
);
typedef NTSTATUS(EXUNSUBSCRIBEWNFSTATECHANGE)(
PVOID Subscription
);
// ==========================================================
// Global Function Pointers for WNF
// ==========================================================
EXSUBSCRIBEWNFSTATECHANGE* ExSubscribeWnfStateChange = NULL;
EXPUBLISHWNFSTATEDATA* ExPublishWnfStateData = NULL;
EXUNSUBSCRIBEWNFSTATECHANGE* ExUnsubscribeWnfStateChange = NULL;
ULONG64 MY_WNF_STATE_NAME_VALUE = MY_WNF_STATE_NAME; // Ensure consistency
PVOID g_WnfSubscription = NULL; // Global WNF subscription handle
// ==========================================================
// Structures
// ==========================================================
#pragma pack(push, 1)
typedef struct _INSTRUCTIONS {
UCHAR close; // Flag to close subscription
UCHAR read; // Flag to perform read operation
UCHAR write; // Flag to perform write operation
UCHAR reqBase; // Flag to request base address
UINT64 processId; // Target process ID
UINT64 address; // Target virtual address
UINT64 size; // Size of read/write
PVOID bufferAddress; // Buffer address in user-mode
PVOID output; // Output buffer (for read operations)
UINT64 baseAddress; // Base address (for base address requests)
CHAR moduleName[256]; // Module name (if needed)
UCHAR data[1024]; // Data buffer for read/write
} INSTRUCTIONS, *PINSTRUCTIONS;
#pragma pack(pop)
// ... rest of your code with corrections applied ...
Conclusion
By addressing the points above and carefully revising your code, you should be able to resolve the compilation errors. Remember to consult the WDK documentation for any uncertainties, and consider using sample driver code from the WDK as a reference for correct coding practices in kernel-mode drivers.