История изменений
Исправление metawishmaster, (текущая версия) :
сорри, отходил... да, то (do-while) был небольшой бред %)
DECLARE_WAIT_QUEUE_HEAD(wq);
static int finished;
unsigned long **sys_call_table;
while (finished != 1)
asmlinkage long (*ref_sys_write) (unsigned int fd, const char __user * buf, size_t count);
asmlinkage long new_sys_write(unsigned int fd, const char __user * buf, size_t count)
{
finished = 0;
// тут я вызываю настоящий вызов, чтобы после проанализировать его результат.
long k = ref_sys_write(fd, buf, count);
MyAnalyzeFunc(k, count);
finished = 1;
wake_up_interruptible(&wq);
return k;
}
static int __init interceptor_start(void)
{
disable_page_protection();
ref_sys_write = (void *)sys_call_table[__NR_write];
sys_call_table[__NR_write] = (unsigned long *)new_sys_write;
enable_page_protection();
return 0;
}
static void __exit interceptor_end(void)
{
if (!sys_call_table)
return;
wait_event_interrutible(wq, finished != 0);
disable_page_protection();
sys_call_table[__NR_write] = (unsigned long *)ref_sys_write;
enable_page_protection();
}
module_init(interceptor_start);
module_exit(interceptor_end);
Исходная версия metawishmaster, :
сорри, отходил... да, то (do-while) был небольшой бред %)
DECLARE_WAIT_QUEUE_HEAD(wq);
static int finished;
unsigned long **sys_call_table;
asmlinkage long (*ref_sys_write) (unsigned int fd, const char __user * buf, size_t count);
asmlinkage long new_sys_write(unsigned int fd, const char __user * buf, size_t count)
{
finished = 0;
// тут я вызываю настоящий вызов, чтобы после проанализировать его результат.
long k = ref_sys_write(fd, buf, count);
MyAnalyzeFunc(k, count);
finished = 1;
wake_up_interruptible(&wq);
return k;
}
static int __init interceptor_start(void)
{
disable_page_protection();
ref_sys_write = (void *)sys_call_table[__NR_write];
sys_call_table[__NR_write] = (unsigned long *)new_sys_write;
enable_page_protection();
return 0;
}
static void __exit interceptor_end(void)
{
if (!sys_call_table)
return;
wait_event_interrutible(wq, finished != 0);
disable_page_protection();
sys_call_table[__NR_write] = (unsigned long *)ref_sys_write;
enable_page_protection();
}
module_init(interceptor_start);
module_exit(interceptor_end);