2Copyright 2022 Intel Corporation
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
24 if (j[i] == null || (typeof(j[i])=='string' && j[i]=='') || i.startsWith('__')) { delete j[i];}
26 if (j['SerialNumber'] < 0) { var tmp = Buffer.alloc(4); tmp.writeInt32LE(j['SerialNumber']); j['SerialNumber'] = tmp.readUInt32LE(); }
33 var v = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_Volume');
40 ret[v[i].DeviceID] = trimObject(v[i]);
43 v = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume');
46 var tmp = trimObject(v[i]);
49 ret[tmp.DeviceID][k] = tmp[k];
56function windows_volumes()
58 var promise = require('promise');
59 var p1 = new promise(function (res, rej) { this._res = res; this._rej = rej; });
61 var values = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_LogicalDisk', ['DeviceID', 'VolumeName', 'FileSystem', 'Size', 'FreeSpace', 'DriveType']);
63 for (var i = 0; i < values.length; ++i) {
64 var drive = values[i]['DeviceID'].slice(0,-1);
66 name: (values[i]['VolumeName'] ? values[i]['VolumeName'] : ""),
67 type: (values[i]['FileSystem'] ? values[i]['FileSystem'] : "Unknown"),
68 size: (values[i]['Size'] ? values[i]['Size'] : 0),
69 sizeremaining: (values[i]['FreeSpace'] ? values[i]['FreeSpace'] : 0),
70 removable: (values[i]['DriveType'] == 2),
71 cdrom: (values[i]['DriveType'] == 5)
76 values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume', ['DriveLetter','ConversionStatus','ProtectionStatus']);
78 for (var i = 0; i < values.length; ++i) {
79 var drive = values[i]['DriveLetter'].slice(0,-1);
83 2: 'EncryptionInProgress',
84 3: 'DecryptionInProgress',
85 4: 'EncryptionPaused',
88 ret[drive].volumeStatus = statuses.hasOwnProperty(values[i].ConversionStatus) ? statuses[values[i].ConversionStatus] : 'FullyDecrypted';
89 ret[drive].protectionStatus = (values[i].ProtectionStatus == 0 ? 'Off' : (values[i].ProtectionStatus == 1 ? 'On' : 'Unknown'));
91 var foundIDMarkedLine = false, foundMarkedLine = false, identifier = '', password = '';
92 var keychild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'manage-bde -protectors -get ' + drive + ': -Type recoverypassword'], {});
93 keychild.stdout.str = ''; keychild.stdout.on('data', function (c) { this.str += c.toString(); });
95 var lines = keychild.stdout.str.trim().split('\r\n');
96 for (var x = 0; x < lines.length; x++) { // Loop each line
97 var abc = lines[x].trim();
98 var englishidpass = (abc !== '' && abc.includes('Numerical Password:')); // English ID
99 var germanidpass = (abc !== '' && abc.includes('Numerisches Kennwort:')); // German ID
100 var frenchidpass = (abc !== '' && abc.includes('Mot de passe num')); // French ID
101 var englishpass = (abc !== '' && abc.includes('Password:') && !abc.includes('Numerical Password:')); // English Password
102 var germanpass = (abc !== '' && abc.includes('Kennwort:') && !abc.includes('Numerisches Kennwort:')); // German Password
103 var frenchpass = (abc !== '' && abc.includes('Mot de passe :') && !abc.includes('Mot de passe num')); // French Password
104 if (englishidpass || germanidpass || frenchidpass|| englishpass || germanpass || frenchpass) {
105 var nextline = lines[x + 1].trim();
106 if (x + 1 < lines.length && (nextline !== '' && (nextline.startsWith('ID:') || nextline.startsWith('ID :')) )) {
107 identifier = nextline.replace('ID:','').replace('ID :', '').trim();
108 foundIDMarkedLine = true;
109 }else if (x + 1 < lines.length && nextline !== '') {
111 foundMarkedLine = true;
115 ret[drive].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier
116 ret[drive].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
117 } catch(ex) { } // just carry on as we cant get bitlocker key
121 } catch (ex) { p1._res(ret); } // just return volumes as cant get encryption/bitlocker
126 getVolumes: function () { try { return (getVolumes()); } catch (x) { return ({}); } },
127 volumes_promise: windows_volumes