feat(native): custom font hook

This commit is contained in:
rhunk 2024-07-27 19:51:41 +02:00
parent b18c969125
commit d3f9d03dcf
4 changed files with 37 additions and 4 deletions

View File

@ -13,7 +13,7 @@ mod modules;
use android_logger::Config;
use log::LevelFilter;
use modules::{composer_hook, duplex_hook, fstat_hook, linker_hook, sqlite_hook, unary_call_hook};
use modules::{composer_hook, custom_font_hook, duplex_hook, fstat_hook, linker_hook, sqlite_hook, unary_call_hook};
use jni::objects::{JObject, JString};
use jni::sys::{jint, jstring, JNI_VERSION_1_6};
@ -67,7 +67,8 @@ fn init(mut env: JNIEnv, _class: JObject, signature_cache: JString) -> jstring {
unary_call_hook::init(),
composer_hook::init(),
fstat_hook::init(),
sqlite_hook::init()
sqlite_hook::init(),
custom_font_hook::init()
);
threads.into_iter().for_each(|t| t.join().unwrap());

View File

@ -0,0 +1,31 @@
use std::{ffi::CStr, fs};
use crate::{config, def_hook, dobby_hook_sym};
def_hook!(
open_hook,
i32,
|path: *const u8, flags: i32| {
let mut path = path;
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);
} else {
warn!("custom emoji font path does not exist: {}", font_path);
}
}
}
}
open_hook_original.unwrap()(path, flags)
}
);
pub fn init() {
dobby_hook_sym!("libc.so", "open", open_hook);
}

View File

@ -15,7 +15,7 @@ def_hook!(
let pathname_str = CStr::from_ptr(pathname).to_str().unwrap().to_string();
if let Some(content) = SHARED_LIBRARIES.lock().unwrap().remove(&pathname_str) {
let memfd = libc::syscall(libc::SYS_memfd_create, "me.rhunk.snapenhance\0".as_ptr(), 0) as i32;
let memfd = libc::syscall(libc::SYS_memfd_create, "jit-cache\0".as_ptr(), 0) as i32;
let content = content.into_boxed_slice();
if libc::write(memfd, content.as_ptr() as *const c_void, content.len() as libc::size_t) == -1 {

View File

@ -3,4 +3,5 @@ pub mod duplex_hook;
pub mod sqlite_hook;
pub mod fstat_hook;
pub mod unary_call_hook;
pub mod composer_hook;
pub mod composer_hook;
pub mod custom_font_hook;