@photostructure/windows-registry 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/License.txt +16 -16
- package/README.md +39 -36
- package/SECURITY.md +41 -41
- package/binding.gyp +71 -71
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +65 -50
- package/prebuilds/win32-arm64/@photostructure+windows-registry.glibc.node +0 -0
- package/prebuilds/win32-x64/@photostructure+windows-registry.glibc.node +0 -0
- package/src/winregistry.cc +214 -214
- package/scripts/build-native.ts +0 -83
package/License.txt
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
Copyright (c) Microsoft Corporation
|
|
2
|
-
|
|
3
|
-
All rights reserved.
|
|
4
|
-
|
|
5
|
-
MIT License
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
8
|
-
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
9
|
-
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
10
|
-
is furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
15
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
16
|
-
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
1
|
+
Copyright (c) Microsoft Corporation
|
|
2
|
+
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
8
|
+
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
9
|
+
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
10
|
+
is furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
15
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
16
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
17
17
|
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
# @photostructure/windows-registry
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
>
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
# @photostructure/windows-registry
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@photostructure/windows-registry)
|
|
4
|
+
[](https://github.com/photostructure/vscode-windows-registry/actions/workflows/build.yml)
|
|
5
|
+
|
|
6
|
+
> **Fork of [@vscode/windows-registry](https://github.com/microsoft/vscode-windows-registry) with prebuilt binaries.**
|
|
7
|
+
>
|
|
8
|
+
> The upstream package requires a C++ build toolchain at install time. This fork
|
|
9
|
+
> ships prebuilt NAPI binaries for `win32-x64` and `win32-arm64`, so no build
|
|
10
|
+
> tools are needed on the target machine.
|
|
11
|
+
|
|
12
|
+
Native node module to access the Windows Registry.
|
|
13
|
+
|
|
14
|
+
## Installing
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @photostructure/windows-registry
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Using
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
const { GetStringRegKey } = require('@photostructure/windows-registry');
|
|
24
|
+
console.log(GetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion', 'ProgramFilesPath'));
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install
|
|
31
|
+
npm run build:native # builds the prebuilt binary
|
|
32
|
+
npm test # builds if necessary, then runs tests
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
[MIT](https://github.com/photostructure/vscode-windows-registry/blob/main/License.txt)
|
|
37
|
+
|
|
38
|
+
Upstream copyright Microsoft Corporation.
|
|
39
|
+
|
package/SECURITY.md
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->
|
|
2
|
-
|
|
3
|
-
## Security
|
|
4
|
-
|
|
5
|
-
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
|
6
|
-
|
|
7
|
-
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
|
|
8
|
-
|
|
9
|
-
## Reporting Security Issues
|
|
10
|
-
|
|
11
|
-
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
12
|
-
|
|
13
|
-
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
|
|
14
|
-
|
|
15
|
-
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
|
|
16
|
-
|
|
17
|
-
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
|
|
18
|
-
|
|
19
|
-
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
20
|
-
|
|
21
|
-
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
22
|
-
* Full paths of source file(s) related to the manifestation of the issue
|
|
23
|
-
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
24
|
-
* Any special configuration required to reproduce the issue
|
|
25
|
-
* Step-by-step instructions to reproduce the issue
|
|
26
|
-
* Proof-of-concept or exploit code (if possible)
|
|
27
|
-
* Impact of the issue, including how an attacker might exploit the issue
|
|
28
|
-
|
|
29
|
-
This information will help us triage your report more quickly.
|
|
30
|
-
|
|
31
|
-
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
|
|
32
|
-
|
|
33
|
-
## Preferred Languages
|
|
34
|
-
|
|
35
|
-
We prefer all communications to be in English.
|
|
36
|
-
|
|
37
|
-
## Policy
|
|
38
|
-
|
|
39
|
-
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
|
|
40
|
-
|
|
41
|
-
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
|
1
|
+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->
|
|
2
|
+
|
|
3
|
+
## Security
|
|
4
|
+
|
|
5
|
+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
|
|
6
|
+
|
|
7
|
+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
|
|
8
|
+
|
|
9
|
+
## Reporting Security Issues
|
|
10
|
+
|
|
11
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
12
|
+
|
|
13
|
+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
|
|
14
|
+
|
|
15
|
+
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
|
|
16
|
+
|
|
17
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
|
|
18
|
+
|
|
19
|
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
20
|
+
|
|
21
|
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
22
|
+
* Full paths of source file(s) related to the manifestation of the issue
|
|
23
|
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
24
|
+
* Any special configuration required to reproduce the issue
|
|
25
|
+
* Step-by-step instructions to reproduce the issue
|
|
26
|
+
* Proof-of-concept or exploit code (if possible)
|
|
27
|
+
* Impact of the issue, including how an attacker might exploit the issue
|
|
28
|
+
|
|
29
|
+
This information will help us triage your report more quickly.
|
|
30
|
+
|
|
31
|
+
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
|
|
32
|
+
|
|
33
|
+
## Preferred Languages
|
|
34
|
+
|
|
35
|
+
We prefer all communications to be in English.
|
|
36
|
+
|
|
37
|
+
## Policy
|
|
38
|
+
|
|
39
|
+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
|
|
40
|
+
|
|
41
|
+
<!-- END MICROSOFT SECURITY.MD BLOCK -->
|
package/binding.gyp
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
{
|
|
2
|
-
"targets": [
|
|
3
|
-
{
|
|
4
|
-
"target_name": "winregistry",
|
|
5
|
-
"conditions": [
|
|
6
|
-
["OS=='win'", {
|
|
7
|
-
"sources": [
|
|
8
|
-
"src/winregistry.cc"
|
|
9
|
-
],
|
|
10
|
-
"msvs_configuration_attributes": {
|
|
11
|
-
"SpectreMitigation": "Spectre"
|
|
12
|
-
},
|
|
13
|
-
"conditions": [
|
|
14
|
-
["target_arch=='x64'", {
|
|
15
|
-
"defines": [
|
|
16
|
-
"_M_X64",
|
|
17
|
-
"_WIN64"
|
|
18
|
-
],
|
|
19
|
-
"msvs_settings": {
|
|
20
|
-
"VCCLCompilerTool": {
|
|
21
|
-
"AdditionalOptions": [
|
|
22
|
-
"/Qspectre",
|
|
23
|
-
"/guard:cf",
|
|
24
|
-
"/sdl",
|
|
25
|
-
"/W3",
|
|
26
|
-
"/we4146",
|
|
27
|
-
"/we4244",
|
|
28
|
-
"/we4267",
|
|
29
|
-
"/ZH:SHA_256"
|
|
30
|
-
]
|
|
31
|
-
},
|
|
32
|
-
"VCLinkerTool": {
|
|
33
|
-
"AdditionalOptions": [
|
|
34
|
-
"/DYNAMICBASE",
|
|
35
|
-
"/guard:cf",
|
|
36
|
-
"/CETCOMPAT"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}],
|
|
41
|
-
["target_arch=='arm64'", {
|
|
42
|
-
"defines": [
|
|
43
|
-
"_M_ARM64",
|
|
44
|
-
"_WIN64"
|
|
45
|
-
],
|
|
46
|
-
"msvs_settings": {
|
|
47
|
-
"VCCLCompilerTool": {
|
|
48
|
-
"AdditionalOptions": [
|
|
49
|
-
"/guard:cf",
|
|
50
|
-
"/sdl",
|
|
51
|
-
"/W3",
|
|
52
|
-
"/we4146",
|
|
53
|
-
"/we4244",
|
|
54
|
-
"/we4267",
|
|
55
|
-
"/ZH:SHA_256"
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
"VCLinkerTool": {
|
|
59
|
-
"AdditionalOptions": [
|
|
60
|
-
"/DYNAMICBASE",
|
|
61
|
-
"/guard:cf"
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}]
|
|
66
|
-
]
|
|
67
|
-
}]
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "winregistry",
|
|
5
|
+
"conditions": [
|
|
6
|
+
["OS=='win'", {
|
|
7
|
+
"sources": [
|
|
8
|
+
"src/winregistry.cc"
|
|
9
|
+
],
|
|
10
|
+
"msvs_configuration_attributes": {
|
|
11
|
+
"SpectreMitigation": "Spectre"
|
|
12
|
+
},
|
|
13
|
+
"conditions": [
|
|
14
|
+
["target_arch=='x64'", {
|
|
15
|
+
"defines": [
|
|
16
|
+
"_M_X64",
|
|
17
|
+
"_WIN64"
|
|
18
|
+
],
|
|
19
|
+
"msvs_settings": {
|
|
20
|
+
"VCCLCompilerTool": {
|
|
21
|
+
"AdditionalOptions": [
|
|
22
|
+
"/Qspectre",
|
|
23
|
+
"/guard:cf",
|
|
24
|
+
"/sdl",
|
|
25
|
+
"/W3",
|
|
26
|
+
"/we4146",
|
|
27
|
+
"/we4244",
|
|
28
|
+
"/we4267",
|
|
29
|
+
"/ZH:SHA_256"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"VCLinkerTool": {
|
|
33
|
+
"AdditionalOptions": [
|
|
34
|
+
"/DYNAMICBASE",
|
|
35
|
+
"/guard:cf",
|
|
36
|
+
"/CETCOMPAT"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}],
|
|
41
|
+
["target_arch=='arm64'", {
|
|
42
|
+
"defines": [
|
|
43
|
+
"_M_ARM64",
|
|
44
|
+
"_WIN64"
|
|
45
|
+
],
|
|
46
|
+
"msvs_settings": {
|
|
47
|
+
"VCCLCompilerTool": {
|
|
48
|
+
"AdditionalOptions": [
|
|
49
|
+
"/guard:cf",
|
|
50
|
+
"/sdl",
|
|
51
|
+
"/W3",
|
|
52
|
+
"/we4146",
|
|
53
|
+
"/we4244",
|
|
54
|
+
"/we4267",
|
|
55
|
+
"/ZH:SHA_256"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"VCLinkerTool": {
|
|
59
|
+
"AdditionalOptions": [
|
|
60
|
+
"/DYNAMICBASE",
|
|
61
|
+
"/guard:cf"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}]
|
|
66
|
+
]
|
|
67
|
+
}]
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.GetStringRegKey = GetStringRegKey;
|
|
8
8
|
exports.GetDWORDRegKey = GetDWORDRegKey;
|
|
9
|
+
// cspell:ignore prebuilds
|
|
9
10
|
const path_1 = require("path");
|
|
11
|
+
const nodeGypBuild = require("node-gyp-build");
|
|
10
12
|
// Use node-gyp-build to load the prebuilt native binary for the current
|
|
11
13
|
// platform/arch. It checks prebuilds/ first, then falls back to build/Release/.
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-explicit-any
|
|
13
|
-
const nodeGypBuild = require('node-gyp-build');
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
15
|
const windowRegistry = process.platform === 'win32'
|
|
16
16
|
? nodeGypBuild((0, path_1.join)(__dirname, '..'))
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAehG,0CAMC;AAED,wCAMC;AA3BD,+BAA4B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAehG,0CAMC;AAED,wCAMC;AA3BD,0BAA0B;AAC1B,+BAA4B;AAC5B,+CAAgD;AAEhD,wEAAwE;AACxE,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,cAAc,GAAQ,OAAO,CAAC,QAAQ,KAAK,OAAO;IACvD,CAAC,CAAC,YAAY,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC,IAAI,CAAC;AAIR,SAAgB,eAAe,CAAC,IAAU,EAAE,IAAY,EAAE,IAAY;IACrE,IAAI,cAAc,EAAE,CAAC;QACpB,OAAO,cAAc,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,cAAc,CAAC,IAAU,EAAE,IAAY,EAAE,IAAY;IACpE,IAAI,cAAc,EAAE,CAAC;QACpB,OAAO,cAAc,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,50 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@photostructure/windows-registry",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Native node module to access the Windows Registry, with prebuilts",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"typings": "dist/index.d.ts",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/photostructure/vscode-windows-registry.git"
|
|
10
|
-
},
|
|
11
|
-
"author": "Microsoft Corporation",
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/photostructure/vscode-windows-registry/issues"
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://github.com/photostructure/vscode-windows-registry#readme",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@photostructure/windows-registry",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Native node module to access the Windows Registry, with prebuilts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/photostructure/vscode-windows-registry.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Microsoft Corporation",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/photostructure/vscode-windows-registry/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/photostructure/vscode-windows-registry#readme",
|
|
17
|
+
"files": [
|
|
18
|
+
"binding.gyp",
|
|
19
|
+
"dist/",
|
|
20
|
+
"prebuilds/",
|
|
21
|
+
"src/",
|
|
22
|
+
"SECURITY.md"
|
|
23
|
+
],
|
|
24
|
+
"os": [
|
|
25
|
+
"win32"
|
|
26
|
+
],
|
|
27
|
+
"cpu": [
|
|
28
|
+
"x64",
|
|
29
|
+
"arm64"
|
|
30
|
+
],
|
|
31
|
+
"cspell": {
|
|
32
|
+
"words": [
|
|
33
|
+
"prebuilds",
|
|
34
|
+
"prebuildify",
|
|
35
|
+
"napi",
|
|
36
|
+
"winregistry"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20.0.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"install": "node-gyp-build",
|
|
47
|
+
"compile": "tsc -p ./",
|
|
48
|
+
"prepare-release": "tsc -p ./",
|
|
49
|
+
"build:native": "tsx scripts/build-native.ts",
|
|
50
|
+
"test": "npm run build:native && npm run compile && mocha -r ts-node/register test/**/*.test.ts"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"node-gyp-build": "^4.8.4"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/mocha": "^10.0.10",
|
|
57
|
+
"@types/node": "^25.3.0",
|
|
58
|
+
"mocha": "^11.7.5",
|
|
59
|
+
"node-gyp": "^12.2.0",
|
|
60
|
+
"prebuildify": "^6.0.1",
|
|
61
|
+
"ts-node": "^10.9.2",
|
|
62
|
+
"tsx": "^4.21.0",
|
|
63
|
+
"typescript": "^5.9.3"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
Binary file
|
package/src/winregistry.cc
CHANGED
|
@@ -1,215 +1,215 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
*license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
|
|
7
|
-
#include <string>
|
|
8
|
-
#include <windows.h>
|
|
9
|
-
|
|
10
|
-
#include <node_api.h>
|
|
11
|
-
|
|
12
|
-
namespace {
|
|
13
|
-
|
|
14
|
-
HKEY GetHive(std::string hkey) {
|
|
15
|
-
if (hkey == "HKEY_CURRENT_USER") {
|
|
16
|
-
return HKEY_CURRENT_USER;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (hkey == "HKEY_LOCAL_MACHINE") {
|
|
20
|
-
return HKEY_LOCAL_MACHINE;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (hkey == "HKEY_CLASSES_ROOT") {
|
|
24
|
-
return HKEY_CLASSES_ROOT;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (hkey == "HKEY_USERS") {
|
|
28
|
-
return HKEY_USERS;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (hkey == "HKEY_CURRENT_CONFIG") {
|
|
32
|
-
return HKEY_CURRENT_CONFIG;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return NULL;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
napi_value GetStringRegKey(napi_env env, napi_callback_info info) {
|
|
39
|
-
napi_value argv[3];
|
|
40
|
-
size_t argc = 3;
|
|
41
|
-
|
|
42
|
-
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
|
43
|
-
|
|
44
|
-
// Check that we have 3 arguments - Hive, Path, Name
|
|
45
|
-
if (argc < 3) {
|
|
46
|
-
napi_throw_error(env, "EINVAL", "Wrong number of arguments");
|
|
47
|
-
return nullptr;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Retrieve the 3 arguments
|
|
51
|
-
for (int i = 0; i < 3; i++) {
|
|
52
|
-
napi_valuetype value_type;
|
|
53
|
-
napi_typeof(env, argv[i], &value_type);
|
|
54
|
-
if (value_type != napi_string) {
|
|
55
|
-
napi_throw_error(env, "EINVAL", "Expected string");
|
|
56
|
-
return nullptr;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
size_t str_len = 0;
|
|
61
|
-
const int MAX_LEN = 16383;
|
|
62
|
-
|
|
63
|
-
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &str_len);
|
|
64
|
-
if (str_len + 1 > MAX_LEN) {
|
|
65
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
66
|
-
}
|
|
67
|
-
std::string hive_arg;
|
|
68
|
-
hive_arg.reserve(str_len + 1);
|
|
69
|
-
hive_arg.resize(str_len);
|
|
70
|
-
napi_get_value_string_utf8(env, argv[0], &hive_arg[0], hive_arg.capacity(), nullptr);
|
|
71
|
-
HKEY hive = GetHive(hive_arg);
|
|
72
|
-
|
|
73
|
-
napi_get_value_string_utf8(env, argv[1], nullptr, 0, &str_len);
|
|
74
|
-
if (str_len + 1 > MAX_LEN) {
|
|
75
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
76
|
-
}
|
|
77
|
-
std::string path;
|
|
78
|
-
path.reserve(str_len + 1);
|
|
79
|
-
path.resize(str_len);
|
|
80
|
-
napi_get_value_string_utf8(env, argv[1], &path[0], path.capacity(), nullptr);
|
|
81
|
-
|
|
82
|
-
napi_get_value_string_utf8(env, argv[2], nullptr, 0, &str_len);
|
|
83
|
-
if (str_len + 1 > MAX_LEN) {
|
|
84
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
85
|
-
}
|
|
86
|
-
std::string name;
|
|
87
|
-
name.reserve(str_len + 1);
|
|
88
|
-
name.resize(str_len);
|
|
89
|
-
napi_get_value_string_utf8(env, argv[2], &name[0], name.capacity(), nullptr);
|
|
90
|
-
|
|
91
|
-
if (hive == NULL) {
|
|
92
|
-
napi_throw_error(env, nullptr, "Unable to open registry hive");
|
|
93
|
-
return nullptr;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
std::string result;
|
|
97
|
-
HKEY hKey;
|
|
98
|
-
if (ERROR_SUCCESS != RegOpenKeyEx(hive, path.c_str(), 0, KEY_READ, &hKey)) {
|
|
99
|
-
napi_throw_error(env, nullptr, "Unable to open registry key");
|
|
100
|
-
return nullptr;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
char szBuffer[512];
|
|
104
|
-
DWORD dwBufferSize = sizeof(szBuffer);
|
|
105
|
-
|
|
106
|
-
if (ERROR_SUCCESS == RegQueryValueEx(hKey, name.c_str(), 0, NULL,
|
|
107
|
-
(LPBYTE)szBuffer, &dwBufferSize)) {
|
|
108
|
-
result = szBuffer;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
RegCloseKey(hKey);
|
|
112
|
-
|
|
113
|
-
napi_value napi_result;
|
|
114
|
-
napi_create_string_utf8(env, result.c_str(), result.length(), &napi_result);
|
|
115
|
-
|
|
116
|
-
return napi_result;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
napi_value GetDWORDRegKey(napi_env env, napi_callback_info info) {
|
|
120
|
-
napi_value argv[3];
|
|
121
|
-
size_t argc = 3;
|
|
122
|
-
|
|
123
|
-
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
|
124
|
-
|
|
125
|
-
// Check that we have 3 arguments - Hive, Path, Name
|
|
126
|
-
if (argc < 3) {
|
|
127
|
-
napi_throw_error(env, "EINVAL", "Wrong number of arguments");
|
|
128
|
-
return nullptr;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Retrieve the 3 arguments
|
|
132
|
-
for (int i = 0; i < 3; i++) {
|
|
133
|
-
napi_valuetype value_type;
|
|
134
|
-
napi_typeof(env, argv[i], &value_type);
|
|
135
|
-
if (value_type != napi_string) {
|
|
136
|
-
napi_throw_error(env, "EINVAL", "Expected string");
|
|
137
|
-
return nullptr;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
size_t str_len = 0;
|
|
142
|
-
const int MAX_LEN = 16383;
|
|
143
|
-
|
|
144
|
-
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &str_len);
|
|
145
|
-
if (str_len + 1 > MAX_LEN) {
|
|
146
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
147
|
-
}
|
|
148
|
-
std::string hive_arg;
|
|
149
|
-
hive_arg.reserve(str_len + 1);
|
|
150
|
-
hive_arg.resize(str_len);
|
|
151
|
-
napi_get_value_string_utf8(env, argv[0], &hive_arg[0], hive_arg.capacity(), nullptr);
|
|
152
|
-
HKEY hive = GetHive(hive_arg);
|
|
153
|
-
|
|
154
|
-
napi_get_value_string_utf8(env, argv[1], nullptr, 0, &str_len);
|
|
155
|
-
if (str_len + 1 > MAX_LEN) {
|
|
156
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
157
|
-
}
|
|
158
|
-
std::string path;
|
|
159
|
-
path.reserve(str_len + 1);
|
|
160
|
-
path.resize(str_len);
|
|
161
|
-
napi_get_value_string_utf8(env, argv[1], &path[0], path.capacity(), nullptr);
|
|
162
|
-
|
|
163
|
-
napi_get_value_string_utf8(env, argv[2], nullptr, 0, &str_len);
|
|
164
|
-
if (str_len + 1 > MAX_LEN) {
|
|
165
|
-
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
166
|
-
}
|
|
167
|
-
std::string name;
|
|
168
|
-
name.reserve(str_len + 1);
|
|
169
|
-
name.resize(str_len);
|
|
170
|
-
napi_get_value_string_utf8(env, argv[2], &name[0], name.capacity(), nullptr);
|
|
171
|
-
|
|
172
|
-
if (hive == NULL) {
|
|
173
|
-
napi_throw_error(env, nullptr, "Unable to open registry hive");
|
|
174
|
-
return nullptr;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
HKEY hKey;
|
|
178
|
-
if (ERROR_SUCCESS != RegOpenKeyEx(hive, path.c_str(), 0, KEY_READ, &hKey)) {
|
|
179
|
-
napi_throw_error(env, nullptr, "Unable to open registry key");
|
|
180
|
-
return nullptr;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
DWORD dwValue = 0;
|
|
184
|
-
DWORD dwBufferSize = sizeof(dwValue);
|
|
185
|
-
DWORD dwType = 0;
|
|
186
|
-
LONG result = RegQueryValueEx(hKey, name.c_str(), 0, &dwType,
|
|
187
|
-
(LPBYTE)&dwValue, &dwBufferSize);
|
|
188
|
-
RegCloseKey(hKey);
|
|
189
|
-
|
|
190
|
-
if (result != ERROR_SUCCESS || dwType != REG_DWORD) {
|
|
191
|
-
return nullptr;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
napi_value napi_result;
|
|
195
|
-
napi_create_uint32(env, dwValue, &napi_result);
|
|
196
|
-
|
|
197
|
-
return napi_result;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
napi_value Init(napi_env env, napi_value exports) {
|
|
201
|
-
napi_value getStringRegKey;
|
|
202
|
-
napi_create_function(env, "GetStringRegKey", NAPI_AUTO_LENGTH,
|
|
203
|
-
GetStringRegKey, NULL, &getStringRegKey);
|
|
204
|
-
napi_set_named_property(env, exports, "GetStringRegKey", getStringRegKey);
|
|
205
|
-
|
|
206
|
-
napi_value getDWORDRegKey;
|
|
207
|
-
napi_create_function(env, "GetDWORDRegKey", NAPI_AUTO_LENGTH,
|
|
208
|
-
GetDWORDRegKey, NULL, &getDWORDRegKey);
|
|
209
|
-
napi_set_named_property(env, exports, "GetDWORDRegKey", getDWORDRegKey);
|
|
210
|
-
|
|
211
|
-
return exports;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init);
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
*license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <windows.h>
|
|
9
|
+
|
|
10
|
+
#include <node_api.h>
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
HKEY GetHive(std::string hkey) {
|
|
15
|
+
if (hkey == "HKEY_CURRENT_USER") {
|
|
16
|
+
return HKEY_CURRENT_USER;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (hkey == "HKEY_LOCAL_MACHINE") {
|
|
20
|
+
return HKEY_LOCAL_MACHINE;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (hkey == "HKEY_CLASSES_ROOT") {
|
|
24
|
+
return HKEY_CLASSES_ROOT;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (hkey == "HKEY_USERS") {
|
|
28
|
+
return HKEY_USERS;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (hkey == "HKEY_CURRENT_CONFIG") {
|
|
32
|
+
return HKEY_CURRENT_CONFIG;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return NULL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
napi_value GetStringRegKey(napi_env env, napi_callback_info info) {
|
|
39
|
+
napi_value argv[3];
|
|
40
|
+
size_t argc = 3;
|
|
41
|
+
|
|
42
|
+
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
|
43
|
+
|
|
44
|
+
// Check that we have 3 arguments - Hive, Path, Name
|
|
45
|
+
if (argc < 3) {
|
|
46
|
+
napi_throw_error(env, "EINVAL", "Wrong number of arguments");
|
|
47
|
+
return nullptr;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Retrieve the 3 arguments
|
|
51
|
+
for (int i = 0; i < 3; i++) {
|
|
52
|
+
napi_valuetype value_type;
|
|
53
|
+
napi_typeof(env, argv[i], &value_type);
|
|
54
|
+
if (value_type != napi_string) {
|
|
55
|
+
napi_throw_error(env, "EINVAL", "Expected string");
|
|
56
|
+
return nullptr;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
size_t str_len = 0;
|
|
61
|
+
const int MAX_LEN = 16383;
|
|
62
|
+
|
|
63
|
+
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &str_len);
|
|
64
|
+
if (str_len + 1 > MAX_LEN) {
|
|
65
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
66
|
+
}
|
|
67
|
+
std::string hive_arg;
|
|
68
|
+
hive_arg.reserve(str_len + 1);
|
|
69
|
+
hive_arg.resize(str_len);
|
|
70
|
+
napi_get_value_string_utf8(env, argv[0], &hive_arg[0], hive_arg.capacity(), nullptr);
|
|
71
|
+
HKEY hive = GetHive(hive_arg);
|
|
72
|
+
|
|
73
|
+
napi_get_value_string_utf8(env, argv[1], nullptr, 0, &str_len);
|
|
74
|
+
if (str_len + 1 > MAX_LEN) {
|
|
75
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
76
|
+
}
|
|
77
|
+
std::string path;
|
|
78
|
+
path.reserve(str_len + 1);
|
|
79
|
+
path.resize(str_len);
|
|
80
|
+
napi_get_value_string_utf8(env, argv[1], &path[0], path.capacity(), nullptr);
|
|
81
|
+
|
|
82
|
+
napi_get_value_string_utf8(env, argv[2], nullptr, 0, &str_len);
|
|
83
|
+
if (str_len + 1 > MAX_LEN) {
|
|
84
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
85
|
+
}
|
|
86
|
+
std::string name;
|
|
87
|
+
name.reserve(str_len + 1);
|
|
88
|
+
name.resize(str_len);
|
|
89
|
+
napi_get_value_string_utf8(env, argv[2], &name[0], name.capacity(), nullptr);
|
|
90
|
+
|
|
91
|
+
if (hive == NULL) {
|
|
92
|
+
napi_throw_error(env, nullptr, "Unable to open registry hive");
|
|
93
|
+
return nullptr;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
std::string result;
|
|
97
|
+
HKEY hKey;
|
|
98
|
+
if (ERROR_SUCCESS != RegOpenKeyEx(hive, path.c_str(), 0, KEY_READ, &hKey)) {
|
|
99
|
+
napi_throw_error(env, nullptr, "Unable to open registry key");
|
|
100
|
+
return nullptr;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
char szBuffer[512];
|
|
104
|
+
DWORD dwBufferSize = sizeof(szBuffer);
|
|
105
|
+
|
|
106
|
+
if (ERROR_SUCCESS == RegQueryValueEx(hKey, name.c_str(), 0, NULL,
|
|
107
|
+
(LPBYTE)szBuffer, &dwBufferSize)) {
|
|
108
|
+
result = szBuffer;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
RegCloseKey(hKey);
|
|
112
|
+
|
|
113
|
+
napi_value napi_result;
|
|
114
|
+
napi_create_string_utf8(env, result.c_str(), result.length(), &napi_result);
|
|
115
|
+
|
|
116
|
+
return napi_result;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
napi_value GetDWORDRegKey(napi_env env, napi_callback_info info) {
|
|
120
|
+
napi_value argv[3];
|
|
121
|
+
size_t argc = 3;
|
|
122
|
+
|
|
123
|
+
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
|
124
|
+
|
|
125
|
+
// Check that we have 3 arguments - Hive, Path, Name
|
|
126
|
+
if (argc < 3) {
|
|
127
|
+
napi_throw_error(env, "EINVAL", "Wrong number of arguments");
|
|
128
|
+
return nullptr;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Retrieve the 3 arguments
|
|
132
|
+
for (int i = 0; i < 3; i++) {
|
|
133
|
+
napi_valuetype value_type;
|
|
134
|
+
napi_typeof(env, argv[i], &value_type);
|
|
135
|
+
if (value_type != napi_string) {
|
|
136
|
+
napi_throw_error(env, "EINVAL", "Expected string");
|
|
137
|
+
return nullptr;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
size_t str_len = 0;
|
|
142
|
+
const int MAX_LEN = 16383;
|
|
143
|
+
|
|
144
|
+
napi_get_value_string_utf8(env, argv[0], nullptr, 0, &str_len);
|
|
145
|
+
if (str_len + 1 > MAX_LEN) {
|
|
146
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
147
|
+
}
|
|
148
|
+
std::string hive_arg;
|
|
149
|
+
hive_arg.reserve(str_len + 1);
|
|
150
|
+
hive_arg.resize(str_len);
|
|
151
|
+
napi_get_value_string_utf8(env, argv[0], &hive_arg[0], hive_arg.capacity(), nullptr);
|
|
152
|
+
HKEY hive = GetHive(hive_arg);
|
|
153
|
+
|
|
154
|
+
napi_get_value_string_utf8(env, argv[1], nullptr, 0, &str_len);
|
|
155
|
+
if (str_len + 1 > MAX_LEN) {
|
|
156
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
157
|
+
}
|
|
158
|
+
std::string path;
|
|
159
|
+
path.reserve(str_len + 1);
|
|
160
|
+
path.resize(str_len);
|
|
161
|
+
napi_get_value_string_utf8(env, argv[1], &path[0], path.capacity(), nullptr);
|
|
162
|
+
|
|
163
|
+
napi_get_value_string_utf8(env, argv[2], nullptr, 0, &str_len);
|
|
164
|
+
if (str_len + 1 > MAX_LEN) {
|
|
165
|
+
napi_throw_error(env, "EINVAL", "Arguments too long");
|
|
166
|
+
}
|
|
167
|
+
std::string name;
|
|
168
|
+
name.reserve(str_len + 1);
|
|
169
|
+
name.resize(str_len);
|
|
170
|
+
napi_get_value_string_utf8(env, argv[2], &name[0], name.capacity(), nullptr);
|
|
171
|
+
|
|
172
|
+
if (hive == NULL) {
|
|
173
|
+
napi_throw_error(env, nullptr, "Unable to open registry hive");
|
|
174
|
+
return nullptr;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
HKEY hKey;
|
|
178
|
+
if (ERROR_SUCCESS != RegOpenKeyEx(hive, path.c_str(), 0, KEY_READ, &hKey)) {
|
|
179
|
+
napi_throw_error(env, nullptr, "Unable to open registry key");
|
|
180
|
+
return nullptr;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
DWORD dwValue = 0;
|
|
184
|
+
DWORD dwBufferSize = sizeof(dwValue);
|
|
185
|
+
DWORD dwType = 0;
|
|
186
|
+
LONG result = RegQueryValueEx(hKey, name.c_str(), 0, &dwType,
|
|
187
|
+
(LPBYTE)&dwValue, &dwBufferSize);
|
|
188
|
+
RegCloseKey(hKey);
|
|
189
|
+
|
|
190
|
+
if (result != ERROR_SUCCESS || dwType != REG_DWORD) {
|
|
191
|
+
return nullptr;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
napi_value napi_result;
|
|
195
|
+
napi_create_uint32(env, dwValue, &napi_result);
|
|
196
|
+
|
|
197
|
+
return napi_result;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
napi_value Init(napi_env env, napi_value exports) {
|
|
201
|
+
napi_value getStringRegKey;
|
|
202
|
+
napi_create_function(env, "GetStringRegKey", NAPI_AUTO_LENGTH,
|
|
203
|
+
GetStringRegKey, NULL, &getStringRegKey);
|
|
204
|
+
napi_set_named_property(env, exports, "GetStringRegKey", getStringRegKey);
|
|
205
|
+
|
|
206
|
+
napi_value getDWORDRegKey;
|
|
207
|
+
napi_create_function(env, "GetDWORDRegKey", NAPI_AUTO_LENGTH,
|
|
208
|
+
GetDWORDRegKey, NULL, &getDWORDRegKey);
|
|
209
|
+
napi_set_named_property(env, exports, "GetDWORDRegKey", getDWORDRegKey);
|
|
210
|
+
|
|
211
|
+
return exports;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init);
|
|
215
215
|
} // namespace
|
package/scripts/build-native.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Cross-platform native build script that checks for existing builds before rebuilding.
|
|
4
|
-
* Adapted from @photostructure/node-sqlite.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { execFileSync } from "node:child_process";
|
|
8
|
-
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if a valid native module exists (>2kB — enough to confirm it's not
|
|
13
|
-
* an empty stub, but well under any real winregistry.node build output).
|
|
14
|
-
*/
|
|
15
|
-
function findValidNativeModule(dir: string): boolean {
|
|
16
|
-
if (!existsSync(dir)) return false;
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const files = readdirSync(dir, {
|
|
20
|
-
recursive: true,
|
|
21
|
-
encoding: "utf8",
|
|
22
|
-
withFileTypes: false,
|
|
23
|
-
});
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
if (file.endsWith(".node")) {
|
|
26
|
-
const fullPath = join(dir, file as string);
|
|
27
|
-
const stats = statSync(fullPath);
|
|
28
|
-
if (stats.size > 2 * 1024) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
// Directory might not exist or be accessible
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Check for existing builds
|
|
40
|
-
if (findValidNativeModule("prebuilds")) {
|
|
41
|
-
console.log(
|
|
42
|
-
"Native module already built (found .node file > 2kB), skipping rebuild",
|
|
43
|
-
);
|
|
44
|
-
process.exit(0);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (findValidNativeModule("build/Release")) {
|
|
48
|
-
console.log("Native module already built in build/Release, skipping rebuild");
|
|
49
|
-
process.exit(0);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// No existing build found, run prebuildify
|
|
53
|
-
console.log("Building native module...");
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
// Extra args (e.g. --target, --arch) are forwarded to prebuildify for
|
|
57
|
-
// cross-compilation: `npm run build:native -- --arch arm64`
|
|
58
|
-
const args = process.argv.slice(2);
|
|
59
|
-
const prebuildifyArgs = [
|
|
60
|
-
"prebuildify",
|
|
61
|
-
"--napi",
|
|
62
|
-
"--tag-libc",
|
|
63
|
-
"--strip",
|
|
64
|
-
...args,
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
execFileSync("npx", prebuildifyArgs, {
|
|
68
|
-
stdio: "inherit",
|
|
69
|
-
shell: process.platform === "win32",
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (!findValidNativeModule("prebuilds")) {
|
|
73
|
-
console.error(
|
|
74
|
-
"Build failed: No valid native module found (expected .node file > 2kB)",
|
|
75
|
-
);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
console.log("Native module built successfully");
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error("Build failed:", (error as Error).message);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|