Hi, i?m developing a filter driver to capture the main audio stream, i have attached successfuly to the main device(a realtek device), i?m capture some irps in deviceiocontrol routine, but i can?t read the main stream(all the buffer?s are empty), and the read/write routine are never called by the application(like windows media player) while it?s sending the audio to sound card.
I will need to access the dma to get the stream?
To get access to dma i will need to use the StartIo routine? and a inf file to PnP Manager start?s this routine?
I tried to use the flags FILE_DEVICE_SOUND, FILE_DEVICE_KS and FILE_DEVICE_WAVE_OUT, but none worked.
My driver doesn?t have a inf file, i?m loading and attaching the device to device stack in DriveEntry function.
That?s my DriveEntry routine:
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
UNICODE_STRING DeviceName, Win32Device;
PDEVICE_OBJECT DeviceObject = NULL;
NTSTATUS status;
UNICODE_STRING DeviceNameDest;
PDEVICE_OBJECT pTargetDeviceObj;
PFILE_OBJECT pFileObj;
PDEVICE_EXTENSION pDeviceExt = NULL;
RtlInitUnicodeString(&DeviceName,L"\Device\FilterAudioTest");
RtlInitUnicodeString(&Win32Device,L"\DosDevices\FilterAudioTest");
for(unsigned int fcount = 0; fcount < IRP_MJ_MAXIMUM_FUNCTION; ++fcount){
DriverObject->MajorFunction[fcount] = OnDispatch;
}
DriverObject->MajorFunction[IRP_MJ_CREATE] = OnCreate;
DriverObject->MajorFunction[IRP_MJ_READ] = OnRead;
DriverObject->MajorFunction[IRP_MJ_WRITE] = OnWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceIOControl;
DriverObject->DriverUnload = OnUnload;
DriverObject->DriverStartIo = OnStartIo;
PWSTR devicelist = NULL;
CHAR convertida[1024];
status = IoGetDeviceInterfaces(&GUID_DEVINTERFACE_SOUND, NULL, 0, &devicelist);
if(!NT_SUCCESS(status)){
DbgPrint(“Audio - Erro ao buscar interfaces\n”);
}
if(!devicelist){
DbgPrint(“Audio - Erro lista nula\n”);
}
else{
DbgPrint(“Audio - Lista\n”);
RtlZeroMemory(convertida, sizeof(convertida));
wcstombs(convertida, devicelist, sizeof(convertida));
DbgPrint(“%s\n”, convertida);
RtlInitUnicodeString(&DeviceNameDest, devicelist);
status = IoGetDeviceObjectPointer(&DeviceNameDest,
FILE_CHARACTERISTICS_PROPAGATED,
&pFileObj,
&pTargetDeviceObj);
if (!NT_SUCCESS(status)){
DbgPrint(“Audio - Erro ao buscar o device de destino\n”);
}
else{
DbgPrint(“ptr\n”);
}
if(pFileObj){
DbgPrint(“FO %p\n”, pFileObj);
}
else{
DbgPrint(“FO - Erro\n”);
}
if(pTargetDeviceObj){
DbgPrint(“DO %p\n”, pTargetDeviceObj);
}
else{
DbgPrint(“DO - Erro\n”);
}
}
DbgPrint(“Criando device\n”);
//Cria o nosso device
status = IoCreateDevice(DriverObject,
sizeof(DEVICE_EXTENSION),
&DeviceName,
//pTargetDeviceObj->DeviceType,
FILE_DEVICE_SOUND,
//FILE_DEVICE_KS,
//FILE_DEVICE_WAVE_OUT,
//pTargetDeviceObj->Characteristics,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(status))
{
DbgPrint(“Erro ao criar device %d\n”, status);
ObDereferenceObject(pFileObj);
return status;
}
DbgPrint(“Criou device\n”);
//-f–> Cria o symbolic link para que aplica??es possam
// obter um handle para este device.
status = IoCreateSymbolicLink(&Win32Device,
&DeviceName);
if (!NT_SUCCESS(status))
{
//-f–> Ops!
DbgPrint(“Audio - Erro criar link\n”);
//IoDeleteDevice(DeviceObject);
}
else{
DbgPrint(“Audio - link criado\n”);
}
//IoGetRelatedDeviceObject
//pTargetDeviceObj = IoGetRelatedDeviceObject(DriverObject->
//-f–> Obtem nosso DEVICE_EXTENSION
pDeviceExt = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
pDeviceExt->LowerDeviceObject = NULL;
pDeviceExt->next = NULL;
pDeviceExt->last = NULL;
pDeviceExt->count = 0;
KeInitializeMutex(&pDeviceExt->kListMutex, 0);
//NtStatus = KeWaitForMutexObject(&pExampleDeviceContext->kListMutex, Executive, KernelMode, FALSE, NULL);
//KeReleaseMutex(&pExampleDeviceContext->kListMutex, FALSE);
//-f–> Utiliza o mesmo m?todo de IO do driver original
//DeviceObject->Flags |= pTargetDeviceObj->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO);
DeviceObject->Flags |= pTargetDeviceObj->Flags | DRVO_LEGACY_RESOURCES | DO_MAP_IO_BUFFER | DO_DIRECT_IO;
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
DbgPrint(“Atachando\n”);
//Aqui nosso driver entra na pilha de dispositivos
status = IoAttachDeviceToDeviceStackSafe(DeviceObject,
pTargetDeviceObj,
&pDeviceExt->LowerDeviceObject);
if (!NT_SUCCESS(status))
{
DbgPrint(“Erro ao atachar %d\n”, status);
IoDeleteDevice(DeviceObject);
}
else{
DbgPrint(“Atachou com sucesso\n”);
}
if(pDeviceExt->LowerDeviceObject){
DbgPrint(“Audio - Lower Device %p\n”, pDeviceExt->LowerDeviceObject);
}
else{
DbgPrint(“Audio - Lower Device NULL\n”);
}
DbgPrint(“IoCallDriver\n”);
ObDereferenceObject(pFileObj);
return status;
}
Thanks.