hi everyone ,
i was trying for the last month to write a network driver that intercept
incoming (compressed) data, uncompress it and forward it, but without any
result. Does anyone have a suggestion ? is there a lot of work to do ?
here is a portion of code i wrote :
NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObjectNetwork,
IN PUNICODE_STRING RegistryPath )
{
NTSTATUS status = STATUS_SUCCESS;
UINT uindex = 0;
UNICODE_STRING usDriverName, usDosDeviceName, deviceObjectNetworkName;
DbgPrint(“DriverEntry Called \r\n”);
RtlInitUnicodeString(&usDriverName, L"\Device\networkTest");
RtlInitUnicodeString(&usDosDeviceName, L"\DosDevices\networkTest");
status = IoCreateDevice(pDriverObjectNetwork,
sizeof(DEVICE_EXTENSION),
&usDriverName,
FILE_DEVICE_NETWORK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&pDeviceObjectNetwork
);
if (!NT_SUCCESS(status))
return status;
for(uindex = 0; uindex < IRP_MJ_MAXIMUM_FUNCTION; uindex++)
pDriverObjectNetwork->MajorFunction[uindex] = PassThrough;
pDriverObjectNetwork->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
OnDeviceControl;
pDriverObjectNetwork->DriverUnload =
OnUnload;
pDeviceObjectNetwork->Flags = pDeviceObjectNetwork->Flags
| DO_DIRECT_IO;
pDeviceObjectNetwork->Flags = pDeviceObjectNetwork->Flags
& ~DO_DEVICE_INITIALIZING;
RtlZeroMemory(pDeviceObjectNetwork->DeviceExtension,
sizeof(DEVICE_EXTENSION));
pDeviceExtensionNetwork
=(PDEVICE_EXTENSION)(pDeviceObjectNetwork->DeviceExtension) ;
if (!pDeviceExtensionNetwork){
DbgPrint(“et merde… l’extension”);
return 1;
}
RtlInitUnicodeString(&deviceObjectNetworkName, L"\Device\Tcp");
status = IoAttachDevice(pDeviceObjectNetwork,
&deviceObjectNetworkName,
&pDeviceExtensionNetwork->pNetworkDevice
);
if (!pDeviceExtensionNetwork->pNetworkDevice){
OnUnload(pDriverObjectNetwork);
return 1;
}
IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
return STATUS_SUCCESS;
}
***********************
NTSTATUS OnDeviceControl(IN PDEVICE_OBJECT DeviceObject,
IN PIRP pIRP
)
{
IoCopyCurrentIrpStackLocationToNext(pIRP);
IoSetCompletionRoutine(pIRP,
OnReadCompletion,
DeviceObject,
TRUE,
TRUE,
TRUE
);
return IoCallDriver(
((PDEVICE_EXTENSION)
pDeviceObjectNetwork->DeviceExtension)->pNetworkDevice, pIRP);
}
************************
NTSTATUS OnReadCompletion(IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIRP, IN PVOID Context
)
{
DbgPrint(“OnReadCompletion called … %d”,
compteur
);
compteur+=pIRP->IoStatus.Information;
if(pIRP->PendingReturned)
IoMarkIrpPending(pIRP);
return pIRP->IoStatus.Status;
}
**************************
void OnUnload (IN PDRIVER_OBJECT pDriverObject){
DbgPrint(“Deleting symbolic link …”);
IoDeleteSymbolicLink(&usDosDeviceName);
DbgPrint(“Detaching device …”);
IoDetachDevice(pDeviceExtensionNetwork->pNetworkDevice);
DbgPrint(“Deleting device …”);
IoDeleteDevice(pDriverObject->DeviceObject);
RtlFreeUnicodeString(&deviceObjectNetworkName);
RtlFreeUnicodeString(&usDriverName);
RtlFreeUnicodeString(&usDosDeviceName);
}
every time i load my driver, i got some output on dbgview’s screen, but
always smaller than the real size of the page (sometimes much smaller), and
when i unload it i get a BSoD.
please help.
thanx
PS: sorry for my poor english.