分类: LINUX
2006-10-23 15:54:28
#include
#include
#include
#include
DECLARE_MUTEX(test_lock);
MODULE_LICENSE("GPL");
static char old_code[5];
static char ret_code[] = {0xE9,0x00,0x00,0x00,0x00};//jmp 到我们的代码
void (*old_free_module)(struct module *mod);
void my_free_module(struct module *mod)
{
down(&test_lock);
memcpy(old_free_module,old_code,5);
printk("no,i do't want to free module %s\n",mod->name);
old_free_module(mod);
memcpy(old_free_module,ret_code,5);
up(&test_lock);
}
int test_init(void)
{
long *p = &ret_code[1];
long offset;
old_free_module = kallsyms_lookup_name("free_module");
if(!old_free_module)
return -1;
offset = my_free_module - old_free_module;
if(offset>0)
*p = offset - 5;