Files
EgtLock/DongleSN.cpp
T
Dario Sassi da6d08e3f1 EgtLock 2.1e1 :
- aggiunte funzioni per leggere SN delle chiavi hardware.
2019-05-13 09:30:15 +00:00

65 lines
2.0 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2019-2019
//----------------------------------------------------------------------------
// File : DongleSN.cpp Data : 13.05.18 Versione : 2.1e1
// Contenuto : Funzioni per lettura SN chiave OxySec.
//
//
//
// Modifiche : 13.05.18 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//------------------ Include -------------------------------------------------
#include "stdafx.h"
#include "Obfuscate.h"
#include "DongleId.h"
#include "/EgtDev/Include/EgtBase64.h"
#include "/EgtDev/Include/EgtCrc32.h"
#include "/EgtDev/Extern/OxySec/Include/xnd.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
GetDongleSN( int& nDongleSN)
{
// imposto l'esito
bool bOk = true ;
// cerco la chiave
unsigned char label[XLT_LABEL_SIZE] ;
string sLabel = "EgalTech s.r.l. - CAD/CAM/CIM Software Solutions" ;
strcpy_s( (char*)label, XLT_LABEL_SIZE, sLabel.c_str()) ;
memset( label + sLabel.size(), 0x00, sizeof( label) - sLabel.size()) ;
XND_XLT_ENV env = xnd_xlt_env_create() ;
if ( env == nullptr) {
bOk = false ;
goto end ;
}
int nStatus = 0 ;
XND_DEVICE_CONTEXT dev_ctx = xnd_xlt_locate( env, label, &nStatus) ;
if ( dev_ctx == nullptr) {
bOk = false ;
goto end ;
}
// eseguo la lettura del Serial Number
unsigned int nVer ;
unsigned int nModel ;
unsigned int nFlags ;
unsigned int nSerial ;
unsigned char szLabelPrint[XLT_LABEL_SIZE + 1] ;
int nRes = xnd_xlt_getinfo( dev_ctx, &nVer, &nModel, &nFlags, &nSerial, szLabelPrint) ;
if ( nRes != XLT_ERROR_SUCCESS) {
bOk = false ;
goto end ;
}
szLabelPrint[XLT_LABEL_SIZE] = '\0' ;
nDongleSN = int( nSerial) ;
end :
xnd_xlt_devctx_release( dev_ctx) ;
xnd_xlt_env_release( env) ;
return bOk ;
}