Skip to content

Commit 22254e1

Browse files
committed
safely check module name and add option to request BindNow
1 parent d3124bf commit 22254e1

File tree

5 files changed

+16
-74
lines changed

5 files changed

+16
-74
lines changed

.cargo/config

Lines changed: 0 additions & 2 deletions
This file was deleted.

Xargo.toml

Lines changed: 0 additions & 22 deletions
This file was deleted.

aarch64-skyline-switch.json

Lines changed: 0 additions & 45 deletions
This file was deleted.

rust-toolchain

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#![feature(proc_macro_hygiene)]
22

3+
use std::sync::atomic::{AtomicBool, Ordering};
4+
35
use skyline::{hook, install_hooks};
46
use skyline::nn::ro;
57
use skyline::libc::{c_void, c_int, size_t};
6-
use skyline::from_c_str;
8+
use skyline::try_from_c_str;
79

810
use parking_lot::Mutex;
911

@@ -14,17 +16,22 @@ type Callback = fn(&NroInfo);
1416
static LOAD_HOOKS: Mutex<Vec<Callback>> = Mutex::new(Vec::new());
1517
static UNLOAD_HOOKS: Mutex<Vec<Callback>> = Mutex::new(Vec::new());
1618

19+
static SHOULD_BIND_NOW: AtomicBool = AtomicBool::new(false);
20+
1721
#[hook(replace = ro::LoadModule)]
1822
pub fn handle_load_module(
1923
out_module: *mut ro::Module,
2024
image: *const c_void,
2125
buffer: *mut c_void,
2226
buffer_size: size_t,
23-
flag: c_int
27+
mut flag: c_int
2428
) -> c_int {
29+
if SHOULD_BIND_NOW.load(Ordering::SeqCst) {
30+
flag = 1;
31+
}
2532
let ret = original!()(out_module, image, buffer, buffer_size, flag);
2633

27-
let name = unsafe { from_c_str(&(*out_module).Name as *const u8) };
34+
let name = unsafe { try_from_c_str(&(*out_module).Name as *const u8).unwrap_or_else(|_| String::from("unknown")) };
2835
println!("[NRO hook] Loaded {}. BindFlag: {}", name, match flag {
2936
1 => "Now",
3037
2 => "Lazy",
@@ -42,7 +49,7 @@ pub fn handle_load_module(
4249
pub fn handle_unload_module(in_module: *mut ro::Module) -> c_int {
4350
let ret = original!()(in_module);
4451

45-
let name = unsafe { from_c_str(&(*in_module).Name as *const u8) };
52+
let name = unsafe { try_from_c_str(&(*in_module).Name as *const u8).unwrap_or_else(|_| String::from("unknown")) };
4653
println!("[NRO hook] Unloaded {}.", name);
4754
let nro_info = NroInfo::new(&name, unsafe { &mut *in_module });
4855
for hook in UNLOAD_HOOKS.lock().iter() {
@@ -72,3 +79,8 @@ pub extern "Rust" fn add_nro_unload_hook(callback: Callback) {
7279

7380
hooks.push(callback);
7481
}
82+
83+
#[no_mangle]
84+
pub extern "Rust" fn nro_request_bind_now() {
85+
SHOULD_BIND_NOW.store(true, Ordering::SeqCst);
86+
}

0 commit comments

Comments
 (0)