commit bc9af4105c60c4b7a5a4a6ed0e1ac0c583a35890
parent 8c4e32d614f5a913eb81eabb5a32a57b3120fcd4
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sun, 28 Jul 2024 19:43:31 +0200
fix(native): custom font hook crash
Diffstat:
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/native/rust/src/modules/custom_font_hook.rs b/native/rust/src/modules/custom_font_hook.rs
@@ -1,19 +1,18 @@
use std::{ffi::CStr, fs};
+use nix::libc::{self, c_uint};
+
use crate::{config, def_hook, dobby_hook_sym};
def_hook!(
open_hook,
i32,
- |path: *const u8, flags: i32| {
- let mut path = path;
-
+ |path: *const u8, flags: i32, mode: c_uint| {
if let Ok(pathname) = CStr::from_ptr(path).to_str() {
if pathname == "/system/fonts/NotoColorEmoji.ttf" {
if let Some(font_path) = config::native_config().custom_emoji_font_path {
if fs::metadata(&font_path).is_ok() {
- path = (font_path.to_owned() + "\0").as_ptr();
- debug!("open {}", font_path);
+ return libc::openat(libc::AT_FDCWD, font_path.as_ptr() as *const u8, flags, mode);
} else {
warn!("custom emoji font path does not exist: {}", font_path);
}
@@ -21,11 +20,15 @@ def_hook!(
}
}
- open_hook_original.unwrap()(path, flags)
+ open_hook_original.unwrap()(path, flags, mode)
}
);
pub fn init() {
+ if config::native_config().custom_emoji_font_path.is_none() {
+ return;
+ }
+
dobby_hook_sym!("libc.so", "open", open_hook);
}
\ No newline at end of file