mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-09 19:04:34 +02:00
feat(native): custom font hook
This commit is contained in:
parent
b18c969125
commit
d3f9d03dcf
@ -13,7 +13,7 @@ mod modules;
|
|||||||
|
|
||||||
use android_logger::Config;
|
use android_logger::Config;
|
||||||
use log::LevelFilter;
|
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::objects::{JObject, JString};
|
||||||
use jni::sys::{jint, jstring, JNI_VERSION_1_6};
|
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(),
|
unary_call_hook::init(),
|
||||||
composer_hook::init(),
|
composer_hook::init(),
|
||||||
fstat_hook::init(),
|
fstat_hook::init(),
|
||||||
sqlite_hook::init()
|
sqlite_hook::init(),
|
||||||
|
custom_font_hook::init()
|
||||||
);
|
);
|
||||||
|
|
||||||
threads.into_iter().for_each(|t| t.join().unwrap());
|
threads.into_iter().for_each(|t| t.join().unwrap());
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -15,7 +15,7 @@ def_hook!(
|
|||||||
let pathname_str = CStr::from_ptr(pathname).to_str().unwrap().to_string();
|
let pathname_str = CStr::from_ptr(pathname).to_str().unwrap().to_string();
|
||||||
|
|
||||||
if let Some(content) = SHARED_LIBRARIES.lock().unwrap().remove(&pathname_str) {
|
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();
|
let content = content.into_boxed_slice();
|
||||||
|
|
||||||
if libc::write(memfd, content.as_ptr() as *const c_void, content.len() as libc::size_t) == -1 {
|
if libc::write(memfd, content.as_ptr() as *const c_void, content.len() as libc::size_t) == -1 {
|
||||||
|
@ -4,3 +4,4 @@ pub mod sqlite_hook;
|
|||||||
pub mod fstat_hook;
|
pub mod fstat_hook;
|
||||||
pub mod unary_call_hook;
|
pub mod unary_call_hook;
|
||||||
pub mod composer_hook;
|
pub mod composer_hook;
|
||||||
|
pub mod custom_font_hook;
|
Loading…
x
Reference in New Issue
Block a user