I am trying to communicate with IOCTL from user mode to a driver.
I have successfully able to send DWORDS from my driver. But I was also willing to have PUCHAR strings from there… This is the driver code i am using :
dwCount is a DWORD that specifies the index to write in PNAME
DWORD dwCount;char PNAME[250][40];.............................int copystr(PUCHAR astring){ for(i=0;(char)astring[i]!=0;i++) RtlCopyBytes(&PNAME[dwCount-1][i],&astring[i],sizeof(PNAME[dwCount-1][i])); PNAME[dwCount-1][i]=0; //DbgPrint("%s",PNAME[dwCount-1]); return 1;}.................................
Is there something that i m missing???
MoreOver ,when i DbgPrint the PNAME[dwCount-1] as %s … it gives me invalid strings mostly NULL.
But the interesting part is that if this function is called from DriverEntry routine rather than the DriverDispatcher… the Same DbgPrint Statement gives me the correct output…
I dont think there is a problem with my DriverDispatcher Function But neways here it is:
NTSTATUS DriverDispatcher(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp )
{
PVOID inputBuffer;
PVOID outputBuffer;
ULONG inputBufferLength;
ULONG outputBufferLength;
int i;
ULONG ioControlCode;
NTSTATUS status;
PIO_STACK_LOCATION irpStack;
UNREFERENCED_PARAMETER( DeviceObject );
irpStack = IoGetCurrentIrpStackLocation( Irp );
inputBuffer = Irp->AssociatedIrp.SystemBuffer;
inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;
outputBuffer = Irp->AssociatedIrp.SystemBuffer;
outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
ioControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;
switch (irpStack->MajorFunction)
{
case IRP_MJ_DEVICE_CONTROL:
switch (ioControlCode)
{
case IOCTL_PID: //This the IOCTL which returns DWORDS and runs perfect
EnumProcessList();
if(outputBufferLength>dwCount*4)
{
RtlCopyMemory(outputBuffer, PID,dwCount*4);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = dwCount*4;
}
else
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
break;
case IOCTL_PNAME: //This is the IOCTL that handles the PUCHAR and is a problem
for(i=0;i<16;i++)
{
DbgPrint(“%s”,PNAME[i]);
}
if(outputBufferLength>dwCount*40)
{
RtlCopyMemory(outputBuffer, PNAME,sizeof(UCHAR)*250*40);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = sizeof(UCHAR)*250*40;
}
else
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
break;
}
break;
}
status = Irp->IoStatus.Status;
IoCompleteRequest( Irp, 0 );
return status;
}
I am kinda stuck please help…
Thanx in advance…