1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <fstream>
#include <iterator>
#include <windows.h>
#include <wincrypt.h>
constexpr std::size_t MD5_SIZE = 16 ;
using md5_digest = std::array< BYTE, MD5_SIZE > ;
std::vector<BYTE> get_bytes( std::string path )
{
std::ifstream file( path, std::ios_base::binary ) ;
return { std::istream_iterator<BYTE>{file}, std::istream_iterator<BYTE>{} } ;
}
md5_digest md5( std::string path ) // MinGW: link with libadvapi32.a
{
md5_digest digest {} ;
const auto bytes = get_bytes(path) ;
if( !bytes.empty() )
{
HCRYPTPROV provider = 0 ;
if( ::CryptAcquireContext( std::addressof(provider), nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) )
{
HCRYPTHASH hash = 0 ;
if( ::CryptCreateHash( provider, CALG_MD5, 0, 0, std::addressof(hash) ) )
{
::CryptHashData( hash, bytes.data(), bytes.size(), 0 ) ;
DWORD nbytes = bytes.size() ;
::CryptGetHashParam( hash, HP_HASHVAL, digest.data(), std::addressof(nbytes), 0 ) ;
::CryptDestroyHash(hash) ;
}
::CryptReleaseContext( provider, 0 ) ;
}
}
return digest ;
}
int main()
{
const std::string anti_cheat_path = "AntiCheat.exe" ;
// initialise with the actual md5 digest for anti_cheat.exe
const md5_digest expected_anti_cheat_md5 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } ;
if( md5(anti_cheat_path) == expected_anti_cheat_md5 ) // if the md5 digest matches
{
// proceed with the game
}
}
|