// Copyright (c) Microsoft Corporation.// Licensed under the MIT license.#include "precomp.h"#include "DeviceHandle.h"#include "WinNTControl.h"#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020/*++Routine Description:- This routine creates a handle to an input or output client of the givenserver. No control io is sent to the server as this request must be comingfrom the server itself.Arguments:- Handle - Receives a handle to the new client.- ServerHandle - Supplies a handle to the server to which to attach thenewly created client.- Name - Supplies the name of the client object.- Inheritable - Supplies a flag indicating if the handle must be inheritable.Return Value:- NTSTATUS indicating if the client was successfully created.--*/[[nodiscard]]NTSTATUSDeviceHandle::CreateClientHandle(_Out_ PHANDLE Handle,_In_ HANDLE ServerHandle,_In_ PCWSTR Name,_In_ BOOLEAN Inheritable){return _CreateHandle(Handle,Name,GENERIC_WRITE | GENERIC_READ | SYNCHRONIZE,ServerHandle,Inheritable,FILE_SYNCHRONOUS_IO_NONALERT);}/*++Routine Description:- This routine creates a new server on the driver and returns a handle to it.Arguments:- Handle - Receives a handle to the new server.- Inheritable - Supplies a flag indicating if the handle must be inheritable.Return Value:- NTSTATUS indicating if the console was successfully created.--*/[[nodiscard]]NTSTATUSDeviceHandle::CreateServerHandle(_Out_ PHANDLE Handle,_In_ BOOLEAN Inheritable){return _CreateHandle(Handle,L"\\Device\\ConDrv\\Server",GENERIC_ALL,NULL,Inheritable,0);}/*++Routine Description:- This routine opens a handle to the console driver.Arguments:- Handle - Receives the handle.- DeviceName - Supplies the name to be used to open the console driver.- DesiredAccess - Supplies the desired access mask.- Parent - Optionally supplies the parent object.- Inheritable - Supplies a boolean indicating if the new handle is to be made inheritable.- OpenOptions - Supplies the open options to be passed to NtOpenFile. A commonoption for clients is FILE_SYNCHRONOUS_IO_NONALERT, to make the handlesynchronous.Return Value:- NTSTATUS indicating if the handle was successfully created.--*/[[nodiscard]]NTSTATUSDeviceHandle::_CreateHandle(_Out_ PHANDLE Handle,_In_ PCWSTR DeviceName,_In_ ACCESS_MASK DesiredAccess,_In_opt_ HANDLE Parent,_In_ BOOLEAN Inheritable,_In_ ULONG OpenOptions){ULONG Flags = OBJ_CASE_INSENSITIVE;if (Inheritable){WI_SetFlag(Flags, OBJ_INHERIT);}UNICODE_STRING Name;Name.Buffer = (wchar_t*)DeviceName;Name.Length = (USHORT)(wcslen(DeviceName) * sizeof(wchar_t));Name.MaximumLength = Name.Length + sizeof(wchar_t);OBJECT_ATTRIBUTES ObjectAttributes;InitializeObjectAttributes(&ObjectAttributes,&Name,Flags,Parent,NULL);IO_STATUS_BLOCK IoStatus;return WinNTControl::NtOpenFile(Handle,DesiredAccess,&ObjectAttributes,&IoStatus,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,OpenOptions);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。