Skip to content

Commit

Permalink
Use process.get_module_path
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Oct 31, 2023
1 parent 48d7ac8 commit 76cb569
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/game_engine/unity/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ impl Module {
/// correct for this function to work. If you don't know the version in
/// advance, use [`attach_auto_detect`](Self::attach_auto_detect) instead.
pub fn attach(process: &Process, version: Version) -> Option<Self> {
let (module_range, format) = [
#[allow(unused)]
let (module_name, module_range, format) = [
("mono.dll", BinaryFormat::PE),
("mono-2.0-bdwgc.dll", BinaryFormat::PE),
#[cfg(feature = "std")]
("libmonobdwgc-2.0.dylib", BinaryFormat::MachO)
].into_iter()
.find_map(|(name, format)| Some((process.get_module_range(name).ok()?, format)))?;
.find_map(|(name, format)| Some((name, process.get_module_range(name).ok()?, format)))?;

let module = module_range.0;

Expand All @@ -78,9 +79,7 @@ impl Module {
},
#[cfg(feature = "std")]
BinaryFormat::MachO => {
let process_path = process.get_path().ok()?;
let contents_path = Path::new(&process_path).parent()?.parent()?;
let mono_module_path = contents_path.join("Frameworks").join("libmonobdwgc-2.0.dylib");
let mono_module_path = process.get_module_path(module_name).ok()?;
let mono_module_bytes = file_read_all_bytes(mono_module_path).ok()?;
macho::get_function_address(process, module_range, &mono_module_bytes, b"_mono_assembly_foreach")?
}
Expand Down

0 comments on commit 76cb569

Please sign in to comment.