mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 13:17:42 +02:00
fix(native): custom font hook crash
This commit is contained in:
@ -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);
|
||||
}
|
Reference in New Issue
Block a user