Skip to content

Commit b3703f9

Browse files
committed
fixes to windows cli --json option bug
1 parent ba1b6a4 commit b3703f9

2 files changed

Lines changed: 17 additions & 26 deletions

File tree

auxiliary/test_cli.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function Fail-Test([string]$desc) { Write-Host " FAIL $desc"; $script:fail++ }
2424
# runtime uses WriteFile (not WriteConsoleW) for std::cout. Without it, when
2525
# the parent process has a console, the CRT routes output through WriteConsoleW
2626
# which silently fails on a pipe handle and the captured output is empty.
27-
function invoke_bin([string[]]$binArgs, [bool]$captureStderr = $true) {
27+
function invoke_bin([string[]]$binArgs, [bool]$captureStderr = $true, [int]$timeoutMs = -1) {
28+
if ($timeoutMs -lt 0) { $timeoutMs = $script:TIMEOUT_SECS * 1000 }
29+
2830
$psi = [System.Diagnostics.ProcessStartInfo]::new($script:BIN)
2931
foreach ($a in $binArgs) { $psi.ArgumentList.Add($a) }
3032
$psi.UseShellExecute = $false
@@ -36,7 +38,7 @@ function invoke_bin([string[]]$binArgs, [bool]$captureStderr = $true) {
3638
$outTask = $proc.StandardOutput.ReadToEndAsync()
3739
$errTask = $proc.StandardError.ReadToEndAsync()
3840

39-
if (-not $proc.WaitForExit($script:TIMEOUT_SECS * 1000)) {
41+
if (-not $proc.WaitForExit($timeoutMs)) {
4042
$proc.Kill()
4143
return $null, -99
4244
}
@@ -211,7 +213,7 @@ Write-Host ""
211213
Write-Host "--json"
212214
$tmpJson = [System.IO.Path]::GetTempFileName() + ".json"
213215
try {
214-
$out, $code = invoke_bin @("--json", "--output", $tmpJson)
216+
$out, $code = invoke_bin @("--json", "--output", $tmpJson) $true 30000
215217
if ($code -eq -99) {
216218
Fail-Test "--json timed out"
217219
Fail-Test "--json output missing expected keys"

src/cli/output.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -318,58 +318,47 @@ bool parse_disable_token(const char* token) {
318318
}
319319

320320
void generate_json(const char* output) {
321+
const VM::vmaware vm(VM::MULTIPLE);
322+
321323
std::vector<std::string> json;
322324

323325
json.emplace_back("{");
324326
json.emplace_back("\n\t\"is_detected\": ");
325-
326-
if (VM::detect()) {
327-
json.emplace_back("true,");
328-
}
329-
else {
330-
json.emplace_back("false,");
331-
}
327+
json.emplace_back(vm.is_vm ? "true," : "false,");
332328

333329
json.emplace_back("\n\t\"brand\": \"");
334-
json.push_back(VM::brand());
330+
json.push_back(vm.brand);
335331
json.emplace_back("\",");
336332

337333
json.emplace_back("\n\t\"conclusion\": \"");
338-
json.push_back(VM::conclusion());
334+
json.push_back(vm.conclusion);
339335
json.emplace_back("\",");
340336

341337
json.emplace_back("\n\t\"percentage\": ");
342-
json.push_back(std::to_string(static_cast<int>(VM::percentage())));
338+
json.push_back(std::to_string(static_cast<int>(vm.percentage)));
343339
json.emplace_back(",");
344340

345341
json.emplace_back("\n\t\"detected_technique_count\": ");
346342
json.push_back(std::to_string(VM::technique_count));
347343
json.emplace_back(",");
348344

349345
json.emplace_back("\n\t\"vm_type\": \"");
350-
json.push_back(VM::type());
346+
json.push_back(vm.type);
351347
json.emplace_back("\",");
352348

353349
json.emplace_back("\n\t\"is_hardened\": ");
354-
355-
if (VM::is_hardened()) {
356-
json.emplace_back("true,");
357-
} else {
358-
json.emplace_back("false,");
359-
}
350+
json.emplace_back(vm.is_hardened ? "true," : "false,");
360351

361352
json.emplace_back("\n\t\"detected_techniques\": [");
362353

363-
const auto detected_status = VM::detected_enums();
364-
365-
if (detected_status.empty()) {
354+
if (vm.detected_techniques.empty()) {
366355
json.emplace_back("]\n}");
367356
} else {
368-
for (size_t i = 0; i < detected_status.size(); i++) {
357+
for (size_t i = 0; i < vm.detected_techniques.size(); i++) {
369358
json.emplace_back("\n\t\t\"");
370-
json.push_back(VM::flag_to_string(detected_status[i]));
359+
json.push_back(VM::flag_to_string(vm.detected_techniques[i]));
371360

372-
if (i == detected_status.size() - 1) {
361+
if (i == vm.detected_techniques.size() - 1) {
373362
json.emplace_back("\"");
374363
} else {
375364
json.emplace_back("\",");

0 commit comments

Comments
 (0)