modify machine code

This commit is contained in:
brige 2025-08-05 08:00:12 +08:00
parent e39922d4ed
commit cc9a5747f1
2 changed files with 34 additions and 3 deletions

View File

@ -3,6 +3,17 @@
#include <string>
#include <algorithm>
#include <cctype>
#include <random>
#include <sstream>
#include <iomanip>
#include "sha256.h"
// 简单的MD5实现只返回32位
std::string simple_md5_32(const std::string& input) {
// 使用SHA256但只取前32位模拟MD5的32位输出
std::string full_hash = picosha2::hash256_hex_string(input);
return full_hash.substr(0, 32);
}
#define IDC_MACHINE_CODE_LABEL 201
#define IDC_MACHINE_CODE_EDIT 202
@ -84,9 +95,29 @@ LRESULT CALLBACK GenWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
// Buttons
CreateWindow("BUTTON", "Copy to Clipboard", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 180, 60, 150, 30, hwnd, (HMENU)IDC_COPY_BUTTON, NULL, NULL);
// Set machine code
// Set machine code with encryption
std::string machineCode = GetMachineCode();
SetWindowText(hMachineCodeEdit, machineCode.c_str());
// 1. 生成一个个位的随机数 (0-9)
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 9);
int randomNum = dis(gen);
// 2. 做一次 32位 MD5 加密 加密后是32位
std::string encryptedCode = simple_md5_32(machineCode);
// 3. 把 encryptedCode 字符串减掉这个数
std::string processedCode = encryptedCode;
for (char& c : processedCode) {
c = c - randomNum;
}
// 4. 把这个数变成一个字符插入到第三位的位置 加密后是33位
char randomChar = '0' + randomNum;
processedCode.insert(2, 1, randomChar);
SetWindowText(hMachineCodeEdit, processedCode.c_str());
break;
}

View File

@ -148,5 +148,5 @@ std::string getMachineCode() {
macAddress.erase(std::remove_if(macAddress.begin(), macAddress.end(), isspace), macAddress.end());
macAddress.erase(std::remove(macAddress.begin(), macAddress.end(), ':'), macAddress.end());
return cpuId + "-" + "-" + macAddress;
return cpuId + "-" + macAddress;
}