custom_font_hook.rs (978B) - raw
1 use std::{ffi::CStr, fs}; 2 3 use nix::libc::{self, c_uint}; 4 5 use crate::{config, def_hook, dobby_hook_sym}; 6 7 def_hook!( 8 open_hook, 9 i32, 10 |path: *const u8, flags: i32, mode: c_uint| { 11 if let Ok(pathname) = CStr::from_ptr(path).to_str() { 12 if pathname == "/system/fonts/NotoColorEmoji.ttf" { 13 if let Some(font_path) = config::native_config().custom_emoji_font_path { 14 if fs::metadata(&font_path).is_ok() { 15 return libc::openat(libc::AT_FDCWD, font_path.as_ptr() as *const u8, flags, mode); 16 } else { 17 warn!("custom emoji font path does not exist: {}", font_path); 18 } 19 } 20 } 21 } 22 23 open_hook_original.unwrap()(path, flags, mode) 24 } 25 ); 26 27 28 pub fn init() { 29 if config::native_config().custom_emoji_font_path.is_none() { 30 return; 31 } 32 33 dobby_hook_sym!("libc.so", "open", open_hook); 34 }