From cc9a5747f15681eee9143ef4590ceeb00cc24429 Mon Sep 17 00:00:00 2001 From: brige Date: Tue, 5 Aug 2025 08:00:12 +0800 Subject: [PATCH] modify machine code --- src/generator_gui.cpp | 35 +++++++++++++++++++++++++++++++++-- src/machine_code.cpp | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/generator_gui.cpp b/src/generator_gui.cpp index 69274f2..2883462 100644 --- a/src/generator_gui.cpp +++ b/src/generator_gui.cpp @@ -3,6 +3,17 @@ #include #include #include +#include +#include +#include +#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; } diff --git a/src/machine_code.cpp b/src/machine_code.cpp index 29c2c0c..c93dd70 100644 --- a/src/machine_code.cpp +++ b/src/machine_code.cpp @@ -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; }