I am new to kernel driver development and I know very little about audio drivers and related knowledge.
Now I have a work item to develop a filter driver to intercept the microphone data and modify it.
I used KMDF to implement a demo. Specifically, I called WdfDeviceInitSetIoInCallerContextCallback
to register a callback function and output some instructions in the callback function. The code is as follows:
VOID AudioFilterIoInCallerContext(_In_ WDFDEVICE Device, _In_ WDFREQUEST Request)
{
NTSTATUS status;
WDF_REQUEST_PARAMETERS params;
WDF_REQUEST_PARAMETERS_INIT(¶ms);
WdfRequestGetParameters(Request, ¶ms);
if (params.Type == WdfRequestTypeDeviceControl)
{
//IOCTL_KS_PROPERTY 3080195
//IOCTL_KS_ENABLE_EVENT 3080199
//IOCTL_KS_DISABLE_EVENT 3080203
//IOCTL_KS_METHOD 3080207
//IOCTL_KS_WRITE_STREAM 3112979
//IOCTL_KS_READ_STREAM 3096599
//IOCTL_KS_RESET_STATE 3080219
size_t inLen = params.Parameters.DeviceIoControl.InputBufferLength;
size_t ouLen = params.Parameters.DeviceIoControl.OutputBufferLength;
PVOID t3Ptr = params.Parameters.DeviceIoControl.Type3InputBuffer;
ULONG ctlCode = params.Parameters.DeviceIoControl.IoControlCode;
if (ctlCode == 3096599)
{
PIRP pIRP = WdfRequestWdmGetIrp(Request);
DbgPrint("[MH]IORD: %lu, IL: %llu, OL: %llu, IP: 0x%p, UP: 0x%p, SP: 0x%p\n", ctlCode, inLen, ouLen, t3Ptr, pIRP->UserBuffer, pIRP->AssociatedIrp.SystemBuffer);
}
else if (ctlCode == 3112979)
{
PIRP pIRP = WdfRequestWdmGetIrp(Request);
DbgPrint("[MH]IOWT: %lu, IL: %llu, OL: %llu, IP: 0x%p, UP: 0x%p, SP: 0x%p\n", ctlCode, inLen, ouLen, t3Ptr, pIRP->UserBuffer, pIRP->AssociatedIrp.SystemBuffer);
}
else
{
DbgPrint("[MH]IOCTL: %lu, IL: %llu, OL: %llu, IP:0x%p\n", ctlCode, inLen, ouLen, t3Ptr);
}
}
else
{
DbgPrint("[MH]IRP, type: %d, func: %lu\n", params.Type, params.MinorFunction);
}
status = WdfDeviceEnqueueRequest(Device, Request);
if (!NT_SUCCESS(status))
{
DbgPrint("[MH]WdfDeviceEnqueueRequest failed with status code 0x%08X\n", status);
WdfRequestComplete(Request, status);
}
}
I then installed the driver as an upper filter driver in the device's registry entry.
HKLM\SYSTEM\CurrentControlSet\Enum\HDAUDIO\FUNC_01&VEN_15AD&DEV_1975&SUBSYS_15AD1975&REV_1001\5&217be3d6&0&0001
UpperFilters
I thought that when I play music, the callback function should be triggered and output IOCTL_KS_WRITE_STREAM
continuously, but in fact it is not, only the output of individual IOCTL_KS_PROPERTY
instructions.
I don't know where the problem is, and Microsoft doesn't seem to have any official documents to refer to.
My system: Windows 11 Pro x64 Build 22621
Request help, thanks.