-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAXIANWARE.cpp
More file actions
1563 lines (1363 loc) · 65.2 KB
/
Copy pathAXIANWARE.cpp
File metadata and controls
1563 lines (1363 loc) · 65.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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE
std::wstring Generate1337PatchText(const std::wstring& targetExePath);
#include <filesystem>
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <richedit.h>
#include <string>
#include <vector>
#include <memory>
#include <sstream>
#include <iomanip>
#include <filesystem>
#include <cstdint>
#include <cmath>
#include <chrono>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <thread>
#include <atomic>
#include <mutex>
#include <__msvc_filebuf.hpp>
#ifdef _MSC_VER
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "comdlg32.lib")
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#define WM_APP_ASYNC_STATUS (WM_APP + 101)
#define WM_APP_AOB_COMPLETE (WM_APP + 102)
#define WM_APP_STRINGS_COMPLETE (WM_APP + 103)
#define WM_APP_CRYPTO_COMPLETE (WM_APP + 104)
#define IDC_MAIN_LISTVIEW 1001
#define IDC_MAIN_RICHEDIT 1002
#define IDC_MAIN_STATUSBAR 1003
#define IDC_SEARCH_EDIT 1004
#define IDC_SEARCH_BTN 1005
#define IDM_FILE_OPEN 2001
#define IDM_FILE_SAVE_AS 2002
#define IDM_FILE_HEXVIEW 2003
#define IDM_FILE_EXIT 2004
#define IDM_ANALYSIS_SUMMARY 2101
#define IDM_ANALYSIS_IMPORTS 2102
#define IDM_ANALYSIS_STRINGS 2103
#define IDM_ANALYSIS_DISASM_EP 2104
#define IDM_ANALYSIS_CRYPTO_SCAN 2105
#define IDM_PATCH_NOP_PROLOGUE 3001
#define IDM_PATCH_RET_PROLOGUE 3002
#define IDM_PATCH_JMP_SHORT 3003
#define IDM_PATCH_INVERT_JUMP 3004
#define IDM_PATCH_GEN_LOADER 3005
#define IDM_PATCH_GEN_MINHOOK 3006
#define IDM_PATCH_GEN_X64DBG 3007
#define IDM_PATCH_GEN_CHEATENG 3008
#define IDM_HELP_ABOUT 4001
class ScopedHandle {
public:
explicit ScopedHandle(HANDLE h = INVALID_HANDLE_VALUE) : m_handle(h) {}
~ScopedHandle() { Close(); }
ScopedHandle(const ScopedHandle&) = delete;
ScopedHandle& operator=(const ScopedHandle&) = delete;
ScopedHandle(ScopedHandle&& other) noexcept : m_handle(other.m_handle) {
other.m_handle = INVALID_HANDLE_VALUE;
}
ScopedHandle& operator=(ScopedHandle&& other) noexcept {
if (this != &other) {
Close();
m_handle = other.m_handle;
other.m_handle = INVALID_HANDLE_VALUE;
}
return *this;
}
void Close() {
if (m_handle != INVALID_HANDLE_VALUE && m_handle != nullptr) {
CloseHandle(m_handle);
m_handle = INVALID_HANDLE_VALUE;
}
}
HANDLE Get() const { return m_handle; }
bool IsValid() const { return m_handle != INVALID_HANDLE_VALUE && m_handle != nullptr; }
private:
HANDLE m_handle;
};
class MemoryMappedFile {
public:
MemoryMappedFile() = default;
~MemoryMappedFile() { Close(); }
bool Open(const std::wstring& filePath, bool writeAccess = false) {
Close();
DWORD access = writeAccess ? (GENERIC_READ | GENERIC_WRITE) : GENERIC_READ;
DWORD share = writeAccess ? FILE_SHARE_READ : (FILE_SHARE_READ | FILE_SHARE_WRITE);
DWORD flProtect = writeAccess ? PAGE_READWRITE : PAGE_READONLY;
DWORD mapAccess = writeAccess ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ;
m_hFile = ScopedHandle(CreateFileW(filePath.c_str(), access, share, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr));
if (!m_hFile.IsValid()) return false;
LARGE_INTEGER size;
if (!GetFileSizeEx(m_hFile.Get(), &size) || size.QuadPart == 0) {
Close();
return false;
}
m_fileSize = static_cast<size_t>(size.QuadPart);
m_hMapping = ScopedHandle(CreateFileMappingW(m_hFile.Get(), nullptr, flProtect, 0, 0, nullptr));
if (!m_hMapping.IsValid()) {
Close();
return false;
}
m_pBase = MapViewOfFile(m_hMapping.Get(), mapAccess, 0, 0, 0);
return m_pBase != nullptr;
}
void Close() {
if (m_pBase) {
UnmapViewOfFile(m_pBase);
m_pBase = nullptr;
}
m_hMapping.Close();
m_hFile.Close();
m_fileSize = 0;
}
const uint8_t* Data() const { return static_cast<const uint8_t*>(m_pBase); }
size_t Size() const { return m_fileSize; }
bool IsOpen() const { return m_pBase != nullptr; }
private:
ScopedHandle m_hFile;
ScopedHandle m_hMapping;
LPVOID m_pBase = nullptr;
size_t m_fileSize = 0;
};
enum class ApiRisk { Normal, MemoryAlloc, ProcessInject, ThreadControl, AntiDebug, Suspicious };
struct ApiMeta {
ApiRisk risk;
const wchar_t* category;
};
const std::unordered_map<std::string, ApiMeta> g_SensitiveApiMap = {
{ "VirtualAlloc", { ApiRisk::MemoryAlloc, L"Memory Allocation / RWX" } },
{ "VirtualAllocEx", { ApiRisk::ProcessInject, L"Remote Memory Allocation" } },
{ "VirtualProtect", { ApiRisk::MemoryAlloc, L"Memory Protection Modification" } },
{ "VirtualProtectEx", { ApiRisk::ProcessInject, L"Remote Memory Protection Mod" } },
{ "WriteProcessMemory", { ApiRisk::ProcessInject, L"Process Memory Modification" } },
{ "ReadProcessMemory", { ApiRisk::ProcessInject, L"Process Memory Read" } },
{ "CreateRemoteThread", { ApiRisk::ProcessInject, L"Remote Thread Execution" } },
{ "NtCreateThreadEx", { ApiRisk::ProcessInject, L"Native Remote Thread Exec" } },
{ "QueueUserAPC", { ApiRisk::ProcessInject, L"APC Injection" } },
{ "SetThreadContext", { ApiRisk::ThreadControl, L"Thread Context Hijacking" } },
{ "GetThreadContext", { ApiRisk::ThreadControl, L"Thread Context Query" } },
{ "OpenProcess", { ApiRisk::Suspicious, L"Process Handle Acquisition" } },
{ "IsDebuggerPresent", { ApiRisk::AntiDebug, L"PEB Anti-Debugging" } },
{ "CheckRemoteDebuggerPresent", { ApiRisk::AntiDebug, L"Remote Debugger Check" } },
{ "NtQueryInformationProcess", { ApiRisk::AntiDebug, L"Process Info Anti-Debug" } }
};
struct SectionInfo {
std::string name;
DWORD virtualAddress = 0;
DWORD virtualSize = 0;
DWORD rawDataOffset = 0;
DWORD rawDataSize = 0;
DWORD characteristics = 0;
double entropy = 0.0;
bool isSuspiciousEntropy = false;
};
struct ExportInfo {
std::string name;
WORD ordinal = 0;
DWORD rva = 0;
DWORD fileOffset = 0;
};
struct ImportFunction {
std::string name;
WORD ordinal = 0;
bool isOrdinal = false;
ApiRisk risk = ApiRisk::Normal;
std::wstring category;
};
struct ImportModule {
std::string dllName;
std::vector<ImportFunction> functions;
size_t sensitiveCount = 0;
};
struct SecurityFlags {
bool aslr = false;
bool highEntropyVA = false;
bool dep = false;
bool safeSEH = false;
bool controlFlowGuard = false;
bool noIsolation = false;
};
struct ExtractedString {
size_t offset = 0;
DWORD rva = 0;
std::wstring text;
bool isUnicode = false;
std::string sectionName;
};
struct CryptoDetection {
std::wstring name;
std::wstring type;
size_t offset;
DWORD rva;
std::string sectionName;
};
struct PatternByte {
uint8_t value;
bool isWildcard;
};
struct PEAnalysisReport {
bool is64Bit = false;
WORD machine = 0;
DWORD entryPointRva = 0;
DWORD entryPointOffset = 0;
ULONGLONG imageBase = 0;
DWORD sizeOfImage = 0;
DWORD checkSumOffset = 0;
DWORD originalCheckSum = 0;
SecurityFlags security;
std::vector<SectionInfo> sections;
std::vector<ExportInfo> exports;
std::vector<ImportModule> imports;
std::vector<ExtractedString> strings;
std::vector<CryptoDetection> cryptoDetections;
double overallEntropy = 0.0;
bool isPatched = false;
};
HWND g_hWndMain = nullptr;
HWND g_hListView = nullptr;
HWND g_hRichEdit = nullptr;
HWND g_hStatusBar = nullptr;
HWND g_hSearchEdit = nullptr;
HWND g_hSearchBtn = nullptr;
HMODULE g_hMsftedit = nullptr;
std::wstring g_currentFilePath;
PEAnalysisReport g_report;
std::map<DWORD, std::pair<uint8_t, uint8_t>> g_stagedPatches;
DWORD RvaToFileOffset(DWORD rva, const std::vector<SectionInfo>& sections, size_t fileSize) {
for (const auto& sec : sections) {
DWORD secSize = sec.virtualSize ? sec.virtualSize : sec.rawDataSize;
if (rva >= sec.virtualAddress && rva < sec.virtualAddress + secSize) {
DWORD offset = sec.rawDataOffset + (rva - sec.virtualAddress);
if (offset < fileSize) return offset;
}
}
return 0;
}
DWORD FileOffsetToRva(DWORD offset, const std::vector<SectionInfo>& sections) {
for (const auto& sec : sections) {
if (offset >= sec.rawDataOffset && offset < sec.rawDataOffset + sec.rawDataSize) {
return sec.virtualAddress + (offset - sec.rawDataOffset);
}
}
return 0;
}
std::string GetSectionNameByOffset(DWORD offset, const std::vector<SectionInfo>& sections) {
for (const auto& sec : sections) {
if (offset >= sec.rawDataOffset && offset < sec.rawDataOffset + sec.rawDataSize) {
return sec.name;
}
}
return "Header";
}
double CalculateShannonEntropy(const uint8_t* data, size_t size) {
if (!data || size == 0) return 0.0;
size_t byteCounts[256] = { 0 };
for (size_t i = 0; i < size; ++i) byteCounts[data[i]]++;
double entropy = 0.0;
double dSize = static_cast<double>(size);
for (int i = 0; i < 256; ++i) {
if (byteCounts[i] > 0) {
double p = static_cast<double>(byteCounts[i]) / dSize;
entropy -= p * (std::log(p) / std::log(2.0));
}
}
return entropy;
}
DWORD CalculatePECheckSum(const uint8_t* base, size_t fileSize, DWORD checkSumFieldOffset) {
uint64_t checksum = 0;
size_t dwords = fileSize / 4;
const uint32_t* pDwords = reinterpret_cast<const uint32_t*>(base);
for (size_t i = 0; i < dwords; ++i) {
if (i * 4 == checkSumFieldOffset) continue;
checksum += pDwords[i];
if (checksum > 0xFFFFFFFF) {
checksum = (checksum & 0xFFFFFFFF) + (checksum >> 32);
}
}
size_t remainder = fileSize % 4;
if (remainder > 0) {
uint32_t lastDword = 0;
memcpy(&lastDword, base + (dwords * 4), remainder);
checksum += lastDword;
if (checksum > 0xFFFFFFFF) {
checksum = (checksum & 0xFFFFFFFF) + (checksum >> 32);
}
}
checksum = (checksum & 0xFFFF) + (checksum >> 16);
checksum = checksum + (checksum >> 16);
checksum = checksum & 0xFFFF;
checksum += fileSize;
return static_cast<DWORD>(checksum);
}
std::vector<PatternByte> ParseAOBPattern(const std::wstring& patternStr) {
std::vector<PatternByte> result;
std::wstringstream ss(patternStr);
std::wstring token;
while (ss >> token) {
if (token == L"?" || token == L"??") {
result.push_back({ 0x00, true });
}
else {
wchar_t* endPtr = nullptr;
auto val = static_cast<uint8_t>(wcstoul(token.c_str(), &endPtr, 16));
result.push_back({ val, false });
}
}
return result;
}
std::vector<size_t> ScanBinaryAOB(const uint8_t* data, size_t dataSize, const std::vector<PatternByte>& pattern) {
std::vector<size_t> matches;
if (pattern.empty() || dataSize < pattern.size()) return matches;
size_t patLen = pattern.size();
for (size_t i = 0; i <= dataSize - patLen; ++i) {
bool match = true;
for (size_t j = 0; j < patLen; ++j) {
if (!pattern[j].isWildcard && data[i + j] != pattern[j].value) {
match = false;
break;
}
}
if (match) {
matches.push_back(i);
if (matches.size() >= 1000) break;
}
}
return matches;
}
struct CryptoSignature {
const wchar_t* name;
const wchar_t* category;
std::wstring pattern;
};
const std::vector<CryptoSignature> g_CryptoAndAntiSignatures = {
{ L"AES S-Box", L"Crypto [AES]", L"63 7C 77 7B F2 6B 6F C5 30 01 67 2B FE D7 AB 76" },
{ L"AES Inverse S-Box", L"Crypto [AES]", L"52 09 6A D5 30 36 A5 38 BF 40 A3 9E 81 F3 D7 FB" },
{ L"MD5 Init Constants", L"Crypto [MD5]", L"01 23 45 67 89 AB CD EF FE DC BA 98 76 54 32 10" },
{ L"SHA-256 Constants", L"Crypto [SHA256]", L"6A 09 E6 67 BB 67 AE 85 3C 6E F3 72 A5 4F F5 3A" },
{ L"Base64 Alphabet Table", L"Crypto [Encoding]", L"41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50" },
{ L"PEB.BeingDebugged (x86)", L"Anti-Debug", L"64 A1 30 00 00 00 8A 40 02" },
{ L"PEB.BeingDebugged (x64)", L"Anti-Debug", L"65 48 8B 04 25 60 00 00 00 0F B6 40 02" },
{ L"PEB.NtGlobalFlag (x86)", L"Anti-Debug", L"64 A1 30 00 00 00 8B 40 68" },
{ L"PEB.NtGlobalFlag (x64)", L"Anti-Debug", L"65 48 8B 04 25 60 00 00 00 8B 40 BC" },
{ L"RDTSC Timing Check", L"Anti-VM/Debug", L"0F 31 ?? ?? ?? ?? 0F 31" },
{ L"CPUID Hypervisor Detection", L"Anti-VM", L"B8 01 00 00 00 0F A2 ?? ?? ?? 01" }
};
void ScanCryptoAndAntiSignatures(const uint8_t* data, size_t size, const std::vector<SectionInfo>& sections, std::vector<CryptoDetection>& outDetections) {
outDetections.clear();
for (const auto& sig : g_CryptoAndAntiSignatures) {
auto pat = ParseAOBPattern(sig.pattern);
auto matches = ScanBinaryAOB(data, size, pat);
for (size_t offset : matches) {
CryptoDetection cd;
cd.name = sig.name;
cd.type = sig.category;
cd.offset = offset;
cd.rva = FileOffsetToRva(static_cast<DWORD>(offset), sections);
cd.sectionName = GetSectionNameByOffset(static_cast<DWORD>(offset), sections);
outDetections.push_back(cd);
}
}
}
struct DecodedInsn {
size_t length;
std::wstring text;
std::wstring bytesHex;
bool isJump;
bool isConditionalJump;
uint8_t invertOpcode;
size_t invertOpcodeOffset;
};
DecodedInsn FullDecodeInstruction(const uint8_t* code, size_t maxLen, ULONGLONG currentAddr, bool is64Bit) {
if (maxLen == 0) return { 1, L"db ??", L"??", false, false, 0, 0 };
size_t idx = 0;
bool hasRex = false;
uint8_t rex = 0;
if (is64Bit && (code[idx] >= 0x40 && code[idx] <= 0x4F)) {
hasRex = true;
rex = code[idx++];
if (idx >= maxLen) return { 1, L"rex prefix", L"40", false, false, 0, 0 };
}
uint8_t op = code[idx++];
std::wstringstream disasm;
size_t insnLen = idx;
bool isJmp = false;
bool isCondJmp = false;
uint8_t invertOp = 0;
size_t invertOffset = (hasRex ? 1 : 0);
if (op >= 0x70 && op <= 0x7F) {
isJmp = true;
isCondJmp = true;
invertOp = (op % 2 == 0) ? (op + 1) : (op - 1); // JZ (74) <-> JNZ (75), etc.
const wchar_t* jccNames[] = {
L"jo", L"jno", L"jb", L"jnb", L"jz", L"jnz", L"jbe", L"ja",
L"js", L"jns", L"jp", L"jnp", L"jl", L"jge", L"jle", L"jg"
};
if (idx < maxLen) {
int8_t rel = static_cast<int8_t>(code[idx++]);
insnLen = idx;
ULONGLONG target = currentAddr + insnLen + rel;
disasm << jccNames[op - 0x70] << L" short 0x" << std::hex << target;
}
else {
disasm << jccNames[op - 0x70] << L" short ...";
}
}
else if (op == 0x0F && idx < maxLen && (code[idx] >= 0x80 && code[idx] <= 0x8F)) {
uint8_t op2 = code[idx++];
isJmp = true;
isCondJmp = true;
invertOp = (op2 % 2 == 0) ? (op2 + 1) : (op2 - 1);
invertOffset = (hasRex ? 2 : 1);
const wchar_t* jccNames[] = {
L"jo", L"jno", L"jb", L"jnb", L"jz", L"jnz", L"jbe", L"ja",
L"js", L"jns", L"jp", L"jnp", L"jl", L"jge", L"jle", L"jg"
};
if (idx + 4 <= maxLen) {
int32_t rel = *reinterpret_cast<const int32_t*>(code + idx);
idx += 4;
insnLen = idx;
ULONGLONG target = currentAddr + insnLen + rel;
disasm << jccNames[op2 - 0x80] << L" near 0x" << std::hex << target;
}
else {
disasm << jccNames[op2 - 0x80] << L" near ...";
}
}
else {
switch (op) {
case 0x90:
disasm << L"nop";
break;
case 0xC3:
disasm << L"ret";
break;
case 0xCC:
disasm << L"int 3";
break;
case 0xEB: {
isJmp = true;
if (idx < maxLen) {
int8_t rel = static_cast<int8_t>(code[idx++]);
insnLen = idx;
disasm << L"jmp short 0x" << std::hex << (currentAddr + insnLen + rel);
}
else disasm << L"jmp short ...";
break;
}
case 0xE9: {
isJmp = true;
if (idx + 4 <= maxLen) {
int32_t rel = *reinterpret_cast<const int32_t*>(code + idx);
idx += 4;
insnLen = idx;
disasm << L"jmp 0x" << std::hex << (currentAddr + insnLen + rel);
}
else disasm << L"jmp ...";
break;
}
case 0xE8: {
if (idx + 4 <= maxLen) {
int32_t rel = *reinterpret_cast<const int32_t*>(code + idx);
idx += 4;
insnLen = idx;
disasm << L"call 0x" << std::hex << (currentAddr + insnLen + rel);
}
else disasm << L"call ...";
break;
}
case 0x85: case 0x84: {
if (idx < maxLen) {
uint8_t modrm = code[idx++];
insnLen = idx;
if (modrm == 0xC0) disasm << L"test eax, eax";
else if (modrm == 0xC9) disasm << L"test ecx, ecx";
else disasm << L"test reg, reg";
}
else disasm << L"test ...";
break;
}
case 0x31: case 0x33: {
if (idx < maxLen) {
uint8_t modrm = code[idx++];
insnLen = idx;
if (modrm == 0xC0) disasm << L"xor eax, eax";
else if (modrm == 0xDB) disasm << L"xor ebx, ebx";
else if (modrm == 0xC9) disasm << L"xor ecx, ecx";
else disasm << L"xor reg, reg";
}
else disasm << L"xor ...";
break;
}
case 0x8B: {
if (idx < maxLen) {
uint8_t modrm = code[idx++];
insnLen = idx;
if (is64Bit && (modrm & 0xC7) == 0x05 && idx + 4 <= maxLen) {
int32_t disp = *reinterpret_cast<const int32_t*>(code + idx);
idx += 4;
insnLen = idx;
disasm << L"mov reg, [rip + 0x" << std::hex << (currentAddr + insnLen + disp) << L"]";
}
else if (modrm == 0xEC) {
disasm << (is64Bit ? L"mov rbp, rsp" : L"mov ebp, esp");
}
else {
disasm << L"mov reg, [modrm]";
}
}
else disasm << L"mov ...";
break;
}
case 0x8D: {
if (idx < maxLen) {
uint8_t modrm = code[idx++];
insnLen = idx;
if (is64Bit && (modrm & 0xC7) == 0x05 && idx + 4 <= maxLen) {
int32_t disp = *reinterpret_cast<const int32_t*>(code + idx);
idx += 4;
insnLen = idx;
disasm << L"lea reg, [rip + 0x" << std::hex << (currentAddr + insnLen + disp) << L"]";
}
else {
disasm << L"lea reg, [modrm]";
}
}
else disasm << L"lea ...";
break;
}
case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: {
const wchar_t* r[] = { L"rax/eax", L"rcx/ecx", L"rdx/edx", L"rbx/ebx", L"rsp/esp", L"rbp/ebp", L"rsi/esi", L"rdi/edi" };
disasm << L"push " << r[op - 0x50];
break;
}
case 0x58: case 0x59: case 0x5A: case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F: {
const wchar_t* r[] = { L"rax/eax", L"rcx/ecx", L"rdx/edx", L"rbx/ebx", L"rsp/esp", L"rbp/ebp", L"rsi/esi", L"rdi/edi" };
disasm << L"pop " << r[op - 0x58];
break;
}
default:
disasm << L"db 0x" << std::hex << std::setw(2) << std::setfill(L'0') << (int)op;
insnLen = 1;
break;
}
}
std::wstringstream hexStr;
for (size_t b = 0; b < insnLen; ++b) {
hexStr << std::hex << std::setw(2) << std::setfill(L'0') << (int)code[b] << L" ";
}
return { insnLen, disasm.str(), hexStr.str(), isJmp, isCondJmp, invertOp, invertOffset };
}
bool ParsePEBinary(const uint8_t* base, size_t fileSize, PEAnalysisReport& outReport) {
outReport = PEAnalysisReport{};
if (fileSize < sizeof(IMAGE_DOS_HEADER)) return false;
const auto* dosHeader = reinterpret_cast<const IMAGE_DOS_HEADER*>(base);
if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) return false;
if (dosHeader->e_lfanew <= 0 || static_cast<size_t>(dosHeader->e_lfanew) + sizeof(IMAGE_NT_HEADERS32) > fileSize) return false;
const auto* ntSignature = reinterpret_cast<const DWORD*>(base + dosHeader->e_lfanew);
if (*ntSignature != IMAGE_NT_SIGNATURE) return false;
const auto* fileHeader = reinterpret_cast<const IMAGE_FILE_HEADER*>(base + dosHeader->e_lfanew + sizeof(DWORD));
outReport.machine = fileHeader->Machine;
const uint8_t* optHeaderPtr = base + dosHeader->e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER);
const auto* optCommon = reinterpret_cast<const IMAGE_OPTIONAL_HEADER32*>(optHeaderPtr);
const IMAGE_DATA_DIRECTORY* dataDirs = nullptr;
const IMAGE_SECTION_HEADER* sectionHeaders = nullptr;
WORD dllCharacteristics = 0;
if (optCommon->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
if (static_cast<size_t>(dosHeader->e_lfanew) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + sizeof(IMAGE_OPTIONAL_HEADER64) > fileSize) return false;
outReport.is64Bit = true;
const auto* opt64 = reinterpret_cast<const IMAGE_OPTIONAL_HEADER64*>(optHeaderPtr);
outReport.entryPointRva = opt64->AddressOfEntryPoint;
outReport.imageBase = opt64->ImageBase;
outReport.sizeOfImage = opt64->SizeOfImage;
outReport.originalCheckSum = opt64->CheckSum;
outReport.checkSumOffset = static_cast<DWORD>(reinterpret_cast<const uint8_t*>(&opt64->CheckSum) - base);
dllCharacteristics = opt64->DllCharacteristics;
dataDirs = opt64->DataDirectory;
sectionHeaders = reinterpret_cast<const IMAGE_SECTION_HEADER*>(optHeaderPtr + fileHeader->SizeOfOptionalHeader);
}
else if (optCommon->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
if (static_cast<size_t>(dosHeader->e_lfanew) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + sizeof(IMAGE_OPTIONAL_HEADER32) > fileSize) return false;
outReport.is64Bit = false;
const auto* opt32 = reinterpret_cast<const IMAGE_OPTIONAL_HEADER32*>(optHeaderPtr);
outReport.entryPointRva = opt32->AddressOfEntryPoint;
outReport.imageBase = opt32->ImageBase;
outReport.sizeOfImage = opt32->SizeOfImage;
outReport.originalCheckSum = opt32->CheckSum;
outReport.checkSumOffset = static_cast<DWORD>(reinterpret_cast<const uint8_t*>(&opt32->CheckSum) - base);
dllCharacteristics = opt32->DllCharacteristics;
dataDirs = opt32->DataDirectory;
sectionHeaders = reinterpret_cast<const IMAGE_SECTION_HEADER*>(optHeaderPtr + fileHeader->SizeOfOptionalHeader);
}
else {
return false;
}
outReport.security.aslr = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE) != 0;
outReport.security.highEntropyVA = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA) != 0;
outReport.security.dep = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_NX_COMPAT) != 0;
outReport.security.safeSEH = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_NO_SEH) == 0;
outReport.security.controlFlowGuard = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_GUARD_CF) != 0;
outReport.security.noIsolation = (dllCharacteristics & IMAGE_DLLCHARACTERISTICS_NO_ISOLATION) != 0;
for (WORD i = 0; i < fileHeader->NumberOfSections; ++i) {
const auto& sec = sectionHeaders[i];
char nameBuf[9] = { 0 };
memcpy(nameBuf, sec.Name, 8);
SectionInfo sInfo;
sInfo.name = nameBuf;
sInfo.virtualAddress = sec.VirtualAddress;
sInfo.virtualSize = sec.Misc.VirtualSize;
sInfo.rawDataOffset = sec.PointerToRawData;
sInfo.rawDataSize = sec.SizeOfRawData;
sInfo.characteristics = sec.Characteristics;
if (sInfo.rawDataOffset < fileSize && sInfo.rawDataSize > 0) {
size_t validRawSize = std::min<size_t>(sInfo.rawDataSize, fileSize - sInfo.rawDataOffset);
sInfo.entropy = CalculateShannonEntropy(base + sInfo.rawDataOffset, validRawSize);
sInfo.isSuspiciousEntropy = (sInfo.entropy > 7.2);
}
outReport.sections.push_back(sInfo);
}
outReport.entryPointOffset = RvaToFileOffset(outReport.entryPointRva, outReport.sections, fileSize);
outReport.overallEntropy = CalculateShannonEntropy(base, fileSize);
const auto& importDir = dataDirs[IMAGE_DIRECTORY_ENTRY_IMPORT];
if (importDir.VirtualAddress != 0 && importDir.Size != 0) {
DWORD impOff = RvaToFileOffset(importDir.VirtualAddress, outReport.sections, fileSize);
if (impOff) {
const auto* impDesc = reinterpret_cast<const IMAGE_IMPORT_DESCRIPTOR*>(base + impOff);
while (impDesc->Characteristics != 0 || impDesc->Name != 0) {
DWORD modNameOff = RvaToFileOffset(impDesc->Name, outReport.sections, fileSize);
if (modNameOff && modNameOff < fileSize) {
ImportModule mod;
mod.dllName = reinterpret_cast<const char*>(base + modNameOff);
DWORD thunkRva = impDesc->OriginalFirstThunk ? impDesc->OriginalFirstThunk : impDesc->FirstThunk;
DWORD thunkOff = RvaToFileOffset(thunkRva, outReport.sections, fileSize);
if (thunkOff) {
if (outReport.is64Bit) {
const auto* thunk = reinterpret_cast<const IMAGE_THUNK_DATA64*>(base + thunkOff);
while (thunk->u1.AddressOfData != 0) {
ImportFunction ifn;
if (IMAGE_SNAP_BY_ORDINAL64(thunk->u1.Ordinal)) {
ifn.isOrdinal = true;
ifn.ordinal = static_cast<WORD>(IMAGE_ORDINAL64(thunk->u1.Ordinal));
}
else {
DWORD ibnOff = RvaToFileOffset(static_cast<DWORD>(thunk->u1.AddressOfData), outReport.sections, fileSize);
if (ibnOff && ibnOff + sizeof(IMAGE_IMPORT_BY_NAME) <= fileSize) {
const auto* ibn = reinterpret_cast<const IMAGE_IMPORT_BY_NAME*>(base + ibnOff);
ifn.name = reinterpret_cast<const char*>(ibn->Name);
}
}
auto it = g_SensitiveApiMap.find(ifn.name);
if (it != g_SensitiveApiMap.end()) {
ifn.risk = it->second.risk;
ifn.category = it->second.category;
mod.sensitiveCount++;
}
mod.functions.push_back(ifn);
thunk++;
}
}
else {
const auto* thunk = reinterpret_cast<const IMAGE_THUNK_DATA32*>(base + thunkOff);
while (thunk->u1.AddressOfData != 0) {
ImportFunction ifn;
if (IMAGE_SNAP_BY_ORDINAL32(thunk->u1.Ordinal)) {
ifn.isOrdinal = true;
ifn.ordinal = static_cast<WORD>(IMAGE_ORDINAL32(thunk->u1.Ordinal));
}
else {
DWORD ibnOff = RvaToFileOffset(thunk->u1.AddressOfData, outReport.sections, fileSize);
if (ibnOff && ibnOff + sizeof(IMAGE_IMPORT_BY_NAME) <= fileSize) {
const auto* ibn = reinterpret_cast<const IMAGE_IMPORT_BY_NAME*>(base + ibnOff);
ifn.name = reinterpret_cast<const char*>(ibn->Name);
}
}
auto it = g_SensitiveApiMap.find(ifn.name);
if (it != g_SensitiveApiMap.end()) {
ifn.risk = it->second.risk;
ifn.category = it->second.category;
mod.sensitiveCount++;
}
mod.functions.push_back(ifn);
thunk++;
}
}
}
outReport.imports.push_back(mod);
}
impDesc++;
}
}
}
return true;
}
void RichEditClear(HWND hRichEdit) {
SetWindowTextW(hRichEdit, L"");
}
void RichEditAppend(HWND hRichEdit, const std::wstring& text, COLORREF color = RGB(220, 220, 220), bool bold = false) {
CHARRANGE cr;
cr.cpMin = -1;
cr.cpMax = -1;
SendMessageW(hRichEdit, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&cr));
CHARFORMAT2W cf;
ZeroMemory(&cf, sizeof(cf));
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_COLOR | CFM_BOLD | CFM_FACE | CFM_SIZE;
cf.crTextColor = color;
cf.dwEffects = bold ? CFE_BOLD : 0;
cf.yHeight = 190;
wcscpy_s(cf.szFaceName, L"Consolas");
SendMessageW(hRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, reinterpret_cast<LPARAM>(&cf));
SendMessageW(hRichEdit, EM_REPLACESEL, FALSE, reinterpret_cast<LPARAM>(text.c_str()));
SendMessageW(hRichEdit, WM_VSCROLL, SB_BOTTOM, 0);
}
std::wstring GenerateMemoryLoaderCode(const std::wstring& targetExePath, DWORD rvaOffset, const std::vector<uint8_t>& patchBytes) {
std::wstringstream ss;
// Находим последний слэш в пути и берём только имя файла
size_t lastSlash = targetExePath.find_last_of(L"\\/");
std::wstring exeName = (lastSlash == std::wstring::npos) ? targetExePath : targetExePath.substr(lastSlash + 1);
ss << L"// ====================================================\r\n";
ss << L"// ============================================================================\r\n";
ss << L"// IN-MEMORY SUSPENDED PROCESS LOADER (AXIANWARE)\r\n";
ss << L"// Target: " << exeName << L" | Target RVA: 0x" << std::hex << std::uppercase << rvaOffset << L"\r\n";
ss << L"// ============================================================================\r\n\r\n";
ss << L"#include <windows.h>\r\n#include <iostream>\r\n#include <vector>\r\n\r\n";
ss << L"int main() {\r\n";
ss << L" STARTUPINFOW si = { sizeof(si) };\r\n PROCESS_INFORMATION pi = { 0 };\r\n";
ss << L" if (!CreateProcessW(L\"" << exeName << L"\", nullptr, nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi)) {\r\n";
ss << L" std::wcout << L\"[-] Failed to spawn process! Error: \" << GetLastError() << std::endl;\r\n return 1;\r\n }\r\n\r\n";
ss << L" DWORD_PTR targetAddr = 0x" << std::hex << g_report.imageBase << L" + 0x" << rvaOffset << L";\r\n";
ss << L" std::vector<uint8_t> patch = { ";
for (size_t i = 0; i < patchBytes.size(); ++i) {
ss << L"0x" << std::hex << std::setw(2) << std::setfill(L'0') << (int)patchBytes[i];
if (i + 1 < patchBytes.size()) ss << L", ";
}
ss << L" };\r\n\r\n";
ss << L" DWORD oldProt = 0;\r\n VirtualProtectEx(pi.hProcess, (LPVOID)targetAddr, patch.size(), PAGE_EXECUTE_READWRITE, &oldProt);\r\n";
ss << L" WriteProcessMemory(pi.hProcess, (LPVOID)targetAddr, patch.data(), patch.size(), nullptr);\r\n";
ss << L" VirtualProtectEx(pi.hProcess, (LPVOID)targetAddr, patch.size(), oldProt, &oldProt);\r\n";
ss << L" ResumeThread(pi.hThread);\r\n CloseHandle(pi.hThread);\r\n CloseHandle(pi.hProcess);\r\n";
ss << L" return 0;\r\n}\r\n";
return ss.str();
}
std::wstring GenerateMinHookDllCode(DWORD rvaOffset) {
std::wstringstream ss;
ss << L"// ============================================================================\r\n";
ss << L"// MINHOOK INLINE HOOK DLL TEMPLATE (AXIANWARE)\r\n";
ss << L"// Target RVA: 0x" << std::hex << std::uppercase << rvaOffset << L"\r\n";
ss << L"// ============================================================================\r\n\r\n";
ss << L"#include <windows.h>\r\n#include \"MinHook.h\"\r\n\r\n";
ss << L"typedef BOOL(WINAPI* tTargetFunc)();\r\n";
ss << L"tTargetFunc oTargetFunc = nullptr;\r\n\r\n";
ss << L"BOOL WINAPI hkTargetFunc() {\r\n";
ss << L" // Custom hook logic / payload here\r\n";
ss << L" return TRUE; // Bypass original check\r\n";
ss << L"}\r\n\r\n";
ss << L"DWORD WINAPI InitHookThread(LPVOID) {\r\n";
ss << L" if (MH_Initialize() != MH_OK) return 1;\r\n";
ss << L" uintptr_t base = (uintptr_t)GetModuleHandleW(nullptr);\r\n";
ss << L" void* target = (void*)(base + 0x" << std::hex << rvaOffset << L");\r\n";
ss << L" MH_CreateHook(target, &hkTargetFunc, reinterpret_cast<LPVOID*>(&oTargetFunc));\r\n";
ss << L" MH_EnableHook(target);\r\n";
ss << L" return 0;\r\n";
ss << L"}\r\n\r\n";
ss << L"BOOL APIENTRY DllMain(HMODULE hMod, DWORD reason, LPVOID) {\r\n";
ss << L" if (reason == DLL_PROCESS_ATTACH) {\r\n";
ss << L" DisableThreadLibraryCalls(hMod);\r\n";
ss << L" CreateThread(nullptr, 0, InitHookThread, nullptr, 0, nullptr);\r\n";
ss << L" }\r\n";
ss << L" return TRUE;\r\n";
ss << L"}\r\n";
return ss.str();
}
std::wstring GenerateMemoryLoaderCode(const std::wstring& targetExePath, DWORD rvaOffset, const std::vector<uint8_t>& patchBytes) {
std::wstringstream ss;
// Находим последний слэш в пути и берём только имя файла
size_t lastSlash = targetExePath.find_last_of(L"\\/");
std::wstring exeName = (lastSlash == std::wstring::npos) ? targetExePath : targetExePath.substr(lastSlash + 1);
ss << L"// ====================================================\r\n";
if (g_stagedPatches.empty()) {
ss << L"00001000:74->75\r\n";
}
else {
for (const auto& kv : g_stagedPatches) {
ss << std::hex << std::uppercase << std::setfill(L'0') << std::setw(8) << kv.first << L":"
<< std::setw(2) << (int)kv.second.first << L"->"
<< std::setw(2) << (int)kv.second.second << L"\r\n";
}
}
return ss.str();
}
std::wstring GenerateCheatEngineScript(DWORD rvaOffset, const std::vector<uint8_t>& patchBytes) {
std::wstringstream ss;
ss << L"[ENABLE]\r\n";
ss << L"// Allocating and applying patch at RVA 0x" << std::hex << std::uppercase << rvaOffset << L"\r\n";
ss << L"define(targetAddr, \"target.exe\"+0x" << std::hex << rvaOffset << L")\r\n";
ss << L"targetAddr:\r\n db ";
for (size_t i = 0; i < patchBytes.size(); ++i) {
ss << std::hex << std::setw(2) << std::setfill(L'0') << (int)patchBytes[i] << L" ";
}
ss << L"\r\n\r\n[DISABLE]\r\n";
ss << L"targetAddr:\r\n // Restore original bytes\r\n";
return ss.str();
}
void RenderSummaryReport(HWND hRichEdit, const std::wstring& filePath, const PEAnalysisReport& rep) {
RichEditClear(hRichEdit);
RichEditAppend(hRichEdit, L"================================================================================\r\n", RGB(0, 150, 255), true);
RichEditAppend(hRichEdit, L" AXIANWARE \r\n", RGB(0, 255, 200), true);
RichEditAppend(hRichEdit, L"================================================================================\r\n\r\n", RGB(0, 150, 255), true);
RichEditAppend(hRichEdit, L"[+] File Path: ", RGB(255, 255, 0), true);
RichEditAppend(hRichEdit, filePath + L"\r\n", RGB(255, 255, 255));
RichEditAppend(hRichEdit, L"[+] Architecture: ", RGB(255, 255, 0), true);
RichEditAppend(hRichEdit, rep.is64Bit ? L"AMD64 / x64 (PE32+)\r\n" : L"i386 / x86 (PE32)\r\n", RGB(255, 255, 255));
std::wstringstream ep;
ep << L"0x" << std::hex << std::uppercase << rep.entryPointRva << L" (File Raw Offset: 0x" << rep.entryPointOffset << L")\r\n";
RichEditAppend(hRichEdit, L"[+] Entry Point: ", RGB(255, 255, 0), true);
RichEditAppend(hRichEdit, ep.str(), RGB(255, 255, 255));
std::wstringstream chk;
chk << L"0x" << std::hex << std::uppercase << rep.originalCheckSum << L"\r\n";
RichEditAppend(hRichEdit, L"[+] PE CheckSum: ", RGB(255, 255, 0), true);
RichEditAppend(hRichEdit, chk.str(), RGB(255, 255, 255));
std::wstringstream ent;
ent << std::fixed << std::setprecision(4) << rep.overallEntropy;
RichEditAppend(hRichEdit, L"[+] Total Entropy: ", RGB(255, 255, 0), true);
RichEditAppend(hRichEdit, ent.str() + (rep.overallEntropy > 7.2 ? L" [ALERT: Packed / Encrypted]\r\n\r\n" : L" [Normal]\r\n\r\n"),
rep.overallEntropy > 7.2 ? RGB(255, 80, 80) : RGB(100, 255, 100));
RichEditAppend(hRichEdit, L"--- [ SECURITY MITIGATIONS AUDIT ] --------------------------------------------\r\n", RGB(100, 200, 255), true);
RichEditAppend(hRichEdit, L" [*] ASLR (Dynamic Base): ", RGB(200, 200, 200));
RichEditAppend(hRichEdit, rep.security.aslr ? L"ENABLED\r\n" : L"DISABLED\r\n", rep.security.aslr ? RGB(100, 255, 100) : RGB(255, 80, 80), true);
RichEditAppend(hRichEdit, L" [*] DEP / NX (Data Execution Prev): ", RGB(200, 200, 200));
RichEditAppend(hRichEdit, rep.security.dep ? L"ENABLED\r\n" : L"DISABLED\r\n", rep.security.dep ? RGB(100, 255, 100) : RGB(255, 80, 80), true);
RichEditAppend(hRichEdit, L" [*] Control Flow Guard (CFG): ", RGB(200, 200, 200));
RichEditAppend(hRichEdit, rep.security.controlFlowGuard ? L"ENABLED\r\n" : L"DISABLED\r\n", rep.security.controlFlowGuard ? RGB(100, 255, 100) : RGB(160, 160, 160));
RichEditAppend(hRichEdit, L" [*] SafeSEH Mitigation: ", RGB(200, 200, 200));
RichEditAppend(hRichEdit, rep.security.safeSEH ? L"ENABLED / N/A (x64)\r\n\r\n" : L"DISABLED / NO SEH\r\n\r\n", rep.security.safeSEH ? RGB(100, 255, 100) : RGB(255, 180, 80));
RichEditAppend(hRichEdit, L"--- [ SECTION ENTROPY TABLE ] -------------------------------------------------\r\n", RGB(100, 200, 255), true);
for (const auto& sec : rep.sections) {
std::wstringstream ss;
ss << L" " << std::left << std::setw(8) << std::wstring(sec.name.begin(), sec.name.end())
<< L" | VirtAddr: 0x" << std::hex << std::setw(8) << sec.virtualAddress
<< L" | RawOffset: 0x" << std::hex << std::setw(8) << sec.rawDataOffset
<< L" | Entropy: " << std::fixed << std::setprecision(4) << sec.entropy;
if (sec.isSuspiciousEntropy) ss << L" [PACKED / OBFUSCATED]";
ss << L"\r\n";
RichEditAppend(hRichEdit, ss.str(), sec.isSuspiciousEntropy ? RGB(255, 80, 80) : RGB(200, 200, 200), sec.isSuspiciousEntropy);
}
}
void RenderDisassemblyView(HWND hRichEdit, const uint8_t* base, size_t fileSize, DWORD targetOffset, DWORD targetRva, size_t instructionCount = 36) {
RichEditClear(hRichEdit);
RichEditAppend(hRichEdit, L"================================================================================\r\n", RGB(0, 150, 255), true);
RichEditAppend(hRichEdit, L" INTERACTIVE DISASSEMBLY & CODE PATCHING VIEW \r\n", RGB(0, 255, 200), true);
RichEditAppend(hRichEdit, L"================================================================================\r\n\r\n", RGB(0, 150, 255), true);
if (targetOffset >= fileSize) {
RichEditAppend(hRichEdit, L"[-] Error: Target offset is outside valid file boundaries.\r\n", RGB(255, 80, 80));
return;
}
size_t currOffset = targetOffset;
ULONGLONG currRva = targetRva;
for (size_t i = 0; i < instructionCount && currOffset < fileSize; ++i) {
size_t bytesLeft = fileSize - currOffset;
DecodedInsn insn = FullDecodeInstruction(base + currOffset, bytesLeft, currRva, g_report.is64Bit);
std::wstringstream ss;
ss << L"0x" << std::hex << std::uppercase << std::setw(8) << std::setfill(L'0') << currRva
<< L" (Raw: 0x" << std::setw(8) << currOffset << L") "
<< std::left << std::setw(18) << std::setfill(L' ') << insn.bytesHex
<< L" " << insn.text;
if (insn.isConditionalJump) {
ss << L" [Can Invert Jcc]";
}
ss << L"\r\n";
RichEditAppend(hRichEdit, ss.str(), insn.isConditionalJump ? RGB(255, 180, 80) : ((i == 0) ? RGB(255, 255, 0) : RGB(200, 220, 255)));
currOffset += insn.length;
currRva += insn.length;
}
}
void UpdateListViewItems(HWND hListView, const PEAnalysisReport& rep) {