Skip to content

Commit

Permalink
关闭GSL的告警。
Browse files Browse the repository at this point in the history
  • Loading branch information
kouzhudong committed Oct 25, 2023
1 parent 4f2b2d9 commit 3cf2ae5
Show file tree
Hide file tree
Showing 29 changed files with 56 additions and 56 deletions.
Binary file modified libdrv/APC.cpp
Binary file not shown.
Binary file modified libdrv/CopyFile.cpp
Binary file not shown.
Binary file modified libdrv/File.cpp
Binary file not shown.
Binary file modified libdrv/Image.cpp
Binary file not shown.
Binary file modified libdrv/Memory.cpp
Binary file not shown.
Binary file modified libdrv/Network.cpp
Binary file not shown.
Binary file modified libdrv/Process.cpp
Binary file not shown.
Binary file modified libdrv/Registry.cpp
Binary file not shown.
4 changes: 2 additions & 2 deletions libdrv/cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
void * __cdecl operator new(_In_ size_t size)
{
if (size == 0) {
return NULL;
return nullptr;
}

const auto p = ExAllocatePoolWithTag(NonPagedPool, size, TAG);
Expand Down Expand Up @@ -40,7 +40,7 @@ void __cdecl operator delete(_In_ void * p, _In_ SIZE_T size)
_IRQL_requires_max_(DISPATCH_LEVEL)
void * __cdecl operator new[](_In_ size_t size) {
if (size == 0) {
return NULL;
return nullptr;
}

const auto p = ExAllocatePoolWithTag(NonPagedPool, size, TAG);
Expand Down
64 changes: 32 additions & 32 deletions libdrv/encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ NTSTATUS WINAPI RsaPrivateKeyDecrypt(_In_reads_bytes_(PrivateKeyLen) PUCHAR Priv
*/
{
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
BCRYPT_KEY_HANDLE hKey = NULL;
BCRYPT_ALG_HANDLE hAlgorithm = nullptr;
BCRYPT_KEY_HANDLE hKey = nullptr;
NTSTATUS Status = STATUS_SUCCESS;

__try {
Status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RSA_ALGORITHM, NULL, 0);
Status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RSA_ALGORITHM, nullptr, 0);
if (!NT_SUCCESS(Status)) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

Status = BCryptImportKeyPair(hAlgorithm,
NULL,
nullptr,
BCRYPT_RSAPRIVATE_BLOB,
&hKey,
PrivateKey,
Expand All @@ -38,8 +38,8 @@ NTSTATUS WINAPI RsaPrivateKeyDecrypt(_In_reads_bytes_(PrivateKeyLen) PUCHAR Priv
Status = BCryptDecrypt(hKey,
CipherText,
CipherTextSize,
NULL,
NULL,
nullptr,
nullptr,
0,
PlainText,
PlainTextSize,
Expand Down Expand Up @@ -76,19 +76,19 @@ NTSTATUS WINAPI RsaPublicKeyEncrypt(_In_reads_bytes_(PublicKeyLen) PUCHAR Public
*/
{
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
BCRYPT_ALG_HANDLE hAlgorithm = nullptr;
NTSTATUS Status = STATUS_SUCCESS;
BCRYPT_KEY_HANDLE hKey = NULL;
BCRYPT_KEY_HANDLE hKey = nullptr;

__try {
Status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RSA_ALGORITHM, NULL, 0);
Status = BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_RSA_ALGORITHM, nullptr, 0);
if (!NT_SUCCESS(Status)) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

Status = BCryptImportKeyPair(hAlgorithm,
NULL,
nullptr,
BCRYPT_RSAPUBLIC_BLOB,
&hKey,
PublicKey,
Expand All @@ -102,8 +102,8 @@ NTSTATUS WINAPI RsaPublicKeyEncrypt(_In_reads_bytes_(PublicKeyLen) PUCHAR Public
Status = BCryptEncrypt(hKey,
PlainText,
PlainTextSize,
NULL,
NULL,
nullptr,
nullptr,
0,
CipherText,
CipherTextSize,
Expand Down Expand Up @@ -137,11 +137,11 @@ Encrypting Data with CNG
https://docs.microsoft.com/zh-cn/windows/win32/seccng/encrypting-data-with-cng
*/
{
BCRYPT_ALG_HANDLE hAesAlg = NULL;
BCRYPT_KEY_HANDLE hKey = NULL;
BCRYPT_ALG_HANDLE hAesAlg = nullptr;
BCRYPT_KEY_HANDLE hKey = nullptr;
NTSTATUS Status = STATUS_UNSUCCESSFUL;
DWORD cbCipherText = 0, cbPlainText = 0, cbData = 0, cbKeyObject = 0, cbBlockLen = 0, cbBlob = 0;
PBYTE pbCipherText = NULL, pbPlainText = NULL, pbKeyObject = NULL, pbIV = NULL, pbBlob = NULL;
PBYTE pbCipherText = nullptr, pbPlainText = nullptr, pbKeyObject = nullptr, pbIV = nullptr, pbBlob = nullptr;

const BYTE rgbPlaintext[] =
{
Expand All @@ -164,7 +164,7 @@ Encrypting Data with CNG
__try {

// Open an algorithm handle.
if (!NT_SUCCESS(Status = BCryptOpenAlgorithmProvider(&hAesAlg, BCRYPT_AES_ALGORITHM, NULL, 0))) {
if (!NT_SUCCESS(Status = BCryptOpenAlgorithmProvider(&hAesAlg, BCRYPT_AES_ALGORITHM, nullptr, 0))) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}
Expand All @@ -182,7 +182,7 @@ Encrypting Data with CNG

// Allocate the key object on the heap.
pbKeyObject = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbKeyObject, TAG);
if (NULL == pbKeyObject) {
if (nullptr == pbKeyObject) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}
Expand All @@ -206,7 +206,7 @@ Encrypting Data with CNG

// Allocate a buffer for the IV. The buffer is consumed during the encrypt/decrypt process.
pbIV = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbBlockLen, TAG);
if (NULL == pbIV) {
if (nullptr == pbIV) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}
Expand Down Expand Up @@ -235,26 +235,26 @@ Encrypting Data with CNG
}

// Save another copy of the key for later.
if (!NT_SUCCESS(Status = BCryptExportKey(hKey, NULL, BCRYPT_OPAQUE_KEY_BLOB, NULL, 0, &cbBlob, 0))) {
if (!NT_SUCCESS(Status = BCryptExportKey(hKey, nullptr, BCRYPT_OPAQUE_KEY_BLOB, nullptr, 0, &cbBlob, 0))) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

// Allocate the buffer to hold the BLOB.
pbBlob = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbBlob, TAG);
if (NULL == pbBlob) {
if (nullptr == pbBlob) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

if (!NT_SUCCESS(Status = BCryptExportKey(hKey, NULL, BCRYPT_OPAQUE_KEY_BLOB, pbBlob, cbBlob, &cbBlob, 0))) {
if (!NT_SUCCESS(Status = BCryptExportKey(hKey, nullptr, BCRYPT_OPAQUE_KEY_BLOB, pbBlob, cbBlob, &cbBlob, 0))) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

cbPlainText = sizeof(rgbPlaintext);
pbPlainText = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbPlainText, TAG);
if (NULL == pbPlainText) {
if (nullptr == pbPlainText) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}
Expand All @@ -265,10 +265,10 @@ Encrypting Data with CNG
if (!NT_SUCCESS(Status = BCryptEncrypt(hKey,
pbPlainText,
cbPlainText,
NULL,
nullptr,
pbIV,
cbBlockLen,
NULL,
nullptr,
0,
&cbCipherText,
BCRYPT_BLOCK_PADDING))) {
Expand All @@ -277,7 +277,7 @@ Encrypting Data with CNG
}

pbCipherText = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbCipherText, TAG);
if (NULL == pbCipherText) {
if (nullptr == pbCipherText) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}
Expand All @@ -287,7 +287,7 @@ Encrypting Data with CNG
if (!NT_SUCCESS(Status = BCryptEncrypt(hKey,
pbPlainText,
cbPlainText,
NULL,
nullptr,
pbIV,
cbBlockLen,
pbCipherText,
Expand All @@ -310,12 +310,12 @@ Encrypting Data with CNG
ExFreePoolWithTag(pbPlainText, TAG);
}

pbPlainText = NULL;
pbPlainText = nullptr;

memset(pbKeyObject, 0, cbKeyObject);// We can reuse the key object.
memcpy(pbIV, rgbIV, cbBlockLen);// Reinitialize the IV because encryption would have modified it.
if (!NT_SUCCESS(Status = BCryptImportKey(hAesAlg,
NULL,
nullptr,
BCRYPT_OPAQUE_KEY_BLOB,
&hKey,
pbKeyObject,
Expand All @@ -331,10 +331,10 @@ Encrypting Data with CNG
if (!NT_SUCCESS(Status = BCryptDecrypt(hKey,
pbCipherText,
cbCipherText,
NULL,
nullptr,
pbIV,
cbBlockLen,
NULL,
nullptr,
0,
&cbPlainText,
BCRYPT_BLOCK_PADDING))) {
Expand All @@ -343,15 +343,15 @@ Encrypting Data with CNG
}

pbPlainText = (PBYTE)ExAllocatePoolWithTag(NonPagedPool, cbPlainText, TAG);
if (NULL == pbPlainText) {
if (nullptr == pbPlainText) {
PrintEx(DPFLTR_DEFAULT_ID, DPFLTR_ERROR_LEVEL, "Status:%#x", Status);
__leave;
}

if (!NT_SUCCESS(Status = BCryptDecrypt(hKey,
pbCipherText,
cbCipherText,
NULL,
nullptr,
pbIV,
cbBlockLen,
pbPlainText,
Expand Down
Binary file modified libdrv/gdt.cpp
Binary file not shown.
Binary file modified libdrv/hash.cpp
Binary file not shown.
Binary file modified libdrv/log.cpp
Binary file not shown.
Binary file modified libdrv/misc.cpp
Binary file not shown.
Binary file modified libdrv/object.cpp
Binary file not shown.
2 changes: 1 addition & 1 deletion libdrv/pch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PVOID NTAPI AllocatePoolZero(
PVOID Allocation;

Allocation = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
if ((Allocation != NULL)) {
if (Allocation) {
RtlZeroMemory(Allocation, NumberOfBytes);
}

Expand Down
Binary file modified libdrv/pe.cpp
Binary file not shown.
22 changes: 11 additions & 11 deletions libdrv/signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ NTSTATUS WINAPI SignHash(_In_z_ LPCWSTR pszHashId,
ASSERT(ret);

NTSTATUS status = STATUS_UNSUCCESSFUL;
BCRYPT_ALG_HANDLE hSignAlg = NULL;
status = BCryptOpenAlgorithmProvider(&hSignAlg, pszAlgId, NULL, 0);
BCRYPT_ALG_HANDLE hSignAlg = nullptr;
status = BCryptOpenAlgorithmProvider(&hSignAlg, pszAlgId, nullptr, 0);
ASSERT(NT_SUCCESS(status));

BCRYPT_KEY_HANDLE hPrivateKey = NULL;
BCRYPT_KEY_HANDLE hPrivateKey = nullptr;
status = BCryptImportKeyPair(hSignAlg,
NULL,
nullptr,
BCRYPT_ECCPRIVATE_BLOB,
&hPrivateKey,
PrivateKey,
PrivateKeyLen,
BCRYPT_NO_KEY_VALIDATION);
ASSERT(NT_SUCCESS(status));

status = BCryptSignHash(hPrivateKey, NULL, Hash, HashSize, NULL, 0, SignSize, 0);
status = BCryptSignHash(hPrivateKey, nullptr, Hash, HashSize, nullptr, 0, SignSize, 0);
ASSERT(NT_SUCCESS(status));

*Sign = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, *SignSize, TAG);
ASSERT(*Sign);

ULONG Result = 0;
status = BCryptSignHash(hPrivateKey, NULL, Hash, HashSize, *Sign, *SignSize, &Result, 0);
status = BCryptSignHash(hPrivateKey, nullptr, Hash, HashSize, *Sign, *SignSize, &Result, 0);
ASSERT(NT_SUCCESS(status));

BCryptCloseAlgorithmProvider(hSignAlg, 0);
Expand Down Expand Up @@ -72,21 +72,21 @@ BOOL WINAPI VerifySignature(_In_z_ LPCWSTR pszHashId,
ASSERT(ret);

NTSTATUS status = STATUS_UNSUCCESSFUL;
BCRYPT_ALG_HANDLE hSignAlg = NULL;
status = BCryptOpenAlgorithmProvider(&hSignAlg, pszAlgId, NULL, 0);
BCRYPT_ALG_HANDLE hSignAlg = nullptr;
status = BCryptOpenAlgorithmProvider(&hSignAlg, pszAlgId, nullptr, 0);
ASSERT(NT_SUCCESS(status));

BCRYPT_KEY_HANDLE hPublicKey = NULL;
BCRYPT_KEY_HANDLE hPublicKey = nullptr;
status = BCryptImportKeyPair(hSignAlg,
NULL,
nullptr,
BCRYPT_ECCPUBLIC_BLOB,
&hPublicKey,
PublicKey,
PublicKeyLen,
BCRYPT_NO_KEY_VALIDATION);
ASSERT(NT_SUCCESS(status));

status = BCryptVerifySignature(hPublicKey, NULL, Hash, HashSize, Sign, SignSize, 0);
status = BCryptVerifySignature(hPublicKey, nullptr, Hash, HashSize, Sign, SignSize, 0);
if (NT_SUCCESS(status)) {
IsVerify = TRUE;
}
Expand Down
Binary file modified libdrv/ssdt.cpp
Binary file not shown.
Binary file modified libdrv/thread.cpp
Binary file not shown.
Binary file modified libdrv/utf8.cpp
Binary file not shown.
Binary file modified test/FileTest.cpp
Binary file not shown.
Binary file modified test/ProcessTest.cpp
Binary file not shown.
Binary file modified test/RegistryTest.cpp
Binary file not shown.
Binary file modified test/SsdtTest.cpp
Binary file not shown.
12 changes: 6 additions & 6 deletions test/encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@ void TestRsaEncrypt()
//////////////////////////////////////////////////////////////////////////////////////////////

ULONG KeyPairLen = 0;
NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, 0, &KeyPairLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAFULLPRIVATE_BLOB, nullptr, 0, &KeyPairLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

BCRYPT_RSAKEY_BLOB * RsaKeyPair = (BCRYPT_RSAKEY_BLOB *)ExAllocatePoolWithTag(NonPagedPool, KeyPairLen, TAG);
ASSERT(RsaKeyPair);//前四个字节是:RSA3

NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, (PUCHAR)RsaKeyPair, KeyPairLen, &KeyPairLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAFULLPRIVATE_BLOB, (PUCHAR)RsaKeyPair, KeyPairLen, &KeyPairLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

//////////////////////////////////////////////////////////////////////////////////////////////

ULONG PrivateKeyLen = 0;
NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAPRIVATE_BLOB, NULL, 0, &PrivateKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAPRIVATE_BLOB, nullptr, 0, &PrivateKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

BCRYPT_RSAKEY_BLOB * PrivateKey = (BCRYPT_RSAKEY_BLOB *)ExAllocatePoolWithTag(NonPagedPool, PrivateKeyLen, TAG);
ASSERT(PrivateKey);//前四个字节是:RSA2

NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAPRIVATE_BLOB, (PUCHAR)PrivateKey, PrivateKeyLen, &PrivateKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAPRIVATE_BLOB, (PUCHAR)PrivateKey, PrivateKeyLen, &PrivateKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

//////////////////////////////////////////////////////////////////////////////////////////////

ULONG PublicKeyLen = 0;
NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, 0, &PublicKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAPUBLIC_BLOB, nullptr, 0, &PublicKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

BCRYPT_RSAKEY_BLOB * PublicKey = (BCRYPT_RSAKEY_BLOB *)ExAllocatePoolWithTag(NonPagedPool, PublicKeyLen, TAG);
ASSERT(PublicKey);//前四个字节是:RSA1

NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_RSAPUBLIC_BLOB, (PUCHAR)PublicKey, PublicKeyLen, &PublicKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_RSAPUBLIC_BLOB, (PUCHAR)PublicKey, PublicKeyLen, &PublicKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Binary file modified test/pch.cpp
Binary file not shown.
Binary file modified test/pch.h
Binary file not shown.
8 changes: 4 additions & 4 deletions test/signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ void TestEcdsaSignature()
//////////////////////////////////////////////////////////////////////////////////////////////

ULONG PrivateKeyLen = 0;
NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_ECCPRIVATE_BLOB, NULL, 0, &PrivateKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_ECCPRIVATE_BLOB, nullptr, 0, &PrivateKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

PBCRYPT_ECCKEY_BLOB PrivateKey = (PBCRYPT_ECCKEY_BLOB)ExAllocatePoolWithTag(NonPagedPool, PrivateKeyLen, TAG);
ASSERT(PrivateKey);

NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_ECCPRIVATE_BLOB, (PUCHAR)PrivateKey, PrivateKeyLen, &PrivateKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_ECCPRIVATE_BLOB, (PUCHAR)PrivateKey, PrivateKeyLen, &PrivateKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

//////////////////////////////////////////////////////////////////////////////////////////////

ULONG PublicKeyLen = 0;
NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_ECCPUBLIC_BLOB, NULL, 0, &PublicKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_ECCPUBLIC_BLOB, nullptr, 0, &PublicKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

PBCRYPT_ECCKEY_BLOB PublicKey = (PBCRYPT_ECCKEY_BLOB)ExAllocatePoolWithTag(NonPagedPool, PublicKeyLen, TAG);
ASSERT(PublicKey);

NtStatus = BCryptExportKey(hKey, NULL, BCRYPT_ECCPUBLIC_BLOB, (PUCHAR)PublicKey, PublicKeyLen, &PublicKeyLen, 0);
NtStatus = BCryptExportKey(hKey, nullptr, BCRYPT_ECCPUBLIC_BLOB, (PUCHAR)PublicKey, PublicKeyLen, &PublicKeyLen, 0);
ASSERT(STATUS_SUCCESS == NtStatus);

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3cf2ae5

Please sign in to comment.