-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fea, 为XP添加CryptBinaryToStringW(A) CRYPT_STRING_NOCRLF支持
- Loading branch information
1 parent
f5ffc8a
commit 8f47d40
Showing
8 changed files
with
278 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "pch.h" | ||
#include "Thunks/Crypt32.hpp" | ||
|
||
#include <wincrypt.h> | ||
|
||
#pragma comment(lib, "Crypt32.lib") | ||
|
||
namespace Crypt32 | ||
{ | ||
TEST_CLASS(CryptBinaryToStringW) | ||
{ | ||
AwaysNullGuard Guard; | ||
|
||
public: | ||
CryptBinaryToStringW() | ||
{ | ||
g_uSystemVersion = MakeVersion(5, 1); | ||
} | ||
|
||
~CryptBinaryToStringW() | ||
{ | ||
g_uSystemVersion = 0; | ||
} | ||
|
||
TEST_METHOD(CRYPT_STRING_NOCRLF参数验证) | ||
{ | ||
wchar_t _szUnitTestDll[512]; | ||
GetModuleFileNameW((HMODULE)&__ImageBase, _szUnitTestDll, std::size(_szUnitTestDll)); | ||
|
||
const auto _FileData = ReadFileData(_szUnitTestDll); | ||
Assert::AreNotEqual(_FileData.size(), size_t(0)); | ||
|
||
{ | ||
DWORD _cchOut = 0; | ||
Assert::IsTrue(::CryptBinaryToStringW((const BYTE*)_FileData.c_str(), _FileData.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &_cchOut)); | ||
|
||
auto _szOutBuffer = new wchar_t[_cchOut]; | ||
Assert::IsNotNull(_szOutBuffer); | ||
|
||
Assert::IsTrue(::CryptBinaryToStringW((const BYTE*)_FileData.c_str(), _FileData.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, _szOutBuffer, &_cchOut)); | ||
|
||
Assert::AreEqual(size_t(_cchOut), wcslen(_szOutBuffer)); | ||
|
||
Assert::IsNull(wcschr(_szOutBuffer, L'\r')); | ||
Assert::IsNull(wcschr(_szOutBuffer, L'\n')); | ||
|
||
DWORD _cbBinary = 0; | ||
Assert::IsTrue(::CryptStringToBinaryW(_szOutBuffer, _cchOut, CRYPT_STRING_BASE64, nullptr, &_cbBinary, nullptr, nullptr)); | ||
Assert::AreEqual(size_t(_cbBinary), _FileData.size()); | ||
|
||
std::string _Binary; | ||
_Binary.resize(_cbBinary); | ||
Assert::IsTrue(::CryptStringToBinaryW(_szOutBuffer, _cchOut, CRYPT_STRING_BASE64, (BYTE*)_Binary.data(), &_cbBinary, nullptr, nullptr)); | ||
Assert::AreEqual(_FileData, _Binary); | ||
|
||
delete[] _szOutBuffer; | ||
} | ||
|
||
{ | ||
DWORD _cchOut = 0; | ||
Assert::IsTrue(::CryptBinaryToStringA((const BYTE*)_FileData.c_str(), _FileData.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &_cchOut)); | ||
|
||
auto _szOutBuffer = new char[_cchOut]; | ||
Assert::IsNotNull(_szOutBuffer); | ||
|
||
Assert::IsTrue(::CryptBinaryToStringA((const BYTE*)_FileData.c_str(), _FileData.size(), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, _szOutBuffer, &_cchOut)); | ||
|
||
Assert::AreEqual(size_t(_cchOut), strlen(_szOutBuffer)); | ||
|
||
Assert::IsNull(strchr(_szOutBuffer, '\r')); | ||
Assert::IsNull(strchr(_szOutBuffer, '\n')); | ||
|
||
DWORD _cbBinary = 0; | ||
Assert::IsTrue(::CryptStringToBinaryA(_szOutBuffer, _cchOut, CRYPT_STRING_BASE64, nullptr, &_cbBinary, nullptr, nullptr)); | ||
Assert::AreEqual(size_t(_cbBinary), _FileData.size()); | ||
|
||
std::string _Binary; | ||
_Binary.resize(_cbBinary); | ||
Assert::IsTrue(::CryptStringToBinaryA(_szOutBuffer, _cchOut, CRYPT_STRING_BASE64, (BYTE*)_Binary.data(), &_cbBinary, nullptr, nullptr)); | ||
Assert::AreEqual(_FileData, _Binary); | ||
|
||
delete[] _szOutBuffer; | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters