pub fn find_library(library_name: &str) -> Result<usize>Expand description
Find the base address of a loaded library in the current process.
Searches through /proc/self/maps to locate the library and returns its base address.
§Arguments
library_name- Name of the library to find (e.g., “libil2cpp.so”)
§Returns
Ok(usize) containing the base address of the library.
Err(SubstrateError::LibraryNotFound) if the library is not loaded.
§Examples
use substrate::utils::find_library;
let base = find_library("libil2cpp.so").expect("Library not found");
println!("libil2cpp.so base: 0x{:x}", base);Examples found in repository?
examples/error_handling.rs (line 16)
4fn demonstrate_error_handling() {
5 println!("=== Error Handling Example ===\n");
6
7 unsafe {
8 println!("1. Testing null pointer hook:");
9 match hook_function(std::ptr::null_mut::<u8>(), std::ptr::null_mut()) {
10 Ok(_) => println!(" Unexpected success"),
11 Err(SubstrateError::NullPointer) => println!(" ✓ Correctly caught null pointer"),
12 Err(e) => println!(" Different error: {}", e),
13 }
14
15 println!("\n2. Testing library not found:");
16 match utils::find_library("nonexistent.so") {
17 Ok(_) => println!(" Unexpected success"),
18 Err(SubstrateError::LibraryNotFound(name)) => {
19 println!(" ✓ Correctly caught missing library: {}", name)
20 }
21 Err(e) => println!(" Different error: {}", e),
22 }
23
24 println!("\n3. Testing invalid offset string:");
25 match utils::string_to_offset("not_a_hex") {
26 Ok(_) => println!(" Unexpected success"),
27 Err(SubstrateError::ParseError(msg)) => {
28 println!(" ✓ Correctly caught parse error: {}", msg)
29 }
30 Err(e) => println!(" Different error: {}", e),
31 }
32
33 println!("\n4. Testing valid hex parsing:");
34 match utils::string_to_offset("0x123ABC") {
35 Ok(offset) => println!(" ✓ Successfully parsed: 0x{:X}", offset),
36 Err(e) => println!(" ✗ Unexpected error: {}", e),
37 }
38 }
39
40 println!("\n=== All Error Cases Handled ===");
41}