desktop: read StartupApproved through the registry API, no reg.exe (the security test allows no other programs)
This commit is contained in:
parent
53845c6dd9
commit
d43c95db7e
4 changed files with 18 additions and 22 deletions
1
apps/desktop/src-tauri/Cargo.lock
generated
1
apps/desktop/src-tauri/Cargo.lock
generated
|
|
@ -4126,6 +4126,7 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
"webview2-com",
|
"webview2-com",
|
||||||
"windows-core",
|
"windows-core",
|
||||||
|
"winreg",
|
||||||
"zip",
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ zip = { version = "4", default-features = false, features = ["deflate-flate2-zli
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
webview2-com = "0.39"
|
webview2-com = "0.39"
|
||||||
windows-core = "0.62"
|
windows-core = "0.62"
|
||||||
|
# reads Startup apps' StartupApproved value (already in the tree through the autostart plugin)
|
||||||
|
winreg = "0.56"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
|
||||||
|
|
@ -90,27 +90,20 @@ fn tray(app: &tauri::App) -> tauri::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A tray menu pick (a menu panel row or the native fallback menu): tray.rs maps the id to what it does.
|
/// A tray menu pick (a menu panel row or the native fallback menu): tray.rs maps the id to what it does.
|
||||||
/// Whether the person turned storebound off in Windows' Startup apps (Settings / Task Manager), from the `reg query`
|
/// Whether the person turned storebound off in Windows' Startup apps (Settings / Task Manager), from the
|
||||||
/// output of HKCU\...\Explorer\StartupApproved\Run /v storebound: the first byte of the REG_BINARY is even when enabled
|
/// HKCU\...\Explorer\StartupApproved\Run value named like the Run entry: its first byte is even when enabled (02, 06),
|
||||||
/// (02, 06), odd when disabled (03, 07). No entry: not turned off. Pure.
|
/// odd when disabled (03, 07). No value: not turned off. Pure.
|
||||||
pub fn startup_approved_off(reg_query_out: &str) -> bool {
|
pub fn startup_approved_off(value: &[u8]) -> bool {
|
||||||
reg_query_out
|
value.first().is_some_and(|b| b & 1 == 1)
|
||||||
.lines()
|
|
||||||
.find(|l| l.contains("REG_BINARY"))
|
|
||||||
.and_then(|l| l.split_whitespace().last())
|
|
||||||
.and_then(|hex| u8::from_str_radix(hex.get(0..2)?, 16).ok())
|
|
||||||
.is_some_and(|b| b & 1 == 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn startup_disabled_by_user() -> bool {
|
fn startup_disabled_by_user() -> bool {
|
||||||
use std::os::windows::process::CommandExt;
|
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
||||||
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
RegKey::predef(HKEY_CURRENT_USER)
|
||||||
std::process::Command::new("reg")
|
.open_subkey(r"Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run")
|
||||||
.args(["query", r"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run", "/v", "storebound"])
|
.and_then(|k| k.get_raw_value("storebound"))
|
||||||
.creation_flags(CREATE_NO_WINDOW)
|
.map(|v| startup_approved_off(&v.bytes))
|
||||||
.output()
|
|
||||||
.map(|o| startup_approved_off(&String::from_utf8_lossy(&o.stdout)))
|
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,9 +146,9 @@ fn background_updater_schedule_and_defer() {
|
||||||
#[test]
|
#[test]
|
||||||
fn startup_apps_choice_is_read_from_startup_approved() {
|
fn startup_apps_choice_is_read_from_startup_approved() {
|
||||||
use storebound_desktop::startup_approved_off;
|
use storebound_desktop::startup_approved_off;
|
||||||
let on = "\r\nHKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\Run\r\n storebound REG_BINARY 020000000000000000000000\r\n";
|
assert!(!startup_approved_off(&[0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||||
let off = "\r\nHKEY_CURRENT_USER\\Run\r\n storebound REG_BINARY 0300000020D1D3B1F0B3DC01\r\n";
|
assert!(!startup_approved_off(&[0x06, 0, 0, 0]));
|
||||||
assert!(!startup_approved_off(on));
|
assert!(startup_approved_off(&[0x03, 0, 0, 0, 0x20, 0xD1, 0xD3, 0xB1, 0xF0, 0xB3, 0xDC, 0x01]));
|
||||||
assert!(startup_approved_off(off));
|
assert!(startup_approved_off(&[0x07]));
|
||||||
assert!(!startup_approved_off("ERROR: The system was unable to find the specified registry key or value."));
|
assert!(!startup_approved_off(&[]));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue