1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/*创建和打开文件 by exchen 2009-10-03 */ #include <ntddk.h> VOID DriverUnload( IN PDRIVER_OBJECT DriverObject ) { DbgPrint("驱动已经被停止了\n"); } NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { OBJECT_ATTRIBUTES obj; NTSTATUS status; HANDLE hFile = NULL; IO_STATUS_BLOCK ioStatus; UNICODE_STRING usPath = RTL_CONSTANT_STRING(L"\\??\\C:\\1.txt"); InitializeObjectAttributes(&obj, &usPath, OBJ_KERNEL_HANDLE, NULL, NULL); status = ZwCreateFile(&hFile, GENERIC_ALL, &obj, &ioStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN_IF, FILE_NON_DIRECTORY_FILE, NULL, 0); if (status == STATUS_SUCCESS) { DbgPrint("创建文件成功\n"); } else { DbgPrint("创建文件失败\n"); } ZwClose(hFile); DriverObject->DriverUnload = DriverUnload; return STATUS_SUCCESS; } |
转载请注明:exchen's blog » 在驱动程序中创建和打开文件