Skip to content

Commit

Permalink
make winreg as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Dec 27, 2024
1 parent 9be3ac0 commit 3455eee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ features = ["async"]

[features]
default = []
# default = ["verify_binary_signature", "panic_on_unsent_packets", "async"]
# default = [
# "verify_binary_signature",
# "panic_on_unsent_packets",
# "async",
# "winreg",
# ]
async = ["blocking", "futures"]
panic_on_unsent_packets = []
verify_binary_signature = []
Expand Down Expand Up @@ -55,7 +60,7 @@ windows-sys = { version = "0.59", features = [
"Win32_System_LibraryLoader",
"Win32_Security_WinTrust",
] }
winreg = "0.52.0"
winreg = { version = "0.52.0", optional = true }

[dev-dependencies]
dotenvy = "0.15"
Expand Down
6 changes: 4 additions & 2 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,21 @@ impl Adapter {

impl Drop for Adapter {
fn drop(&mut self) {
let name = self.get_name();
let _name = self.get_name();
//Close adapter on drop
//This is why we need an Arc of wintun
unsafe { self.wintun.WintunCloseAdapter(self.adapter.0) };
self.adapter = UnsafeHandle(ptr::null_mut());
if let Ok(name) = name {
#[cfg(feature = "winreg")]
if let Ok(name) = _name {
// Delete registry related to network card
_ = delete_adapter_info_from_reg(&name);
}
}
}

/// This function is used to avoid the adapter name and guid being recorded in the registry
#[cfg(feature = "winreg")]
pub(crate) fn delete_adapter_info_from_reg(dev_name: &str) -> std::io::Result<()> {
use winreg::{enums::HKEY_LOCAL_MACHINE, enums::KEY_ALL_ACCESS, RegKey};
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
Expand Down

0 comments on commit 3455eee

Please sign in to comment.