d711d731d7
## Summary of the Pull Request - Enables auditing of some Terminal libraries (Connection, Core, Settings) - Also audit WinConPTY.LIB since Connection depends on it ## PR Checklist * [x] Rolls audit out to more things * [x] I work here * [x] Tests should still pass * [x] Am core contributor ## Detailed Description of the Pull Request / Additional comments This is turning on the auditing of these projects (as enabled by the heavier lifting in the other refactor) and then cleaning up the remaining warnings. ## Validation Steps Performed - [x] Built it - [x] Ran the tests
52 lines
2.2 KiB
C++
52 lines
2.2 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "precomp.h"
|
|
#include "WinNTControl.h"
|
|
|
|
// Routine Description:
|
|
// - Creates an instance of the NTDLL method-invoking class.
|
|
// - This class helps maintain a loose coupling on NTDLL without reliance on the driver kit headers/libs.
|
|
#pragma warning(suppress : 26490) // reinterpret_cast is prohibited but it's way more steps to make it happy
|
|
#pragma warning(suppress : 26455) // Default constructors cannot throw, but passing the library in is clumsy.
|
|
WinNTControl::WinNTControl() :
|
|
// NOTE: Use LoadLibraryExW with LOAD_LIBRARY_SEARCH_SYSTEM32 flag below to avoid unneeded directory traversal.
|
|
// This has triggered CPG boot IO warnings in the past.
|
|
_NtDllDll(THROW_LAST_ERROR_IF_NULL(LoadLibraryExW(L"ntdll.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32))),
|
|
_NtOpenFile(reinterpret_cast<PfnNtOpenFile>(THROW_LAST_ERROR_IF_NULL(GetProcAddress(_NtDllDll.get(), "NtOpenFile"))))
|
|
{
|
|
}
|
|
|
|
// Routine Description:
|
|
// - Provides the singleton pattern for WinNT control. Stores the single instance and returns it.
|
|
// Arguments:
|
|
// - <none>
|
|
// Return Value:
|
|
// - Reference to the single instance of NTDLL.dll wrapped methods.
|
|
WinNTControl& WinNTControl::GetInstance()
|
|
{
|
|
static WinNTControl Instance;
|
|
return Instance;
|
|
}
|
|
|
|
// Routine Description:
|
|
// - Provides access to the NtOpenFile method documented at:
|
|
// https://msdn.microsoft.com/en-us/library/bb432381(v=vs.85).aspx
|
|
// Arguments:
|
|
// - See definitions at MSDN
|
|
// Return Value:
|
|
// - See definitions at MSDN
|
|
[[nodiscard]] NTSTATUS WinNTControl::NtOpenFile(_Out_ PHANDLE FileHandle,
|
|
_In_ ACCESS_MASK DesiredAccess,
|
|
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
|
|
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
|
|
_In_ ULONG ShareAccess,
|
|
_In_ ULONG OpenOptions)
|
|
{
|
|
try
|
|
{
|
|
return GetInstance()._NtOpenFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, ShareAccess, OpenOptions);
|
|
}
|
|
CATCH_RETURN();
|
|
}
|