-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerfectLoader.c
More file actions
336 lines (295 loc) · 12.2 KB
/
PerfectLoader.c
File metadata and controls
336 lines (295 loc) · 12.2 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <d3d11.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_D3D11_IMPLEMENTATION
#include "nuklear/nuklear.h"
#include "nuklear/nuklear_d3d11.h"
#include "core/PLRing3.h"
#include "gui/PLGui.h"
// Entry point
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
struct nk_context* ctx;
WNDCLASSW wc;
RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
DWORD style = WS_OVERLAPPEDWINDOW, exstyle = WS_EX_APPWINDOW;
HWND wnd;
DXGI_SWAP_CHAIN_DESC scd;
D3D_FEATURE_LEVEL fl;
HRESULT hr;
int running = 1;
(void)hPrevInstance; (void)lpCmdLine;
/* Window */
memset(&wc, 0, sizeof(wc));
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
wc.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
wc.lpszClassName = L"PerfectLoaderClass";
RegisterClassW(&wc);
AdjustWindowRectEx(&rect, style, FALSE, exstyle);
wnd = CreateWindowExW(exstyle, wc.lpszClassName, L"PerfectLoader",
style | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top,
NULL, NULL, hInstance, NULL);
/* D3D11 */
memset(&scd, 0, sizeof(scd));
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.RefreshRate.Numerator = 60;
scd.BufferDesc.RefreshRate.Denominator = 1;
scd.SampleDesc.Count = 1;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
scd.OutputWindow = wnd;
scd.Windowed = TRUE;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE,
NULL, 0, NULL, 0, D3D11_SDK_VERSION,
&scd, &swap_chain, &device, &fl, &context);
if (FAILED(hr)) {
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_WARP,
NULL, 0, NULL, 0, D3D11_SDK_VERSION,
&scd, &swap_chain, &device, &fl, &context);
if (FAILED(hr)) {
MessageBoxW(wnd, L"D3D11 init failed", L"Error", MB_OK);
return 1;
}
}
set_swap_chain_size(WINDOW_WIDTH, WINDOW_HEIGHT);
/* Nuklear */
ctx = nk_d3d11_init(device, WINDOW_WIDTH, WINDOW_HEIGHT,
MAX_VERTEX_BUFFER, MAX_INDEX_BUFFER);
{
struct nk_font_atlas* atlas;
nk_d3d11_font_stash_begin(&atlas);
nk_d3d11_font_stash_end();
}
set_dark_theme(ctx);
refresh_process_list();
gui_log("[*] PerfectLoader ready\n");
//Main loop
while (running)
{
MSG msg;
nk_input_begin(ctx);
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
nk_input_end(ctx);
//GUI
if (nk_begin(ctx, "PerfectLoader", nk_rect(5, 5, 630, 680),
NK_WINDOW_BORDER | NK_WINDOW_TITLE))
{
// DLL Path
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "DLL Path:", NK_TEXT_LEFT);
nk_layout_row_begin(ctx, NK_STATIC, 28, 2);
nk_layout_row_push(ctx, 510);
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD,
dll_path, sizeof(dll_path), nk_filter_default);
nk_layout_row_push(ctx, 90);
if (nk_button_label(ctx, "Browse..."))
browse_dll();
nk_layout_row_end(ctx);
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
// Target Process
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Target Process:", NK_TEXT_LEFT);
nk_layout_row_begin(ctx, NK_STATIC, 28, 2);
nk_layout_row_push(ctx, 510);
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD,
process_name, sizeof(process_name), nk_filter_default);
nk_layout_row_push(ctx, 90);
if (nk_button_label(ctx, "Refresh"))
refresh_process_list();
nk_layout_row_end(ctx);
// Process dropdown
if (proc_count > 0) {
char combo_lbl[300];
if (proc_sel >= 0 && proc_sel < proc_count)
snprintf(combo_lbl, sizeof(combo_lbl), "%s [PID %lu]",
proc_list[proc_sel].name, proc_list[proc_sel].pid);
else
snprintf(combo_lbl, sizeof(combo_lbl), "-- select from list --");
nk_layout_row_dynamic(ctx, 28, 1);
if (nk_combo_begin_label(ctx, combo_lbl, nk_vec2(610, 200))) {
nk_layout_row_dynamic(ctx, 22, 1);
for (int i = 0; i < proc_count; i++) {
char lbl[300];
snprintf(lbl, sizeof(lbl), "%-28s [%lu]",
proc_list[i].name, proc_list[i].pid);
if (nk_combo_item_label(ctx, lbl, NK_TEXT_LEFT))
proc_sel = i;
}
nk_combo_end(ctx);
}
}
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
// Injection Method
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Injection Method:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, PL_METHOD_COUNT);
for (int i = 0; i < PL_METHOD_COUNT; i++) {
if (nk_option_label(ctx, PL_MethodNames[i], method_sel == i))
method_sel = i;
}
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
// Options
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Options:", NK_TEXT_LEFT);
if (method_sel == PL_METHOD_MANUAL_MAP)
{
// IAT sub-options
nk_layout_row_dynamic(ctx, 24, PL_IAT_COUNT);
for (int i = 0; i < PL_IAT_COUNT; i++) {
if (nk_option_label(ctx, PL_IATModeNames[i], iat_mode_sel == i))
iat_mode_sel = i;
}
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Execution Method:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 24, 2);
for (int i = 0; i < PL_EXEC_COUNT; i++) {
if (nk_option_label(ctx, PL_ExecMethodNames[i], exec_method_sel == i))
exec_method_sel = i;
}
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Allocation Method:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 24, PL_ALLOC_COUNT);
for (int i = 0; i < PL_ALLOC_COUNT; i++) {
if (nk_option_label(ctx, PL_AllocMethodNames[i], alloc_method_sel == i))
alloc_method_sel = i;
}
}
// Export name (only for SetWindowsHookEx)
if (method_sel == PL_METHOD_SET_WINDOWS_HOOK) {
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Exported Hook Proc:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 28, 1);
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD,
export_name, sizeof(export_name), nk_filter_default);
}
if (method_sel == PL_METHOD_SHELLCODE) {
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Shellcode:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 28, 1);
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD,
shellcode, sizeof(shellcode), nk_filter_default);
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Execution Method:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 24, 2);
for (int i = 0; i < PL_EXEC_COUNT; i++) {
if (nk_option_label(ctx, PL_ExecMethodNames[i], exec_method_sel == i))
exec_method_sel = i;
}
nk_layout_row_dynamic(ctx, 18, 1);
nk_label(ctx, "Allocation Method:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 24, PL_ALLOC_COUNT);
for (int i = 0; i < PL_ALLOC_COUNT; i++) {
if (nk_option_label(ctx, PL_AllocMethodNames[i], alloc_method_sel == i))
alloc_method_sel = i;
}
}
nk_layout_row_dynamic(ctx, 8, 1);
nk_spacing(ctx, 1);
// INJECT button
nk_layout_row_dynamic(ctx, 38, 1);
{
struct nk_style_button btn = ctx->style.button;
btn.normal = nk_style_item_color(nk_rgb(30, 110, 200));
btn.hover = nk_style_item_color(nk_rgb(40, 130, 230));
btn.active = nk_style_item_color(nk_rgb(20, 90, 170));
btn.text_normal = nk_rgb(255, 255, 255);
btn.text_hover = nk_rgb(255, 255, 255);
btn.text_active = nk_rgb(200, 200, 200);
if (nk_button_label_styled(ctx, &btn, "INJECT"))
do_inject();
}
nk_layout_row_dynamic(ctx, 6, 1);
nk_spacing(ctx, 1);
// Log header row
nk_layout_row_begin(ctx, NK_STATIC, 18, 2);
nk_layout_row_push(ctx, 540);
nk_label(ctx, "Log:", NK_TEXT_LEFT);
nk_layout_row_push(ctx, 60);
if (nk_button_label(ctx, "Clear")) {
log_buf[0] = '\0';
log_len = 0;
log_scroll_x = 0;
log_scroll_y = 0;
}
nk_layout_row_end(ctx);
// Auto-scroll to bottom
{
static int prev_log_len = 0;
if (log_len != prev_log_len) {
log_scroll_y = (nk_uint)0xFFFFFFFFu; /* clamps to max */
prev_log_len = log_len;
}
}
// Scrollable log group
nk_layout_row_dynamic(ctx, 120, 1);
if (nk_group_scrolled_offset_begin(ctx, &log_scroll_x, &log_scroll_y,
"LogOutput", NK_WINDOW_BORDER))
{
const char* p = log_buf;
while (*p)
{
const char* nl = strchr(p, '\n');
int len = nl ? (int)(nl - p) : (int)strlen(p);
if (len > 0) {
char line[512];
if (len >= (int)sizeof(line))
len = (int)sizeof(line) - 1;
memcpy(line, p, len);
line[len] = '\0';
nk_layout_row_dynamic(ctx, 16, 1);
nk_label(ctx, line, NK_TEXT_LEFT);
}
if (nl) p = nl + 1;
else break;
}
nk_group_scrolled_end(ctx);
}
}
nk_end(ctx);
// render
{
float clr[4] = { 0.06f, 0.06f, 0.09f, 1.0f };
ID3D11DeviceContext_ClearRenderTargetView(context, rt_view, clr);
ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rt_view, NULL);
nk_d3d11_render(context, NK_ANTI_ALIASING_ON);
hr = IDXGISwapChain_Present(swap_chain, 1, 0);
if (hr == DXGI_STATUS_OCCLUDED) Sleep(10);
}
}
ID3D11DeviceContext_ClearState(context);
nk_d3d11_shutdown();
ID3D11RenderTargetView_Release(rt_view);
ID3D11DeviceContext_Release(context);
ID3D11Device_Release(device);
IDXGISwapChain_Release(swap_chain);
UnregisterClassW(wc.lpszClassName, wc.hInstance);
return 0;
}