windows driver 写数据到txt

HANDLE hFile;
	OBJECT_ATTRIBUTES oa;
	IO_STATUS_BLOCK iosb;
	LARGE_INTEGER li;

	UNICODE_STRING strPath = RTL_CONSTANT_STRING(L"\\??\\E:\\123.txt");
	UNICODE_STRING str = RTL_CONSTANT_STRING(L"我爱你");

	char strWriteInfo[ArrayLength] = {0};
	ANSI_STRING sWrite;

	InitializeObjectAttributes(&oa, &strPath, OBJ_KERNEL_HANDLE, NULL, NULL);
	ZwCreateFile(&hFile,
		GENERIC_READ | GENERIC_WRITE,
		&oa,
		&iosb,
		NULL, 
		FILE_ATTRIBUTE_NORMAL,
		FILE_SHARE_READ,
		FILE_OPEN,
		FILE_SYNCHRONOUS_IO_NONALERT,
		NULL,
		0);

	li.HighPart = -1;
	li.LowPart = FILE_WRITE_TO_END_OF_FILE;

	RtlInitEmptyAnsiString(&sWrite, strWriteInfo, ArrayLength);
	RtlUnicodeStringToAnsiString(&sWrite, &str, TRUE);
	ZwWriteFile(hFile, NULL, NULL, NULL, &iosb, sWrite.Buffer, sWrite.Length, &li, NULL);
	ZwClose(hFile);

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

posted @ 2014-11-13 20:18  QQ76211822  阅读(197)  评论(0编辑  收藏  举报