mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
## Summary of the Pull Request Removes all C++/CX code, replacing it with C++/WinRT. ## Detailed Description of the Pull Request / Additional comments Removes all C++/CX code. Renames interop namespaces to be better consumed by CsWinRT. Standardizes all projects on net8.0-windows10.0.20348.0, which is a requirement for C++/WinRT usage. FileLocksmithLibInterop brought to stdcpplatest and static analysis errors were corrected. Removed now unneeded string conversion code from FileLocksmithLibInterop. Changed interop KeyboardHook to use a single hook across all instances. Required because on C++/WinRT we don't have the .NET runtime to bind a object instance to a delegate and be able to pass it to a C function pointer argument (still no idea why this worked correctly on C++/CX to be honest). This change actually makes us create less low level keyboard hooks. Changed some code that depended on arrays since WinRT/C++ returns null instead of an empty array through the interface. ## Validation Steps Performed Built and tested runtime.
62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
#include "pch.h"
|
|
|
|
#include "NtdllBase.h"
|
|
|
|
Ntdll::Ntdll()
|
|
{
|
|
m_module = GetModuleHandleW(L"ntdll.dll");
|
|
if (m_module == 0)
|
|
{
|
|
throw std::runtime_error{ "GetModuleHandleW returned null" };
|
|
}
|
|
|
|
m_NtQuerySystemInformation = reinterpret_cast<NtQuerySystemInformation_t>(GetProcAddress(m_module, "NtQuerySystemInformation"));
|
|
if (m_NtQuerySystemInformation == 0)
|
|
{
|
|
throw std::runtime_error{ "GetProcAddress returned null for NtQuerySystemInformation" };
|
|
}
|
|
|
|
m_NtDuplicateObject = reinterpret_cast<NtDuplicateObject_t>(GetProcAddress(m_module, "NtDuplicateObject"));
|
|
if (m_NtDuplicateObject == 0)
|
|
{
|
|
throw std::runtime_error{ "GetProcAddress returned null for NtDuplicateObject" };
|
|
}
|
|
|
|
m_NtQueryObject = reinterpret_cast<NtQueryObject_t>(GetProcAddress(m_module, "NtQueryObject"));
|
|
if (m_NtQueryObject == 0)
|
|
{
|
|
throw std::runtime_error{ "GetProcAddress returned null for NtQueryObject" };
|
|
}
|
|
}
|
|
|
|
NTSTATUS Ntdll::NtQuerySystemInformation(
|
|
ULONG SystemInformationClass,
|
|
PVOID SystemInformation,
|
|
ULONG SystemInformationLength,
|
|
PULONG ReturnLength)
|
|
{
|
|
return m_NtQuerySystemInformation(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
|
|
}
|
|
|
|
NTSTATUS Ntdll::NtDuplicateObject(
|
|
HANDLE SourceProcessHandle,
|
|
HANDLE SourceHandle,
|
|
HANDLE TargetProcessHandle,
|
|
PHANDLE TargetHandle,
|
|
ACCESS_MASK DesiredAccess,
|
|
ULONG Attributes,
|
|
ULONG Options)
|
|
{
|
|
return m_NtDuplicateObject(SourceProcessHandle, SourceHandle, TargetProcessHandle, TargetHandle, DesiredAccess, Attributes, Options);
|
|
}
|
|
|
|
NTSTATUS Ntdll::NtQueryObject(
|
|
HANDLE ObjectHandle,
|
|
ULONG ObjectInformationClass,
|
|
PVOID ObjectInformation,
|
|
ULONG ObjectInformationLength,
|
|
PULONG ReturnLength)
|
|
{
|
|
return m_NtQueryObject(ObjectHandle, ObjectInformationClass, ObjectInformation, ObjectInformationLength, ReturnLength);
|
|
}
|