forked from emilytouchingcomputers/CTFium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabyk.c
68 lines (51 loc) · 1.19 KB
/
babyk.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
62
63
64
65
66
67
68
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#define BUFSIZE 100
static int leetness=20;
module_param(leetness,int,0660);
static struct proc_dir_entry *ent;
static ssize_t babywrite(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
{
int num, c, m;
char buf[BUFSIZE];
// if(*ppos > 0 || count > BUFSIZE)
// return -EFAULT;
if(raw_copy_from_user(buf, ubuf, count))
return -EFAULT;
num = sscanf(buf,"%d",&m);
if(num != 1)
return -EFAULT;
leetness = m;
c = strlen(buf);
printk("LEETNESS SCORE: %d", leetness);
*ppos = c;
return c;
}
static ssize_t babyread(struct file *file, char __user *ubuf,size_t count, loff_t *ppos)
{
printk("READ NOT IMPLEMENTED YET");
return 0;
}
static struct file_operations myops =
{
.owner = THIS_MODULE,
.read = babyread,
.write = babywrite,
};
static int baby_init(void)
{
ent=proc_create("babydev",0660,NULL,&myops);
printk(KERN_ALERT "Baby initialized!");
return 0;
}
static void baby_cleanup(void)
{
proc_remove(ent);
printk(KERN_WARNING "BYE!");
}
module_init(baby_init);
module_exit(baby_cleanup);