生成guid
This commit is contained in:
Generated
+1
@@ -1968,6 +1968,7 @@ dependencies = [
|
|||||||
"libloading",
|
"libloading",
|
||||||
"log",
|
"log",
|
||||||
"rand",
|
"rand",
|
||||||
|
"sha2",
|
||||||
"widestring",
|
"widestring",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ libc = "0.2.153"
|
|||||||
|
|
||||||
log = { version = "0.4.20", features = [] }
|
log = { version = "0.4.20", features = [] }
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
sha2 = { version = "0.10.6", features = ["oid"] }
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
|
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
|
||||||
ioctl = { version = "0.8", package = "ioctl-sys" }
|
ioctl = { version = "0.8", package = "ioctl-sys" }
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use libloading::Library;
|
use libloading::Library;
|
||||||
|
use sha2::Digest;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
|
|
||||||
use rand::Rng;
|
|
||||||
use winapi::um::winbase;
|
use winapi::um::winbase;
|
||||||
use winapi::um::{synchapi, winnt};
|
use winapi::um::{synchapi, winnt};
|
||||||
|
|
||||||
@@ -81,8 +80,7 @@ impl Device {
|
|||||||
if Self::delete_for_name(&win_tun, &name_utf16).is_ok() {
|
if Self::delete_for_name(&win_tun, &name_utf16).is_ok() {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
}
|
}
|
||||||
let mut guid_bytes: [u8; 16] = [0u8; 16];
|
let guid_bytes: [u8; 16] = hash_guid(&name);
|
||||||
rand::thread_rng().fill(&mut guid_bytes);
|
|
||||||
let guid = u128::from_ne_bytes(guid_bytes);
|
let guid = u128::from_ne_bytes(guid_bytes);
|
||||||
//SAFETY: guid is a unique integer so transmuting either all zeroes or the user's preferred
|
//SAFETY: guid is a unique integer so transmuting either all zeroes or the user's preferred
|
||||||
//guid to the winapi guid type is safe and will allow the windows kernel to see our GUID
|
//guid to the winapi guid type is safe and will allow the windows kernel to see our GUID
|
||||||
@@ -154,7 +152,14 @@ impl Device {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn hash_guid(input: &str) -> [u8; 16] {
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
hasher.update(b"VNT");
|
||||||
|
hasher.update(input.as_bytes());
|
||||||
|
hasher.update(b"2024");
|
||||||
|
let hash: [u8; 32] = hasher.finalize().into();
|
||||||
|
hash[..16].try_into().unwrap()
|
||||||
|
}
|
||||||
impl IFace for Device {
|
impl IFace for Device {
|
||||||
fn version(&self) -> io::Result<String> {
|
fn version(&self) -> io::Result<String> {
|
||||||
let version = unsafe { self.win_tun.WintunGetRunningDriverVersion() };
|
let version = unsafe { self.win_tun.WintunGetRunningDriverVersion() };
|
||||||
|
|||||||
Reference in New Issue
Block a user