1
1
import { BacktraceAttributeProvider , IdGenerator } from '@backtrace/sdk-core' ;
2
2
import { execSync } from 'child_process' ;
3
- import { getValue , HKEY } from 'native-reg' ;
4
3
5
4
export class MachineIdentitfierAttributeProvider implements BacktraceAttributeProvider {
6
5
public static readonly SUPPORTED_PLATFORMS = [ 'win32' , 'darwin' , 'linux' , 'freebsd' ] ;
7
6
private readonly MACHINE_ID_ATTRIBUTE = 'guid' ;
8
7
9
8
private readonly COMMANDS = {
9
+ win32 : 'reg query "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Cryptography" /v MachineGuid' ,
10
10
darwin : 'ioreg -rd1 -c IOPlatformExpertDevice' ,
11
11
linux : '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :' ,
12
12
freebsd : 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid' ,
@@ -26,8 +26,9 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
26
26
public generateGuid ( ) {
27
27
switch ( process . platform ) {
28
28
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 ]
31
32
. toLowerCase ( ) ;
32
33
}
33
34
case 'darwin' : {
@@ -50,9 +51,4 @@ export class MachineIdentitfierAttributeProvider implements BacktraceAttributePr
50
51
}
51
52
}
52
53
}
53
-
54
- private getWindowsMachineId ( ) {
55
- const regVal = getValue ( HKEY . LOCAL_MACHINE , 'SOFTWARE\\Microsoft\\Cryptography' , 'MachineGuid' ) ;
56
- return regVal ?. toString ( ) ;
57
- }
58
54
}
0 commit comments