I need to use the driver and have it read information from a text file periodically. Being new to drivers I thought it would be great to start with strings.
What I cannot understand is how to actually compile the following code in WinDDK. I can do a simple Hello world but..
Is there a way to read a line of text from a text file, and output it to the dbg console.
Am I doing something wrong in this code? Any help would be most appreciated.
What I cannot understand is how to actually compile the following code in WinDDK. I can do a simple Hello world but..
Is there a way to read a line of text from a text file, and output it to the dbg console.
Am I doing something wrong in this code? Any help would be most appreciated.
Code: Select all
#include <ntddk.h>
//1.Path information
UNICODE_STRING uniName;
OBJECT_ATTRIBUTES objAttr;
//Path
RtlInitUnicodeString(&uniName, L"\\SystemRoot\\example.txt")); // or L"\\SystemRoot\\example.txt"
InitializeObjectAttributes(&objAttr, &uniName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL, NULL);
//
//2.Obtain file handle From 1.
HANDLE handle;
NTSTATUS ntstatus;
IO_STATUS_BLOCK ioStatusBlock;
if(KeGetCurrentIrql() != PASSIVE_LEVEL)
return STATUS_INVALID_DEVICE_STATE;
ntstatus = ZwCreateFile(&handle,
GENERIC_WRITE,
&objAttr, &ioStatusBlock, NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OVERWRITE_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
//
//3. Load the buffer (ie. contents of text file to the console)
LARGE_INTEGER byteOffset;
ntstatus = ZwCreateFile(&handle,
GENERIC_READ,
&objAttr, &ioStatusBlock,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL, 0);
if(NT_SUCCESS(ntstatus)) {
byteOffset.LowPart = byteOffset.HighPart = 0;
ntstatus = ZwReadFile(handle, NULL, NULL, NULL, &ioStatusBlock,
buffer, BUFFER_SIZE, &byteOffset, NULL);
if(NT_SUCCESS(ntstatus)) {
buffer[BUFFER_SIZE-1] = '\0';
DbgPrint("%s\n", buffer);
}
ZwClose(handle);
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{ //Driver entry <--am I supposed to put some of the code above into this area? Or are they supposed to be outside of it?
//DbgPrint("Hello World\n");
return STATUS_SUCCESS;
}