sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.7k stars 307 forks source link

Incorrect value fetched for mac m1 model #773

Closed Xutaotaotao closed 1 year ago

Xutaotaotao commented 1 year ago

Describe the bug When I develop HelloKnight(The best ZeroTrust in the world), I found incorrect value fetched for mac M1 model.

To Reproduce Steps to reproduce the behavior:

used function

si.get({system: "model,serial,uuid"})

Current Output

Get value is model-config value not model value.

Expected behavior Get value should be model value

Environment (please complete the following information):

Additional context

this problem may be in lib/util.js, function getValue

function getValue(lines, property, separator, trimmed, lineMatch) {
  separator = separator || ':';
  property = property.toLowerCase();
  trimmed = trimmed || false;
  lineMatch = lineMatch || false;
  let result = '';
  lines.forEach((line) => {
    let lineLower = line.toLowerCase().replace(/\t/g, '');
    if (trimmed) {
      lineLower = lineLower.trim();
    }
    if (lineLower.startsWith(property) && (lineMatch ? (lineLower.match(property + separator)) : true)) {
      const parts = trimmed ? line.trim().split(separator) : line.split(separator);
      if (parts.length >= 2) {
        parts.shift();
        result = parts.join(separator).trim();
      }
    }
  });
  return result;
}

lineLower.startsWith will match the latest property

avatar

avatar

athenakia commented 1 year ago

I met this problem too, it didn't return MacBookPro17,1 but a string like 'AMP;MoPED=0xABCDEF...'

Xutaotaotao commented 1 year ago

I met this problem too, it didn't return MacBookPro17,1 but a string like 'AMP;MoPED=0xABCDEF...'

temporary solution

you can get mac systeminfo by this way

function getValue(lines, property, separator, trimmed, lineMatch) {
  separator = separator || ':';
  property = property.toLowerCase();
  trimmed = trimmed || false;
  lineMatch = lineMatch || false;
  let result = '';
  lines.forEach((line) => {
    let lineLower = line.toLowerCase().replace(/\t/g, '');
    if (trimmed) {
      lineLower = lineLower.trim();
    }
    if (lineLower.startsWith(property) && (lineMatch ? (lineLower.match(property + separator)) : true)) {
      const parts = trimmed ? line.trim().split(separator) : line.split(separator);
      const isMatchProperty = trimmed ? parts[0].toLowerCase().replace(/\t/g, '').trim() === property : parts[0].toLowerCase().replace(/\t/g, '') === property;
      if (parts.length >= 2 && isMatchProperty) {
        parts.shift();
        result = parts.join(separator).trim();
      }
    }
  });
  return result;
}

const getMacSystemInfo = () => {
  return new Promise((resolve)) => {
    const result = {}
    exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
      if (!error) {
        let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
        result.manufacturer = getValue(lines, 'manufacturer', '=', true);
        result.model = getValue(lines, 'model', '=', true);
        result.version = getValue(lines, 'version', '=', true);
        result.serial = getValue(lines, 'ioplatformserialnumber', '=', true);
        result.uuid = getValue(lines, 'ioplatformuuid', '=', true).toLowerCase();
        result.sku = getValue(lines, 'board-id', '=', true);
      }
      resolve(result);
    });
  })
}
sebhildebrandt commented 1 year ago

@Xutaotaotao @athenakia can you pull the lates version if the main branch here in GitHub ad test it once again?

git clone https://github.com/sebhildebrandt/systeminformation.git

cd systeminformation
npm run test

Then press the "y" button ... now the model should return the correct value. If you can confirm this, I will publish a new version as soon as possible. Thank you for your support.

athenakia commented 1 year ago

@Xutaotaotao @athenakia can you pull the lates version if the main branch here in GitHub ad test it once again?

git clone https://github.com/sebhildebrandt/systeminformation.git

cd systeminformation
npm run test

Then press the "y" button ... now the model should return the correct value. If you can confirm this, I will publish a new version as soon as possible. Thank you for your support.

Yes, the model value is 'MacBookPro17,1', which is correct.

sebhildebrandt commented 1 year ago

@athenakia ... thank you for testing @athenakia @Xutaotaotao new version 5.17.9 just released. Thank you for your support, If you experience any other issues, please feel free to reopen this issue.