//---------------------------------------------------------------------------- // EgalTech 2024-2024 //---------------------------------------------------------------------------- // File : EgtBasis.cpp Data : 05.10.24 Versione : 2.6j1 // Contenuto : Implementazione funzioni protezione. // // // Modifiche : 05.10.24 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "/EgtDev/Include/EBsAPI.h" #include "/EgtDev/Include/EgtStringConverter.h" #include "/EgtDev/Include/SELkKeyProc.h" #include "/EgtDev/Include/SELkLockId.h" #include using namespace std ; //---------------------------------------------------------------------------- static string s_sLockId ; static int s_nLockSN = 0 ; static int s_nKeyLev = 0 ; static int s_nKeyExpDays = 0 ; static int s_nKeyAssExpDays = 0 ; static unsigned int s_nKeyOpt1 = 0 ; static unsigned int s_nKeyOpt2 = 0 ; static int s_nKeyOptExpDays = 0 ; //---------------------------------------------------------------------------- BOOL __stdcall EgtSetKey( const wchar_t* wsLockId) { // Salvo stringa di licenza s_sLockId = wstrztoA( wsLockId) ; if ( s_sLockId.empty() || all_of( s_sLockId.begin(), s_sLockId.end(), isspace)) return FALSE ; // Ammessa solo chiave di tipo hardware if ( ! SetLockType( KEY_LOCK_TYPE_HW)) return FALSE ; // Non ammesse chiavi di rete if ( ! SetNetHwKey( false, 0, "")) return FALSE ; // Verifico esistenza chiave OxySec int nLockSN = 0 ; if ( ! GetLockSN( nLockSN)) nLockSN = 0 ; s_nLockSN = nLockSN ; bool bOk = ( nLockSN > 0) ; return ( bOk ? TRUE : FALSE) ; } //---------------------------------------------------------------------------- BOOL __stdcall EgtGetKeyLevel( int nProd, int nVer, int nLev, int* pnKLev) { // Verifico parametro di ritorno if ( pnKLev == nullptr) return FALSE ; // Verifico chiave int nRet = GetKeyLevelEx( s_sLockId, nProd, nVer, nLev, s_nKeyLev, s_nKeyExpDays, s_nKeyAssExpDays) ; if ( nRet != KEY_OK) { *pnKLev = -nRet ; return FALSE ; } *pnKLev = s_nKeyLev ; return TRUE ; } //---------------------------------------------------------------------------- BOOL __stdcall EgtGetKeyOptions( int nProd, int nVer, int nLev, unsigned int* pnOpt1, unsigned int* pnOpt2) { // Verifico parametri di ritorno if ( pnOpt1 == nullptr || pnOpt2 == nullptr) return FALSE ; // Verifico chiave e opzioni int nRet = GetKeyOptions( s_sLockId, nProd, nVer, nLev, s_nKeyOpt1, s_nKeyOpt2, s_nKeyOptExpDays) ; if ( nRet != KEY_OK) { *pnOpt1 = 0 ; *pnOpt2 = 0 ; return FALSE ; } *pnOpt1 = s_nKeyOpt1 ; *pnOpt2 = s_nKeyOpt2 ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetKeyLeftDays( int* pnLeftDays) { if ( pnLeftDays == nullptr) return FALSE ; if ( s_nKeyExpDays == 0) return FALSE ; *pnLeftDays = s_nKeyExpDays - GetCurrDay() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetKeyAssLeftDays( int* pnAssLeftDays) { if ( pnAssLeftDays == nullptr) return FALSE ; if ( s_nKeyAssExpDays == 0) return FALSE ; *pnAssLeftDays = s_nKeyAssExpDays - GetCurrDay() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetKeyOptLeftDays( int* pnOptLeftDays) { if ( pnOptLeftDays == nullptr) return FALSE ; if ( s_nKeyOptExpDays == 0) return FALSE ; *pnOptLeftDays = s_nKeyOptExpDays - GetCurrDay() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtFreeMemory( void* pMem) { if ( pMem == nullptr) return FALSE ; free( pMem) ; return TRUE ; }