#include "LicenseManger.h" #include "dlginputaddr.h" #include #include #include #include #include #include #include #include #include "qnamespace.h" #include #include MACHINE_INFO_t machine_info; LICENSE_DATA_t license_data; QMutex machine_info_mutex; QMutex license_data_mutex; void adjustDateAndTime(int year, int mon, int mday, int hour, int min, int sec); LicenseManger::LicenseManger() { #if 1 UCHAR e_key[1024] = "dangerous IOP 0908 "; pAes = new TAesClass; pAes->InitializePrivateKey(16, e_key); //进行初始化 //setMachineInfo(16); #endif } //set machine info qint32 LicenseManger::setMachineInfo(quint32 serial_num) { //check serial number size if(serial_num>999999) { return -1; } machine_info_mutex.lock(); QString serial; serial.sprintf("VB%06d", serial_num); QByteArray hash_data; hash_data = QCryptographicHash::hash(serial.toAscii(),QCryptographicHash::Md5 ); //MACHINE_INFO_t machine_info; machine_info.serial_number=serial_num; memcpy(&machine_info.md5[0],hash_data.data(),MD5_LENGTH); //qDebug()<<"org sn info"<OnAesEncrypt((LPVOID)&machine_info, sizeof(machine_info), (LPVOID)encrypt_buff); //进行加密 //qDebug()<<"sn jiami:"<OnAesUncrypt((LPVOID)encrypt_buff, (DWORD)sizeof(encrypt_buff),(LPVOID)decrypt_buff); //进行解密 //qDebug()<<"jiemi:"<OnAesEncrypt((LPVOID)&license_data, sizeof(license_data), (LPVOID)encrypt_buff); //进行加密 //qDebug()<<"jiami:"<OnAesUncrypt((LPVOID)encrypt_buff, (DWORD)sizeof(encrypt_buff),(LPVOID)decrypt_buff); //进行解密 //qDebug()<<"jiemi:"< void adjustDateAndTime(int year, int mon, int mday, int hour, int min, int sec) { time_t t; struct tm nowtime; nowtime.tm_sec = sec; // Seconds.[0-60] (1 leap second) nowtime.tm_min = min; // Minutes.[0-59] nowtime.tm_hour = hour; // Hours. [0-23] nowtime.tm_mday = mday; // Day.[1-31] nowtime.tm_mon = mon - 1; // Month. [0-11] nowtime.tm_year = year - 1900; // Year- 1900. nowtime.tm_isdst = -1; // DST.[-1/0/1] t = mktime(&nowtime); // qDebug()<= 6*60*18*367) { qDebug()<<"license file was invalid"; return 0; } if(license_data.vernon_bach_version != VERNONBACH_VERSION_CODE) { qDebug()<<"license file was invalid"; return 0; } qDebug()<<"license serial number"<= 6*60*18*367) { qDebug()<<"license file was invalid"; return 0; } if(license_data.remainingTime) license_data.remainingTime--; if(license_data.remainingTime<=0) { license_data.workout = 1; } SaveLicData2File(); //license_data.remainingTime=0; return license_data.remainingTime; } quint32 LicenseManger::CheckUpdateFileState() { QFile file(UPDATE_LIC_FILE); LICENSE_DATA_t update_license_data; quint32 state = UPDATE_LICENSE_FILE_OK; if(!file.exists()) { state = -UPDATE_LICENSE_FILE_NOT_EXIT; } else { if(!file.open(QIODevice::ReadOnly | QIODevice::Truncate)){ QMessageBox::warning(0,"警告",QString("无法打开license文件") ); state = -UPDATE_LICENSE_FILE_OPEN_FAILED; } else { //license_data_mutex.lock(); char encrypt_buff[1024]; char decrypt_buff[1024]; file.read((char *)encrypt_buff,(qint64)sizeof(encrypt_buff)); pAes->OnAesUncrypt((LPVOID)encrypt_buff, (DWORD)sizeof(encrypt_buff),(LPVOID)decrypt_buff); //进行解密 //qDebug()<<"jiemi:"<= (license_data.printer_active_count+3) ) { state = -UPDATE_LICENSE_FILE_ACTIVE_NUMBER_ERR; } else if(update_license_data.vernon_bach_version != VERNONBACH_VERSION_CODE) { state = -UPDATE_LICENSE_FILE_SW_VERSION_ERR; } } } return state; } quint32 LicenseManger::UpdateLicenseFileData() { QFile file(UPDATE_LIC_FILE); LICENSE_DATA_t update_license_data; quint32 state = UPDATE_LICENSE_FILE_OK; if(!file.exists()) { state = -UPDATE_LICENSE_FILE_NOT_EXIT; } else { if(!file.open(QIODevice::ReadOnly | QIODevice::Truncate)){ QMessageBox::warning(0,"警告",QString("无法打开更新license文件") ); state = -UPDATE_LICENSE_FILE_OPEN_FAILED; } else { //license_data_mutex.lock(); char encrypt_buff[1024]; char decrypt_buff[1024]; file.read((char *)encrypt_buff,(qint64)sizeof(encrypt_buff)); pAes->OnAesUncrypt((LPVOID)encrypt_buff, (DWORD)sizeof(encrypt_buff),(LPVOID)decrypt_buff); //进行解密 //qDebug()<<"jiemi:"<