-
Notifications
You must be signed in to change notification settings - Fork 76
/
asm.asm
126 lines (96 loc) · 1.92 KB
/
asm.asm
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.code
extern CalledHookTimes:dq
extern CheckCallCtx:PROC
extern ExceptionHandler:PROC
extern FindExceptionRecord:PROC
extern KeBugCheck:PROC
extern OldHalQueryCounter:dq
HalpTscQueryCounterOrdered PROC
rdtscp
shl rdx, 20h
or rax, rdx
ret
HalpTscQueryCounterOrdered ENDP;
;r13 = exception context
HookPosition PROC
push rcx
push rdx
sub rsp,0E8h
lea rax, CalledHookTimes
lock inc qword ptr [rax]
call CheckCallCtx
cmp rax,1
jne filt
;to do clear KiFreezeFlag
;fix: not neccessary to clear since no other function use it
;is an exception
call FindExceptionRecord
cmp rax,0
je dbgbreak
mov rcx, rax
mov rdx, r13
call ExceptionHandler
; still here so it's a debug break or something
dbgbreak:
xor rcx, rcx
call KeBugCheck
filt:
add rsp, 0E8h
pop rdx
pop rcx
;jmp HalpTscQueryCounterOrdered
jmp [OldHalQueryCounter]
HookPosition ENDP
CalloutReturn proc
;push stack segment selector
mov eax, ss
push rax
;push stack pointer
mov rax, [rcx + 0]
push rax
;push arithmetic/system flags rflags
mov rax, [rcx + 78h]
;xor rax, 200h ; enable interrupts
push rax
;push code segment selector
mov eax, cs
push rax
;push instruction pointer
mov rax, [rcx + 8]
push rax
;set arguments
mov rdx, [rcx + 18h]
mov r8, [rcx + 20h]
mov r9, [rcx + 28h]
mov rax, [rcx + 30h]
mov r12, [rcx + 38h]
mov r13, [rcx + 40h]
mov r14, [rcx + 48h]
mov r15, [rcx + 50h]
mov rdi, [rcx + 58h]
mov rsi, [rcx + 60h]
mov rbx, [rcx + 68h]
mov rbp, [rcx + 70h]
mov rcx, [rcx + 10h]
;clear trace
xor rax, rax
;goto code
iretq
CalloutReturn endp
GetR12 proc
mov rax,r12
ret
GetR12 endp
SetR12 proc
mov r12,rcx
ret
SetR12 endp
GetR13 proc
mov rax,r13
ret
GetR13 endp
SetR13 proc
mov r13,rcx
ret
SetR13 endp
end