-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule1.c
61 lines (50 loc) · 1.31 KB
/
module1.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
53
54
55
56
57
58
59
60
61
#include <linux/module.h> // Needed by all modules
#include <linux/kernel.h> // Needed for KERN_INFO
#include <linux/fs.h> // Needed by filp
#include <asm/uaccess.h> // Needed by segment descriptors
static int __init init_module1 (void)
{
char entry[128];
char message[128];
char type_of_elf[14];
struct file *file;
char buf[128];
mm_segment_t fs;
int i;
int isELF;
for(i=0;i<128;i++){
buf[i] = 0;
}
//char ELF_start[4];
//char Python_start[17];
//fread(ELF_start, 1, 4, filename);
//fread(Python_start, 1, 17, filename);
file = filp_open("a", O_RDONLY, 0);
if(!file)
printk(KERN_ALERT "filp_open error!\n");
else{
// Get current segment descriptor
fs = get_fs();
// Set segment descriptor associated to kernel space
set_fs(get_ds());
// Read the file
file->f_op->read(file, buf, 4, &file->f_pos);
if(strcmp(buf, "0x7F454C46") == 0){
printk("!!!\n");
isELF = 1;
}
// Restore segment descriptor
set_fs(fs);
// See what we read from file
printk(KERN_INFO "buf:%s\n",buf);
}
filp_close(file,NULL);
return 0;
}
static void __exit exit_module1(void)
{
printk(KERN_INFO "exit module\n");
}
module_init(init_module1);
module_exit(exit_module1);
MODULE_LICENSE("GPL v3");