11#include " ../vmaware.hpp"
22#include " output.hpp"
3- #include " windows_cli .hpp"
3+ #include " windows_tui .hpp"
44#include " globals.hpp"
55
66#include < chrono>
@@ -121,6 +121,7 @@ static std::pair<bool, VM::enum_flags> string_to_technique(const std::string& na
121121 return { true , flag };
122122 }
123123 }
124+
124125 return { false , VM ::NULL_ARG };
125126}
126127
@@ -132,6 +133,7 @@ const char* get_vm_description(const std::string& vm_brand) {
132133 if (is_vm_brand_multiple (vm_brand)) {
133134 return " " ;
134135 }
136+
135137 struct brand_entry { const char * brand; const char * description; };
136138
137139 static const brand_entry table[] = {
@@ -244,7 +246,7 @@ static void checker(const VM::enum_flags flag, const char* message) {
244246 const bool result = VM::check (flag);
245247 auto end_time = std::chrono::high_resolution_clock::now ();
246248
247- double ms = std::chrono::duration<double , std::milli>(end_time - start_time).count ();
249+ const double ms = std::chrono::duration<double , std::milli>(end_time - start_time).count ();
248250
249251 if (arg_bitset.test (DETECTED_ONLY ) && !result) {
250252 return ;
@@ -254,12 +256,15 @@ static void checker(const VM::enum_flags flag, const char* message) {
254256 if (are_perms_required (flag)) {
255257 no_perms_count++;
256258 VM::check (flag);
259+ std::ostringstream perms_oss;
260+ perms_oss << tag_no_perms << " " << grey << " Skipped " << message << " ." << ansi_exit;
261+ PRINT_LINE (perms_oss.str ());
257262 return ;
258263 }
259264 #endif
260265
261266 std::ostringstream cycle_oss;
262- cycle_oss << dim << message << " " << medium << " | " << white << std::fixed << std::setprecision (4 ) << ms << " ms" << ansi_exit;
267+ cycle_oss << dim << message << " | " << white << std::fixed << std::setprecision (4 ) << ms << " ms" << ansi_exit;
263268 #if (CLI_WINDOWS)
264269 g_tui.addCycle (cycle_oss.str ());
265270 #endif
@@ -276,11 +281,11 @@ static void checker(const VM::enum_flags flag, const char* message) {
276281}
277282
278283bool parse_disable_token (const char * token) {
279- std::string tok (token);
284+ const std::string tok (token);
280285 std::vector<std::string> names;
281286 std::string current;
282287
283- for (char c : tok) {
288+ for (const char c : tok) {
284289 if (c == ' ,' ) {
285290 if (!current.empty ()) {
286291 names.push_back (current);
@@ -296,7 +301,7 @@ bool parse_disable_token(const char* token) {
296301 }
297302
298303 for (const auto & name : names) {
299- std::pair<bool , VM ::enum_flags> technique = string_to_technique (name);
304+ const std::pair<bool , VM ::enum_flags> technique = string_to_technique (name);
300305
301306 const bool found = technique.first ;
302307 const VM ::enum_flags flag = technique.second ;
@@ -357,7 +362,7 @@ void generate_json(const char* output) {
357362
358363 const auto detected_status = VM::detected_enums ();
359364
360- if (detected_status.size () == 0 ) {
365+ if (detected_status.empty () ) {
361366 json.emplace_back (" ]\n }" );
362367 } else {
363368 for (size_t i = 0 ; i < detected_status.size (); i++) {
@@ -448,7 +453,7 @@ void general(bool high_threshold, bool all, bool dynamic, const char* output_fil
448453 const VM ::enum_flags dynamic_arg = dynamic ? VM ::DYNAMIC : VM ::NULL_ARG ;
449454
450455 #if (CLI_LINUX)
451- [[maybe_unused]] bool notes_enabled = !arg_bitset.test (NOTES );
456+ [[maybe_unused]] const bool notes_enabled = !arg_bitset.test (NOTES );
452457 #endif
453458
454459 std::ofstream output_fstream;
@@ -482,11 +487,11 @@ void general(bool high_threshold, bool all, bool dynamic, const char* output_fil
482487 }
483488
484489 #if (CLI_WINDOWS)
485- DebugInterceptor* interceptor = nullptr ;
486- if (!arg_bitset.test (NO_ANSI )) {
490+ std::unique_ptr< DebugInterceptor> interceptor;
491+ if (!arg_bitset.test (NO_ANSI ) && !arg_bitset. test ( SIMPLE ) ) {
487492 g_tui.init ();
488- interceptor = new DebugInterceptor (std::cout.rdbuf ());
489- std::cout.rdbuf (interceptor);
493+ interceptor = std::make_unique< DebugInterceptor> (std::cout.rdbuf ());
494+ std::cout.rdbuf (interceptor. get () );
490495 }
491496 #endif
492497
@@ -598,15 +603,15 @@ void general(bool high_threshold, bool all, bool dynamic, const char* output_fil
598603 checker (VM ::TIMER , " timing anomalies" );
599604
600605 const auto t2 = std::chrono::high_resolution_clock::now ();
601- VM ::vmaware vm (VM ::MULTIPLE , high_thresh_arg, all_arg, dynamic_arg);
606+ const VM ::vmaware vm (VM ::MULTIPLE , high_thresh_arg, all_arg, dynamic_arg);
602607 std::vector<std::string> summary;
603608
604- std::string brand = vm.brand ;
609+ const std::string brand = vm.brand ;
605610 const bool is_red = ((brand == VM ::brands::NULL_BRAND ) || (brand == VM ::brands::HYPERV_ROOT ));
606611 summary.push_back (bold + " \n VM brand: " + ansi_exit + (is_red ? red : green) + brand + ansi_exit);
607612
608613 if (!is_vm_brand_multiple (vm.brand )) {
609- std::string current_color = (vm.type == " Unknown" || vm.type == " Host machine" ) ? red : green;
614+ const std::string current_color = (vm.type == " Unknown" || vm.type == " Host machine" ) ? red : green;
610615 summary.push_back (bold + " VM type: " + ansi_exit + current_color + vm.type + ansi_exit);
611616 }
612617
@@ -696,8 +701,8 @@ void general(bool high_threshold, bool all, bool dynamic, const char* output_fil
696701 }
697702
698703 const std::string is_bold = (vm.is_vm ? bold : " " );
699-
700704 const char * conclusion_color = color (vm.percentage , vm.is_hardened );
705+
701706 summary.push_back (
702707 bold +
703708 " ===== CONCLUSION: " +
@@ -712,68 +717,67 @@ void general(bool high_threshold, bool all, bool dynamic, const char* output_fil
712717 );
713718
714719#if (CLI_WINDOWS)
715- if (!arg_bitset.test (NO_ANSI )) {
720+ if (!arg_bitset.test (NO_ANSI ) && !arg_bitset. test ( SIMPLE ) ) {
716721 g_tui.drawSummaryBox (summary);
717- } else {
718- for (const auto & l : summary) {
719- std::cout << l << " \n " ;
722+
723+ g_tui.finalize ();
724+
725+ if (g_tui.raw_out ) {
726+ *(g_tui.raw_out ) << " \x1B [90mPress Enter, Q, or Ctrl+C to exit. Exceptions (Left/Right), Timings (Up/Down), Debug (PgUp/PgDn) to scroll.\x1B [0m\n " ;
727+ } else {
728+ std::cout << " \x1B [90mPress Enter, Q, or Ctrl+C to exit. Exceptions (Left/Right), Timings (Up/Down), Debug (PgUp/PgDn) to scroll.\x1B [0m\n " ;
720729 }
721- }
722730
723- g_tui.finalize ();
731+ constexpr u8 KEY_ESCAPE_PREFIX = 0 ;
732+ constexpr u8 KEY_EXTENDED = 224 ;
733+ constexpr u8 KEY_UP = 72 ;
734+ constexpr u8 KEY_DOWN = 80 ;
735+ constexpr u8 KEY_PAGE_UP = 73 ;
736+ constexpr u8 KEY_PAGE_DOWN = 81 ;
737+ constexpr u8 KEY_LEFT = 75 ;
738+ constexpr u8 KEY_RIGHT = 77 ;
739+ constexpr u8 KEY_CTRL_C = 3 ;
740+
741+ while (true ) {
742+ int ch = _getch ();
743+
744+ if (ch == KEY_ESCAPE_PREFIX || ch == KEY_EXTENDED ) {
745+ ch = _getch ();
746+
747+ switch (ch) {
748+ case KEY_UP : g_tui.scrollCyclesUp (); continue ;
749+ case KEY_DOWN : g_tui.scrollCyclesDown (); continue ;
750+ case KEY_PAGE_UP : g_tui.scrollDebugUp (); continue ;
751+ case KEY_PAGE_DOWN : g_tui.scrollDebugDown (); continue ;
752+ case KEY_LEFT : g_tui.scrollExceptionsUp (); continue ;
753+ case KEY_RIGHT : g_tui.scrollExceptionsDown (); continue ;
754+ default : continue ;
755+ }
756+ }
757+
758+ bool should_break = false ;
724759
725- if (g_tui.raw_out ) {
726- *(g_tui.raw_out ) << " \x1B [90mPress Enter, Q, or Ctrl+C to exit. Exceptions (Left/Right), Timings (Up/Down), Debug (PgUp/PgDn) to scroll.\x1B [0m\n " ;
727- } else {
728- std::cout << " \x1B [90mPress Enter, Q, or Ctrl+C to exit. Exceptions (Left/Right), Timings (Up/Down), Debug (PgUp/PgDn) to scroll.\x1B [0m\n " ;
729- }
730-
731- constexpr u8 KEY_ESCAPE_PREFIX = 0 ;
732- constexpr u8 KEY_EXTENDED = 224 ;
733- constexpr u8 KEY_UP = 72 ;
734- constexpr u8 KEY_DOWN = 80 ;
735- constexpr u8 KEY_PAGE_UP = 73 ;
736- constexpr u8 KEY_PAGE_DOWN = 81 ;
737- constexpr u8 KEY_LEFT = 75 ;
738- constexpr u8 KEY_RIGHT = 77 ;
739- constexpr u8 KEY_CTRL_C = 3 ;
740-
741- while (true ) {
742- int ch = _getch ();
743-
744- if (ch == KEY_ESCAPE_PREFIX || ch == KEY_EXTENDED ) {
745- ch = _getch ();
746-
747760 switch (ch) {
748- case KEY_UP : g_tui.scrollCyclesUp (); continue ;
749- case KEY_DOWN : g_tui.scrollCyclesDown (); continue ;
750- case KEY_PAGE_UP : g_tui.scrollDebugUp (); continue ;
751- case KEY_PAGE_DOWN : g_tui.scrollDebugDown (); continue ;
752- case KEY_LEFT : g_tui.scrollExceptionsUp (); continue ;
753- case KEY_RIGHT : g_tui.scrollExceptionsDown (); continue ;
754- default : continue ;
761+ case ' \r ' :
762+ case ' \n ' :
763+ case ' q' :
764+ case ' Q' :
765+ case KEY_CTRL_C :
766+ should_break = true ;
755767 }
756- }
757768
758- bool should_break = false ;
759-
760- switch (ch) {
761- case ' \r ' :
762- case ' \n ' :
763- case ' q' :
764- case ' Q' :
765- case KEY_CTRL_C :
766- should_break = true ;
769+ if (should_break) {
770+ break ;
771+ }
767772 }
768773
769- if (should_break) {
770- break ;
774+ if (interceptor) {
775+ std::cout.rdbuf (interceptor->original );
776+ }
777+ } else {
778+ for (const auto & l : summary) {
779+ std::cout << l << " \n " ;
771780 }
772- }
773-
774- if (interceptor) {
775- std::cout.rdbuf (interceptor->original );
776- delete interceptor;
777781 }
778782#else
779783 for (const auto & line : summary) {
0 commit comments