usb() fix parsing JSON (mac OS)
This commit is contained in:
parent
8bb47e5b4e
commit
68b4e5b273
@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
|
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
|
||||||
|
| 5.17.16 | 2023-05-30 | `usb()` fix parsing JSON (mac OS) |
|
||||||
| 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) |
|
| 5.17.15 | 2023-05-29 | `powershell()` added NoProfile to speed up powershell (windows) |
|
||||||
| 5.17.14 | 2023-05-29 | `diskLayout()`, `osInfo()` fix parsing issues (mac OS) |
|
| 5.17.14 | 2023-05-29 | `diskLayout()`, `osInfo()` fix parsing issues (mac OS) |
|
||||||
| 5.17.13 | 2023-05-24 | `typings` fix typings dynamicData, networkInterfaceDatass |
|
| 5.17.13 | 2023-05-24 | `typings` fix typings dynamicData, networkInterfaceDatass |
|
||||||
|
|||||||
@ -57,6 +57,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">5.17.16</th>
|
||||||
|
<td>2023-05-30</td>
|
||||||
|
<td><span class="code">usb()</span> fix parsing JSON (mac OS)</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">5.17.15</th>
|
<th scope="row">5.17.15</th>
|
||||||
<td>2023-05-29</td>
|
<td>2023-05-29</td>
|
||||||
|
|||||||
@ -1053,7 +1053,7 @@ function getUniqueMacAdresses() {
|
|||||||
for (let dev in ifaces) {
|
for (let dev in ifaces) {
|
||||||
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
||||||
ifaces[dev].forEach(function (details) {
|
ifaces[dev].forEach(function (details) {
|
||||||
if (details?.mac && details.mac !== '00:00:00:00:00:00') {
|
if (details && details.mac && details.mac !== '00:00:00:00:00:00') {
|
||||||
const mac = details.mac.toLowerCase();
|
const mac = details.mac.toLowerCase();
|
||||||
if (macs.indexOf(mac) === -1) {
|
if (macs.indexOf(mac) === -1) {
|
||||||
macs.push(mac);
|
macs.push(mac);
|
||||||
|
|||||||
20
lib/usb.js
20
lib/usb.js
@ -125,20 +125,36 @@ function parseDarwinUsb(usb, id) {
|
|||||||
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
|
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
|
||||||
lines[i] = lines[i] + ',';
|
lines[i] = lines[i] + ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lines[i] = lines[i].replace(':Yes,', ':"Yes",');
|
||||||
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
|
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
|
||||||
|
lines[i] = lines[i].replace(': Yes', ': "Yes"');
|
||||||
|
lines[i] = lines[i].replace(':No,', ':"No",');
|
||||||
lines[i] = lines[i].replace(': No,', ': "No",');
|
lines[i] = lines[i].replace(': No,', ': "No",');
|
||||||
|
lines[i] = lines[i].replace(': No', ': "No"');
|
||||||
|
|
||||||
|
// In this case (("com.apple.developer.driverkit.transport.usb"))
|
||||||
|
lines[i] = lines[i].replace('((', '').replace('))', '');
|
||||||
|
|
||||||
|
// In case we have <923c11> we need make it "<923c11>" for correct JSON parse
|
||||||
|
const match = /<(\w+)>/.exec(lines[i]);
|
||||||
|
if (match) {
|
||||||
|
const number = match[0];
|
||||||
|
lines[i] = lines[i].replace(number, `"${number}"`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const usbObj = JSON.parse(lines.join('\n'));
|
const usbObj = JSON.parse(lines.join('\n'));
|
||||||
const removableDrive = usbObj['Built-In'].toLowerCase() !== 'yes' && usbObj['non-removable'].toLowerCase() === 'no';
|
const removableDrive = (usbObj['Built-In'] ? usbObj['Built-In'].toLowerCase() !== 'yes' : true) && (usbObj['non-removable'] ? usbObj['non-removable'].toLowerCase() === 'no' : true);
|
||||||
|
|
||||||
result.bus = null;
|
result.bus = null;
|
||||||
result.deviceId = null;
|
result.deviceId = null;
|
||||||
result.id = usbObj['USB Address'] || null;
|
result.id = usbObj['USB Address'] || null;
|
||||||
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
|
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
|
||||||
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase() + (removableDrive ? ' removable' : ''));
|
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase() + (removableDrive ? ' removable' : ''));
|
||||||
result.removable = usbObj['non-removable'].toLowerCase() === 'no';
|
result.removable = usbObj['non-removable'] ? usbObj['non-removable'].toLowerCase() || '' === 'no' : true;
|
||||||
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||||
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||||
|
|
||||||
result.maxPower = null;
|
result.maxPower = null;
|
||||||
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
|
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
|
||||||
|
|
||||||
|
|||||||
12
lib/util.js
12
lib/util.js
@ -315,7 +315,7 @@ function getWmic() {
|
|||||||
if (!fs.existsSync(wmicPath)) {
|
if (!fs.existsSync(wmicPath)) {
|
||||||
try {
|
try {
|
||||||
const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n');
|
const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n');
|
||||||
if (wmicPathArray?.length) {
|
if (wmicPathArray && wmicPathArray.length) {
|
||||||
wmicPath = wmicPathArray[0];
|
wmicPath = wmicPathArray[0];
|
||||||
} else {
|
} else {
|
||||||
wmicPath = 'wmic';
|
wmicPath = 'wmic';
|
||||||
@ -385,7 +385,7 @@ function powerShellStart() {
|
|||||||
encoding: 'UTF-8',
|
encoding: 'UTF-8',
|
||||||
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
||||||
});
|
});
|
||||||
if (_psChild?.pid) {
|
if (_psChild && _psChild.pid) {
|
||||||
_psPersistent = true;
|
_psPersistent = true;
|
||||||
_psChild.stdout.on('data', function (data) {
|
_psChild.stdout.on('data', function (data) {
|
||||||
_psResult = _psResult + data.toString('utf8');
|
_psResult = _psResult + data.toString('utf8');
|
||||||
@ -436,7 +436,7 @@ function powerShell(cmd) {
|
|||||||
start: new Date()
|
start: new Date()
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
if (_psChild?.pid) {
|
if (_psChild && _psChild.pid) {
|
||||||
_psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
|
_psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -464,7 +464,7 @@ function powerShell(cmd) {
|
|||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (child?.pid) {
|
if (child && child.pid) {
|
||||||
child.stdout.on('data', function (data) {
|
child.stdout.on('data', function (data) {
|
||||||
result = result + data.toString('utf8');
|
result = result + data.toString('utf8');
|
||||||
});
|
});
|
||||||
@ -514,7 +514,7 @@ function execSafe(cmd, args, options) {
|
|||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (child?.pid) {
|
if (child && child.pid) {
|
||||||
child.stdout.on('data', function (data) {
|
child.stdout.on('data', function (data) {
|
||||||
result += data.toString();
|
result += data.toString();
|
||||||
});
|
});
|
||||||
@ -576,7 +576,7 @@ function smartMonToolsInstalled() {
|
|||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
const pathArray = execSync('WHERE smartctl 2>nul', execOptsWin).toString().split('\r\n');
|
const pathArray = execSync('WHERE smartctl 2>nul', execOptsWin).toString().split('\r\n');
|
||||||
if (pathArray?.length) {
|
if (pathArray && pathArray.length) {
|
||||||
_smartMonToolsInstalled = pathArray[0].indexOf(':\\') >= 0;
|
_smartMonToolsInstalled = pathArray[0].indexOf(':\\') >= 0;
|
||||||
} else {
|
} else {
|
||||||
_smartMonToolsInstalled = false;
|
_smartMonToolsInstalled = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user