Improve OutputDebugString messages (Issue 314)

This commit is contained in:
Jeffrey Walton 2016-10-02 18:40:28 -04:00
parent e3c4ccb0fc
commit 1dd0b07a1e
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 16 additions and 7 deletions

View File

@ -42,6 +42,7 @@ extern "C" {void __cdecl _CRT_DEBUGGER_HOOK(int); }
#endif
#endif
#include <sstream>
#include <iostream>
#if CRYPTOPP_MSC_VERSION
@ -330,11 +331,19 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
#endif
}
if (h != g_BaseAddressOfMAC)
if (h == g_BaseAddressOfMAC)
{
std::ostringstream oss;
oss << "Crypto++ DLL loaded at base address 0x" << std::hex << h << ".\n";
#ifdef CRYPTOPP_WIN32_AVAILABLE
OutputDebugString(oss.str().c_str());
#endif
}
else
{
std::ostringstream oss;
oss << "Crypto++ DLL integrity check may fail. Expected module base address is 0x";
oss << std::hex << g_BaseAddressOfMAC << ", but module loaded at 0x" << h << "\n";
oss << std::hex << g_BaseAddressOfMAC << ", but module loaded at 0x" << h << ".\n";
#ifdef CRYPTOPP_WIN32_AVAILABLE
OutputDebugString(oss.str().c_str());
#endif
@ -456,7 +465,7 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
#ifdef CRYPTOPP_WIN32_AVAILABLE
std::string hexMac;
HexEncoder(new StringSink(hexMac)).PutMessageEnd(actualMac, actualMac.size());
OutputDebugString((("Crypto++ DLL integrity check failed. Actual MAC is: " + hexMac) + "\n").c_str());
OutputDebugString((("Crypto++ DLL integrity check failed. Actual MAC is: " + hexMac) + ".\n").c_str());
#endif
return false;
}

View File

@ -288,14 +288,14 @@ int CRYPTOPP_API main(int argc, char *argv[])
f.PutMessageEnd(buf.begin(), buf.size());
// Encode MAC
string hexEncoded;
string hexMac;
HexEncoder encoder;
encoder.Put(mac, sizeof(mac)), encoder.MessageEnd();
hexEncoded.resize(static_cast<size_t>(encoder.MaxRetrievable()));
encoder.Get(reinterpret_cast<byte*>(&hexEncoded[0]), hexEncoded.size());
hexMac.resize(static_cast<size_t>(encoder.MaxRetrievable()));
encoder.Get(reinterpret_cast<byte*>(&hexMac[0]), hexMac.size());
// Report MAC and location
std::cout << "Placing MAC " << hexEncoded << " in " << fname << " at file offset " << macPos;
std::cout << "Placing MAC " << hexMac << " in " << fname << " at file offset " << macPos;
std::cout << " (0x" << std::hex << macPos << std::dec << ").\n";
// place MAC