Resolve code analysis reported warnings
This commit is contained in:
277
src/EAP.cpp
277
src/EAP.cpp
@@ -1,137 +1,140 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#pragma comment(lib, "Eappcfg.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_attr
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
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)
|
||||
{
|
||||
BYTE nPaddingLength = (BYTE)((16 - (1 + (DWORD)nKeySize)) % 16);
|
||||
DWORD dwLengthNew =
|
||||
4 + // Vendor-Id
|
||||
1 + // Vendor type
|
||||
1 + // Vendor length
|
||||
2 + // Salt
|
||||
1 + // Key-Length
|
||||
nKeySize + // Key
|
||||
nPaddingLength; // Padding
|
||||
|
||||
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] = (BYTE)(dwLengthNew - 4); // Vendor length
|
||||
p[6] = 0x00; // Salt
|
||||
p[7] = 0x00; // --^
|
||||
p[8] = nKeySize; // Key-Length
|
||||
memcpy(p + 9, pbKey, nKeySize); // Key
|
||||
memset(p + 9 + nKeySize, 0, nPaddingLength); // Padding
|
||||
|
||||
if (pValue)
|
||||
delete [] pValue;
|
||||
|
||||
eaType = eatVendorSpecific;
|
||||
dwLength = dwLengthNew;
|
||||
pValue = p;
|
||||
}
|
||||
|
||||
|
||||
const EAP_ATTRIBUTE winstd::eap_attr::blank = {};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_packet
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::eap_packet::~eap_packet()
|
||||
{
|
||||
if (m_h)
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_packet::free_internal()
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const
|
||||
{
|
||||
WORD n = ntohs(*(WORD*)h->Length);
|
||||
handle_type h2 = (handle_type)HeapAlloc(GetProcessHeap(), 0, n);
|
||||
if (!h2) {
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
for (DWORD i = 0; i < dwNumberOfMethods; i++)
|
||||
free_internal(pEapMethods + i);
|
||||
|
||||
EapHostPeerFreeMemory((BYTE*)pEapMethods);
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo)
|
||||
{
|
||||
if (pMethodInfo->pInnerMethodInfo)
|
||||
free_internal(pMethodInfo->pInnerMethodInfo);
|
||||
|
||||
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszAuthorName);
|
||||
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszFriendlyName);
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#pragma comment(lib, "Eappcfg.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_attr
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
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)
|
||||
{
|
||||
BYTE nPaddingLength = (BYTE)((16 - (1 + (DWORD)nKeySize)) % 16);
|
||||
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] = (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;
|
||||
|
||||
eaType = eatVendorSpecific;
|
||||
dwLength = dwLengthNew;
|
||||
pValue = p;
|
||||
}
|
||||
|
||||
|
||||
const EAP_ATTRIBUTE winstd::eap_attr::blank = {};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::eap_packet
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::eap_packet::~eap_packet()
|
||||
{
|
||||
if (m_h)
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_packet::free_internal()
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
|
||||
winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const
|
||||
{
|
||||
WORD n = ntohs(*(WORD*)h->Length);
|
||||
handle_type h2 = (handle_type)HeapAlloc(GetProcessHeap(), 0, n);
|
||||
if (!h2) {
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
for (DWORD i = 0; i < dwNumberOfMethods; i++)
|
||||
free_internal(pEapMethods + i);
|
||||
|
||||
EapHostPeerFreeMemory((BYTE*)pEapMethods);
|
||||
}
|
||||
|
||||
|
||||
void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo)
|
||||
{
|
||||
if (pMethodInfo->pInnerMethodInfo)
|
||||
free_internal(pMethodInfo->pInnerMethodInfo);
|
||||
|
||||
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszAuthorName);
|
||||
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszFriendlyName);
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
|
82
src/StdAfx.h
82
src/StdAfx.h
@@ -1,40 +1,42 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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/Common.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/Shell.h"
|
||||
#include "../include/WinStd/Win.h"
|
||||
#include "../include/WinStd/WLAN.h"
|
||||
|
||||
#include <tchar.h>
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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/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/Shell.h"
|
||||
#include "../include/WinStd/Win.h"
|
||||
#include "../include/WinStd/WinTrust.h"
|
||||
#include "../include/WinStd/WLAN.h"
|
||||
#include "../include/WinStd/Common.h"
|
||||
|
||||
#include <tchar.h>
|
||||
|
656
src/Win.cpp
656
src/Win.cpp
@@ -1,328 +1,328 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// StringToGuidA
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd)
|
||||
{
|
||||
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 = (unsigned short)ulTmp;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = (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] = (unsigned char)((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = (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] = (unsigned char)((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd)
|
||||
{
|
||||
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 = (unsigned short)ulTmp;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = (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] = (unsigned char)((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = (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] = (unsigned char)((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::win_handle
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::win_handle::~win_handle()
|
||||
{
|
||||
if (m_h)
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::win_handle::free_internal()
|
||||
{
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::library
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::library::~library()
|
||||
{
|
||||
if (m_h)
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::library::free_internal()
|
||||
{
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::heap
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::heap::~heap()
|
||||
{
|
||||
if (m_h) {
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool winstd::heap::enumerate()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::actctx_activator
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx)
|
||||
{
|
||||
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_ HANDLE hToken)
|
||||
{
|
||||
m_cookie = ImpersonateLoggedOnUser(hToken);
|
||||
}
|
||||
|
||||
|
||||
winstd::user_impersonator::~user_impersonator()
|
||||
{
|
||||
if (m_cookie)
|
||||
RevertToSelf();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::vmemory
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::vmemory::~vmemory()
|
||||
{
|
||||
if (m_h)
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
void winstd::vmemory::free_internal()
|
||||
{
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::reg_key
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::reg_key::~reg_key()
|
||||
{
|
||||
if (m_h)
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::reg_key::free_internal()
|
||||
{
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::security_id
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::security_id::~security_id()
|
||||
{
|
||||
if (m_h)
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::security_id::free_internal()
|
||||
{
|
||||
FreeSid(m_h);
|
||||
}
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// StringToGuidA
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd)
|
||||
{
|
||||
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 = (unsigned short)ulTmp;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = (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] = (unsigned char)((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = (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] = (unsigned char)((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd)
|
||||
{
|
||||
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 = (unsigned short)ulTmp;
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '-') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
|
||||
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
|
||||
g.Data3 = (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] = (unsigned char)((ulTmp >> 8) & 0xff);
|
||||
g.Data4[1] = (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] = (unsigned char)((ullTmp >> 40) & 0xff);
|
||||
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
|
||||
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
|
||||
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
|
||||
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
|
||||
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
|
||||
lpszGuid = lpszEnd;
|
||||
|
||||
if (*lpszGuid != '}') return FALSE;
|
||||
lpszGuid++;
|
||||
|
||||
if (lpszGuidEnd)
|
||||
*lpszGuidEnd = lpszGuid;
|
||||
|
||||
*lpGuid = g;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::win_handle
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::win_handle::~win_handle()
|
||||
{
|
||||
if (m_h)
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::win_handle::free_internal()
|
||||
{
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::library
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::library::~library()
|
||||
{
|
||||
if (m_h)
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::library::free_internal()
|
||||
{
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::heap
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::heap::~heap()
|
||||
{
|
||||
if (m_h) {
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool winstd::heap::enumerate()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::actctx_activator
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx)
|
||||
{
|
||||
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_ HANDLE hToken)
|
||||
{
|
||||
m_cookie = ImpersonateLoggedOnUser(hToken);
|
||||
}
|
||||
|
||||
|
||||
winstd::user_impersonator::~user_impersonator()
|
||||
{
|
||||
if (m_cookie)
|
||||
RevertToSelf();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::vmemory
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::vmemory::~vmemory()
|
||||
{
|
||||
if (m_h)
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
void winstd::vmemory::free_internal()
|
||||
{
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::reg_key
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::reg_key::~reg_key()
|
||||
{
|
||||
if (m_h)
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::reg_key::free_internal()
|
||||
{
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::security_id
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::security_id::~security_id()
|
||||
{
|
||||
if (m_h)
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::security_id::free_internal()
|
||||
{
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
Reference in New Issue
Block a user