From 42d7f87d90cc7ada9723762b557aa2709974cd81 Mon Sep 17 00:00:00 2001 From: xoffio <38369407+Xoffio@users.noreply.github.com> Date: Wed, 6 Nov 2024 00:39:43 -0500 Subject: [PATCH] use LazyLock & clean unnecessary crates (#175) - Use of LazyLock instead of lazy_static - Clean up unnecessary frida-sys & lazy_static crates --- examples/core/console_log/Cargo.toml | 1 - examples/core/console_log/src/main.rs | 6 ++---- examples/core/get_processes/Cargo.toml | 2 -- examples/core/get_processes/src/main.rs | 6 ++---- examples/core/hello/Cargo.toml | 2 -- examples/core/hello/src/main.rs | 6 ++---- examples/core/inject_lib_blob/Cargo.toml | 1 - examples/core/inject_lib_file/Cargo.toml | 1 - examples/core/list_exports/Cargo.toml | 2 -- examples/core/list_exports/src/main.rs | 6 ++---- examples/core/rpc_execute_function/Cargo.toml | 2 -- examples/core/rpc_execute_function/src/main.rs | 6 ++---- examples/core/usb_device/Cargo.toml | 2 -- 13 files changed, 10 insertions(+), 33 deletions(-) diff --git a/examples/core/console_log/Cargo.toml b/examples/core/console_log/Cargo.toml index 5cf6f511..598eeacf 100644 --- a/examples/core/console_log/Cargo.toml +++ b/examples/core/console_log/Cargo.toml @@ -7,4 +7,3 @@ publish = false [dependencies] frida = { path = "../../../frida" } -lazy_static = "1.4" diff --git a/examples/core/console_log/src/main.rs b/examples/core/console_log/src/main.rs index cbc1b9a1..4cfeea79 100644 --- a/examples/core/console_log/src/main.rs +++ b/examples/core/console_log/src/main.rs @@ -1,9 +1,7 @@ use frida::{DeviceManager, Frida, ScriptHandler, ScriptOption, ScriptRuntime}; -use lazy_static::lazy_static; +use std::sync::LazyLock; -lazy_static! { - static ref FRIDA: Frida = unsafe { Frida::obtain() }; -} +static FRIDA: LazyLock = LazyLock::new(|| unsafe { Frida::obtain() }); fn main() { let args: Vec = std::env::args().collect(); diff --git a/examples/core/get_processes/Cargo.toml b/examples/core/get_processes/Cargo.toml index 4f3a0b90..5fefcf79 100644 --- a/examples/core/get_processes/Cargo.toml +++ b/examples/core/get_processes/Cargo.toml @@ -7,5 +7,3 @@ publish = false [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } -lazy_static = "1.5.0" diff --git a/examples/core/get_processes/src/main.rs b/examples/core/get_processes/src/main.rs index 5a7076de..5a9455c9 100644 --- a/examples/core/get_processes/src/main.rs +++ b/examples/core/get_processes/src/main.rs @@ -1,9 +1,7 @@ use frida::Frida; -use lazy_static::lazy_static; +use std::sync::LazyLock; -lazy_static! { - static ref FRIDA: Frida = unsafe { Frida::obtain() }; -} +static FRIDA: LazyLock = LazyLock::new(|| unsafe { Frida::obtain() }); fn main() { let device_manager = frida::DeviceManager::obtain(&FRIDA); diff --git a/examples/core/hello/Cargo.toml b/examples/core/hello/Cargo.toml index 0c6690f6..e15182e2 100644 --- a/examples/core/hello/Cargo.toml +++ b/examples/core/hello/Cargo.toml @@ -8,5 +8,3 @@ publish = false [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } -lazy_static = "1.4" diff --git a/examples/core/hello/src/main.rs b/examples/core/hello/src/main.rs index 47cfc2e2..36f3db12 100644 --- a/examples/core/hello/src/main.rs +++ b/examples/core/hello/src/main.rs @@ -1,11 +1,9 @@ /* This example is in the public domain */ use frida::Frida; -use lazy_static::lazy_static; +use std::sync::LazyLock; -lazy_static! { - static ref FRIDA: Frida = unsafe { Frida::obtain() }; -} +static FRIDA: LazyLock = LazyLock::new(|| unsafe { Frida::obtain() }); fn main() { println!("Hello, world!"); diff --git a/examples/core/inject_lib_blob/Cargo.toml b/examples/core/inject_lib_blob/Cargo.toml index a12410a9..d605089f 100644 --- a/examples/core/inject_lib_blob/Cargo.toml +++ b/examples/core/inject_lib_blob/Cargo.toml @@ -10,4 +10,3 @@ crate-type = ["cdylib"] [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } diff --git a/examples/core/inject_lib_file/Cargo.toml b/examples/core/inject_lib_file/Cargo.toml index 24f19bc4..e6573add 100644 --- a/examples/core/inject_lib_file/Cargo.toml +++ b/examples/core/inject_lib_file/Cargo.toml @@ -10,4 +10,3 @@ crate-type = ["cdylib"] [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } diff --git a/examples/core/list_exports/Cargo.toml b/examples/core/list_exports/Cargo.toml index bdaebb57..dc204640 100644 --- a/examples/core/list_exports/Cargo.toml +++ b/examples/core/list_exports/Cargo.toml @@ -7,5 +7,3 @@ publish = false [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } -lazy_static = "1.5.0" diff --git a/examples/core/list_exports/src/main.rs b/examples/core/list_exports/src/main.rs index 68d300fe..61d0178a 100644 --- a/examples/core/list_exports/src/main.rs +++ b/examples/core/list_exports/src/main.rs @@ -1,10 +1,8 @@ use frida::{Frida, Message}; -use lazy_static::lazy_static; +use std::sync::LazyLock; use std::{thread, time::Duration}; -lazy_static! { - static ref FRIDA: Frida = unsafe { Frida::obtain() }; -} +static FRIDA: LazyLock = LazyLock::new(|| unsafe { Frida::obtain() }); fn main() { let device_manager = frida::DeviceManager::obtain(&FRIDA); diff --git a/examples/core/rpc_execute_function/Cargo.toml b/examples/core/rpc_execute_function/Cargo.toml index 67573b86..249dff57 100644 --- a/examples/core/rpc_execute_function/Cargo.toml +++ b/examples/core/rpc_execute_function/Cargo.toml @@ -7,7 +7,5 @@ publish = false [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } -lazy_static = "1.5.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.127" diff --git a/examples/core/rpc_execute_function/src/main.rs b/examples/core/rpc_execute_function/src/main.rs index 615a57d0..e9f94776 100644 --- a/examples/core/rpc_execute_function/src/main.rs +++ b/examples/core/rpc_execute_function/src/main.rs @@ -1,10 +1,8 @@ use frida::{Frida, Message}; -use lazy_static::lazy_static; use serde_json::json; +use std::sync::LazyLock; -lazy_static! { - static ref FRIDA: Frida = unsafe { Frida::obtain() }; -} +static FRIDA: LazyLock = LazyLock::new(|| unsafe { Frida::obtain() }); fn main() { let device_manager = frida::DeviceManager::obtain(&FRIDA); diff --git a/examples/core/usb_device/Cargo.toml b/examples/core/usb_device/Cargo.toml index a74b7de4..f0542786 100644 --- a/examples/core/usb_device/Cargo.toml +++ b/examples/core/usb_device/Cargo.toml @@ -8,5 +8,3 @@ publish = false [dependencies] frida = { path = "../../../frida" } -frida-sys = { path = "../../../frida-sys" } -lazy_static = "1.4"