|
@@ -0,0 +1,129 @@
|
|
|
|
+#include "adclicense.h"
|
|
|
|
+
|
|
|
|
+#include "modulecomm.h"
|
|
|
|
+#include <thread>
|
|
|
|
+#include <iostream>
|
|
|
|
+#include <QRegularExpression>
|
|
|
|
+#include <QCryptographicHash>
|
|
|
|
+#include <QFile>
|
|
|
|
+#include <QTextStream>
|
|
|
|
+#include <QMessageBox>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ADCLicenseServ::ADCLicenseServ()
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+QString ADCLicenseServ::hashString(const QString &str) {
|
|
|
|
+ QString strippedStr = str;
|
|
|
|
+ strippedStr.remove(QChar('-'));
|
|
|
|
+ QByteArray hashData = QCryptographicHash::hash(strippedStr.toUtf8(), QCryptographicHash::Sha256);
|
|
|
|
+ QString hashedStr = QString::fromLatin1(hashData.toHex());
|
|
|
|
+ return hashedStr;
|
|
|
|
+}
|
|
|
|
+QString ADCLicenseServ::caesarCipher(const QString &text, int shift) {
|
|
|
|
+ QString result;
|
|
|
|
+ const int alphabetSize = 26;
|
|
|
|
+ const int digitSize = 10;
|
|
|
|
+
|
|
|
|
+ for (const QChar &ch : text) {
|
|
|
|
+ if (ch.isLetter()) {
|
|
|
|
+ QChar base = ch.isLower() ? 'a' : 'A';
|
|
|
|
+ result.append(QChar((ch.toLatin1() - base.toLatin1() + shift + alphabetSize) % alphabetSize + base.toLatin1()));
|
|
|
|
+ } else if (ch.isDigit()) {
|
|
|
|
+ result.append(QChar((ch.toLatin1() - '0' + shift + digitSize) % digitSize + '0'));
|
|
|
|
+ } else {
|
|
|
|
+ result.append(ch);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+QString ADCLicenseServ::getDiskID()
|
|
|
|
+{
|
|
|
|
+ QProcess process;
|
|
|
|
+ QString command="echo 'nvidia' | sudo -S blkid";
|
|
|
|
+ process.start("/bin/bash", QStringList() << "-c" << command);
|
|
|
|
+ process.waitForFinished();
|
|
|
|
+ QString output=process.readAllStandardOutput();
|
|
|
|
+ QStringList diskidlist=output.split("/dev/");
|
|
|
|
+ QString k0p1;
|
|
|
|
+ for (int i=0;i<diskidlist.size();i++)
|
|
|
|
+ {
|
|
|
|
+ if (diskidlist[i].contains("mmcblk0p1:"))
|
|
|
|
+ {
|
|
|
|
+ k0p1=diskidlist[i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ QStringList k0p1list=k0p1.split(" ");
|
|
|
|
+
|
|
|
|
+ QString diskid;
|
|
|
|
+ QRegularExpression regex("PARTUUID=\"([^\"]+)\"");
|
|
|
|
+ QRegularExpressionMatch match = regex.match(k0p1);
|
|
|
|
+ if (match.hasMatch()) {
|
|
|
|
+ QString subStr = match.captured(1);
|
|
|
|
+ diskid=subStr;
|
|
|
|
+ } else {
|
|
|
|
+ qDebug() << "UUID not found.";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return diskid;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+QString ADCLicenseServ::readLicense()
|
|
|
|
+{
|
|
|
|
+ QString filePath = "./license";
|
|
|
|
+
|
|
|
|
+ QFile file(filePath);
|
|
|
|
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
+ qDebug() << "Failed to open file.";
|
|
|
|
+ return "1";
|
|
|
|
+ }
|
|
|
|
+ QTextStream in(&file);
|
|
|
|
+
|
|
|
|
+ QString fileContent = in.readAll();
|
|
|
|
+ fileContent=fileContent.remove(QChar('\n'));
|
|
|
|
+ file.close();
|
|
|
|
+ return fileContent;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void ADCLicenseServ::creatMachFile(const QString &str)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ QString filePath = "./machineID";
|
|
|
|
+ QFile file(filePath);
|
|
|
|
+
|
|
|
|
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
+ qDebug() << "Failed to open file for writing.";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ QString strippedStr = str;
|
|
|
|
+ strippedStr.remove(QChar('-'));
|
|
|
|
+ QTextStream out(&file);
|
|
|
|
+ out << strippedStr;
|
|
|
|
+ file.close();
|
|
|
|
+
|
|
|
|
+ qDebug() << "MachID File created and written successfully.";
|
|
|
|
+}
|
|
|
|
+int ADCLicenseServ::CheckLincese()
|
|
|
|
+{
|
|
|
|
+ QString diskid=getDiskID();
|
|
|
|
+ QString filelicense=readLicense();
|
|
|
|
+ QString final_license="catarc"+diskid+"shenlanv2pro";
|
|
|
|
+ QString hashedStr=hashString(final_license);
|
|
|
|
+ if (hashedStr==filelicense)
|
|
|
|
+ {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ QString writeid=caesarCipher(diskid,7);
|
|
|
|
+ creatMachFile(writeid);
|
|
|
|
+ QMessageBox::warning(nullptr, "未注册程序", "请在程序目录下找到machineID文件并联系管理员进行注册", QMessageBox::Ok);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
+}
|