Refactor Kconfig and Makefile, update KPROBES related configurations, simplify conditional compilation logic

This commit is contained in:
ShirkNeko
2025-04-17 19:46:14 +08:00
parent 140ebd196f
commit 28f006ed39
7 changed files with 78 additions and 61 deletions

View File

@@ -49,7 +49,7 @@ static void stop_vfs_read_hook();
static void stop_execve_hook();
static void stop_input_hook();
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
static struct work_struct stop_vfs_read_work;
static struct work_struct stop_execve_hook_work;
static struct work_struct stop_input_hook_work;
@@ -162,7 +162,7 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr,
struct user_arg_ptr *argv,
struct user_arg_ptr *envp, int *flags)
{
#ifndef KSU_HOOK_WITH_KPROBES
#ifndef CONFIG_KSU_HOOK_KPROBES
if (!ksu_execveat_hook) {
return 0;
}
@@ -318,7 +318,7 @@ static ssize_t read_iter_proxy(struct kiocb *iocb, struct iov_iter *to)
int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
size_t *count_ptr, loff_t **pos)
{
#ifndef KSU_HOOK_WITH_KPROBES
#ifndef CONFIG_KSU_HOOK_KPROBES
if (!ksu_vfs_read_hook) {
return 0;
}
@@ -431,7 +431,7 @@ static bool is_volumedown_enough(unsigned int count)
int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code,
int *value)
{
#ifndef KSU_HOOK_WITH_KPROBES
#ifndef CONFIG_KSU_HOOK_KPROBES
if (!ksu_input_hook) {
return 0;
}
@@ -472,7 +472,7 @@ bool ksu_is_safe_mode()
return false;
}
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs)
{
@@ -630,7 +630,7 @@ static void do_stop_input_hook(struct work_struct *work)
static void stop_vfs_read_hook()
{
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
bool ret = schedule_work(&stop_vfs_read_work);
pr_info("unregister vfs_read kprobe: %d!\n", ret);
#else
@@ -641,7 +641,7 @@ static void stop_vfs_read_hook()
static void stop_execve_hook()
{
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
bool ret = schedule_work(&stop_execve_hook_work);
pr_info("unregister execve kprobe: %d!\n", ret);
#else
@@ -656,7 +656,7 @@ static void stop_execve_hook()
static void stop_input_hook()
{
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
static bool input_hook_stopped = false;
if (input_hook_stopped) {
return;
@@ -675,7 +675,7 @@ static void stop_input_hook()
// ksud: module support
void ksu_ksud_init()
{
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
int ret;
ret = register_kprobe(&execve_kp);
@@ -695,7 +695,7 @@ void ksu_ksud_init()
void ksu_ksud_exit()
{
#ifdef KSU_HOOK_WITH_KPROBES
#ifdef CONFIG_KSU_HOOK_KPROBES
unregister_kprobe(&execve_kp);
// this should be done before unregister vfs_read_kp
// unregister_kprobe(&vfs_read_kp);