-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlooksee.c
102 lines (88 loc) · 1.91 KB
/
looksee.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
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
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/smp.h>
#include <linux/jiffies.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("kromych");
MODULE_DESCRIPTION("LookSee");
MODULE_VERSION("0.1");
#define ISAY "LOOKSEE:"
#define DUMP_CPU_DATA \
{\
int smp_id = raw_smp_processor_id();\
__u64 cr3 = 0; \
__u64 cr8 = 0; \
__u64 rflags = 0;\
__u64 rsp = 0;\
\
asm volatile (\
"movq %%cr3, %%rax" \
: "=a"(cr3)\
: \
: "memory"\
);\
\
asm volatile (\
"movq %%cr8, %%rax" \
: "=a"(cr8)\
: \
: "memory"\
);\
\
asm volatile (\
"pushfq; popq %%rax" \
: "=a"(rflags)\
: \
: "memory"\
);\
\
asm volatile (\
"movq %%rsp, %%rax" \
: "=a"(rsp)\
: \
: "memory"\
);\
\
printk(KERN_INFO ISAY "On CPU %u, cr3=0x%llx, cr8=%llx, rflags=0x%llx, rsp=0x%llx, interrupts enabled=%s", \
smp_id, cr3, cr8, rflags, rsp, (rflags & 0x0200) != 0 ? "true" : "false");\
}\
static void cpu_func(void* ParamPtr)
{
DUMP_CPU_DATA
asm volatile (
"movq $15, %%rax; movq %%rax, %%cr8; "
:
:
: "%rax", "memory"
);
__u64 i;
for (i = 0; i < (1ULL << 32); ++i)
{
asm volatile ("pause" : : : "memory");
}
asm volatile (
"movq $0, %%rax; movq %%rax, %%cr8; "
:
:
: "%rax", "memory"
);
}
static int __init look_see_start(void)
{
printk(KERN_INFO ISAY "Loading module...");
DUMP_CPU_DATA
on_each_cpu(cpu_func, NULL, 0);
return 0;
}
static void __exit look_see_end(void)
{
printk(KERN_INFO ISAY "Unloaded");
}
module_init(look_see_start);
module_exit(look_see_end);