diff --git a/DongleSN.cpp b/DongleSN.cpp new file mode 100644 index 0000000..82e37da --- /dev/null +++ b/DongleSN.cpp @@ -0,0 +1,64 @@ +//---------------------------------------------------------------------------- +// 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 ; +} diff --git a/DongleSN.h b/DongleSN.h new file mode 100644 index 0000000..1c2a5a4 --- /dev/null +++ b/DongleSN.h @@ -0,0 +1,17 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : DongleSN.h Data : 13.05.18 Versione : 2.1e1 +// Contenuto : Dichiarazione funzioni locali per lettura SN chiave. +// +// +// +// Modifiche : 13.05.18 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +//------------------------------------------------------------------------------- +bool GetDongleSN( int& nDongleSN) ; diff --git a/EgtLock.vcxproj b/EgtLock.vcxproj index 8f63f92..8e98edc 100644 --- a/EgtLock.vcxproj +++ b/EgtLock.vcxproj @@ -192,6 +192,7 @@ copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ + diff --git a/EgtLock.vcxproj.filters b/EgtLock.vcxproj.filters index 4a9ba75..0a6ecbc 100644 --- a/EgtLock.vcxproj.filters +++ b/EgtLock.vcxproj.filters @@ -71,5 +71,8 @@ File di origine + + File di origine + \ No newline at end of file diff --git a/LockId.cpp b/LockId.cpp index 07fccf4..8a4d47b 100644 --- a/LockId.cpp +++ b/LockId.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "MachineId.h" #include "DongleId.h" +#include "DongleSN.h" #include "Obfuscate.h" #include "/EgtDev/Include/EgtBase64.h" #include "/EgtDev/Include/EgtCrc32.h" @@ -131,3 +132,23 @@ ConvertLockId2ToScramKey( const string& sLockId2, string& sScramKey) AddCrc32ToString( sScramKey) ; return true ; } + +//---------------------------------------------------------------------------- +bool +GetLockSN( int& nLockSN) +{ + switch ( s_nLockType) { + default : // KEY_LOCK_TYPE_ANY + if ( GetDongleSN( nLockSN)) + return true ; + else { + nLockSN = 0 ; + return false ; + } + case KEY_LOCK_TYPE_SW : + nLockSN = 0 ; + return false ; + case KEY_LOCK_TYPE_HW : + return GetDongleSN( nLockSN) ; + } +}