mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2025-02-19 04:48:00 +00:00
Add information for expected and load address for FIPS DLL module (Issue 314)
This commit is contained in:
parent
55bbc55a7e
commit
578b0e2a07
26
fipstest.cpp
26
fipstest.cpp
@ -54,6 +54,13 @@ extern PowerUpSelfTestStatus g_powerUpSelfTestStatus;
|
||||
SecByteBlock g_actualMac;
|
||||
unsigned long g_macFileLocation = 0;
|
||||
|
||||
// $ grep -iIR baseaddress *.*proj
|
||||
// cryptdll.vcxproj: <BaseAddress>0x42900000</BaseAddress>
|
||||
// cryptdll.vcxproj: <BaseAddress>0x42900000</BaseAddress>
|
||||
// cryptdll.vcxproj: <BaseAddress>0x42900000</BaseAddress>
|
||||
// cryptdll.vcxproj: <BaseAddress>0x42900000</BaseAddress>
|
||||
const void* g_BaseAddressOfMAC = reinterpret_cast<void*>(0x42900000);
|
||||
|
||||
// use a random dummy string here, to be searched/replaced later with the real MAC
|
||||
static const byte s_moduleMac[CryptoPP::HMAC<CryptoPP::SHA1>::DIGESTSIZE] = CRYPTOPP_DUMMY_DLL_MAC;
|
||||
CRYPTOPP_COMPILE_ASSERT(sizeof(s_moduleMac) == CryptoPP::SHA1::DIGESTSIZE);
|
||||
@ -294,12 +301,13 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
|
||||
#ifdef CRYPTOPP_WIN32_AVAILABLE
|
||||
HMODULE h = NULL;
|
||||
{
|
||||
char moduleFilenameBuf[MAX_PATH] = "";
|
||||
const size_t FIPS_MODULE_MAX_PATH = 2*MAX_PATH;
|
||||
char moduleFilenameBuf[FIPS_MODULE_MAX_PATH] = "";
|
||||
if (moduleFilename == NULL)
|
||||
{
|
||||
#if (_MSC_VER >= 1400 && !defined(_STLPORT_VERSION)) // ifstream doesn't support wide filename on other compilers
|
||||
wchar_t wideModuleFilename[MAX_PATH];
|
||||
if (GetModuleFileNameW(s_hModule, wideModuleFilename, MAX_PATH) > 0)
|
||||
wchar_t wideModuleFilename[FIPS_MODULE_MAX_PATH];
|
||||
if (GetModuleFileNameW(s_hModule, wideModuleFilename, FIPS_MODULE_MAX_PATH) > 0)
|
||||
{
|
||||
moduleStream.open(wideModuleFilename, std::ios::in | std::ios::binary);
|
||||
h = GetModuleHandleW(wideModuleFilename);
|
||||
@ -307,7 +315,7 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
|
||||
else
|
||||
#endif
|
||||
{
|
||||
GetModuleFileNameA(s_hModule, moduleFilenameBuf, MAX_PATH);
|
||||
GetModuleFileNameA(s_hModule, moduleFilenameBuf, FIPS_MODULE_MAX_PATH);
|
||||
moduleFilename = moduleFilenameBuf;
|
||||
}
|
||||
}
|
||||
@ -322,6 +330,16 @@ bool IntegrityCheckModule(const char *moduleFilename, const byte *expectedModule
|
||||
#endif
|
||||
}
|
||||
|
||||
if (h != g_BaseAddressOfMAC)
|
||||
{
|
||||
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;
|
||||
#ifdef CRYPTOPP_WIN32_AVAILABLE
|
||||
OutputDebugStringA(oss.str().c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!moduleStream)
|
||||
{
|
||||
#ifdef CRYPTOPP_WIN32_AVAILABLE
|
||||
|
2
test.cpp
2
test.cpp
@ -295,7 +295,7 @@ int CRYPTOPP_API main(int argc, char *argv[])
|
||||
encoder.Get(reinterpret_cast<byte*>(&hexEncoded[0]), hexEncoded.size());
|
||||
|
||||
// Report MAC and location
|
||||
std::cout << "Placing MAC " << hexEncoded << " in " << fname << "at location " << macPos;
|
||||
std::cout << "Placing MAC " << hexEncoded << " in " << fname << " at file offset " << macPos;
|
||||
std::cout << " (0x" << std::hex << macPos << std::dec << ").\n";
|
||||
|
||||
// place MAC
|
||||
|
Loading…
x
Reference in New Issue
Block a user