-
Notifications
You must be signed in to change notification settings - Fork 9
/
mkpoly.inc
61 lines (55 loc) · 1.19 KB
/
mkpoly.inc
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
extern getpagesize
extern mprotect
; protection mode flags
%define PROT_NONE 0x0
%define PROT_READ 0x1
%define PROT_WRITE 0x2
%define PROT_EXEC 0x4
; no operation x86 opcode
%define OPCODE_NOP 0x90
; the size of the encryption/decryption functions
%define MKPOLY_FUNC_SIZE 0x100
; %1 the label of the section to decrypt
; %2 the size of the section to decrypt
%macro DECRYPTOR_SECTION 2
push r12
push r13
call getpagesize
mov rcx, rax
sub rcx, 1
mov rdi, %1
mov rsi, %2
mov rax, rdi
add rsi, rcx
not rcx
and rdi, rcx
sub rax, rdi
add rsi, rax
and rsi, rcx
mov r12, rdi
mov r13, rsi
mov edx, (PROT_READ | PROT_WRITE | PROT_EXEC)
call mprotect
mov rdi, %1
lea rsi, [rdi+%2]
.mkpoly_loop:
mov eax, [rdi ]
mov ecx, [rdi+0x4]
mov edx, [rdi+0x8]
mov ebx, [rdi+0xC]
.mkpoly_func:
times MKPOLY_FUNC_SIZE db OPCODE_NOP
mov [rdi ], eax
mov [rdi+0x4], ecx
mov [rdi+0x8], edx
mov [rdi+0xC], ebx
add rdi, 0x10
cmp rdi, rsi
jne .mkpoly_loop
mov rdi, r12
mov rsi, r13
mov edx, (PROT_READ | PROT_EXEC)
call mprotect
pop r13
pop r12
%endmacro