Updated AV() to support UTF8

Bryan Roe committed Jul 6, 2021 at 14:08 UTC c9e6b0312e1d5a20d3946aa24d13fd847d6dceca
1 file changed +24 -17
agents/modules_meshcore/win-info.js
+24 -17
@@ -1,5 +1,5 @@
1 /*
2 -Copyright 2019-2021 Intel Corporation
2 +Copyright 2019-2020 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
@@ -43,30 +43,37 @@ function qfe()
43 }
44 function av()
45 {
46 - var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/Namespace:\\\\root\\SecurityCenter2', 'Path', 'AntiVirusProduct', 'get', '/FORMAT:CSV']);
46 + var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
47 + if (child == null) { return ([]); }
48 +
49 + child.descriptorMetadata = 'process-manager';
50 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
48 - child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); })
51 + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
52 +
53 + child.stdin.write('[reflection.Assembly]::LoadWithPartialName("system.core")\r\n');
54 + child.stdin.write('Get-WmiObject -Namespace "root/SecurityCenter2" -Class AntiVirusProduct | ');
55 + child.stdin.write('ForEach-Object -Process { ');
56 + child.stdin.write('$Bytes = [System.Text.Encoding]::UTF8.GetBytes($_.displayName); ');
57 + child.stdin.write('$EncodedText =[Convert]::ToBase64String($Bytes); ');
58 + child.stdin.write('Write-Host ("{0},{1}" -f $_.productState,$EncodedText); }\r\n');
59 + child.stdin.write('exit\r\n');
60 child.waitExit();
61
62 + if (child.stdout.str == '') { return ([]); }
63 +
64 var lines = child.stdout.str.trim().split('\r\n');
52 - var keys = lines[0].split(',');
53 - var i, key;
54 - var tokens;
65 var result = [];
56 -
57 - for (i = 1; i < lines.length; ++i)
66 + for (i = 0; i < lines.length; ++i)
67 {
59 - var obj = {};
60 - var status = {};
61 - tokens = lines[i].split(',');
62 - for (key = 0; key < keys.length; ++key)
68 + var keys = lines[i].split(',');
69 + if(keys.length == 2)
70 {
64 - if (tokens[key] != undefined) { obj[keys[key].trim()] = tokens[key]; }
71 + var status = {};
72 + status.product = Buffer.from(keys[1], 'base64').toString();
73 + status.updated = (parseInt(keys[0]) & 0x10) == 0;
74 + status.enabled = (parseInt(keys[0]) & 0x1000) == 0x1000;
75 + result.push(status);
76 }
66 - status.product = obj.displayName;
67 - status.updated = (parseInt(obj.productState) & 0x10) == 0;
68 - status.enabled = (parseInt(obj.productState) & 0x1000) == 0x1000;
69 - result.push(status);
77 }
78 return (result);
79 }