From e36733602b853134846a1a678d3fe7fbceec6499 Mon Sep 17 00:00:00 2001 From: ajwerner Date: Wed, 11 Sep 2024 01:56:10 -0400 Subject: [PATCH] frida-gum: add std feature (#156) The use of an ad-hoc list of features to enable std is weird. It's better to centralize under one std feature that these features enable. Fixes #154 --- frida-gum/Cargo.toml | 9 +++++---- frida-gum/src/lib.rs | 21 +++------------------ frida-gum/src/memory_range.rs | 6 +----- frida-gum/src/module.rs | 6 +----- frida-gum/src/module_map.rs | 6 +----- frida-gum/src/range_details.rs | 6 +----- frida-gum/src/stalker/transformer.rs | 6 +----- 7 files changed, 13 insertions(+), 47 deletions(-) diff --git a/frida-gum/Cargo.toml b/frida-gum/Cargo.toml index 02b65a25..7ee8187c 100644 --- a/frida-gum/Cargo.toml +++ b/frida-gum/Cargo.toml @@ -9,13 +9,14 @@ description.workspace = true [features] auto-download = ["frida-gum-sys/auto-download"] -backtrace = ["libc"] +backtrace = ["libc", "std"] event-sink = ["frida-gum-sys/event-sink"] invocation-listener = ["frida-gum-sys/invocation-listener"] -memory-access-monitor = [] -module-names = [] +memory-access-monitor = ["std"] +module-names = ["std"] stalker-observer = ["frida-gum-sys/stalker-observer"] stalker-params = ["frida-gum-sys/stalker-params"] +std = [] [dependencies] cstr_core = { version = "0.2.6", default-features = false, features = ["alloc"] } @@ -33,4 +34,4 @@ lazy_static = "1" maintenance = { status = "experimental" } [package.metadata.docs.rs] -features = ["event-sink", "invocation-listener", "stalker-observer", "stalker-params"] +features = ["event-sink", "invocation-listener", "stalker-observer", "stalker-params", "std"] diff --git a/frida-gum/src/lib.rs b/frida-gum/src/lib.rs index 091ac5cf..a1c9d97a 100644 --- a/frida-gum/src/lib.rs +++ b/frida-gum/src/lib.rs @@ -45,23 +45,12 @@ //! } //! ``` -#![cfg_attr( - not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" - )), - no_std -)] +#![cfg_attr(not(feature = "std"), no_std)] #![deny(warnings)] #![allow(clippy::needless_doctest_main)] #![allow(clippy::missing_safety_doc)] -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] extern crate alloc; extern crate num; @@ -74,11 +63,7 @@ use core::{ fmt::{Debug, Display, Formatter, LowerHex, UpperHex}, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::string::String; pub mod stalker; diff --git a/frida-gum/src/memory_range.rs b/frida-gum/src/memory_range.rs index b92eea8a..fa25f06c 100644 --- a/frida-gum/src/memory_range.rs +++ b/frida-gum/src/memory_range.rs @@ -11,11 +11,7 @@ use core::{ ops::Range, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::vec::Vec; pub struct MatchPattern { diff --git a/frida-gum/src/module.rs b/frida-gum/src/module.rs index 956f6d1e..b5dfd978 100644 --- a/frida-gum/src/module.rs +++ b/frida-gum/src/module.rs @@ -21,11 +21,7 @@ use { frida_gum_sys::{gboolean, gpointer, GumExportDetails, GumModuleDetails, GumSymbolDetails}, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::{boxed::Box, string::String, vec, vec::Vec}; extern "C" fn enumerate_ranges_callout( diff --git a/frida-gum/src/module_map.rs b/frida-gum/src/module_map.rs index 61e249d8..a661fe2e 100644 --- a/frida-gum/src/module_map.rs +++ b/frida-gum/src/module_map.rs @@ -19,11 +19,7 @@ use { frida_gum_sys as gum_sys, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::{ boxed::Box, string::{String, ToString}, diff --git a/frida-gum/src/range_details.rs b/frida-gum/src/range_details.rs index f39c5312..d8a3277b 100644 --- a/frida-gum/src/range_details.rs +++ b/frida-gum/src/range_details.rs @@ -20,11 +20,7 @@ use { frida_gum_sys as gum_sys, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::{boxed::Box, string::String}; /// The memory protection of an unassociated page. diff --git a/frida-gum/src/stalker/transformer.rs b/frida-gum/src/stalker/transformer.rs index b9ed2422..48a29d6b 100644 --- a/frida-gum/src/stalker/transformer.rs +++ b/frida-gum/src/stalker/transformer.rs @@ -10,11 +10,7 @@ use { core::{ffi::c_void, marker::PhantomData}, }; -#[cfg(not(any( - feature = "module-names", - feature = "backtrace", - feature = "memory-access-monitor" -)))] +#[cfg(not(feature = "std"))] use alloc::boxed::Box; pub struct StalkerIterator<'a> {