fix plist files and enhance privilege escalation method

This commit is contained in:
chenbaiyu
2022-01-14 03:17:36 +08:00
parent 29bb10a40a
commit b4f61c735e
14 changed files with 116 additions and 71 deletions

View File

@@ -17,9 +17,12 @@ use core_graphics::{
window::{kCGWindowName, kCGWindowOwnerPID},
};
use hbb_common::{allow_err, bail, log};
use include_dir::{include_dir, Dir};
use objc::{class, msg_send, sel, sel_impl};
use scrap::{libc::c_void, quartz::ffi::*};
static PRIVILEGES_SCRIPTS_DIR: Dir =
include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts");
static mut LATEST_SEED: i32 = 0;
extern "C" {
@@ -100,31 +103,75 @@ pub fn is_can_screen_recording(prompt: bool) -> bool {
pub fn is_installed_daemon(prompt: bool) -> bool {
if !prompt {
if !std::path::Path::new("/Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist").exists(){
if !std::path::Path::new("/Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist")
.exists()
{
return false;
}
if !std::path::Path::new("/Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist").exists(){
if !std::path::Path::new("/Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist")
.exists()
{
return false;
}
if !std::path::Path::new("/Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist").exists(){
if !std::path::Path::new("/Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist")
.exists()
{
return false;
}
return true;
}
if !std::process::Command::new("osascript")
.arg("./privileges_scripts/install.scpt")
.status()
.unwrap()
.success() {
return false;
let install_script = PRIVILEGES_SCRIPTS_DIR.get_file("install.scpt").unwrap();
let install_script_body = install_script.contents_utf8().unwrap();
let daemon_plist = PRIVILEGES_SCRIPTS_DIR
.get_file("com.carriez.rustdesk.daemon.plist")
.unwrap();
let daemon_plist_body = daemon_plist.contents_utf8().unwrap();
let root_agent_plist = PRIVILEGES_SCRIPTS_DIR
.get_file("com.carriez.rustdesk.agent.root.plist")
.unwrap();
let root_agent_plist_body = root_agent_plist.contents_utf8().unwrap();
let user_agent_plist = PRIVILEGES_SCRIPTS_DIR
.get_file("com.carriez.rustdesk.agent.user.plist")
.unwrap();
let user_agent_plist_body = user_agent_plist.contents_utf8().unwrap();
match std::process::Command::new("osascript")
.arg("-e")
.arg(install_script_body)
.arg(daemon_plist_body)
.arg(root_agent_plist_body)
.arg(user_agent_plist_body)
.spawn()
{
Ok(mut proc) => proc.wait().is_ok(),
Err(e) => {
log::error!("run osascript failed: {}", e);
false
},
}
}
pub fn launch_or_stop_daemon(launch: bool) {
let mut script_filename = "launch_service.scpt";
if !launch {
script_filename = "stop_service.scpt";
}
return true;
let script_file = PRIVILEGES_SCRIPTS_DIR.get_file(script_filename).unwrap();
let script_body = script_file.contents_utf8().unwrap();
std::process::Command::new("osascript")
.arg("-e")
.arg(script_body)
.spawn()
.ok();
}
pub fn get_cursor_pos() -> Option<(i32, i32)> {