diff --git a/apps/desktop/src-tauri/src/agent.rs b/apps/desktop/src-tauri/src/agent.rs index ab787d8..e18b530 100644 --- a/apps/desktop/src-tauri/src/agent.rs +++ b/apps/desktop/src-tauri/src/agent.rs @@ -682,41 +682,6 @@ fn collect_windows_extended() -> serde_json::Value { use std::process::Command; const CREATE_NO_WINDOW: u32 = 0x08000000; - fn parse_utf16_le_bytes(bytes: &[u8]) -> Option { - if bytes.len() % 2 != 0 { - return None; - } - let utf16: Vec = bytes - .chunks_exact(2) - .map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]])) - .collect(); - let text = String::from_utf16(&utf16).ok()?; - let trimmed = text.trim(); - if trimmed.is_empty() { - return None; - } - serde_json::from_str(trimmed).ok() - } - - fn parse_powershell_json(bytes: &[u8]) -> Option { - let text = decode_powershell_text(bytes)?; - if text.is_empty() { - return None; - } - match serde_json::from_str::(&text) { - Ok(value) => Some(value), - Err(err) => { - if cfg!(test) { - let preview = text.chars().take(512).collect::(); - eprintln!( - "[collect_windows_extended] falha ao interpretar JSON: {err}; amostra: {preview}" - ); - } - None - } - } - } - fn decode_powershell_text(bytes: &[u8]) -> Option { if bytes.is_empty() { return None; @@ -781,7 +746,7 @@ fn collect_windows_extended() -> serde_json::Value { fn ps(cmd: &str) -> Option { let script = format!( - "$ErrorActionPreference='SilentlyContinue';$ProgressPreference='SilentlyContinue';$result = ({});if ($null -eq $result) {{ return }};$json = $result | ConvertTo-Json -Depth 4 -Compress;if ([string]::IsNullOrWhiteSpace($json)) {{ return }};[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;$json;", + "$ErrorActionPreference='SilentlyContinue';$ProgressPreference='SilentlyContinue';$result = & {{\n{}\n}};if ($null -eq $result) {{ return }};$json = $result | ConvertTo-Json -Depth 4 -Compress;if ([string]::IsNullOrWhiteSpace($json)) {{ return }};[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;$json;", cmd ); let encoded = encode_ps_script(&script);