Make code portable
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
7882064e0b
commit
6e34783ed5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
||||
/doc
|
||||
/.vs
|
||||
|
23
README.md
23
README.md
@ -1,9 +1,13 @@
|
||||
# WinStd [](https://ci.appveyor.com/project/Amebis/winstd)
|
||||
|
||||
Provides additional templates and function helpers for Windows API using Standard C++
|
||||
Provides additional templates and function helpers for Windows API using Standard C++ in Microsoft Visual C++ 2017-2019
|
||||
|
||||
## Features
|
||||
|
||||
### Portable
|
||||
|
||||
This project does not require building. Just `#include` individual files from this repository into your source code and get started.
|
||||
|
||||
### Lightweight Classes
|
||||
|
||||
...to simplify Windows allocated memory and resources focused on their release to prevent leakage
|
||||
@ -51,24 +55,11 @@ if (dwMaxSendPacketSize < sizeof(EapPacket))
|
||||
dwMaxSendPacketSize));
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Requires:
|
||||
- Microsoft Visual Studio 2017-2019
|
||||
- `..\..\include` folder with the following files to customize building process for individual applications (optional):
|
||||
- `Debug.props`
|
||||
- `Release.props`
|
||||
- `ARM64.props`
|
||||
- `x64.props`
|
||||
- `Win32.props`
|
||||
|
||||
## Usage
|
||||
|
||||
1. Clone the repository into your solution folder.
|
||||
2. Add the appropriate `build\WinStd-<version>.vcxproj` to your solution.
|
||||
3. Add WinStd's `include` folder to _Additional Include Directories_ in your project's C/C++ settings.
|
||||
4. Add a new reference to WinStd project from your project's common properties.
|
||||
5. Include `.h` files from WinStd as needed:
|
||||
2. Add WinStd's `include` folder to _Additional Include Directories_ in your project's C/C++ settings.
|
||||
3. Include `.h` files from WinStd as needed:
|
||||
```C++
|
||||
#include <WinStd/Shell.h>
|
||||
#include <string>
|
||||
|
37
WinStd.sln
37
WinStd.sln
@ -1,37 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29009.5
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinStd", "build\WinStd.vcxproj", "{47399D91-7EB9-41DE-B521-514BA5DB0C43}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.Build.0 = Debug|x64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.Build.0 = Release|Win32
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.ActiveCfg = Release|x64
|
||||
{47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CDBF4F12-7487-465C-8F31-9CFB3BDC2EE3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
16
appveyor.yml
16
appveyor.yml
@ -1,16 +0,0 @@
|
||||
version: 1.0.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
platform:
|
||||
- Win32
|
||||
- x64
|
||||
- ARM64
|
||||
build:
|
||||
project: WinStd.sln
|
||||
parallel: true
|
||||
verbosity: minimal
|
2
build/.gitignore
vendored
2
build/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/*.user
|
||||
/temp
|
@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|ARM64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{47399D91-7EB9-41DE-B521-514BA5DB0C43}</ProjectGuid>
|
||||
<RootNamespace>WinStd</RootNamespace>
|
||||
<ProjectName>WinStd</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Platform)'=='ARM64'">
|
||||
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\include\$(Platform).props" Condition="exists('..\..\..\include\$(Platform).props')" />
|
||||
<Import Project="..\..\..\include\$(Configuration).props" Condition="exists('..\..\..\include\$(Configuration).props')" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<OutDir>..\..\..\output\$(Platform).$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>PCH.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\Base64.cpp" />
|
||||
<ClCompile Include="..\src\COM.cpp" />
|
||||
<ClCompile Include="..\src\Crypt.cpp" />
|
||||
<ClCompile Include="..\src\EAP.cpp" />
|
||||
<ClCompile Include="..\src\ETW.cpp" />
|
||||
<ClCompile Include="..\src\GDI.cpp" />
|
||||
<ClCompile Include="..\src\Sec.cpp" />
|
||||
<ClCompile Include="..\src\SetupAPI.cpp" />
|
||||
<ClCompile Include="..\src\PCH.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Win.cpp" />
|
||||
<ClCompile Include="..\src\WinSock2.cpp" />
|
||||
<ClCompile Include="..\src\WinTrust.cpp" />
|
||||
<ClCompile Include="..\src\WLAN.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\WinStd\Base64.h" />
|
||||
<ClInclude Include="..\include\WinStd\COM.h" />
|
||||
<ClInclude Include="..\include\WinStd\Common.h" />
|
||||
<ClInclude Include="..\include\WinStd\Cred.h" />
|
||||
<ClInclude Include="..\include\WinStd\Crypt.h" />
|
||||
<ClInclude Include="..\include\WinStd\EAP.h" />
|
||||
<ClInclude Include="..\include\WinStd\ETW.h" />
|
||||
<ClInclude Include="..\include\WinStd\GDI.h" />
|
||||
<ClInclude Include="..\include\WinStd\Hex.h" />
|
||||
<ClInclude Include="..\include\WinStd\MSI.h" />
|
||||
<ClInclude Include="..\include\WinStd\Sec.h" />
|
||||
<ClInclude Include="..\include\WinStd\SetupAPI.h" />
|
||||
<ClInclude Include="..\include\WinStd\Shell.h" />
|
||||
<ClInclude Include="..\include\WinStd\Win.h" />
|
||||
<ClInclude Include="..\include\WinStd\WinSock2.h" />
|
||||
<ClInclude Include="..\include\WinStd\WinTrust.h" />
|
||||
<ClInclude Include="..\include\WinStd\WLAN.h" />
|
||||
<ClInclude Include="..\src\PCH.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
@ -1,110 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\PCH.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Base64.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\ETW.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\COM.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Crypt.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\EAP.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Win.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WinTrust.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Sec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WLAN.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\SetupAPI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WinSock2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\GDI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\PCH.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Win.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WinTrust.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\MSI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Crypt.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WLAN.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Shell.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Common.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\EAP.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Sec.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Base64.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Cred.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\COM.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\ETW.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Hex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\SetupAPI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\GDI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -159,6 +159,16 @@ namespace winstd
|
||||
};
|
||||
|
||||
|
||||
/// \cond internal
|
||||
const char base64_enc::lookup[64] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
/// \endcond
|
||||
|
||||
|
||||
///
|
||||
/// Base64 decoding session
|
||||
///
|
||||
@ -269,5 +279,28 @@ namespace winstd
|
||||
/// \endcond
|
||||
};
|
||||
|
||||
|
||||
/// \cond internal
|
||||
const unsigned char base64_dec::lookup[256] = {
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
/* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 2 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
/* 3 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 64, 255, 255,
|
||||
/* 4 */ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
/* 5 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
||||
/* 6 */ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
/* 7 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255,
|
||||
/* 8 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 9 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* A */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* B */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* C */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* D */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* E */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* F */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
|
||||
};
|
||||
/// \endcond
|
||||
|
||||
/// @}
|
||||
}
|
||||
|
@ -259,7 +259,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SysFreeString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221481.aspx)
|
||||
///
|
||||
virtual ~bstr();
|
||||
virtual ~bstr()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
SysFreeString(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns the length of the string
|
||||
@ -277,7 +281,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SysFreeString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221481.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
SysFreeString(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the string
|
||||
@ -288,7 +295,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SysAllocString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221458.aspx)
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
return SysAllocStringLen(h, SysStringLen(h));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -522,7 +532,10 @@ namespace winstd
|
||||
///
|
||||
/// Destroys VARIANT
|
||||
///
|
||||
virtual ~variant();
|
||||
virtual ~variant()
|
||||
{
|
||||
VariantClear(this);
|
||||
}
|
||||
|
||||
///
|
||||
/// Copy from another VARIANT
|
||||
@ -1081,7 +1094,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CoUninitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms688715.aspx)
|
||||
///
|
||||
virtual ~com_initializer();
|
||||
virtual ~com_initializer()
|
||||
{
|
||||
if (SUCCEEDED(m_result))
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
@ -116,7 +116,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertFreeCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075.aspx)
|
||||
///
|
||||
virtual ~cert_context();
|
||||
virtual ~cert_context()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateContext(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates the certificate context.
|
||||
@ -228,7 +232,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertFreeCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CertFreeCertificateContext(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the certificate context.
|
||||
@ -239,7 +246,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx)
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
return CertDuplicateCertificateContext(h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -256,7 +266,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertFreeCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073.aspx)
|
||||
///
|
||||
virtual ~cert_chain_context();
|
||||
virtual ~cert_chain_context()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateChain(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates the certificate chain context.
|
||||
@ -283,7 +297,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertFreeCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CertFreeCertificateChain(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the certificate chain context.
|
||||
@ -294,7 +311,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx)
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
return CertDuplicateCertificateChain(h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -311,7 +331,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertCloseStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026.aspx)
|
||||
///
|
||||
virtual ~cert_store();
|
||||
virtual ~cert_store()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertCloseStore(m_h, 0);
|
||||
}
|
||||
|
||||
///
|
||||
/// Opens the certificate store.
|
||||
@ -357,7 +381,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CertCloseStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CertCloseStore(m_h, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -374,7 +401,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx)
|
||||
///
|
||||
virtual ~crypt_prov();
|
||||
virtual ~crypt_prov()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptReleaseContext(m_h, 0);
|
||||
}
|
||||
|
||||
///
|
||||
/// Acquires the cryptographic context.
|
||||
@ -401,7 +432,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CryptReleaseContext(m_h, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -418,7 +452,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDestroyHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917.aspx)
|
||||
///
|
||||
virtual ~crypt_hash();
|
||||
virtual ~crypt_hash()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptDestroyHash(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates the hash context.
|
||||
@ -445,7 +483,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDestroyHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CryptDestroyHash(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the hash context.
|
||||
@ -456,7 +497,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDuplicateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379919.aspx)
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -473,7 +518,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDestroyKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918.aspx)
|
||||
///
|
||||
virtual ~crypt_key();
|
||||
virtual ~crypt_key()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptDestroyKey(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Generates the key.
|
||||
@ -543,7 +592,67 @@ namespace winstd
|
||||
/// \param[in] hProv Handle of cryptographics provider to use
|
||||
/// \param[in] dwKeySpec Key specification (`AT_KEYEXCHANGE` or `AT_SIGNATURE`)
|
||||
///
|
||||
bool create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec);
|
||||
bool create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
|
||||
{
|
||||
if (dwKeySpec != AT_KEYEXCHANGE && dwKeySpec != AT_SIGNATURE) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate the private key.
|
||||
handle_type h;
|
||||
if (CryptGenKey(hProv, dwKeySpec, CRYPT_EXPORTABLE, &h)) {
|
||||
// Export the private key, we'll convert it to a private exponent of one key.
|
||||
std::vector<BYTE, sanitizing_allocator<BYTE>> key_blob;
|
||||
if (CryptExportKey(h, 0, PRIVATEKEYBLOB, 0, key_blob)) {
|
||||
CryptDestroyKey(h);
|
||||
|
||||
// Get the byte length of the key.
|
||||
size_t
|
||||
size_key = *reinterpret_cast<DWORD*>(&key_blob[12])/8,
|
||||
size_prime = size_key/2;
|
||||
|
||||
// Modify the Exponent in Key BLOB format
|
||||
// Key BLOB format is documented in SDK
|
||||
|
||||
// Convert pubexp in rsapubkey to 1
|
||||
LPBYTE ptr = &key_blob[16];
|
||||
*reinterpret_cast<DWORD*>(ptr) = 1;
|
||||
ptr += sizeof(DWORD);
|
||||
|
||||
// Skip modulus, prime1, prime2
|
||||
ptr += size_key;
|
||||
ptr += size_prime;
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert exponent1 to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_prime - 1);
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert exponent2 to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_prime - 1);
|
||||
ptr += size_prime;
|
||||
|
||||
// Skip coefficient
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert privateExponent to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_key - 1);
|
||||
|
||||
// Import the exponent-of-one private key.
|
||||
if (CryptImportKey(hProv, key_blob.data(), static_cast<DWORD>(key_blob.size()), 0, 0, &h)) {
|
||||
attach(h);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
CryptDestroyKey(h);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -551,7 +660,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDestroyKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CryptDestroyKey(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the key.
|
||||
@ -562,7 +674,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CryptDuplicateKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379920.aspx)
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
@ -619,7 +735,11 @@ namespace winstd
|
||||
///
|
||||
/// Destroys the BLOB.
|
||||
///
|
||||
virtual ~data_blob();
|
||||
virtual ~data_blob()
|
||||
{
|
||||
if (pbData != NULL)
|
||||
LocalFree(pbData);
|
||||
}
|
||||
|
||||
///
|
||||
/// Copy an existing BLOB.
|
||||
|
@ -271,7 +271,11 @@ namespace winstd
|
||||
///
|
||||
/// Destroys the EAP attribute.
|
||||
///
|
||||
~eap_attr();
|
||||
~eap_attr()
|
||||
{
|
||||
if (pValue)
|
||||
delete [] pValue;
|
||||
}
|
||||
|
||||
///
|
||||
/// Copies an existing EAP attribute.
|
||||
@ -323,13 +327,50 @@ namespace winstd
|
||||
/// \sa [MS-MPPE-Send-Key](https://tools.ietf.org/html/rfc2548#section-2.4.2)
|
||||
/// \sa [MS-MPPE-Recv-Key](https://tools.ietf.org/html/rfc2548#section-2.4.3)
|
||||
///
|
||||
void create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize);
|
||||
void create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize)
|
||||
{
|
||||
const BYTE nPaddingLength = static_cast<BYTE>((16 - (1 + static_cast<DWORD>(nKeySize))) % 16);
|
||||
const DWORD dwLengthNew =
|
||||
4 + // Vendor-Id
|
||||
1 + // Vendor type
|
||||
1 + // Vendor length
|
||||
2 + // Salt
|
||||
1 + // Key-Length
|
||||
nKeySize + // Key
|
||||
nPaddingLength; // Padding
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 6386)
|
||||
LPBYTE p = new BYTE[dwLengthNew];
|
||||
p[0] = 0x00; // Vendor-Id (0x137 = 311 = Microsoft)
|
||||
p[1] = 0x00; // --|
|
||||
p[2] = 0x01; // --|
|
||||
p[3] = 0x37; // --^
|
||||
p[4] = bVendorType; // Vendor type
|
||||
p[5] = static_cast<BYTE>(dwLengthNew - 4); // Vendor length
|
||||
p[6] = 0x00; // Salt
|
||||
p[7] = 0x00; // --^
|
||||
p[8] = nKeySize; // Key-Length
|
||||
#pragma warning(pop)
|
||||
memcpy(p + 9, pbKey, nKeySize); // Key
|
||||
memset(p + 9 + nKeySize, 0, nPaddingLength); // Padding
|
||||
|
||||
if (pValue)
|
||||
delete [] pValue;
|
||||
|
||||
#pragma warning(suppress: 26812) // EAP_ATTRIBUTE_TYPE is unscoped.
|
||||
eaType = eatVendorSpecific;
|
||||
dwLength = dwLengthNew;
|
||||
pValue = p;
|
||||
}
|
||||
|
||||
public:
|
||||
static const EAP_ATTRIBUTE blank; ///< Blank EAP attribute
|
||||
};
|
||||
#pragma warning(pop)
|
||||
|
||||
const EAP_ATTRIBUTE eap_attr::blank = {};
|
||||
|
||||
|
||||
///
|
||||
/// EAP_METHOD_PROPERTY wrapper class
|
||||
@ -394,7 +435,11 @@ namespace winstd
|
||||
///
|
||||
/// Destroys the EAP packet.
|
||||
///
|
||||
virtual ~eap_packet();
|
||||
virtual ~eap_packet()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -442,12 +487,25 @@ namespace winstd
|
||||
///
|
||||
/// Destroys the EAP packet.
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Duplicates the EAP packet.
|
||||
///
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
|
||||
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
|
||||
{
|
||||
const WORD n = ntohs(*reinterpret_cast<WORD*>(h->Length));
|
||||
handle_type h2 = static_cast<handle_type>(HeapAlloc(GetProcessHeap(), 0, n));
|
||||
if (h2 == NULL) {
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(h2, h, n);
|
||||
return h2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -484,7 +542,11 @@ namespace winstd
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
~eap_method_info_array();
|
||||
~eap_method_info_array()
|
||||
{
|
||||
if (pEapMethods)
|
||||
free_internal();
|
||||
}
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
@ -506,8 +568,24 @@ namespace winstd
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
void free_internal() noexcept;
|
||||
static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept;
|
||||
|
||||
void free_internal() noexcept
|
||||
{
|
||||
for (DWORD i = 0; i < dwNumberOfMethods; i++)
|
||||
free_internal(pEapMethods + i);
|
||||
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pEapMethods));
|
||||
}
|
||||
|
||||
static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept
|
||||
{
|
||||
if (pMethodInfo->pInnerMethodInfo)
|
||||
free_internal(pMethodInfo->pInnerMethodInfo);
|
||||
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszAuthorName));
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszFriendlyName));
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
};
|
||||
|
||||
|
@ -258,6 +258,8 @@ namespace winstd
|
||||
static const event_data blank;
|
||||
};
|
||||
|
||||
const event_data event_data::blank;
|
||||
|
||||
|
||||
///
|
||||
/// EVENT_RECORD wrapper
|
||||
@ -312,7 +314,14 @@ namespace winstd
|
||||
///
|
||||
/// Destroys event record data and frees the allocated memory.
|
||||
///
|
||||
~event_rec();
|
||||
~event_rec()
|
||||
{
|
||||
if (ExtendedData)
|
||||
delete reinterpret_cast<unsigned char*>(ExtendedData);
|
||||
|
||||
if (UserData)
|
||||
delete reinterpret_cast<unsigned char*>(UserData);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -371,7 +380,13 @@ namespace winstd
|
||||
/// \param[in] count \p data size (in number of elements)
|
||||
/// \param[in] data Record extended data
|
||||
///
|
||||
void set_extended_data(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data);
|
||||
void set_extended_data(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
|
||||
{
|
||||
if (ExtendedData)
|
||||
delete reinterpret_cast<unsigned char*>(ExtendedData);
|
||||
|
||||
set_extended_data_internal(count, data);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -380,7 +395,13 @@ namespace winstd
|
||||
/// \param[in] size \p data size (in bytes)
|
||||
/// \param[in] data Record user data
|
||||
///
|
||||
void set_user_data(_In_ USHORT size, _In_bytecount_(size) LPCVOID data);
|
||||
void set_user_data(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
|
||||
{
|
||||
if (UserData)
|
||||
delete reinterpret_cast<unsigned char*>(UserData);
|
||||
|
||||
set_user_data_internal(size, data);
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -389,7 +410,37 @@ namespace winstd
|
||||
/// \param[in] count \p data size (in number of elements)
|
||||
/// \param[in] data Record extended data
|
||||
///
|
||||
void set_extended_data_internal(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data);
|
||||
void set_extended_data_internal(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
|
||||
{
|
||||
if (count) {
|
||||
assert(data);
|
||||
|
||||
// Count the total required memory.
|
||||
size_t data_size = 0;
|
||||
for (size_t i = 0; i < count; i++)
|
||||
data_size += data[i].DataSize;
|
||||
|
||||
// Allocate memory for extended data.
|
||||
ExtendedData = reinterpret_cast<EVENT_HEADER_EXTENDED_DATA_ITEM*>(new unsigned char[sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM)*count + data_size]);
|
||||
|
||||
// Bulk-copy extended data descriptors.
|
||||
memcpy(ExtendedData, data, sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM) * count);
|
||||
|
||||
// Copy the data.
|
||||
unsigned char *ptr = reinterpret_cast<unsigned char*>(ExtendedData + count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (data[i].DataSize) {
|
||||
memcpy(ptr, (void*)(data[i].DataPtr), data[i].DataSize);
|
||||
ExtendedData[i].DataPtr = (ULONGLONG)ptr;
|
||||
ptr += data[i].DataSize;
|
||||
} else
|
||||
ExtendedData[i].DataPtr = NULL;
|
||||
}
|
||||
} else
|
||||
ExtendedData = NULL;
|
||||
|
||||
ExtendedDataCount = count;
|
||||
}
|
||||
|
||||
///
|
||||
/// Sets event record user data.
|
||||
@ -397,7 +448,21 @@ namespace winstd
|
||||
/// \param[in] size \p data size (in bytes)
|
||||
/// \param[in] data Record user data
|
||||
///
|
||||
void set_user_data_internal(_In_ USHORT size, _In_bytecount_(size) LPCVOID data);
|
||||
void set_user_data_internal(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
|
||||
{
|
||||
if (size) {
|
||||
assert(data);
|
||||
|
||||
// Allocate memory for user data.
|
||||
UserData = new unsigned char[size];
|
||||
|
||||
// Copy user data.
|
||||
memcpy(UserData, data, size);
|
||||
} else
|
||||
UserData = NULL;
|
||||
|
||||
UserDataLength = size;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -414,7 +479,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [EventUnregister function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363749.aspx)
|
||||
///
|
||||
virtual ~event_provider();
|
||||
virtual ~event_provider()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
EventUnregister(m_h);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -599,7 +668,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [EventUnregister function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363749.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
EventUnregister(m_h);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -607,7 +679,15 @@ namespace winstd
|
||||
///
|
||||
/// \sa [EnableCallback callback function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363707.aspx)
|
||||
///
|
||||
virtual void enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData);
|
||||
virtual void enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(SourceId);
|
||||
UNREFERENCED_PARAMETER(IsEnabled);
|
||||
UNREFERENCED_PARAMETER(Level);
|
||||
UNREFERENCED_PARAMETER(MatchAnyKeyword);
|
||||
UNREFERENCED_PARAMETER(MatchAllKeyword);
|
||||
UNREFERENCED_PARAMETER(FilterData);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -615,7 +695,13 @@ namespace winstd
|
||||
///
|
||||
/// \sa [EnableCallback callback function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363707.aspx)
|
||||
///
|
||||
static VOID NTAPI enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _Inout_opt_ PVOID CallbackContext);
|
||||
static VOID NTAPI enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _Inout_opt_ PVOID CallbackContext)
|
||||
{
|
||||
if (CallbackContext)
|
||||
static_cast<event_provider*>(CallbackContext)->enable_callback(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData);
|
||||
else
|
||||
assert(0); // Where did the "this" pointer get lost?
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -666,7 +752,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ControlTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363696.aspx)
|
||||
///
|
||||
virtual ~event_session();
|
||||
virtual ~event_session()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -799,7 +889,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ControlTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363696.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<EVENT_TRACE_PROPERTIES> m_prop; ///< Session properties
|
||||
@ -819,7 +912,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CloseTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363686.aspx)
|
||||
///
|
||||
virtual ~event_trace();
|
||||
virtual ~event_trace()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CloseTrace(m_h);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
@ -847,7 +944,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [CloseTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363686.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
CloseTrace(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -944,7 +1044,20 @@ namespace winstd
|
||||
///
|
||||
/// \sa [EnableTraceEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363711.aspx)
|
||||
///
|
||||
virtual ~event_trace_enabler();
|
||||
virtual ~event_trace_enabler()
|
||||
{
|
||||
if (m_status == ERROR_SUCCESS)
|
||||
EnableTraceEx(
|
||||
m_provider_id,
|
||||
m_source_id,
|
||||
m_trace_handle,
|
||||
EVENT_CONTROL_CODE_DISABLE_PROVIDER,
|
||||
m_level,
|
||||
m_match_any_keyword,
|
||||
m_match_all_keyword,
|
||||
m_enable_property,
|
||||
m_enable_filter_desc);
|
||||
}
|
||||
|
||||
protected:
|
||||
ULONG m_status; ///< Result of EnableTraceEx call
|
||||
|
@ -73,7 +73,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
|
||||
///
|
||||
virtual ~dc();
|
||||
virtual ~dc()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
DeleteDC(m_h);
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -81,7 +85,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
DeleteDC(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -120,7 +127,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
|
||||
///
|
||||
virtual ~window_dc();
|
||||
virtual ~window_dc()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
ReleaseDC(m_hwnd, m_h);
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -128,7 +139,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
ReleaseDC(m_hwnd, m_h);
|
||||
}
|
||||
|
||||
protected:
|
||||
HWND m_hwnd; ///< Window handle
|
||||
@ -161,7 +175,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SelectObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject)
|
||||
///
|
||||
virtual ~dc_selector();
|
||||
virtual ~dc_selector()
|
||||
{
|
||||
if (m_orig)
|
||||
SelectObject(m_hdc, m_orig);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
@ -90,7 +90,13 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeCredentialsHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375417.aspx)
|
||||
///
|
||||
virtual ~sec_credentials();
|
||||
virtual ~sec_credentials()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
FreeCredentialsHandle(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
@ -141,7 +147,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeCredentialsHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375417.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
FreeCredentialsHandle(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
|
||||
public:
|
||||
TimeStamp m_expires; ///< Credentials expiration time
|
||||
@ -181,7 +191,13 @@ namespace winstd
|
||||
///
|
||||
/// \sa [DeleteSecurityContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375354.aspx)
|
||||
///
|
||||
virtual ~sec_context();
|
||||
virtual ~sec_context()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
DeleteSecurityContext(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
@ -256,7 +272,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [DeleteSecurityContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375354.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
DeleteSecurityContext(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
|
||||
public:
|
||||
ULONG m_attrib; ///< Context attributes
|
||||
@ -285,7 +305,13 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeContextBuffer function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375416.aspx)
|
||||
///
|
||||
virtual ~sec_buffer_desc();
|
||||
virtual ~sec_buffer_desc()
|
||||
{
|
||||
for (ULONG i = 0; i < cBuffers; i++) {
|
||||
if (pBuffers[i].pvBuffer)
|
||||
FreeContextBuffer(pBuffers[i].pvBuffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
@ -41,7 +41,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
|
||||
///
|
||||
virtual ~setup_device_info_list();
|
||||
virtual ~setup_device_info_list()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates an empty device information set and optionally associates the set with a device setup class and a top-level window.
|
||||
@ -98,7 +102,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -132,7 +139,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SetupDiDestroyDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydriverinfolist)
|
||||
///
|
||||
virtual ~setup_driver_info_list_builder();
|
||||
virtual ~setup_driver_info_list_builder()
|
||||
{
|
||||
if (m_result)
|
||||
SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
|
@ -120,7 +120,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
virtual ~wlan_handle();
|
||||
virtual ~wlan_handle()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
///
|
||||
/// Opens a connection to the server.
|
||||
@ -150,7 +154,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
@ -96,7 +96,7 @@ template<class _Elem, class _Traits, class _Ax> inline VOID GuidToStringW(_In_ L
|
||||
#endif
|
||||
|
||||
/// @copydoc StringToGuidW()
|
||||
_Success_(return) BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL) noexcept;
|
||||
_Success_(return) static BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL) noexcept;
|
||||
|
||||
///
|
||||
/// Parses string with GUID and stores it to GUID
|
||||
@ -109,7 +109,7 @@ _Success_(return) BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid
|
||||
/// - `TRUE` if GUID successfuly parsed;
|
||||
/// - `FALSE` otherwise.
|
||||
///
|
||||
_Success_(return) BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL) noexcept;
|
||||
_Success_(return) static BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL) noexcept;
|
||||
|
||||
/// @copydoc StringToGuidW()
|
||||
#ifdef _UNICODE
|
||||
@ -429,7 +429,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeLibrary function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152.aspx)
|
||||
///
|
||||
virtual ~library();
|
||||
virtual ~library()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Loads the specified module into the address space of the calling process.
|
||||
@ -456,7 +460,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeLibrary function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -574,14 +581,24 @@ namespace winstd
|
||||
///
|
||||
/// \sa [InitializeCriticalSection function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-initializecriticalsection)
|
||||
///
|
||||
critical_section();
|
||||
critical_section()
|
||||
{
|
||||
__try {
|
||||
InitializeCriticalSection(&m_data);
|
||||
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
||||
throw std::runtime_error("InitializeCriticalSection failed");
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Releases all resources used by an unowned critical section object.
|
||||
///
|
||||
/// \sa [DeleteCriticalSection function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-deletecriticalsection)
|
||||
///
|
||||
virtual ~critical_section();
|
||||
virtual ~critical_section()
|
||||
{
|
||||
DeleteCriticalSection(&m_data);
|
||||
}
|
||||
|
||||
///
|
||||
/// Auto-typecasting operator
|
||||
@ -611,7 +628,12 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FindClose function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findclose)
|
||||
///
|
||||
virtual ~find_file();
|
||||
virtual ~find_file()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
FindClose(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).
|
||||
@ -638,7 +660,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FindClose function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findclose)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
FindClose(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -655,7 +680,13 @@ namespace winstd
|
||||
///
|
||||
/// \sa [HeapDestroy function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700.aspx)
|
||||
///
|
||||
virtual ~heap();
|
||||
virtual ~heap()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates the heap.
|
||||
@ -683,7 +714,43 @@ namespace winstd
|
||||
/// - `true` if any blocks found;
|
||||
/// - `false` otherwise.
|
||||
///
|
||||
bool enumerate() noexcept;
|
||||
bool enumerate() noexcept
|
||||
{
|
||||
assert(m_h != invalid);
|
||||
|
||||
bool found = false;
|
||||
|
||||
// Lock the heap for exclusive access.
|
||||
HeapLock(m_h);
|
||||
|
||||
PROCESS_HEAP_ENTRY e;
|
||||
e.lpData = NULL;
|
||||
while (HeapWalk(m_h, &e) != FALSE) {
|
||||
if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
|
||||
OutputDebugStr(
|
||||
_T("Allocated block%s%s\n")
|
||||
_T(" Data portion begins at: %#p\n Size: %d bytes\n")
|
||||
_T(" Overhead: %d bytes\n Region index: %d\n"),
|
||||
(e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ? tstring_printf(_T(", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(""),
|
||||
(e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(", DDESHARE") : _T(""),
|
||||
e.lpData,
|
||||
e.cbData,
|
||||
e.cbOverhead,
|
||||
e.iRegionIndex);
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
const DWORD dwResult = GetLastError();
|
||||
if (dwResult != ERROR_NO_MORE_ITEMS)
|
||||
OutputDebugStr(_T("HeapWalk failed (error %u).\n"), dwResult);
|
||||
|
||||
// Unlock the heap.
|
||||
HeapUnlock(m_h);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -691,7 +758,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [HeapDestroy function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -828,14 +899,22 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ActivateActCtx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374151.aspx)
|
||||
///
|
||||
actctx_activator(_In_ HANDLE hActCtx) noexcept;
|
||||
actctx_activator(_In_ HANDLE hActCtx) noexcept
|
||||
{
|
||||
if (!ActivateActCtx(hActCtx, &m_cookie))
|
||||
m_cookie = 0;
|
||||
}
|
||||
|
||||
///
|
||||
/// Deactivates activation context and destructs the activator
|
||||
///
|
||||
/// \sa [DeactivateActCtx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375140.aspx)
|
||||
///
|
||||
virtual ~actctx_activator();
|
||||
virtual ~actctx_activator()
|
||||
{
|
||||
if (m_cookie)
|
||||
DeactivateActCtx(0, m_cookie);
|
||||
}
|
||||
|
||||
protected:
|
||||
ULONG_PTR m_cookie; ///< Cookie for context deactivation
|
||||
@ -858,14 +937,21 @@ namespace winstd
|
||||
///
|
||||
/// \sa [ImpersonateLoggedOnUser function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378612.aspx)
|
||||
///
|
||||
user_impersonator(_In_opt_ HANDLE hToken) noexcept;
|
||||
user_impersonator(_In_opt_ HANDLE hToken) noexcept
|
||||
{
|
||||
m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
|
||||
}
|
||||
|
||||
///
|
||||
/// Reverts to current user and destructs the impersonator
|
||||
///
|
||||
/// \sa [RevertToSelf function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379317.aspx)
|
||||
///
|
||||
virtual ~user_impersonator();
|
||||
virtual ~user_impersonator()
|
||||
{
|
||||
if (m_cookie)
|
||||
RevertToSelf();
|
||||
}
|
||||
|
||||
protected:
|
||||
BOOL m_cookie; ///< Did impersonation succeed?
|
||||
@ -888,14 +974,21 @@ namespace winstd
|
||||
///
|
||||
/// \sa [SetConsoleCtrlHandler function](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler)
|
||||
///
|
||||
console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept;
|
||||
console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept : m_handler(HandlerRoutine)
|
||||
{
|
||||
m_cookie = SetConsoleCtrlHandler(m_handler, TRUE);
|
||||
}
|
||||
|
||||
///
|
||||
/// Pops console control handler from the console control handler stack
|
||||
///
|
||||
/// \sa [SetConsoleCtrlHandler function](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler)
|
||||
///
|
||||
virtual ~console_ctrl_handler();
|
||||
virtual ~console_ctrl_handler()
|
||||
{
|
||||
if (m_cookie)
|
||||
SetConsoleCtrlHandler(m_handler, FALSE);
|
||||
}
|
||||
|
||||
protected:
|
||||
BOOL m_cookie; ///< Did pushing the console control handler succeed?
|
||||
@ -946,7 +1039,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [VirtualFreeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366894.aspx)
|
||||
///
|
||||
virtual ~vmemory();
|
||||
virtual ~vmemory()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
@ -1008,7 +1105,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [VirtualFreeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366894.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
protected:
|
||||
HANDLE m_proc; ///< Handle of memory's process
|
||||
@ -1028,7 +1128,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [RegCloseKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724837.aspx)
|
||||
///
|
||||
virtual ~reg_key();
|
||||
virtual ~reg_key()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates the specified registry key. If the key already exists, the function opens it.
|
||||
@ -1094,7 +1198,41 @@ namespace winstd
|
||||
/// - true when creation succeeds;
|
||||
/// - false when creation fails. For extended error information, call `GetLastError()`.
|
||||
///
|
||||
bool delete_subkey(_In_z_ LPCTSTR szSubkey);
|
||||
bool delete_subkey(_In_z_ LPCTSTR szSubkey)
|
||||
{
|
||||
LSTATUS s;
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
|
||||
return true;
|
||||
|
||||
{
|
||||
reg_key k;
|
||||
if (!k.open(m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS))
|
||||
return false;
|
||||
for (;;) {
|
||||
TCHAR szName[MAX_PATH];
|
||||
DWORD dwSize = _countof(szName);
|
||||
s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
|
||||
if (s == ERROR_SUCCESS)
|
||||
k.delete_subkey(szName);
|
||||
else if (s == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS)
|
||||
return true;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -1102,7 +1240,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [RegCloseKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724837.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1119,7 +1260,11 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446631.aspx)
|
||||
///
|
||||
virtual ~security_id();
|
||||
virtual ~security_id()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -1127,7 +1272,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446631.aspx)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
FreeSid(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1389,6 +1537,132 @@ inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T
|
||||
}
|
||||
|
||||
|
||||
_Success_(return) static BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) noexcept
|
||||
{
|
||||
GUID g;
|
||||
LPSTR lpszEnd;
|
||||
unsigned long ulTmp;
|
||||
unsigned long long ullTmp;
|
||||
|
||||
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE) return FALSE;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data2 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
|
||||
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
_Success_(return) static BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) noexcept
|
||||
{
|
||||
GUID g;
|
||||
LPWSTR lpszEnd;
|
||||
unsigned long ulTmp;
|
||||
unsigned long long ullTmp;
|
||||
|
||||
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE) return FALSE;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data2 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
|
||||
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept
|
||||
{
|
||||
|
@ -135,7 +135,12 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
|
||||
///
|
||||
virtual ~addrinfo();
|
||||
virtual ~addrinfo()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
///
|
||||
@ -143,7 +148,10 @@ namespace winstd
|
||||
///
|
||||
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
|
||||
///
|
||||
void free_internal() noexcept override;
|
||||
void free_internal() noexcept override
|
||||
{
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -53,7 +53,11 @@ namespace winstd
|
||||
///
|
||||
/// Destroys the WinTrust context.
|
||||
///
|
||||
virtual ~wintrust();
|
||||
virtual ~wintrust()
|
||||
{
|
||||
m_wtd.dwStateAction = WTD_STATEACTION_CLOSE;
|
||||
WinVerifyTrust(m_hwnd, &m_action, &m_wtd);
|
||||
}
|
||||
|
||||
protected:
|
||||
HWND m_hwnd;
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::base64_enc
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// \cond internal
|
||||
const char winstd::base64_enc::lookup[64] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
/// \endcond
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::base64_dec
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// \cond internal
|
||||
const unsigned char winstd::base64_dec::lookup[256] = {
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
/* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 2 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
/* 3 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 64, 255, 255,
|
||||
/* 4 */ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
/* 5 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
||||
/* 6 */ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
/* 7 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255,
|
||||
/* 8 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* 9 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* A */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* B */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* C */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* D */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* E */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
/* F */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
|
||||
};
|
||||
/// \endcond
|
52
src/COM.cpp
52
src/COM.cpp
@ -1,52 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::bstr
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::bstr::~bstr()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
SysFreeString(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::bstr::free_internal() noexcept
|
||||
{
|
||||
SysFreeString(m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
return SysAllocStringLen(h, SysStringLen(h));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::variant
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
|
||||
winstd::variant::~variant()
|
||||
{
|
||||
VariantClear(this);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::com_initializer
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::com_initializer::~com_initializer()
|
||||
{
|
||||
if (SUCCEEDED(m_result))
|
||||
CoUninitialize();
|
||||
}
|
212
src/Crypt.cpp
212
src/Crypt.cpp
@ -1,212 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
#pragma comment(lib, "Crypt32.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::cert_context
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::cert_context::~cert_context()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateContext(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::cert_context::free_internal() noexcept
|
||||
{
|
||||
CertFreeCertificateContext(m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
return CertDuplicateCertificateContext(h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::cert_chain_context
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::cert_chain_context::~cert_chain_context()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateChain(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::cert_chain_context::free_internal() noexcept
|
||||
{
|
||||
CertFreeCertificateChain(m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
return CertDuplicateCertificateChain(h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::cert_store
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::cert_store::~cert_store()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CertCloseStore(m_h, 0);
|
||||
}
|
||||
|
||||
|
||||
void winstd::cert_store::free_internal() noexcept
|
||||
{
|
||||
CertCloseStore(m_h, 0);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::crypt_prov
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::crypt_prov::~crypt_prov()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptReleaseContext(m_h, 0);
|
||||
}
|
||||
|
||||
|
||||
void winstd::crypt_prov::free_internal() noexcept
|
||||
{
|
||||
CryptReleaseContext(m_h, 0);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::crypt_hash
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::crypt_hash::~crypt_hash()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptDestroyHash(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::crypt_hash::free_internal() noexcept
|
||||
{
|
||||
CryptDestroyHash(m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::crypt_key
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::crypt_key::~crypt_key()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CryptDestroyKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
|
||||
{
|
||||
if (dwKeySpec != AT_KEYEXCHANGE && dwKeySpec != AT_SIGNATURE) {
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate the private key.
|
||||
handle_type h;
|
||||
if (CryptGenKey(hProv, dwKeySpec, CRYPT_EXPORTABLE, &h)) {
|
||||
// Export the private key, we'll convert it to a private exponent of one key.
|
||||
std::vector<BYTE, sanitizing_allocator<BYTE>> key_blob;
|
||||
if (CryptExportKey(h, 0, PRIVATEKEYBLOB, 0, key_blob)) {
|
||||
CryptDestroyKey(h);
|
||||
|
||||
// Get the byte length of the key.
|
||||
size_t
|
||||
size_key = *reinterpret_cast<DWORD*>(&key_blob[12])/8,
|
||||
size_prime = size_key/2;
|
||||
|
||||
// Modify the Exponent in Key BLOB format
|
||||
// Key BLOB format is documented in SDK
|
||||
|
||||
// Convert pubexp in rsapubkey to 1
|
||||
LPBYTE ptr = &key_blob[16];
|
||||
*reinterpret_cast<DWORD*>(ptr) = 1;
|
||||
ptr += sizeof(DWORD);
|
||||
|
||||
// Skip modulus, prime1, prime2
|
||||
ptr += size_key;
|
||||
ptr += size_prime;
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert exponent1 to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_prime - 1);
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert exponent2 to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_prime - 1);
|
||||
ptr += size_prime;
|
||||
|
||||
// Skip coefficient
|
||||
ptr += size_prime;
|
||||
|
||||
// Convert privateExponent to 1
|
||||
ptr[0] = 1;
|
||||
memset(ptr + 1, 0, size_key - 1);
|
||||
|
||||
// Import the exponent-of-one private key.
|
||||
if (CryptImportKey(hProv, key_blob.data(), static_cast<DWORD>(key_blob.size()), 0, 0, &h)) {
|
||||
attach(h);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
CryptDestroyKey(h);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void winstd::crypt_key::free_internal() noexcept
|
||||
{
|
||||
CryptDestroyKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::data_blob
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
|
||||
winstd::data_blob::~data_blob()
|
||||
{
|
||||
if (pbData != NULL)
|
||||
LocalFree(pbData);
|
||||
}
|
128
src/EAP.cpp
128
src/EAP.cpp
@ -1,128 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
#pragma comment(lib, "Eappcfg.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_attr
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
|
||||
winstd::eap_attr::~eap_attr()
|
||||
{
|
||||
if (pValue)
|
||||
delete [] pValue;
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize)
|
||||
{
|
||||
const BYTE nPaddingLength = static_cast<BYTE>((16 - (1 + static_cast<DWORD>(nKeySize))) % 16);
|
||||
const DWORD dwLengthNew =
|
||||
4 + // Vendor-Id
|
||||
1 + // Vendor type
|
||||
1 + // Vendor length
|
||||
2 + // Salt
|
||||
1 + // Key-Length
|
||||
nKeySize + // Key
|
||||
nPaddingLength; // Padding
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 6386)
|
||||
LPBYTE p = new BYTE[dwLengthNew];
|
||||
p[0] = 0x00; // Vendor-Id (0x137 = 311 = Microsoft)
|
||||
p[1] = 0x00; // --|
|
||||
p[2] = 0x01; // --|
|
||||
p[3] = 0x37; // --^
|
||||
p[4] = bVendorType; // Vendor type
|
||||
p[5] = static_cast<BYTE>(dwLengthNew - 4); // Vendor length
|
||||
p[6] = 0x00; // Salt
|
||||
p[7] = 0x00; // --^
|
||||
p[8] = nKeySize; // Key-Length
|
||||
#pragma warning(pop)
|
||||
memcpy(p + 9, pbKey, nKeySize); // Key
|
||||
memset(p + 9 + nKeySize, 0, nPaddingLength); // Padding
|
||||
|
||||
if (pValue)
|
||||
delete [] pValue;
|
||||
|
||||
#pragma warning(suppress: 26812) // EAP_ATTRIBUTE_TYPE is unscoped.
|
||||
eaType = eatVendorSpecific;
|
||||
dwLength = dwLengthNew;
|
||||
pValue = p;
|
||||
}
|
||||
|
||||
|
||||
const EAP_ATTRIBUTE winstd::eap_attr::blank = {};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_packet
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::eap_packet::~eap_packet()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_packet::free_internal() noexcept
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const noexcept
|
||||
{
|
||||
const WORD n = ntohs(*reinterpret_cast<WORD*>(h->Length));
|
||||
handle_type h2 = static_cast<handle_type>(HeapAlloc(GetProcessHeap(), 0, n));
|
||||
if (h2 == invalid) {
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return invalid;
|
||||
}
|
||||
|
||||
memcpy(h2, h, n);
|
||||
|
||||
return h2;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_method_info_array
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::eap_method_info_array::~eap_method_info_array()
|
||||
{
|
||||
if (pEapMethods)
|
||||
free_internal();
|
||||
}
|
||||
|
||||
|
||||
/// \cond internal
|
||||
|
||||
void winstd::eap_method_info_array::free_internal() noexcept
|
||||
{
|
||||
for (DWORD i = 0; i < dwNumberOfMethods; i++)
|
||||
free_internal(pEapMethods + i);
|
||||
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pEapMethods));
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept
|
||||
{
|
||||
if (pMethodInfo->pInnerMethodInfo)
|
||||
free_internal(pMethodInfo->pInnerMethodInfo);
|
||||
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszAuthorName));
|
||||
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszFriendlyName));
|
||||
}
|
||||
|
||||
/// \endcond
|
191
src/ETW.cpp
191
src/ETW.cpp
@ -1,191 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_data
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
const winstd::event_data winstd::event_data::blank;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_rec
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::event_rec::~event_rec()
|
||||
{
|
||||
if (ExtendedData)
|
||||
delete reinterpret_cast<unsigned char*>(ExtendedData);
|
||||
|
||||
if (UserData)
|
||||
delete reinterpret_cast<unsigned char*>(UserData);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_rec::set_extended_data(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
|
||||
{
|
||||
if (ExtendedData)
|
||||
delete reinterpret_cast<unsigned char*>(ExtendedData);
|
||||
|
||||
set_extended_data_internal(count, data);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_rec::set_user_data(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
|
||||
{
|
||||
if (UserData)
|
||||
delete reinterpret_cast<unsigned char*>(UserData);
|
||||
|
||||
set_user_data_internal(size, data);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_rec::set_extended_data_internal(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
|
||||
{
|
||||
if (count) {
|
||||
assert(data);
|
||||
|
||||
// Count the total required memory.
|
||||
size_t data_size = 0;
|
||||
for (size_t i = 0; i < count; i++)
|
||||
data_size += data[i].DataSize;
|
||||
|
||||
// Allocate memory for extended data.
|
||||
ExtendedData = reinterpret_cast<EVENT_HEADER_EXTENDED_DATA_ITEM*>(new unsigned char[sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM)*count + data_size]);
|
||||
|
||||
// Bulk-copy extended data descriptors.
|
||||
memcpy(ExtendedData, data, sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM) * count);
|
||||
|
||||
// Copy the data.
|
||||
unsigned char *ptr = reinterpret_cast<unsigned char*>(ExtendedData + count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (data[i].DataSize) {
|
||||
memcpy(ptr, (void*)(data[i].DataPtr), data[i].DataSize);
|
||||
ExtendedData[i].DataPtr = (ULONGLONG)ptr;
|
||||
ptr += data[i].DataSize;
|
||||
} else
|
||||
ExtendedData[i].DataPtr = NULL;
|
||||
}
|
||||
} else
|
||||
ExtendedData = NULL;
|
||||
|
||||
ExtendedDataCount = count;
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_rec::set_user_data_internal(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
|
||||
{
|
||||
if (size) {
|
||||
assert(data);
|
||||
|
||||
// Allocate memory for user data.
|
||||
UserData = new unsigned char[size];
|
||||
|
||||
// Copy user data.
|
||||
memcpy(UserData, data, size);
|
||||
} else
|
||||
UserData = NULL;
|
||||
|
||||
UserDataLength = size;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_provider
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::event_provider::~event_provider()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
EventUnregister(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_provider::free_internal() noexcept
|
||||
{
|
||||
EventUnregister(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_provider::enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(SourceId);
|
||||
UNREFERENCED_PARAMETER(IsEnabled);
|
||||
UNREFERENCED_PARAMETER(Level);
|
||||
UNREFERENCED_PARAMETER(MatchAnyKeyword);
|
||||
UNREFERENCED_PARAMETER(MatchAllKeyword);
|
||||
UNREFERENCED_PARAMETER(FilterData);
|
||||
}
|
||||
|
||||
|
||||
VOID NTAPI winstd::event_provider::enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _Inout_opt_ PVOID CallbackContext)
|
||||
{
|
||||
if (CallbackContext)
|
||||
static_cast<event_provider*>(CallbackContext)->enable_callback(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData);
|
||||
else
|
||||
assert(0); // Where did the "this" pointer get lost?
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_session
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::event_session::~event_session()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_session::free_internal() noexcept
|
||||
{
|
||||
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_trace_enabler
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::event_trace_enabler::~event_trace_enabler()
|
||||
{
|
||||
if (m_status == ERROR_SUCCESS)
|
||||
EnableTraceEx(
|
||||
m_provider_id,
|
||||
m_source_id,
|
||||
m_trace_handle,
|
||||
EVENT_CONTROL_CODE_DISABLE_PROVIDER,
|
||||
m_level,
|
||||
m_match_any_keyword,
|
||||
m_match_all_keyword,
|
||||
m_enable_property,
|
||||
m_enable_filter_desc);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::event_trace
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::event_trace::~event_trace()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
CloseTrace(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::event_trace::free_internal() noexcept
|
||||
{
|
||||
CloseTrace(m_h);
|
||||
}
|
||||
|
||||
#endif
|
52
src/GDI.cpp
52
src/GDI.cpp
@ -1,52 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::dc
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::dc::~dc()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
DeleteDC(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::dc::free_internal() noexcept
|
||||
{
|
||||
DeleteDC(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::window_dc
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::window_dc::~window_dc()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
ReleaseDC(m_hwnd, m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::window_dc::free_internal() noexcept
|
||||
{
|
||||
ReleaseDC(m_hwnd, m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::dc_selector
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::dc_selector::~dc_selector()
|
||||
{
|
||||
if (m_orig)
|
||||
SelectObject(m_hdc, m_orig);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
31
src/PCH.h
31
src/PCH.h
@ -1,31 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../include/WinStd/Base64.h"
|
||||
#include "../include/WinStd/COM.h"
|
||||
#include "../include/WinStd/Cred.h"
|
||||
#include "../include/WinStd/Crypt.h"
|
||||
#include "../include/WinStd/EAP.h"
|
||||
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||
#include "../include/WinStd/ETW.h"
|
||||
#endif
|
||||
#include "../include/WinStd/GDI.h"
|
||||
#include "../include/WinStd/Hex.h"
|
||||
#include "../include/WinStd/MSI.h"
|
||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||
#include "../include/WinStd/Sec.h"
|
||||
#endif
|
||||
#include "../include/WinStd/SetupAPI.h"
|
||||
#include "../include/WinStd/Shell.h"
|
||||
#include "../include/WinStd/Win.h"
|
||||
#include "../include/WinStd/WinSock2.h"
|
||||
#include "../include/WinStd/WinTrust.h"
|
||||
#include "../include/WinStd/WLAN.h"
|
||||
#include "../include/WinStd/Common.h"
|
||||
|
||||
#include <tchar.h>
|
64
src/Sec.cpp
64
src/Sec.cpp
@ -1,64 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::sec_credentials
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::sec_credentials::~sec_credentials()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
FreeCredentialsHandle(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::sec_credentials::free_internal() noexcept
|
||||
{
|
||||
FreeCredentialsHandle(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::sec_context
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::sec_context::~sec_context()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
DeleteSecurityContext(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::sec_context::free_internal() noexcept
|
||||
{
|
||||
DeleteSecurityContext(m_h);
|
||||
delete m_h;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::sec_buffer_desc
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::sec_buffer_desc::~sec_buffer_desc()
|
||||
{
|
||||
for (ULONG i = 0; i < cBuffers; i++) {
|
||||
if (pBuffers[i].pvBuffer)
|
||||
FreeContextBuffer(pBuffers[i].pvBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
#pragma comment(lib, "Setupapi.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::setup_device_info_list
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::setup_device_info_list::~setup_device_info_list()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::setup_device_info_list::free_internal() noexcept
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::setup_device_info_list
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::setup_driver_info_list_builder::~setup_driver_info_list_builder()
|
||||
{
|
||||
if (m_result)
|
||||
SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
|
||||
}
|
24
src/WLAN.cpp
24
src/WLAN.cpp
@ -1,24 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::wlan_handle
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::wlan_handle::~wlan_handle()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
|
||||
void winstd::wlan_handle::free_internal() noexcept
|
||||
{
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
392
src/Win.cpp
392
src/Win.cpp
@ -1,392 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// StringToGuidA
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
_Success_(return) BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) noexcept
|
||||
{
|
||||
GUID g;
|
||||
LPSTR lpszEnd;
|
||||
unsigned long ulTmp;
|
||||
unsigned long long ullTmp;
|
||||
|
||||
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE) return FALSE;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data2 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
|
||||
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
_Success_(return) BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) noexcept
|
||||
{
|
||||
GUID g;
|
||||
LPWSTR lpszEnd;
|
||||
unsigned long ulTmp;
|
||||
unsigned long long ullTmp;
|
||||
|
||||
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE) return FALSE;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data2 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = static_cast<unsigned short>(ulTmp);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
|
||||
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::library
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::library::~library()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::library::free_internal() noexcept
|
||||
{
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::critical_section
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::critical_section::critical_section()
|
||||
{
|
||||
__try {
|
||||
InitializeCriticalSection(&m_data);
|
||||
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
||||
throw std::runtime_error("InitializeCriticalSection failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
winstd::critical_section::~critical_section()
|
||||
{
|
||||
DeleteCriticalSection(&m_data);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::find_file
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::find_file::~find_file()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
FindClose(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::find_file::free_internal() noexcept
|
||||
{
|
||||
FindClose(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::heap
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::heap::~heap()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool winstd::heap::enumerate() noexcept
|
||||
{
|
||||
assert(m_h != invalid);
|
||||
|
||||
bool found = false;
|
||||
|
||||
// Lock the heap for exclusive access.
|
||||
HeapLock(m_h);
|
||||
|
||||
PROCESS_HEAP_ENTRY e;
|
||||
e.lpData = NULL;
|
||||
while (HeapWalk(m_h, &e) != FALSE) {
|
||||
if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
|
||||
OutputDebugStr(
|
||||
_T("Allocated block%s%s\n")
|
||||
_T(" Data portion begins at: %#p\n Size: %d bytes\n")
|
||||
_T(" Overhead: %d bytes\n Region index: %d\n"),
|
||||
(e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ? tstring_printf(_T(", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(""),
|
||||
(e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(", DDESHARE") : _T(""),
|
||||
e.lpData,
|
||||
e.cbData,
|
||||
e.cbOverhead,
|
||||
e.iRegionIndex);
|
||||
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
const DWORD dwResult = GetLastError();
|
||||
if (dwResult != ERROR_NO_MORE_ITEMS)
|
||||
OutputDebugStr(_T("HeapWalk failed (error %u).\n"), dwResult);
|
||||
|
||||
// Unlock the heap.
|
||||
HeapUnlock(m_h);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
void winstd::heap::free_internal() noexcept
|
||||
{
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::actctx_activator
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx) noexcept
|
||||
{
|
||||
if (!ActivateActCtx(hActCtx, &m_cookie))
|
||||
m_cookie = 0;
|
||||
}
|
||||
|
||||
|
||||
winstd::actctx_activator::~actctx_activator()
|
||||
{
|
||||
if (m_cookie)
|
||||
DeactivateActCtx(0, m_cookie);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::user_impersonator
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken) noexcept
|
||||
{
|
||||
m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
|
||||
}
|
||||
|
||||
|
||||
winstd::user_impersonator::~user_impersonator()
|
||||
{
|
||||
if (m_cookie)
|
||||
RevertToSelf();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::console_ctrl_handler
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept :
|
||||
m_handler(HandlerRoutine)
|
||||
{
|
||||
m_cookie = SetConsoleCtrlHandler(m_handler, TRUE);
|
||||
}
|
||||
|
||||
|
||||
winstd::console_ctrl_handler::~console_ctrl_handler()
|
||||
{
|
||||
if (m_cookie)
|
||||
SetConsoleCtrlHandler(m_handler, FALSE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::vmemory
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::vmemory::~vmemory()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
void winstd::vmemory::free_internal() noexcept
|
||||
{
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::reg_key
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::reg_key::~reg_key()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
bool winstd::reg_key::delete_subkey(_In_z_ LPCTSTR szSubkey)
|
||||
{
|
||||
LSTATUS s;
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
|
||||
return true;
|
||||
|
||||
{
|
||||
reg_key k;
|
||||
if (!k.open(m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS))
|
||||
return false;
|
||||
for (;;) {
|
||||
TCHAR szName[MAX_PATH];
|
||||
DWORD dwSize = _countof(szName);
|
||||
s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
|
||||
if (s == ERROR_SUCCESS)
|
||||
k.delete_subkey(szName);
|
||||
else if (s == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s = RegDeleteKey(m_h, szSubkey);
|
||||
if (s == ERROR_SUCCESS)
|
||||
return true;
|
||||
else {
|
||||
SetLastError(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::reg_key::free_internal() noexcept
|
||||
{
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::security_id
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::security_id::~security_id()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::security_id::free_internal() noexcept
|
||||
{
|
||||
FreeSid(m_h);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
|
||||
#if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::addrinfo
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::addrinfo::~addrinfo()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::addrinfo::free_internal() noexcept
|
||||
{
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
Copyright © 1991-2022 Amebis
|
||||
Copyright © 2016 GÉANT
|
||||
*/
|
||||
|
||||
#include "PCH.h"
|
||||
|
||||
#pragma comment(lib, "Wintrust.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::wintrust
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::wintrust::~wintrust()
|
||||
{
|
||||
m_wtd.dwStateAction = WTD_STATEACTION_CLOSE;
|
||||
WinVerifyTrust(m_hwnd, &m_action, &m_wtd);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user