-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
392 lines (382 loc) · 17.6 KB
/
Menu.cpp
File metadata and controls
392 lines (382 loc) · 17.6 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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include "Menu.hpp"
#define NOMINMAX
#include <windows.h>
#include <algorithm>
#include <cmath>
#include "UIUtils.hpp"
// Win32 helpers declared in GuiMain.cpp
extern bool MinimizeWindow(HWND hwnd);
extern bool MaximizeToggle(HWND hwnd);
extern bool CloseWindowSafe(HWND hwnd);
static inline ImVec4 Hex(unsigned r, unsigned g, unsigned b, float a=1.0f){return ImVec4(r/255.f,g/255.f,b/255.f,a);}
static inline ImU32 HexU(unsigned r, unsigned g, unsigned b, float a=1.0f){return IM_COL32(r,g,b,(int)(a*255));}
static ImFont* g_font_regular = nullptr;
static ImFont* g_font_bold = nullptr;
static float easeOutCubic(float t){return 1.0f - (float)pow(1.0f - t, 3.0f);}
static BackdropStyle kBackdrop{ IM_COL32(51,51,51,60), IM_COL32(51,51,51,90), 8.0f, 3.0f, 3.0f };
static float gMinFeatureBlockH = 0.0f;
static bool NavItem(const char* label, int i, MenuState& ui, float width)
{
ImGui::PushID(i);
ImVec2 pos = ImGui::GetCursorScreenPos();
float item_h = 36.0f;
ImGui::InvisibleButton("navbtn", ImVec2(width, item_h));
bool hovered = ImGui::IsItemHovered();
bool clicked = ImGui::IsItemClicked();
bool selected = (ui.active_nav == i);
float dt = ImGui::GetIO().DeltaTime;
float target = (hovered || selected) ? 1.0f : 0.0f;
ui.sidebar[i].underline += (target - ui.sidebar[i].underline) * std::min(1.0f, dt * 8.0f);
float u = easeOutCubic(std::max(0.0f, std::min(1.0f, ui.sidebar[i].underline)));
ImDrawList* dl = ImGui::GetWindowDrawList();
ImU32 textCol = HexU(255,255,255);
ImVec2 icon_center = ImVec2(pos.x + 14, pos.y + item_h * 0.5f);
float iconTarget = (selected || ui.sidebar[i].expanded) ? 1.0f : 0.0f;
// 300ms transition ~ 3.33 units/sec; use dt*4 for snappier yet smooth
ui.sidebar[i].icon += (iconTarget - ui.sidebar[i].icon) * std::min(1.0f, ImGui::GetIO().DeltaTime * 4.0f);
if (ui.sidebar[i].icon < 0.0f) ui.sidebar[i].icon = 0.0f;
if (ui.sidebar[i].icon > 1.0f) ui.sidebar[i].icon = 1.0f;
ImVec4 grey = ImVec4(0.5f,0.5f,0.5f,1.0f);
ImVec4 red = ImVec4(1.0f,0.0f,0.0f,1.0f);
ImVec4 mix = ImVec4(
grey.x + (red.x - grey.x) * ui.sidebar[i].icon,
grey.y + (red.y - grey.y) * ui.sidebar[i].icon,
grey.z + (red.z - grey.z) * ui.sidebar[i].icon,
1.0f);
ImU32 iconCol = ImGui::ColorConvertFloat4ToU32(mix);
dl->AddCircleFilled(icon_center, 5.0f, iconCol, 16);
ImVec2 text_pos = ImVec2(pos.x + 28, pos.y + 10);
ImGui::PushFont(selected ? g_font_bold : g_font_regular);
dl->AddText(text_pos, textCol, label);
ImGui::PopFont();
ImVec2 ul = ImVec2(pos.x + 28, pos.y + item_h - 4);
ImVec2 ur = ImVec2(ul.x + (width - 40) * u, ul.y + 2);
dl->AddRectFilled(ul, ur, HexU(235,5,90));
if (clicked) ui.active_nav = i;
bool toggled = false;
if (hovered && ImGui::IsMouseDoubleClicked(0)) { ui.sidebar[i].expanded = !ui.sidebar[i].expanded; toggled = true; }
ImGui::PopID();
return clicked || toggled;
}
void ApplyStyle()
{
auto& style = ImGui::GetStyle();
ImVec4* c = style.Colors;
style.WindowPadding = ImVec2(0, 0);
style.ItemSpacing = ImVec2(12, 8);
style.FramePadding = ImVec2(10, 6);
style.ChildBorderSize = 0.0f;
style.FrameBorderSize = 0.0f;
style.TabBorderSize = 0.0f;
style.WindowBorderSize = 0.0f;
style.WindowRounding = 4.0f;
style.FrameRounding = 3.0f;
style.GrabRounding = 2.0f;
style.ScrollbarSize = 0.0f;
c[ImGuiCol_WindowBg] = Hex(31,25,66,1.0f);
c[ImGuiCol_ChildBg] = Hex(31,25,66,1.0f);
c[ImGuiCol_FrameBg] = Hex(31,25,66,1.0f);
c[ImGuiCol_FrameBgHovered] = Hex(31,25,66,0.95f);
c[ImGuiCol_FrameBgActive] = Hex(31,25,66,0.9f);
c[ImGuiCol_CheckMark] = Hex(235,5,90,1.0f);
c[ImGuiCol_SliderGrab] = Hex(235,5,90,1.0f);
c[ImGuiCol_SliderGrabActive] = Hex(70,50,240,1.0f);
c[ImGuiCol_Border] = Hex(31,25,66,1.0f);
c[ImGuiCol_Tab] = Hex(31,25,66,0.6f);
c[ImGuiCol_TabHovered] = Hex(31,25,66,0.8f);
c[ImGuiCol_TabActive] = Hex(31,25,66,1.0f);
c[ImGuiCol_Separator] = Hex(0,0,0,0.0f);
}
void SetupFonts()
{
ImGuiIO& io = ImGui::GetIO();
ImGui::GetBackgroundDrawList()->AddRectFilled(ImVec2(0,0), io.DisplaySize, HexU(31,25,66));
io.MouseWheel = 0.0f;
io.MouseWheelH = 0.0f;
ImFontConfig cfg;
cfg.OversampleH = 2; cfg.OversampleV = 2; cfg.PixelSnapH = true;
g_font_regular = io.Fonts->AddFontFromFileTTF("JosefinSans-Regular.ttf", 16.0f, &cfg);
if (!g_font_regular) g_font_regular = io.Fonts->AddFontDefault();
g_font_bold = io.Fonts->AddFontFromFileTTF("JosefinSans-Bold.ttf", 18.0f, &cfg);
if (!g_font_bold) g_font_bold = g_font_regular;
}
static void HeaderBar(float w, ImVec2 win_pos)
{
ImDrawList* dl = ImGui::GetWindowDrawList();
ImVec2 logo_pos = ImVec2(win_pos.x + 18, win_pos.y + 28);
ImU32 c1 = HexU(255,255,255);
ImU32 cA = HexU(235,5,90);
ImU32 cB = HexU(70,50,240);
float t = (float)ImGui::GetTime();
int phase = ((int)(t*10))%4;
ImVec2 offA, offB;
if (phase==0){ offA=ImVec2(-1.5f,-1.5f); offB=ImVec2( 1.5f, 1.5f);}
else if (phase==1){ offA=ImVec2( 1.5f,-1.5f); offB=ImVec2(-1.5f, 1.5f);}
else if (phase==2){ offA=ImVec2(-1.5f, 1.5f); offB=ImVec2( 1.5f,-1.5f);}
else { offA=ImVec2( 1.5f, 1.5f); offB=ImVec2(-1.5f,-1.5f);}
ImVec2 posA = ImVec2(logo_pos.x + offA.x, logo_pos.y + offA.y);
ImVec2 posB = ImVec2(logo_pos.x + offB.x, logo_pos.y + offB.y);
ImGui::GetWindowDrawList()->AddText(g_font_bold, 18.0f, posA, cA, "Obfuscator");
ImGui::GetWindowDrawList()->AddText(g_font_bold, 18.0f, posB, cB, "Obfuscator");
ImGui::GetWindowDrawList()->AddText(g_font_bold, 18.0f, logo_pos, c1, "Obfuscator");
}
MenuOutput RenderMenu(MenuState& ui,
ObfuscationOptions& opts,
std::vector<std::string>& logLines,
std::string& status,
void* hwnd)
{
MenuOutput out{};
ImGuiIO& io = ImGui::GetIO();
if (ImGui::IsKeyPressed(ImGuiKey_Delete)) ui.show_menu = !ui.show_menu;
if (!ui.show_menu) return out;
// Unified container: no overlay background
ImVec2 min_size = ImVec2(600, 480);
ImVec2 max_size = ImVec2(io.DisplaySize.x * 0.95f, io.DisplaySize.y * 0.95f);
ImGui::SetNextWindowSizeConstraints(min_size, max_size);
ImGui::SetNextWindowPos(ImVec2(0,0));
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::Begin("Obfuscator", &ui.show_menu, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImVec2 win_pos = ImGui::GetWindowPos();
float w = ImGui::GetContentRegionAvail().x;
HeaderBar(w, win_pos);
ImGuiWindowFlags topFlags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0,0,0,0));
ImGui::BeginChild("TopBarControls", ImVec2(0, 60), false, topFlags);
float ctrl_w = ImGui::GetContentRegionAvail().x;
float btn_w = 24.0f, btn_h = 20.0f;
float spacing = ImGui::GetStyle().ItemSpacing.x;
ImGui::SetCursorPosY(10.0f);
ImGui::SetCursorPosX(ctrl_w - (btn_w * 2.0f + spacing));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, Hex(70,50,240,0.7f));
ImGui::PushStyleColor(ImGuiCol_Button, Hex(70,50,240,0.5f));
if (ImGui::Button("_", ImVec2(btn_w, btn_h)))
{
OutputDebugStringW(L"Minimize button clicked\n");
MinimizeWindow((HWND)hwnd);
}
ImGui::PopStyleColor(2);
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, Hex(235,5,90,0.7f));
ImGui::PushStyleColor(ImGuiCol_Button, Hex(235,5,90,0.5f));
if (ImGui::Button("X", ImVec2(btn_w, btn_h)))
{
OutputDebugStringW(L"Close button clicked\n");
CloseWindowSafe((HWND)hwnd);
}
ImGui::PopStyleColor(2);
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::Separator();
float leftPad = 18.0f;
ImGui::Indent(leftPad);
ImGui::PushFont(g_font_bold);
ImGui::Text("Input File:");
ImGui::PopFont();
ImGui::InputText("##input", ui.inputBuf, sizeof(ui.inputBuf));
ImGui::SameLine();
if (ImGui::Button("Browse")) out.request_browse = true;
ImGui::PushStyleColor(ImGuiCol_Separator, Hex(51,51,51,1.0f));
ImGui::Separator();
ImGui::PopStyleColor();
std::string inputFile = ui.inputBuf;
std::string outputFile = ui.outputBuf;
if (outputFile.empty() && !inputFile.empty())
{
size_t pos = inputFile.find_last_of('.');
outputFile = (pos != std::string::npos ? inputFile.substr(0, pos) : inputFile) + "_obfuscated.exe";
strncpy_s(ui.outputBuf, sizeof(ui.outputBuf), outputFile.c_str(), _TRUNCATE);
}
ImGui::PushFont(g_font_bold);
ImGui::Text("Output File:");
ImGui::PopFont();
ImGui::InputText("##output", ui.outputBuf, sizeof(ui.outputBuf));
ImGui::Separator();
ImVec2 full = ImGui::GetContentRegionAvail();
float sidebar_w = 180.0f;
ImGui::BeginChild("Sidebar", ImVec2(sidebar_w, full.y), false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
const char* labels[] = {".Text mutation",".rdata Mutation","Import Table Obfuscation","Debug info","Misc"};
for (int i = 0; i < 5; ++i)
{
ImVec2 start = ImGui::GetCursorScreenPos();
float w = ImGui::GetContentRegionAvail().x;
NavItem(labels[i], i, ui, w);
float etarget = ui.sidebar[i].expanded ? 1.0f : 0.0f;
float dt = ImGui::GetIO().DeltaTime;
ui.sidebar[i].expand += (etarget - ui.sidebar[i].expand) * std::min(1.0f, dt * 6.0f);
float base_h = (i==0?96.0f:(i==1?48.0f:(i==2?72.0f:(i==3?48.0f:24.0f))));
float ch = base_h * easeOutCubic(std::max(0.0f, std::min(1.0f, ui.sidebar[i].expand)));
if (ch > 1.0f)
{
ImGui::SetCursorScreenPos(ImVec2(start.x + 20, start.y + 36));
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)(100+i)), ImVec2(w - 40, ch), false);
if (i == 0)
{
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("NOP Instruction Replacement", &opts.mutate_nop_pairs);
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("Single NOP Replacement", &opts.mutate_single_nops);
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("Padding Obfuscation", &opts.padding_obfuscation);
}
else if (i == 1)
{
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("String Encryption", &opts.string_encryption);
}
else if (i == 2)
{
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("DLL Name Encryption", &opts.dll_name_encryption);
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("Function Name Encryption", &opts.function_name_encryption);
}
else if (i == 3)
{
DrawBackdropForNextItem(kBackdrop); ImGui::Checkbox("Debug Directory Removal", &opts.debug_stripping);
}
ImGui::EndChild();
ImGui::SetCursorScreenPos(ImVec2(start.x, start.y + 36 + ch));
}
}
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("Content", ImVec2(0, full.y), false);
if (ui.active_nav == 0)
{
ImGui::PushFont(g_font_bold);
ImGui::Text("Code Section Mutations (.text)");
ImGui::PopFont();
ImGuiStyle& st = ImGui::GetStyle();
float fh = ImGui::GetFrameHeight();
float sp = st.ItemSpacing.y;
const char* flabels[] = {
"NOP Instruction Replacement",
"Single NOP Replacement",
"Padding Obfuscation",
"Dead Code Insertion",
"Loop Unrolling Simulation",
"Control Flow Flattening"
};
float textPadX = 12.0f;
float lrPad = 16.0f;
float maxRowW = 0.0f;
for (int i = 0; i < 6; ++i)
{
float rowW = fh + textPadX + ImGui::CalcTextSize(flabels[i]).x;
if (rowW > maxRowW) maxRowW = rowW;
}
float padY = 8.0f;
float blockH = 6 * fh + 5 * sp + padY * 2.0f;
gMinFeatureBlockH = blockH;
float availW = ImGui::GetContentRegionAvail().x;
float blockW = std::min(maxRowW + lrPad * 2.0f, availW);
ImGui::PushStyleColor(ImGuiCol_ChildBg, Hex(51,51,51,1.0f));
ImGui::BeginChild("FeaturesBlock", ImVec2(blockW, blockH + 10.0f), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Dummy(ImVec2(0, padY));
FeatureCheckbox(flabels[0], &opts.mutate_nop_pairs);
FeatureCheckbox(flabels[1], &opts.mutate_single_nops);
FeatureCheckbox(flabels[2], &opts.padding_obfuscation);
FeatureCheckbox(flabels[3], &opts.dead_code_insertion);
FeatureCheckbox(flabels[4], &opts.loop_unrolling);
FeatureCheckbox(flabels[5], &opts.control_flow_flattening);
ImGui::Dummy(ImVec2(0, padY + 10.0f));
ImGui::EndChild();
ImGui::PopStyleColor();
}
else if (ui.active_nav == 1)
{
ImGui::PushFont(g_font_bold);
ImGui::Text("String Obfuscation (.rdata)");
ImGui::PopFont();
ImGuiStyle& st = ImGui::GetStyle();
float fh = ImGui::GetFrameHeight();
float sp = st.ItemSpacing.y;
const char* flabels[] = { "String Encryption" };
float textPadX = 12.0f;
float lrPad = 16.0f;
float maxRowW = fh + textPadX + ImGui::CalcTextSize(flabels[0]).x;
float padY = 8.0f;
float blockH = std::max(fh + padY * 2.0f, gMinFeatureBlockH);
float availW = ImGui::GetContentRegionAvail().x;
float blockW = std::min(maxRowW + lrPad * 2.0f, availW);
ImGui::PushStyleColor(ImGuiCol_ChildBg, Hex(51,51,51,1.0f));
ImGui::BeginChild("RDataBlock", ImVec2(blockW, blockH + 10.0f), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Dummy(ImVec2(0, padY + 10.0f));
FeatureCheckbox(flabels[0], &opts.string_encryption);
ImGui::Dummy(ImVec2(0, padY));
ImGui::EndChild();
ImGui::PopStyleColor();
}
else if (ui.active_nav == 2)
{
ImGui::PushFont(g_font_bold);
ImGui::Text("Import Table Obfuscation");
ImGui::PopFont();
ImGuiStyle& st = ImGui::GetStyle();
float fh = ImGui::GetFrameHeight();
float sp = st.ItemSpacing.y;
const char* flabels[] = { "DLL Name Encryption", "Function Name Encryption" };
float textPadX = 12.0f;
float lrPad = 16.0f;
float maxRowW = 0.0f;
for (int i = 0; i < 2; ++i) {
float rowW = fh + textPadX + ImGui::CalcTextSize(flabels[i]).x;
if (rowW > maxRowW) maxRowW = rowW;
}
float padY = 8.0f;
float blockH = std::max(2 * fh + 1 * sp + padY * 2.0f, gMinFeatureBlockH);
float availW = ImGui::GetContentRegionAvail().x;
float blockW = std::min(maxRowW + lrPad * 2.0f, availW);
ImGui::PushStyleColor(ImGuiCol_ChildBg, Hex(51,51,51,1.0f));
ImGui::BeginChild("ImportBlock", ImVec2(blockW, blockH + 10.0f), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Dummy(ImVec2(0, padY + 10.0f));
FeatureCheckbox(flabels[0], &opts.dll_name_encryption);
FeatureCheckbox(flabels[1], &opts.function_name_encryption);
ImGui::Dummy(ImVec2(0, padY));
ImGui::EndChild();
ImGui::PopStyleColor();
}
else if (ui.active_nav == 3)
{
ImGui::PushFont(g_font_bold);
ImGui::Text("Debug Information");
ImGui::PopFont();
ImGuiStyle& st = ImGui::GetStyle();
float fh = ImGui::GetFrameHeight();
const char* flabels[] = { "Debug Directory Removal" };
float textPadX = 12.0f;
float lrPad = 16.0f;
float maxRowW = fh + textPadX + ImGui::CalcTextSize(flabels[0]).x;
float padY = 8.0f;
float blockH = std::max(fh + padY * 2.0f, gMinFeatureBlockH);
float availW = ImGui::GetContentRegionAvail().x;
float blockW = std::min(maxRowW + lrPad * 2.0f, availW);
ImGui::PushStyleColor(ImGuiCol_ChildBg, Hex(51,51,51,1.0f));
ImGui::BeginChild("DebugBlock", ImVec2(blockW, blockH + 10.0f), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Dummy(ImVec2(0, padY + 10.0f));
FeatureCheckbox(flabels[0], &opts.debug_stripping);
ImGui::Dummy(ImVec2(0, padY));
ImGui::EndChild();
ImGui::PopStyleColor();
}
else if (ui.active_nav == 4)
{
ImGuiStyle& st = ImGui::GetStyle();
float fh = ImGui::GetFrameHeight();
const char* text = "Controls TBD";
float lrPad = 16.0f;
float padY = 8.0f;
float blockH = std::max(fh + padY * 2.0f, gMinFeatureBlockH);
float maxRowW = ImGui::CalcTextSize(text).x + fh;
float availW = ImGui::GetContentRegionAvail().x;
float blockW = std::min(maxRowW + lrPad * 2.0f, availW);
ImGui::PushStyleColor(ImGuiCol_ChildBg, Hex(51,51,51,1.0f));
ImGui::BeginChild("MiscBlock", ImVec2(blockW, blockH + 10.0f), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImGui::Dummy(ImVec2(0, padY + 10.0f));
ImGui::TextUnformatted(text);
ImGui::Dummy(ImVec2(0, padY));
ImGui::EndChild();
ImGui::PopStyleColor();
}
ImGui::EndChild();
if (ImGui::Button("Obfuscate")) out.request_obfuscate = true;
if (!status.empty()) ImGui::TextWrapped("%s", status.c_str());
ImGui::Unindent(leftPad);
ImGui::End();
return out;
}