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
|
#include <stdio.h>
#include "winapi.h"
const wchar_t* const kernel32_str = L"KERNEL32.DLL";
const wchar_t* const ucrtbase_str = L"ucrtbase.dll";
const char* const loadlib_str = "LoadLibraryA";
const char* const printf_str = "printf";
const char* const printf_fmt = "print: %08x\n\0";
const char* const fail_msg = "k32 null\n";
const char* const pause_str = "pause";
const char* const system_str = "system";
uintptr_t printf_addr = ( uintptr_t )&printf;
uintptr_t system_addr = 0;
//i dont even
//unfinished btw
__declspec( naked ) int print_var( uint32_t var ) {
__asm {
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
mov eax, var
push eax
push printf_fmt
call printf_addr
add esp, 8
mov esp, ebp
pop ebp
mov eax, 0
ret
}
}
__declspec( naked ) void print_error( const char* err ) {
__asm {
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
mov eax, err
push eax
call printf_addr
add esp, 8
mov esp, ebp
pop ebp
}
}
__declspec( naked ) int main( void ) {
void* k32;
void* ucrtbase;
uintptr_t loadlib;
__asm {
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
mov eax, ds:ucrtbase_str
push eax
call winapi::k32::get_module_handle
add esp, 4
mov ucrtbase, eax
mov eax, ds:system_str
push eax
mov ecx, ucrtbase
push ecx
call winapi::k32::get_proc_address
add esp, 4
mov system_addr, eax
mov eax, ds:kernel32_str
push eax
call winapi::k32::get_module_handle
add esp, 4
mov k32, eax
mov eax, k32
push eax
call print_var
cmp k32, 0
je K32_FAIL
mov eax, ds:loadlib_str
push eax
mov ecx, k32
push ecx
call winapi::k32::get_proc_address
add esp, 8
mov loadlib, eax
mov eax, loadlib
push eax
call print_var
jmp END
K32_FAIL:
mov eax, fail_msg
push eax
call printf_addr
END:
mov eax, pause_str
push eax
call system_addr
mov esp, ebp
pop ebp
ret
}
}
|