11import { BacktraceAttributeProvider , IdGenerator } from '@backtrace/sdk-core' ;
22import { execSync } from 'child_process' ;
3- import { getValue , HKEY } from 'native-reg' ;
43
54export class MachineIdentitfierAttributeProvider implements BacktraceAttributeProvider {
65 public static readonly SUPPORTED_PLATFORMS = [ 'win32' , 'darwin' , 'linux' , 'freebsd' ] ;
76 private readonly MACHINE_ID_ATTRIBUTE = 'guid' ;
87
98 private readonly COMMANDS = {
9+ win32 : 'reg query "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Cryptography" /v MachineGuid' ,
1010 darwin : 'ioreg -rd1 -c IOPlatformExpertDevice' ,
1111 linux : '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :' ,
1212 freebsd : 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid' ,
@@ -26,8 +26,9 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
2626 public generateGuid ( ) {
2727 switch ( process . platform ) {
2828 case 'win32' : {
29- return this . getWindowsMachineId ( )
30- ?. replace ( / \r + | \n + | \s + / gi, '' )
29+ return execSync ( this . COMMANDS [ 'win32' ] )
30+ . toString ( )
31+ . match ( / [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } / i) ?. [ 0 ]
3132 . toLowerCase ( ) ;
3233 }
3334 case 'darwin' : {
@@ -50,9 +51,4 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
5051 }
5152 }
5253 }
53-
54- private getWindowsMachineId ( ) {
55- const regVal = getValue ( HKEY . LOCAL_MACHINE , 'SOFTWARE\\Microsoft\\Cryptography' , 'MachineGuid' ) ;
56- return regVal ?. toString ( ) ;
57- }
5854}
0 commit comments