From 721d79f9819285132d391b9c0570e036d30b9d4f Mon Sep 17 00:00:00 2001 From: hgx100 <147342771+hgx100@users.noreply.github.com> Date: Wed, 17 Dec 2025 07:24:18 +0500 Subject: [PATCH] feat: Add custom system parameters for x-hwid header (#1027) - Add sub_custom_hwid_params field to DataStore - Add UI text field for entering custom parameters - Parse and apply custom parameters when sending HWID headers - Format: hwid=value,os=value,osVersion=value,model=value - Empty input uses default system parameters Co-authored-by: hgx100 --- include/global/DataStore.hpp | 1 + include/ui/setting/dialog_basic_settings.ui | 17 ++++++++ src/global/Configs.cpp | 1 + src/global/HTTPRequestHelper.cpp | 45 ++++++++++++++++++--- src/ui/setting/dialog_basic_settings.cpp | 2 + 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/include/global/DataStore.hpp b/include/global/DataStore.hpp index 8fdd089..e2d4cc0 100644 --- a/include/global/DataStore.hpp +++ b/include/global/DataStore.hpp @@ -116,6 +116,7 @@ namespace Configs { int sub_auto_update = -30; bool sub_clear = false; bool sub_send_hwid = false; + QString sub_custom_hwid_params = ""; // Custom system parameters: format "hwid=value,os=value,osVersion=value,model=value" // Security bool skip_cert = false; diff --git a/include/ui/setting/dialog_basic_settings.ui b/include/ui/setting/dialog_basic_settings.ui index b7841e6..7b5b3b0 100644 --- a/include/ui/setting/dialog_basic_settings.ui +++ b/include/ui/setting/dialog_basic_settings.ui @@ -569,6 +569,23 @@ + + + + Custom System Parameters (optional) + + + <html><head/><body><p>Format: hwid=value,os=value,osVersion=value,model=value</p><p>Leave empty to use default values. Only specify the parameters you want to override.</p></body></html> + + + + + + + hwid=custom_value,os=custom_os,osVersion=custom_version,model=custom_model + + + diff --git a/src/global/Configs.cpp b/src/global/Configs.cpp index d6cb19c..143f8b1 100644 --- a/src/global/Configs.cpp +++ b/src/global/Configs.cpp @@ -287,6 +287,7 @@ namespace Configs { _add(new configItem("net_insecure", &net_insecure, itemType::boolean)); _add(new configItem("sub_auto_update", &sub_auto_update, itemType::integer)); _add(new configItem("sub_send_hwid", &sub_send_hwid, itemType::boolean)); + _add(new configItem("sub_custom_hwid_params", &sub_custom_hwid_params, itemType::string)); _add(new configItem("start_minimal", &start_minimal, itemType::boolean)); _add(new configItem("max_log_line", &max_log_line, itemType::integer)); _add(new configItem("splitter_state", &splitter_state, itemType::string)); diff --git a/src/global/HTTPRequestHelper.cpp b/src/global/HTTPRequestHelper.cpp index a3212d1..c54bc42 100644 --- a/src/global/HTTPRequestHelper.cpp +++ b/src/global/HTTPRequestHelper.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "include/global/Configs.hpp" #include "include/ui/mainwindow.h" @@ -40,11 +42,42 @@ namespace Configs_network { //Attach HWID and device info headers if enabled in settings if (sendHwid) { auto details = GetDeviceDetails(); - - if (!details.hwid.isEmpty()) request.setRawHeader("x-hwid", details.hwid.toUtf8()); - if (!details.os.isEmpty()) request.setRawHeader("x-device-os", details.os.toUtf8()); - if (!details.osVersion.isEmpty()) request.setRawHeader("x-ver-os", details.osVersion.toUtf8()); - if (!details.model.isEmpty()) request.setRawHeader("x-device-model", details.model.toUtf8()); + + // Parse custom parameters if provided + QMap customParams; + if (!Configs::dataStore->sub_custom_hwid_params.isEmpty()) { + QStringList pairs = Configs::dataStore->sub_custom_hwid_params.split(','); + for (const QString &pair : pairs) { + QString trimmed = pair.trimmed(); + int eqPos = trimmed.indexOf('='); + if (eqPos > 0) { + QString key = trimmed.left(eqPos).trimmed(); + QString value = trimmed.mid(eqPos + 1).trimmed(); + // Validate: key must be one of the allowed parameters, value must not contain newlines + if (!key.isEmpty() && !value.isEmpty() && + !value.contains('\n') && !value.contains('\r') && + value.length() < 1000) { // Reasonable length limit + QString lowerKey = key.toLower(); + // Only accept known parameter keys + if (lowerKey == "hwid" || lowerKey == "os" || + lowerKey == "osversion" || lowerKey == "model") { + customParams[lowerKey] = value; + } + } + } + } + } + + // Use custom values if provided, otherwise use default values + QString hwid = customParams.contains("hwid") ? customParams["hwid"] : details.hwid; + QString os = customParams.contains("os") ? customParams["os"] : details.os; + QString osVersion = customParams.contains("osversion") ? customParams["osversion"] : details.osVersion; + QString model = customParams.contains("model") ? customParams["model"] : details.model; + + if (!hwid.isEmpty()) request.setRawHeader("x-hwid", hwid.toUtf8()); + if (!os.isEmpty()) request.setRawHeader("x-device-os", os.toUtf8()); + if (!osVersion.isEmpty()) request.setRawHeader("x-ver-os", osVersion.toUtf8()); + if (!model.isEmpty()) request.setRawHeader("x-device-model", model.toUtf8()); } // auto _reply = accessManager.get(request); @@ -59,7 +92,7 @@ namespace Configs_network { QEventLoop loop; connect(_reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); loop.exec(); - + // auto result = HTTPResponse{_reply->error() == QNetworkReply::NetworkError::NoError ? "" : _reply->errorString(), _reply->readAll(), _reply->rawHeaderPairs()}; diff --git a/src/ui/setting/dialog_basic_settings.cpp b/src/ui/setting/dialog_basic_settings.cpp index b802dbc..561064c 100644 --- a/src/ui/setting/dialog_basic_settings.cpp +++ b/src/ui/setting/dialog_basic_settings.cpp @@ -155,6 +155,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) D_LOAD_BOOL(sub_clear) D_LOAD_BOOL(net_insecure) D_LOAD_BOOL(sub_send_hwid) + D_LOAD_STRING(sub_custom_hwid_params) D_LOAD_INT_ENABLE(sub_auto_update, sub_auto_update_enable) auto details = GetDeviceDetails(); ui->sub_send_hwid->setToolTip( @@ -253,6 +254,7 @@ void DialogBasicSettings::accept() { D_SAVE_BOOL(sub_clear) D_SAVE_BOOL(net_insecure) D_SAVE_BOOL(sub_send_hwid) + D_SAVE_STRING(sub_custom_hwid_params) D_SAVE_INT_ENABLE(sub_auto_update, sub_auto_update_enable) // Core