Skip to content

Commit

Permalink
Feature std to disable no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Sep 17, 2023
1 parent cd6ac64 commit 8d863b0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ libm = { version = "0.2.7", optional = true }
wasi = { version = "0.11.0", default-features = false }

[features]
std = ["alloc"]
alloc = []
derive = ["asr-derive"]
flags = ["bitflags"]
Expand Down
2 changes: 1 addition & 1 deletion src/file_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
pub mod elf;
pub mod pe;
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
pub mod macho;
22 changes: 11 additions & 11 deletions src/game_engine/unity/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use core::iter;

#[cfg(feature = "alloc")]
use alloc::collections::BTreeSet;
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
use crate::file_format::macho;
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
use alloc::vec::Vec;
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
use std::{path::Path, fs::File, io, io::Read};

#[cfg(feature = "derive")]
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Module {
.find_map(|&name| process.get_module_range(name).ok()) {
return Self::attach_dll(process, version, module);
}
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
if let Ok(module) = process.get_module_range("libmonobdwgc-2.0.dylib") {
return Self::attach_dylib(process, version, module);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Module {
})
}

#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
fn attach_dylib(process: &Process, version: Version, module_range: (Address, u64)) -> Option<Self> {
let is_64_bit = macho::is_64_bit(process)?;
let offsets = Offsets::new(version, is_64_bit, BinaryFormat::MachO);
Expand Down Expand Up @@ -707,7 +707,7 @@ impl Offsets {
monoclassfieldalignment: 0x10,
},
},
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
(true, BinaryFormat::MachO) => match version {
Version::V1 => panic!("MachO V1 not supported"),
// 64-bit MachO V2 matches Unity2019_4_2020_3_x64_MachO_Offsets from
Expand Down Expand Up @@ -736,7 +736,7 @@ impl Offsets {
},
Version::V3 => panic!("MachO V3 not supported"),
},
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
(false, BinaryFormat::MachO) => panic!("32-bit MachO format not supported"),
}
}
Expand Down Expand Up @@ -784,7 +784,7 @@ fn detect_version(process: &Process) -> Option<Version> {
if let Ok(unity_module) = process.get_module_range("UnityPlayer.dll") {
return detect_version_dll(process, unity_module);
}
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
if process.get_module_range("UnityPlayer.dylib").is_ok() {
return detect_version_dylib(process);
}
Expand Down Expand Up @@ -826,7 +826,7 @@ fn detect_version_dll(process: &Process, unity_module: (Address, u64)) -> Option
})
}

#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
fn detect_version_dylib(process: &Process) -> Option<Version> {
const UNITY_PLAYER_VERSION: &[u8] = b"Unity Player version ";
const UNITY_PLAYER_VERSION_LEN: usize = UNITY_PLAYER_VERSION.len();
Expand Down Expand Up @@ -869,13 +869,13 @@ fn detect_version_dylib(process: &Process) -> Option<Version> {
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
enum BinaryFormat {
PE,
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
MachO,
}

// --------------------------------------------------------

#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
fn file_read_all_bytes<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
let mut f = File::open(path)?;
let mut buffer: Vec<u8> = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions src/game_engine/unity/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Address64, Error, Process,
};

#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
use crate::file_format::macho;

/// The scene manager allows you to easily identify the current scene loaded in
Expand All @@ -32,7 +32,7 @@ impl SceneManager {
if let Ok(unity_player) = process.get_module_range("UnityPlayer.dll") {
return Self::attach_dll(process, unity_player);
}
#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
if let Ok(unity_player) = process.get_module_range("UnityPlayer.dylib") {
return Self::attach_dylib(process, unity_player);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ impl SceneManager {
})
}

#[cfg(feature = "alloc")]
#[cfg(feature = "std")]
fn attach_dylib(process: &Process, unity_player: (Address, u64)) -> Option<Self> {
const SIG_64_BIT_DYLIB: Signature<13> = Signature::new("41 54 53 50 4C 8B ?5 ???????? 41 83");

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
clippy::complexity,
clippy::correctness,
Expand Down

0 comments on commit 8d863b0

Please sign in to comment.