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
| #include <iostream> #include <windows.h> #include "Winternl.h"
NTSTATUS(WINAPI *pNtCreateFile)(PHANDLE FileHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock, PVOID AllocationSize, ULONG FileAttributes, ULONG ShareAccess, ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength);
VOID(WINAPI *pRtlInitUnicodeString)(PUNICODE_STRING DestinationString, PCWSTR SourceString);
int main() { HANDLE pFile; wchar_t path[] = L"\\??\\H:\\script\\test.txt";
*(FARPROC *)&pRtlInitUnicodeString = GetProcAddress(GetModuleHandle(L"ntdll"), "RtlInitUnicodeString");
*(FARPROC *)&pNtCreateFile = GetProcAddress(GetModuleHandle(L"ntdll"), "NtCreateFile");
UNICODE_STRING file_fname; pRtlInitUnicodeString(&file_fname, path);
OBJECT_ATTRIBUTES obj_file; InitializeObjectAttributes(&obj_file, &file_fname, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
HANDLE file_handle; IO_STATUS_BLOCK io_file; NTSTATUS ret = pNtCreateFile(&file_handle, GENERIC_WRITE, &obj_file, &io_file, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_WRITE, FILE_SUPERSEDE, FILE_NON_DIRECTORY_FILE, NULL, 0);
std::cout << "Hello World!\n"; }
|