HWID implementation

This commit is contained in:
coolcoala
2025-07-10 20:50:12 +03:00
parent d6014865d6
commit 1274ba2324
9 changed files with 100 additions and 16 deletions

View File

@@ -10,3 +10,4 @@ pub mod resolve;
pub mod server;
pub mod tmpl;
pub mod window_manager;
pub mod sys_info;

View File

@@ -7,7 +7,7 @@ use std::{
};
use tokio::runtime::{Builder, Runtime};
use crate::{config::Config, logging, utils::logging::Type};
use crate::{config::Config, logging, utils::logging::Type, utils::sys_info};
// HTTP2 相关
const H2_CONNECTION_WINDOW_SIZE: u32 = 1024 * 1024;
@@ -248,6 +248,7 @@ impl NetworkManager {
timeout_secs: Option<u64>,
user_agent: Option<String>,
accept_invalid_certs: bool,
use_hwid: bool,
) -> RequestBuilder {
if self.should_reset_clients() {
self.reset_clients();
@@ -331,7 +332,18 @@ impl NetworkManager {
let client = builder.build().expect("Failed to build custom HTTP client");
client.get(url)
let mut request_builder = client.get(url);
if use_hwid {
let sys_info = sys_info::get_system_info();
logging!(info, Type::Network, true, "Adding HWID headers to request");
request_builder = request_builder
.header("x-hwid", &sys_info.hwid)
.header("x-device-os", &sys_info.os_type)
.header("x-ver-os", &sys_info.os_ver);
}
request_builder
}
/* /// 执行GET请求添加错误跟踪
@@ -378,6 +390,7 @@ impl NetworkManager {
timeout_secs: Option<u64>,
user_agent: Option<String>,
accept_invalid_certs: bool,
use_hwid: bool,
) -> Result<Response> {
let request = self.create_request(
url,
@@ -385,6 +398,7 @@ impl NetworkManager {
timeout_secs,
user_agent,
accept_invalid_certs,
use_hwid,
);
let timeout_duration = timeout_secs.unwrap_or(20);

View File

@@ -23,6 +23,7 @@ use tauri::{AppHandle, Manager};
use tokio::net::TcpListener;
use tauri::Url;
use crate::config::PrfOption;
//#[cfg(not(target_os = "linux"))]
// use window_shadows::set_shadow;
@@ -549,19 +550,25 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
};
if link_parsed.scheme() == "clash" || link_parsed.scheme() == "clash-verge" {
let name = link_parsed
.query_pairs()
.find(|(key, _)| key == "name")
.map(|(_, value)| value.into_owned());
let mut name: Option<String> = None;
let mut url_param: Option<String> = None;
let mut use_hwid = true;
let url_param = if let Some(query) = link_parsed.query() {
let prefix = "url=";
if let Some(pos) = query.find(prefix) {
let raw_url = &query[pos + prefix.len()..];
Some(percent_decode_str(raw_url).decode_utf8_lossy().to_string())
} else {
None
for (key, value) in link_parsed.query_pairs() {
match key.as_ref() {
"name" => name = Some(value.into_owned()),
"url" => url_param = Some(percent_decode_str(&value).decode_utf8_lossy().to_string()),
"hwid" => use_hwid = value == "1" || value == "true",
_ => {}
}
}
let option = if use_hwid {
log::info!(target:"app", "HWID usage requested via deep link");
Some(PrfOption {
use_hwid: Some(true),
..Default::default()
})
} else {
None
};
@@ -571,7 +578,7 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
log::info!(target:"app", "decoded subscription url: {url}");
create_window(false);
match PrfItem::from_url(url.as_ref(), name, None, None).await {
match PrfItem::from_url(url.as_ref(), name, None, option).await {
Ok(item) => {
let uid = item.uid.clone().unwrap();
let _ = wrap_err!(Config::profiles().data().append_item(item));

View File

@@ -0,0 +1,22 @@
use once_cell::sync::Lazy;
use serde::Serialize;
#[derive(Serialize, Debug, Clone)]
pub struct SystemInfo {
pub hwid: String,
pub os_type: String,
pub os_ver: String,
}
pub static SYSTEM_INFO: Lazy<SystemInfo> = Lazy::new(|| {
let os_info = os_info::get();
SystemInfo {
hwid: machine_uid::get().unwrap_or_else(|_| "unknown_hwid".to_string()),
os_type: os_info.os_type().to_string(),
os_ver: os_info.version().to_string(),
}
});
pub fn get_system_info() -> &'static SystemInfo {
&SYSTEM_INFO
}