forked from milabs/khook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
52 lines (37 loc) · 1.21 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <linux/kernel.h>
#include <linux/module.h>
#include "khook/engine.c"
////////////////////////////////////////////////////////////////////////////////
// An example of using KHOOK
////////////////////////////////////////////////////////////////////////////////
#include <linux/fs.h>
KHOOK(inode_permission);
static int khook_inode_permission(struct inode *inode, int mask)
{
int ret = 0;
ret = KHOOK_ORIGIN(inode_permission, inode, mask);
printk("%s(%p, %08x) = %d\n", __func__, inode, mask, ret);
return ret;
}
////////////////////////////////////////////////////////////////////////////////
// An example of using KHOOK_EXT
////////////////////////////////////////////////////////////////////////////////
#include <linux/binfmts.h>
KHOOK_EXT(int, load_elf_binary, struct linux_binprm *);
static int khook_load_elf_binary(struct linux_binprm *bprm)
{
int ret = 0;
ret = KHOOK_ORIGIN(load_elf_binary, bprm);
printk("%s(%p) = %d (%s)\n", __func__, bprm, ret, bprm->filename);
return ret;
}
////////////////////////////////////////////////////////////////////////////////
int init_module(void)
{
return khook_init();
}
void cleanup_module(void)
{
khook_cleanup();
}
MODULE_LICENSE("GPL\0but who really cares?");