forked from Jiang-Night/Kernel_driver_hack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.c
More file actions
executable file
·112 lines (101 loc) · 2.08 KB
/
entry.c
File metadata and controls
executable file
·112 lines (101 loc) · 2.08 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <linux/module.h>
#include <linux/tty.h>
#include <linux/miscdevice.h>
#include "comm.h"
#include "memory.h"
#include "process.h"
#define DEVICE_NAME "JiangNight"
int dispatch_open(struct inode *node, struct file *file)
{
return 0;
}
int dispatch_close(struct inode *node, struct file *file)
{
return 0;
}
long dispatch_ioctl(struct file *const file, unsigned int const cmd, unsigned long const arg)
{
static COPY_MEMORY cm;
static MODULE_BASE mb;
static char key[0x100] = {0};
static char name[0x100] = {0};
static bool is_verified = false;
if (cmd == OP_INIT_KEY && !is_verified)
{
if (copy_from_user(key, (void __user *)arg, sizeof(key) - 1) != 0)
{
return -1;
}
}
switch (cmd)
{
case OP_READ_MEM:
{
if (copy_from_user(&cm, (void __user *)arg, sizeof(cm)) != 0)
{
return -1;
}
if (read_process_memory(cm.pid, cm.addr, cm.buffer, cm.size) == false)
{
return -1;
}
break;
}
case OP_WRITE_MEM:
{
if (copy_from_user(&cm, (void __user *)arg, sizeof(cm)) != 0)
{
return -1;
}
if (write_process_memory(cm.pid, cm.addr, cm.buffer, cm.size) == false)
{
return -1;
}
break;
}
case OP_MODULE_BASE:
{
if (copy_from_user(&mb, (void __user *)arg, sizeof(mb)) != 0 || copy_from_user(name, (void __user *)mb.name, sizeof(name) - 1) != 0)
{
return -1;
}
mb.base = get_module_base(mb.pid, name);
if (copy_to_user((void __user *)arg, &mb, sizeof(mb)) != 0)
{
return -1;
}
break;
}
default:
break;
}
return 0;
}
struct file_operations dispatch_functions = {
.owner = THIS_MODULE,
.open = dispatch_open,
.release = dispatch_close,
.unlocked_ioctl = dispatch_ioctl,
};
struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dispatch_functions,
};
int __init driver_entry(void)
{
int ret;
printk("[+] driver_entry");
ret = misc_register(&misc);
return ret;
}
void __exit driver_unload(void)
{
printk("[+] driver_unload");
misc_deregister(&misc);
}
module_init(driver_entry);
module_exit(driver_unload);
MODULE_DESCRIPTION("Linux Kernel.");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("JiangNight");