Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
POS/scripts/check-native-runtime.js at develop · Posnic/POS · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Posnic
POS
Repository navigation
Code
Issues
396
(396)
Pull requests
14
(14)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
POS
/
scripts
/
check-native-runtime.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
123 lines (107 loc) · 4.7 KB
develop
Breadcrumbs
POS
/
scripts
/
check-native-runtime.js
Copy path
Top
File metadata and controls
Code
Blame
123 lines (107 loc) · 4.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict'
;
/*
* Every native binary we ship must be able to load on a clean Windows.
*
* Windows does not include the Visual C++ runtime. It arrives with Office,
* Visual Studio or another application that installed the redistributable, so
* a developer machine always has it and a shop's new till does not. A binary
* that imports it and cannot find it fails with 0xC0000135 before it can log
* anything - which is exactly how a customer install died in the field.
*
* This walks the packaged application, reads each PE binary's import table,
* and reports any that needs the runtime without a copy it can actually reach.
*
* node scripts/check-native-runtime.js [dist/win-unpacked]
*
* Windows searches, in order: the folder of the EXE that started the process,
* then system folders. A .node addon or a DLL is therefore resolved against
* the executable that loaded it, not against its own folder - which is why the
* check below asks where the owning executable lives.
*/
const
fs
=
require
(
'fs'
)
;
const
path
=
require
(
'path'
)
;
const
ROOT
=
path
.
join
(
__dirname
,
'..'
)
;
const
target
=
process
.
argv
[
2
]
||
path
.
join
(
ROOT
,
'dist'
,
'win-unpacked'
)
;
// Shipped by Windows itself since Windows 10, so importing these is fine.
const
OS_PROVIDED
=
/
^
(
a
p
i
-
m
s
-
w
i
n
-
|
k
e
r
n
e
l
3
2
|
a
d
v
a
p
i
3
2
|
u
s
e
r
3
2
|
g
d
i
3
2
|
s
h
e
l
l
3
2
|
o
l
e
3
2
|
o
l
e
a
u
t
3
2
|
w
s
2
_
3
2
|
c
r
y
p
t
3
2
|
b
c
r
y
p
t
|
s
e
c
u
r
3
2
|
d
b
g
h
e
l
p
|
v
e
r
s
i
o
n
|
w
i
n
m
m
|
p
s
a
p
i
|
i
p
h
l
p
a
p
i
|
n
e
t
a
p
i
3
2
|
u
s
e
r
e
n
v
|
d
n
s
a
p
i
|
w
l
d
a
p
3
2
|
s
h
l
w
a
p
i
|
c
o
m
d
l
g
3
2
|
c
o
m
c
t
l
3
2
|
i
m
m
3
2
|
s
e
t
u
p
a
p
i
|
p
o
w
r
p
r
o
f
|
d
w
m
a
p
i
|
u
x
t
h
e
m
e
|
r
p
c
r
t
4
|
m
s
v
c
r
t
|
n
t
d
l
l
|
w
i
n
h
t
t
p
|
w
i
n
i
n
e
t
|
c
f
g
m
g
r
3
2
|
p
r
o
p
s
y
s
|
d
b
g
c
o
r
e
|
d
3
d
|
d
x
g
i
|
h
i
d
|
u
s
p
1
0
|
n
o
r
m
a
l
i
z
|
m
s
w
s
o
c
k
|
m
p
r
|
w
i
n
s
p
o
o
l
)
/
i
;
// The Visual C++ runtime, which is not.
const
VC_RUNTIME
=
/
^
(
v
c
r
u
n
t
i
m
e
1
4
0
(
_
1
)
?
|
m
s
v
c
p
1
4
0
(
_
1
|
_
2
|
_
a
t
o
m
i
c
_
w
a
i
t
|
_
c
o
d
e
c
v
t
_
i
d
s
)
?
|
c
o
n
c
r
t
1
4
0
)
\.
d
l
l
$
/
i
;
function
peImports
(
file
)
{
let
buf
;
try
{
buf
=
fs
.
readFileSync
(
file
)
;
}
catch
{
return
null
;
}
if
(
buf
.
length
<
0x40
||
buf
.
readUInt16LE
(
0
)
!==
0x5a4d
)
return
null
;
// MZ
const
peOff
=
buf
.
readUInt32LE
(
0x3c
)
;
if
(
peOff
+
6
>
buf
.
length
||
buf
.
readUInt32LE
(
peOff
)
!==
0x00004550
)
return
null
;
// PE\0\0
const
machine
=
buf
.
readUInt16LE
(
peOff
+
4
)
;
// Import DLL names are plain ASCII in the binary. Parsing the full import
// directory means walking section headers to convert RVAs; scanning for the
// names is enough to answer "does this need the VC runtime", and cannot miss
// one that is present.
const
names
=
new
Set
(
)
;
const
text
=
buf
.
toString
(
'latin1'
)
;
for
(
const
m
of
text
.
matchAll
(
/
[
A
-
Z
a
-
z
0
-
9
_
.
\-
]
+
\.
d
l
l
/
g
)
)
names
.
add
(
m
[
0
]
.
toLowerCase
(
)
)
;
return
{
machine
,
names
:
[
...
names
]
}
;
}
function
walk
(
dir
,
out
=
[
]
)
{
let
entries
=
[
]
;
try
{
entries
=
fs
.
readdirSync
(
dir
,
{
withFileTypes
:
true
}
)
;
}
catch
{
return
out
;
}
for
(
const
e
of
entries
)
{
const
p
=
path
.
join
(
dir
,
e
.
name
)
;
if
(
e
.
isDirectory
(
)
)
walk
(
p
,
out
)
;
else
if
(
/
\.
(
e
x
e
|
d
l
l
|
n
o
d
e
)
$
/
i
.
test
(
e
.
name
)
)
out
.
push
(
p
)
;
}
return
out
;
}
function
main
(
)
{
if
(
!
fs
.
existsSync
(
target
)
)
{
console
.
log
(
`
${
path
.
relative
(
ROOT
,
target
)
}
does not exist; build first`
)
;
return
;
}
const
binaries
=
walk
(
target
)
;
const
problems
=
[
]
;
let
needing
=
0
;
for
(
const
file
of
binaries
)
{
const
pe
=
peImports
(
file
)
;
if
(
!
pe
)
continue
;
const
vc
=
pe
.
names
.
filter
(
(
n
)
=>
VC_RUNTIME
.
test
(
n
)
)
;
if
(
!
vc
.
length
)
continue
;
needing
++
;
/*
* Which folders will Windows search?
*
* An .exe resolves against its own folder. A .dll or .node resolves
* against the folder of the executable that loaded it - which for a
* satellite sitting beside an .exe is that same folder, and otherwise is
* the app root where the Electron binary lives. Both are allowed, because
* either one satisfies the loader.
*/
const
own
=
path
.
dirname
(
file
)
;
const
searchDirs
=
/
\.
e
x
e
$
/
i
.
test
(
file
)
?
[
own
]
:
[
own
,
target
]
;
const
unresolved
=
vc
.
filter
(
(
dll
)
=>
!
searchDirs
.
some
(
(
d
)
=>
fs
.
existsSync
(
path
.
join
(
d
,
dll
)
)
)
)
;
if
(
unresolved
.
length
)
{
problems
.
push
(
{
file
:
path
.
relative
(
target
,
file
)
,
searchDir
:
searchDirs
.
map
(
(
d
)
=>
path
.
relative
(
target
,
d
)
||
'.'
)
.
join
(
' or '
)
,
unresolved
,
}
)
;
}
}
console
.
log
(
` scanned
${
binaries
.
length
}
binaries,
${
needing
}
need the Visual C++ runtime\n`
)
;
if
(
!
problems
.
length
)
{
console
.
log
(
' every one of them can reach a bundled copy: this will start on a clean Windows'
)
;
return
;
}
console
.
log
(
' these would fail with 0xC0000135 on a machine without the runtime installed:\n'
)
;
for
(
const
p
of
problems
)
{
console
.
log
(
`
${
p
.
file
}
`
)
;
console
.
log
(
` looks in:
${
p
.
searchDir
}
`
)
;
console
.
log
(
` missing :
${
p
.
unresolved
.
join
(
', '
)
}
`
)
;
}
console
.
log
(
'\n run: node scripts/bundle-vc-runtime.js'
)
;
process
.
exit
(
1
)
;
}
main
(
)
;
You can’t perform that action at this time.