Я пишу очень простой драйвер ядра, который хранит строку Юникода в качестве глобальной переменной, а затем просто отображает строку, которую вы передаете в нее.
Вот скриншот DebugView
![debugview](https://i.stack.imgur.com/EjpRg.png)
Прогон 2 ![debugview2](https://i.stack.imgur.com/eYFLi.png)
Вот мой код
UNICODE_STRING ProcessName;
//...
PIO_STACK_LOCATION irpSp;// Pointer to current stack location
irpSp = IoGetCurrentIrpStackLocation(Irp);
ULONG inBufLength = irpSp->Parameters.DeviceIoControl.InputBufferLength; // Input buffer length
ULONG outBufLength = irpSp->Parameters.DeviceIoControl.OutputBufferLength; // Output buffer length
DbgPrintEx(0, 0, "Size: %lu %lu \n", inBufLength, outBufLength);
if (inBufLength == 0) {
Status = STATUS_INVALID_PARAMETER;
BytesIO = 0;
goto finish;
}
PWSTR processBuffer;
// Allocate the buffer that will contain the string
processBuffer =ExAllocatePoolWithTag(NonPagedPool, irpSp->Parameters.DeviceIoControl.InputBufferLength+2, '5PWA');
if(processBuffer == NULL){
DbgPrint("Unable to allocate the dump filename: not enough memory.\n");
Status = STATUS_INSUFFICIENT_RESOURCES;
BytesIO = 0;
goto finish;
}
DbgPrint("Before New Process to %ws, len=%d\n", Irp->AssociatedIrp.SystemBuffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
// Copy the buffer
RtlCopyBytes((PVOID)processBuffer, Irp->AssociatedIrp.SystemBuffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
DbgPrint("Set New Process to 1=%d\n", processBuffer[0]);
DbgPrint("Set New Process to 2=%d\n", processBuffer[1]);
DbgPrint("Set New Process to 3=%d\n", processBuffer[2]);
DbgPrint("Set New Process to 4=%d\n", processBuffer[3]);
DbgPrint("Set New Process to 5=%d\n", processBuffer[4]);
DbgPrint("Set New Process to 6=%d\n", processBuffer[5]);
// Force a \0 at the end of the filename to avoid that malformed strings cause RtlInitUnicodeString to crash the system
((PSHORT)processBuffer)[(irpSp->Parameters.DeviceIoControl.InputBufferLength+2)/2-1]=0;
DbgPrint("After NULL New Process to %ws, len=%d\n", processBuffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
// Create the unicode string
RtlInitUnicodeString(&ProcessName, processBuffer);
ExFreePool(processBuffer);
UNICODE_STRING test;
RtlInitUnicodeString(&test, L"test123");
DbgPrint("test is %ws\n", test.Buffer);
RtlInitUnicodeString(&test, L"test123");
DbgPrint("test2 is %ws\n", test.Buffer);
DbgPrint("Set New Process to 1=%d\n", ProcessName.Buffer[0]);
DbgPrint("Set New Process to 2=%d\n", ProcessName.Buffer[1]);
DbgPrint("Set New Process to 3=%d\n", ProcessName.Buffer[2]);
DbgPrint("Set New Process to 4=%d\n", ProcessName.Buffer[3]);
DbgPrint("Set New Process to 5=%d\n", ProcessName.Buffer[4]);
DbgPrint("Set New Process to 6=%d\n", ProcessName.Buffer[5]);
DbgPrint("Set New Process to %ws, len=%d\n", ProcessName.Buffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
Status = STATUS_SUCCESS;
BytesIO = 0;