create handle function
vxcall opened this issue · 0 comments
vxcall commented
in init function,
- it needs opening device handle by NtOpenFile
// L"\\Device\\echo", GENERIC_READ | GENERIC_WRITE
auto retrieve_device_handle(std::wstring device_name, ACCESS_MASK access_mask) -> PHANDLE
{
NTSTATUS status;
HANDLE device_handle;
OBJECT_ATTRIBUTES obj_attr;
UNICODE_STRING uni_device_name;
IO_STATUS_BLOCK io_status_block;
RtlInitUnicodeString(&uni_device_name, device_name);
InitializeObjectAttributes(&obj_attr, &uni_device_name,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
ACCESS_MASK access_mask = ;
ULONG share_access = 0;
ULONG open_options = 0;
status = NtOpenFile(&device_handle,
access_mask,
&obj_attr,
&io_status_block,
share_access,
open_options);
if (!NT_SUCCESS(status)) {
std::cerr << "Failed to open handle. Status code: " << std::hex << status << std::endl;
return nullptr;
}
// This handle has to be closed with CloseHandle(device_handle);
return device_handle;
}