Skip to content

Commit 4cecd4e

Browse files
authored
CLI fixes & VM::SVM_EXCEPTIONS improvements
CLI fixes & VM::SVM_EXCEPTIONS improvement
2 parents d2d0738 + 2153808 commit 4cecd4e

7 files changed

Lines changed: 426 additions & 251 deletions

File tree

src/cli/main.cpp

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
#include <array>
2929
#include <algorithm>
3030
#include <cstring>
31+
#include <string>
3132

3233
#include "types.hpp"
3334
#include "strings.hpp"
3435
#include "output.hpp"
3536

3637
#if (CLI_WINDOWS)
3738
#include "windows_cli.hpp"
39+
#include <windows.h>
40+
#include <shellapi.h>
3841
#endif
3942

4043
constexpr const char* ver = "2.7.0";
@@ -164,10 +167,57 @@ constexpr const char* date = "April 2026";
164167
}
165168

166169
int main(int argc, char* argv[]) {
167-
#if (CLI_WINDOWS)
168-
win_ansi_enabler_t ansi_enabler;
169-
AddVectoredExceptionHandler(1, VehLogger);
170-
#endif
170+
#if (CLI_WINDOWS)
171+
bool relaunched = false;
172+
int new_argc = 1;
173+
static char* new_argv[256];
174+
new_argv[0] = argv[0];
175+
176+
for (int i = 1; i < argc; ++i) {
177+
if (std::strcmp(argv[i], "--no-relaunch") == 0) {
178+
relaunched = true;
179+
}
180+
else {
181+
if (new_argc < 255) {
182+
new_argv[new_argc++] = argv[i];
183+
}
184+
}
185+
}
186+
187+
argc = new_argc;
188+
argv = new_argv;
189+
190+
if (!relaunched) {
191+
char exePath[MAX_PATH];
192+
GetModuleFileNameA(NULL, exePath, MAX_PATH);
193+
194+
char currentDir[MAX_PATH];
195+
GetCurrentDirectoryA(MAX_PATH, currentDir);
196+
197+
std::string args = "\"" + std::string(exePath) + "\" --no-relaunch";
198+
for (int i = 1; i < argc; ++i) {
199+
args += " \"";
200+
args += argv[i];
201+
args += "\"";
202+
}
203+
204+
SHELLEXECUTEINFOA sei = { sizeof(sei) };
205+
sei.fMask = 0;
206+
sei.hwnd = NULL;
207+
sei.lpVerb = "open";
208+
sei.lpFile = "conhost.exe";
209+
sei.lpParameters = args.c_str();
210+
sei.lpDirectory = currentDir;
211+
sei.nShow = SW_SHOWNORMAL;
212+
213+
if (!IsDebuggerPresent() && ShellExecuteExA(&sei)) {
214+
ExitProcess(0);
215+
}
216+
}
217+
218+
win_ansi_enabler_t ansi_enabler;
219+
AddVectoredExceptionHandler(1, VehLogger);
220+
#endif
171221

172222
const std::vector<std::string> args(argv + 1, argv + argc);
173223
const u32 arg_count = static_cast<u32>(argc - 1);
@@ -178,38 +228,38 @@ int main(int argc, char* argv[]) {
178228
}
179229

180230
static const std::array<std::pair<const char*, arg_enum>, 33> table{ {
181-
{ "-h", HELP },
182-
{ "-v", VERSION },
183-
{ "-a", ALL },
184-
{ "-d", DETECT },
185-
{ "-s", STDOUT },
231+
{ "-h", HELP },
232+
{ "-v", VERSION },
233+
{ "-a", ALL },
234+
{ "-d", DETECT },
235+
{ "-s", STDOUT },
186236
{ "-b", BRAND },
187-
{ "-p", PERCENT },
188-
{ "-c", CONCLUSION },
189-
{ "-l", BRAND_LIST },
190-
{ "-n", NUMBER },
191-
{ "-t", TYPE },
237+
{ "-p", PERCENT },
238+
{ "-c", CONCLUSION },
239+
{ "-l", BRAND_LIST },
240+
{ "-n", NUMBER },
241+
{ "-t", TYPE },
192242
{ "-o", OUTPUT },
193-
{ "help", HELP },
194-
{ "--help", HELP },
195-
{ "--version", VERSION },
196-
{ "--all", ALL },
243+
{ "help", HELP },
244+
{ "--help", HELP },
245+
{ "--version", VERSION },
246+
{ "--all", ALL },
197247
{ "--detect", DETECT },
198-
{ "--stdout", STDOUT },
199-
{ "--brand", BRAND },
200-
{ "--percent", PERCENT },
248+
{ "--stdout", STDOUT },
249+
{ "--brand", BRAND },
250+
{ "--percent", PERCENT },
201251
{ "--conclusion", CONCLUSION },
202-
{ "--brand-list", BRAND_LIST },
203-
{ "--number", NUMBER },
204-
{ "--type", TYPE },
252+
{ "--brand-list", BRAND_LIST },
253+
{ "--number", NUMBER },
254+
{ "--type", TYPE },
205255
{ "--disable-notes", NOTES },
206256
{ "--high-threshold", HIGH_THRESHOLD },
207-
{ "--dynamic", DYNAMIC },
208-
{ "--verbose", VERBOSE },
257+
{ "--dynamic", DYNAMIC },
258+
{ "--verbose", VERBOSE },
209259
{ "--enums", ENUMS },
210-
{ "--no-ansi", NO_ANSI },
211-
{ "--detected-only", DETECTED_ONLY },
212-
{ "--json", JSON },
260+
{ "--no-ansi", NO_ANSI },
261+
{ "--detected-only", DETECTED_ONLY },
262+
{ "--json", JSON },
213263
{ "--output", OUTPUT }
214264
} };
215265

@@ -247,7 +297,8 @@ int main(int argc, char* argv[]) {
247297
potential_output_arg = arg_string;
248298
}
249299
arg_bitset.set(OUTPUT, false);
250-
} else {
300+
}
301+
else {
251302
arg_bitset.set(NULL_ARG);
252303
potential_null_arg = arg_string;
253304
}
@@ -331,4 +382,4 @@ int main(int argc, char* argv[]) {
331382

332383
general(high_threshold, all, dynamic);
333384
return 0;
334-
}
385+
}

0 commit comments

Comments
 (0)