@swf2es/desktop 0.0.0-stage → 0.1.14
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 +202 -0
- package/README.md +132 -2
- package/dist/launch/electron.d.ts +14 -0
- package/dist/launch/electron.d.ts.map +1 -0
- package/dist/launch/electron.js +40 -0
- package/dist/launch/electron.js.map +1 -0
- package/dist/launch/launch.d.ts +3 -0
- package/dist/launch/launch.d.ts.map +1 -0
- package/dist/launch/launch.js +69 -0
- package/dist/launch/launch.js.map +1 -0
- package/dist/main/addresses.d.ts +7 -0
- package/dist/main/addresses.d.ts.map +1 -0
- package/dist/main/addresses.js +155 -0
- package/dist/main/addresses.js.map +1 -0
- package/dist/main/air.d.ts +71 -0
- package/dist/main/air.d.ts.map +1 -0
- package/dist/main/air.js +216 -0
- package/dist/main/air.js.map +1 -0
- package/dist/main/connections.d.ts +38 -0
- package/dist/main/connections.d.ts.map +1 -0
- package/dist/main/connections.js +103 -0
- package/dist/main/connections.js.map +1 -0
- package/dist/main/decompress.d.ts +51 -0
- package/dist/main/decompress.d.ts.map +1 -0
- package/dist/main/decompress.js +184 -0
- package/dist/main/decompress.js.map +1 -0
- package/dist/main/files.d.ts +9 -0
- package/dist/main/files.d.ts.map +1 -0
- package/dist/main/files.js +120 -0
- package/dist/main/files.js.map +1 -0
- package/dist/main/main.d.ts +2 -0
- package/dist/main/main.d.ts.map +1 -0
- package/dist/main/main.js +979 -0
- package/dist/main/main.js.map +1 -0
- package/dist/main/network.d.ts +182 -0
- package/dist/main/network.d.ts.map +1 -0
- package/dist/main/network.js +909 -0
- package/dist/main/network.js.map +1 -0
- package/dist/main/policy.d.ts +103 -0
- package/dist/main/policy.d.ts.map +1 -0
- package/dist/main/policy.js +481 -0
- package/dist/main/policy.js.map +1 -0
- package/dist/main/protocol.d.ts +14 -0
- package/dist/main/protocol.d.ts.map +1 -0
- package/dist/main/protocol.js +216 -0
- package/dist/main/protocol.js.map +1 -0
- package/dist/main/sandbox.d.ts +67 -0
- package/dist/main/sandbox.d.ts.map +1 -0
- package/dist/main/sandbox.js +182 -0
- package/dist/main/sandbox.js.map +1 -0
- package/dist/main/settings.d.ts +37 -0
- package/dist/main/settings.d.ts.map +1 -0
- package/dist/main/settings.js +88 -0
- package/dist/main/settings.js.map +1 -0
- package/dist/main/sockets.d.ts +10 -0
- package/dist/main/sockets.d.ts.map +1 -0
- package/dist/main/sockets.js +71 -0
- package/dist/main/sockets.js.map +1 -0
- package/dist/preload/preload.cjs +91 -0
- package/dist/preload/preload.cjs.map +1 -0
- package/dist/preload/preload.d.cts +2 -0
- package/dist/preload/preload.d.cts.map +1 -0
- package/dist/preload/prompt.cjs +12 -0
- package/dist/preload/prompt.cjs.map +1 -0
- package/dist/preload/prompt.d.cts +2 -0
- package/dist/preload/prompt.d.cts.map +1 -0
- package/dist/renderer/air.d.ts +14 -0
- package/dist/renderer/air.d.ts.map +1 -0
- package/dist/renderer/air.js +83 -0
- package/dist/renderer/air.js.map +1 -0
- package/dist/renderer/files.d.ts +4 -0
- package/dist/renderer/files.d.ts.map +1 -0
- package/dist/renderer/files.js +58 -0
- package/dist/renderer/files.js.map +1 -0
- package/dist/renderer/index.d.ts +7 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +126 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/network.d.ts +6 -0
- package/dist/renderer/network.d.ts.map +1 -0
- package/dist/renderer/network.js +39 -0
- package/dist/renderer/network.js.map +1 -0
- package/dist/renderer/open-url.d.ts +10 -0
- package/dist/renderer/open-url.d.ts.map +1 -0
- package/dist/renderer/open-url.js +38 -0
- package/dist/renderer/open-url.js.map +1 -0
- package/dist/renderer/sockets.d.ts +4 -0
- package/dist/renderer/sockets.d.ts.map +1 -0
- package/dist/renderer/sockets.js +36 -0
- package/dist/renderer/sockets.js.map +1 -0
- package/dist/renderer/stage3d.d.ts +3 -0
- package/dist/renderer/stage3d.d.ts.map +1 -0
- package/dist/renderer/stage3d.js +26 -0
- package/dist/renderer/stage3d.js.map +1 -0
- package/dist/shared/api.d.ts +205 -0
- package/dist/shared/api.d.ts.map +1 -0
- package/dist/shared/api.js +5 -0
- package/dist/shared/api.js.map +1 -0
- package/package.json +46 -3
- package/src/launch/electron.ts +44 -0
- package/src/launch/launch.ts +72 -0
- package/src/launch/tsconfig.json +14 -0
- package/src/main/addresses.ts +184 -0
- package/src/main/air.ts +275 -0
- package/src/main/connections.ts +125 -0
- package/src/main/decompress.ts +219 -0
- package/src/main/files.ts +147 -0
- package/src/main/main.ts +1146 -0
- package/src/main/network.ts +1205 -0
- package/src/main/policy.ts +630 -0
- package/src/main/protocol.ts +237 -0
- package/src/main/sandbox.ts +213 -0
- package/src/main/settings.ts +117 -0
- package/src/main/sockets.ts +81 -0
- package/src/main/tsconfig.json +15 -0
- package/src/preload/preload.cts +110 -0
- package/src/preload/prompt.cts +11 -0
- package/src/preload/tsconfig.json +12 -0
- package/src/renderer/air.ts +100 -0
- package/src/renderer/files.ts +65 -0
- package/src/renderer/index.ts +145 -0
- package/src/renderer/network.ts +56 -0
- package/src/renderer/open-url.ts +50 -0
- package/src/renderer/sockets.ts +42 -0
- package/src/renderer/stage3d.ts +27 -0
- package/src/renderer/tsconfig.json +17 -0
- package/src/shared/api.ts +204 -0
- package/src/shared/tsconfig.json +11 -0
- package/static/icon.png +0 -0
- package/static/index.html +22 -0
- package/static/open-url.html +21 -0
- package/static/style.css +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The swf2es authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,133 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @swf2es/desktop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
swf2es's desktop app: an Electron window that plays local SWFs, SWFs by
|
|
4
|
+
their http or https URL, and AIR applications, with the `<swf2es-player>`
|
|
5
|
+
element of `@swf2es/web`.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx @swf2es/desktop [options] [file.swf | https://host/movie.swf]
|
|
9
|
+
npx @swf2es/desktop [options] app.xml [root-dir] [-- arguments...]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Node 22.18 or later runs it. The first run downloads Electron's binary
|
|
13
|
+
(about 100 MB), once; installed, the command is `swf2es-desktop`. A
|
|
14
|
+
relative path is taken from the directory the command was run in.
|
|
15
|
+
|
|
16
|
+
In a checkout of the repository:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pnpm install && pnpm build
|
|
20
|
+
pnpm --filter @swf2es/desktop start [options] [file.swf | https://host/movie.swf]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`pnpm install` does not download Electron's binary (pnpm-workspace.yaml
|
|
24
|
+
lists electron under `ignoredBuiltDependencies`), so the rest of the
|
|
25
|
+
repository builds and tests without it. `start` downloads it the first
|
|
26
|
+
time, as the installed command does; `pnpm --filter @swf2es/desktop
|
|
27
|
+
fetch-electron` does so ahead, for the tests.
|
|
28
|
+
|
|
29
|
+
- **Open** a SWF with File › Open (Ctrl+O), by dropping it on the window,
|
|
30
|
+
by its http or https URL with File › Open URL (Ctrl+L), or on the
|
|
31
|
+
command line, a path or a URL, which also hands it to an app already
|
|
32
|
+
open; File › Open Recent lists the last ten, files and URLs. The
|
|
33
|
+
window takes the SWF's name. View › Reload Movie (Ctrl+R) starts it
|
|
34
|
+
again, View › Toggle Full Screen (F11) fills the screen, and File ›
|
|
35
|
+
Close Movie (Ctrl+W) stops it. Opening another SWF destroys the
|
|
36
|
+
player before the next starts.
|
|
37
|
+
- **Stage3D.** View › Stage3D (Experimental) opts in to Context3D playback.
|
|
38
|
+
It starts off, remembers the choice in `settings.json`, and restarts the
|
|
39
|
+
current movie when changed. The desktop loads the optional WebGL2 backend
|
|
40
|
+
only when enabled and uses the web element's composition, live AS3 Stage
|
|
41
|
+
layout and context recovery. If that module cannot load, playback continues
|
|
42
|
+
with the usual unavailable-context fallback and logs the cause. The saved
|
|
43
|
+
choice remains enabled. Each slot owns a separate WebGL2 context;
|
|
44
|
+
closing or reloading the movie releases its resources and browser contexts.
|
|
45
|
+
Each resource type has its own 4,096-resource count limit.
|
|
46
|
+
Buffer and texture byte allowances follow the shared backend's AIR-backed
|
|
47
|
+
limits, with separate host budgets for target attachments. Supported
|
|
48
|
+
formats and remaining gaps are in [Context3D](../../packages/context3d/README.md).
|
|
49
|
+
- **Libraries.** ActionScript 3 plays on the `builtin.abc` (avmplus',
|
|
50
|
+
MPL-2.0) and playerglobal that ship with the player, with nothing to set
|
|
51
|
+
up. File › Choose playerglobal.abc… plays on another playerglobal, such
|
|
52
|
+
as Flash Player's, in place of the app's own; the app keeps its path in
|
|
53
|
+
`settings.json` in Electron's user data directory.
|
|
54
|
+
- **Trace.** `--trace` prints what the page logs, a SWF's `trace()` among
|
|
55
|
+
it, to the terminal: trace lines to stdout, warnings and errors to stderr.
|
|
56
|
+
- **Certificates.** `--ignore-certificate-errors` leaves every HTTPS
|
|
57
|
+
server's certificate unverified for this run, and
|
|
58
|
+
`--ignore-certificate-errors=dev.test,localhost` those hosts' alone, on
|
|
59
|
+
any port: for a server of your own whose certificate it signed itself.
|
|
60
|
+
Whoever is between you and such a host can then read and change what the
|
|
61
|
+
SWF loads from it. It is never kept in the settings, and the app says on
|
|
62
|
+
stderr, each time it starts with it, which hosts go unverified. The page
|
|
63
|
+
itself has no network (the main process makes a SWF's requests), so
|
|
64
|
+
nothing but those requests is affected.
|
|
65
|
+
- **Sandbox.** A SWF plays in the sandbox Flash Player gave a local SWF,
|
|
66
|
+
by its FileAttributes' UseNetwork bit. Without it,
|
|
67
|
+
local-with-filesystem: it reads the files in its own directory and below
|
|
68
|
+
(only itself if that is your home directory, the one holding every
|
|
69
|
+
user's, a temporary directory or a drive's root; keep a SWF in a
|
|
70
|
+
directory of its own) and reaches no network, no socket and no page.
|
|
71
|
+
With it, local-with-networking: it reads no local file but itself, loads
|
|
72
|
+
content (images, sounds, SWFs) from the network, reads data only where
|
|
73
|
+
the server's `crossdomain.xml` grants every domain (`domain="*"`), as
|
|
74
|
+
Flash had it, and connects sockets as you allow. Only the SWF playing
|
|
75
|
+
has access; opening another or closing it takes it away. Its URL
|
|
76
|
+
(`loaderInfo.url`) does not tell where on the disk it is. A SWF opened
|
|
77
|
+
by its URL plays in Flash's remote sandbox: it reads no local file,
|
|
78
|
+
loads anything from its own origin, reads another's data only as that
|
|
79
|
+
site's `crossdomain.xml` grants its domain, and opens a socket only
|
|
80
|
+
where you allow it and the server's socket policy (port 843, or the
|
|
81
|
+
port itself) grants it.
|
|
82
|
+
- **Network.** A SWF's http and https requests go through the main
|
|
83
|
+
process, judged by Flash's rules and policy files rather than CORS, so
|
|
84
|
+
`http:` and servers without CORS work. No request carries your cookies
|
|
85
|
+
or credentials, and none reaches this machine or your local network
|
|
86
|
+
unless the SWF came from there or a policy file there grants it. That
|
|
87
|
+
is judged by address range, as a browser judges it: this machine's own
|
|
88
|
+
public address, or a LAN device's global IPv6 address, counts as the
|
|
89
|
+
internet, which any web page could reach too.
|
|
90
|
+
- **Sockets** (`flash.net.Socket`) connect over TCP through the main
|
|
91
|
+
process. The first connection to each server asks: Allow Once, Always
|
|
92
|
+
Allow for This SWF (remembered in `settings.json`) or Deny.
|
|
93
|
+
- **AIR applications** run by their descriptor (`app.xml`), as adl runs
|
|
94
|
+
them: its first window's content SWF, from the descriptor's directory
|
|
95
|
+
or the root directory given after it, at the descriptor's size and with
|
|
96
|
+
its title, the arguments after `--` handed to its InvokeEvent. It plays
|
|
97
|
+
with AIR's API (NativeApplication, the window, `flash.filesystem.File`)
|
|
98
|
+
in AIR's application sandbox: it is played from `app:/`, reads any
|
|
99
|
+
local file through File, FileStream and its `app:`, `app-storage:` and
|
|
100
|
+
`file:` URLs, writes any file but through its `app:` URLs, as AIR does,
|
|
101
|
+
and reaches the network and sockets without Flash's policy files or a
|
|
102
|
+
prompt, as an installed application does. Its storage directory is
|
|
103
|
+
under the app's user data, by its id, and its `EncryptedLocalStore`
|
|
104
|
+
beside it, encrypted by the system's keychain (Electron's
|
|
105
|
+
`safeStorage`) where there is one. Only the application playing has
|
|
106
|
+
that reach, and only while it plays; run one you trust, as you would
|
|
107
|
+
install it.
|
|
108
|
+
- **File dialogs** requested by AS2 or AS3 FileReference use native open
|
|
109
|
+
and save dialogs after a click or key. Uploads and downloads use the
|
|
110
|
+
same network permissions as other data requests.
|
|
111
|
+
- **Pages** a SWF with the network opens with navigateToURL go to
|
|
112
|
+
the system's browser, http and https only, one for each click or key in
|
|
113
|
+
the window.
|
|
114
|
+
|
|
115
|
+
## Layout
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
src/main/ the main process: window, menu, settings, swf2es://, sockets and the network
|
|
119
|
+
src/preload/ window.swf2esDesktop, the page's only way to the main process, and the
|
|
120
|
+
URL dialog's window.swf2esPrompt
|
|
121
|
+
src/renderer/ the page: the element, the welcome and library panels, the socket and
|
|
122
|
+
fetch hosts; and the URL dialog's page
|
|
123
|
+
src/shared/ api.ts, the types of window.swf2esDesktop
|
|
124
|
+
static/ index.html (with the page's import map), open-url.html and style.css
|
|
125
|
+
src/launch/ the swf2es-desktop command, and `start`: finds Electron, fetching its
|
|
126
|
+
binary the first time, and runs the app
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The page (`src/renderer`, `static`) knows the shell only through
|
|
130
|
+
`window.swf2esDesktop` (`src/shared/api.ts`), so another shell, Tauri
|
|
131
|
+
say, can serve the same page by giving the same API.
|
|
132
|
+
[docs/architecture/desktop.md](../../docs/architecture/desktop.md) has
|
|
133
|
+
the design, its security among it.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The app's folder: package.json, dist/ and static/. */
|
|
2
|
+
export declare const appRoot: string;
|
|
3
|
+
/**
|
|
4
|
+
* The Electron binary, or null where `pnpm install` skipped its download.
|
|
5
|
+
* Read from the package's path.txt and dist/, not by requiring it: its
|
|
6
|
+
* index.js downloads the binary when it is missing, which would make a
|
|
7
|
+
* check for it the download it is meant to avoid.
|
|
8
|
+
*/
|
|
9
|
+
export declare function electronBinary(): string | null;
|
|
10
|
+
/** The electron package's folder; throws where it is not installed. */
|
|
11
|
+
export declare function electronPackage(): string;
|
|
12
|
+
/** Why the app cannot start yet, or null. */
|
|
13
|
+
export declare function missing(): string | null;
|
|
14
|
+
//# sourceMappingURL=electron.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electron.d.ts","sourceRoot":"","sources":["../../src/launch/electron.ts"],"names":[],"mappings":"AAOA,yDAAyD;AACzD,eAAO,MAAM,OAAO,QAAoD,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAS9C;AAED,uEAAuE;AACvE,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,6CAA6C;AAC7C,wBAAgB,OAAO,IAAI,MAAM,GAAG,IAAI,CAUvC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Where Electron and the built app are, for launch.ts and the tests: from the
|
|
2
|
+
// checkout's src/launch or the package's dist/launch, the app two folders up.
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
/** The app's folder: package.json, dist/ and static/. */
|
|
8
|
+
export const appRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
9
|
+
/**
|
|
10
|
+
* The Electron binary, or null where `pnpm install` skipped its download.
|
|
11
|
+
* Read from the package's path.txt and dist/, not by requiring it: its
|
|
12
|
+
* index.js downloads the binary when it is missing, which would make a
|
|
13
|
+
* check for it the download it is meant to avoid.
|
|
14
|
+
*/
|
|
15
|
+
export function electronBinary() {
|
|
16
|
+
try {
|
|
17
|
+
const root = electronPackage();
|
|
18
|
+
const name = readFileSync(join(root, "path.txt"), "utf8");
|
|
19
|
+
const path = join(root, "dist", name);
|
|
20
|
+
return existsSync(path) ? path : null;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** The electron package's folder; throws where it is not installed. */
|
|
27
|
+
export function electronPackage() {
|
|
28
|
+
return dirname(createRequire(import.meta.url).resolve("electron/package.json"));
|
|
29
|
+
}
|
|
30
|
+
/** Why the app cannot start yet, or null. */
|
|
31
|
+
export function missing() {
|
|
32
|
+
if (!electronBinary()) {
|
|
33
|
+
return "Electron is not downloaded: run `pnpm --filter @swf2es/desktop fetch-electron` once.";
|
|
34
|
+
}
|
|
35
|
+
if (!existsSync(`${appRoot}dist/main/main.js`)) {
|
|
36
|
+
return "The app is not built: run `pnpm build`.";
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=electron.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electron.js","sourceRoot":"","sources":["../../src/launch/electron.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,8EAA8E;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,yDAAyD;AACzD,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACtC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe;IAC7B,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,OAAO;IACrB,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QACtB,OAAO,sFAAsF,CAAC;IAChG,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,mBAAmB,CAAC,EAAE,CAAC;QAC/C,OAAO,yCAAyC,CAAC;IACnD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../src/launch/launch.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Starts the desktop app in Electron, with a SWF if one is named: the
|
|
3
|
+
// swf2es-desktop command of the package npm installs, and a checkout's
|
|
4
|
+
// `start`.
|
|
5
|
+
//
|
|
6
|
+
// npx @swf2es/desktop [--trace] [file.swf | https://host/movie.swf]
|
|
7
|
+
// npx @swf2es/desktop [--trace] app.xml [root-dir] [-- arguments...]
|
|
8
|
+
// pnpm --filter @swf2es/desktop start ... the same, in a checkout
|
|
9
|
+
//
|
|
10
|
+
// A relative path is the caller's: from the directory the command was run
|
|
11
|
+
// in, which pnpm and npm name in INIT_CWD where they change it.
|
|
12
|
+
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
|
+
import { appRoot, electronBinary, electronPackage, missing } from "./electron.js";
|
|
16
|
+
// Electron's binary comes by its package's install script, which a package manager may not
|
|
17
|
+
// have run: pnpm runs none it was not told to, and a checkout's install skips this one. Then
|
|
18
|
+
// it is fetched now, once, as that script fetches it.
|
|
19
|
+
if (!electronBinary()) {
|
|
20
|
+
let install = "";
|
|
21
|
+
try {
|
|
22
|
+
install = join(electronPackage(), "install.js");
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Not installed at all: `missing` says so.
|
|
26
|
+
}
|
|
27
|
+
if (install && existsSync(install)) {
|
|
28
|
+
console.error("swf2es: downloading Electron, once...");
|
|
29
|
+
spawnSync(process.execPath, [install], { stdio: "inherit" });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const why = missing();
|
|
33
|
+
if (why) {
|
|
34
|
+
console.error(why);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
const cwd = process.env.INIT_CWD ?? process.cwd();
|
|
38
|
+
// Switches and URLs as they are; a path from where the command was run. What follows "--" is
|
|
39
|
+
// an AIR application's own arguments, as they are.
|
|
40
|
+
const given = process.argv.slice(2);
|
|
41
|
+
const end = given.indexOf("--");
|
|
42
|
+
const own = end < 0 ? given : given.slice(0, end);
|
|
43
|
+
const args = [
|
|
44
|
+
...own.map((a) => (a.startsWith("-") || /^https?:\/\//i.test(a) ? a : resolve(cwd, a))),
|
|
45
|
+
...(end < 0 ? [] : given.slice(end)),
|
|
46
|
+
];
|
|
47
|
+
// What the context menu's About item names: a checkout's commit, else the package's version.
|
|
48
|
+
let build = "";
|
|
49
|
+
try {
|
|
50
|
+
build = execFileSync("git", ["rev-parse", "--short=12", "HEAD"], {
|
|
51
|
+
cwd: appRoot,
|
|
52
|
+
encoding: "utf8",
|
|
53
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
54
|
+
}).trim();
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Not a checkout, or no git.
|
|
58
|
+
}
|
|
59
|
+
// An installed package may sit inside some other project's checkout: its commit is not the app's.
|
|
60
|
+
if (!build || appRoot.includes(`${join("node_modules", "@swf2es")}`)) {
|
|
61
|
+
build = JSON.parse(readFileSync(join(appRoot, "package.json"), "utf8")).version;
|
|
62
|
+
}
|
|
63
|
+
const env = { ...process.env, SWF2ES_DESKTOP_BUILD: build };
|
|
64
|
+
const child = spawn(electronBinary(), [appRoot, ...args], { stdio: "inherit", env });
|
|
65
|
+
child.on("exit", (code, signal) => process.exit(signal ? 1 : (code ?? 0)));
|
|
66
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
67
|
+
process.on(signal, () => child.kill(signal));
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=launch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch.js","sourceRoot":"","sources":["../../src/launch/launch.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type AddressClass = "public" | "private" | "loopback";
|
|
2
|
+
/** How private a class is: a request to a higher rank than its SWF's needs the target's word. */
|
|
3
|
+
export declare const RANK: Record<AddressClass, number>;
|
|
4
|
+
/** Where `address` is; null for one no request may reach, or for what is no IP address. */
|
|
5
|
+
export declare function addressClass(address: string): AddressClass | null;
|
|
6
|
+
export declare function badPort(port: number): boolean;
|
|
7
|
+
//# sourceMappingURL=addresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/main/addresses.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAE7D,iGAAiG;AACjG,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAA0C,CAAC;AAiJzF,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAQjE;AAeD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7C"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Where an IP address is, for the network the desktop app reaches for a
|
|
2
|
+
// SWF: on the internet, on a private network (a LAN, a link, a cloud's
|
|
3
|
+
// metadata service at 169.254.169.254), or on this machine. A SWF reaches
|
|
4
|
+
// a place more private than the one it came from only as that place's own
|
|
5
|
+
// policy file allows, as Chromium's Private Network Access asks a server
|
|
6
|
+
// there before a public page may. Some addresses no request may reach.
|
|
7
|
+
// Pure, so that node tests it (tests/desktop/network.test.ts).
|
|
8
|
+
import { isIPv4, isIPv6 } from "node:net";
|
|
9
|
+
/** How private a class is: a request to a higher rank than its SWF's needs the target's word. */
|
|
10
|
+
export const RANK = { public: 0, private: 1, loopback: 2 };
|
|
11
|
+
/** An IPv4 address as a number, or null. */
|
|
12
|
+
function ipv4(text) {
|
|
13
|
+
if (!isIPv4(text)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return text.split(".").reduce((n, part) => n * 256 + Number(part), 0);
|
|
17
|
+
}
|
|
18
|
+
const inV4 = (n, base, bits) => {
|
|
19
|
+
const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;
|
|
20
|
+
return (n & mask) >>> 0 === (ipv4(base) & mask) >>> 0;
|
|
21
|
+
};
|
|
22
|
+
function classOfV4(n) {
|
|
23
|
+
// This network, multicast, and the reserved block with broadcast: never a server.
|
|
24
|
+
if (inV4(n, "0.0.0.0", 8) || inV4(n, "224.0.0.0", 4) || inV4(n, "240.0.0.0", 4)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (inV4(n, "127.0.0.0", 8)) {
|
|
28
|
+
return "loopback";
|
|
29
|
+
}
|
|
30
|
+
const special = [
|
|
31
|
+
["10.0.0.0", 8],
|
|
32
|
+
// Carrier-grade NAT.
|
|
33
|
+
["100.64.0.0", 10],
|
|
34
|
+
// Link-local, where clouds keep their metadata service.
|
|
35
|
+
["169.254.0.0", 16],
|
|
36
|
+
["172.16.0.0", 12],
|
|
37
|
+
["192.0.0.0", 24],
|
|
38
|
+
// The documentation and benchmarking blocks, never on the internet.
|
|
39
|
+
["192.0.2.0", 24],
|
|
40
|
+
["192.168.0.0", 16],
|
|
41
|
+
["198.18.0.0", 15],
|
|
42
|
+
["198.51.100.0", 24],
|
|
43
|
+
["203.0.113.0", 24],
|
|
44
|
+
];
|
|
45
|
+
return special.some(([base, bits]) => inV4(n, base, bits)) ? "private" : "public";
|
|
46
|
+
}
|
|
47
|
+
/** An IPv6 address's 16 bytes, its zone dropped; null if it is not one. */
|
|
48
|
+
function ipv6(text) {
|
|
49
|
+
const address = text.replace(/%.*$/, "");
|
|
50
|
+
if (!isIPv6(address)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
let head = address;
|
|
54
|
+
let tail = "";
|
|
55
|
+
const bytes = new Uint8Array(16);
|
|
56
|
+
// A dotted IPv4 tail fills the last four bytes.
|
|
57
|
+
const dotted = /^(.*:)(\d+\.\d+\.\d+\.\d+)$/.exec(address);
|
|
58
|
+
let v4 = null;
|
|
59
|
+
if (dotted) {
|
|
60
|
+
v4 = ipv4(dotted[2]);
|
|
61
|
+
head = `${dotted[1]}0:0`;
|
|
62
|
+
}
|
|
63
|
+
const halves = head.split("::");
|
|
64
|
+
[head, tail] = [halves[0], halves[1] ?? ""];
|
|
65
|
+
const groups = (part) => (part === "" ? [] : part.split(":"));
|
|
66
|
+
const front = groups(head);
|
|
67
|
+
const back = groups(tail);
|
|
68
|
+
const all = [...front, ...Array(8 - front.length - back.length).fill("0"), ...back];
|
|
69
|
+
all.forEach((group, i) => {
|
|
70
|
+
const value = Number.parseInt(group, 16);
|
|
71
|
+
bytes[i * 2] = value >> 8;
|
|
72
|
+
bytes[i * 2 + 1] = value & 0xff;
|
|
73
|
+
});
|
|
74
|
+
if (v4 !== null) {
|
|
75
|
+
bytes.set([v4 >>> 24, (v4 >>> 16) & 0xff, (v4 >>> 8) & 0xff, v4 & 0xff], 12);
|
|
76
|
+
}
|
|
77
|
+
return bytes;
|
|
78
|
+
}
|
|
79
|
+
const v4At = (bytes, at) => ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
|
|
80
|
+
function startsWith(bytes, prefix, bits) {
|
|
81
|
+
for (let bit = 0; bit < bits; bit++) {
|
|
82
|
+
const byte = bit >> 3;
|
|
83
|
+
const mask = 0x80 >> (bit & 7);
|
|
84
|
+
if ((bytes[byte] & mask) !== ((prefix[byte] ?? 0) & mask)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
function classOfV6(bytes) {
|
|
91
|
+
const zero = (from, to) => bytes.subarray(from, to).every((b) => b === 0);
|
|
92
|
+
if (zero(0, 16)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (zero(0, 15) && bytes[15] === 1) {
|
|
96
|
+
return "loopback";
|
|
97
|
+
}
|
|
98
|
+
// An IPv4 address within, mapped, translated (RFC 2765's ::ffff:0:a.b.c.d),
|
|
99
|
+
// compatible, by NAT64 or by 6to4: that address's class.
|
|
100
|
+
if (zero(0, 10) && bytes[10] === 0xff && bytes[11] === 0xff) {
|
|
101
|
+
return classOfV4(v4At(bytes, 12));
|
|
102
|
+
}
|
|
103
|
+
if (zero(0, 8) && bytes[8] === 0xff && bytes[9] === 0xff && zero(10, 12)) {
|
|
104
|
+
return classOfV4(v4At(bytes, 12));
|
|
105
|
+
}
|
|
106
|
+
if (zero(0, 12)) {
|
|
107
|
+
return classOfV4(v4At(bytes, 12));
|
|
108
|
+
}
|
|
109
|
+
if (startsWith(bytes, [0, 0x64, 0xff, 0x9b], 96)) {
|
|
110
|
+
return classOfV4(v4At(bytes, 12));
|
|
111
|
+
}
|
|
112
|
+
if (startsWith(bytes, [0x20, 0x02], 16)) {
|
|
113
|
+
return classOfV4(v4At(bytes, 2));
|
|
114
|
+
}
|
|
115
|
+
// Multicast, and the discard block.
|
|
116
|
+
if (bytes[0] === 0xff || startsWith(bytes, [0x01, 0x00], 64)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const special = [
|
|
120
|
+
// Unique local, link-local and the old site-local.
|
|
121
|
+
[[0xfc], 7],
|
|
122
|
+
[[0xfe, 0x80], 10],
|
|
123
|
+
[[0xfe, 0xc0], 10],
|
|
124
|
+
// NAT64 for local use, Teredo, whose IPv4 address is hidden, and documentation.
|
|
125
|
+
[[0, 0x64, 0xff, 0x9b, 0, 1], 48],
|
|
126
|
+
[[0x20, 0x01, 0, 0], 32],
|
|
127
|
+
[[0x20, 0x01, 0x0d, 0xb8], 32],
|
|
128
|
+
];
|
|
129
|
+
return special.some(([prefix, bits]) => startsWith(bytes, prefix, bits)) ? "private" : "public";
|
|
130
|
+
}
|
|
131
|
+
/** Where `address` is; null for one no request may reach, or for what is no IP address. */
|
|
132
|
+
export function addressClass(address) {
|
|
133
|
+
const v4 = ipv4(address);
|
|
134
|
+
if (v4 !== null) {
|
|
135
|
+
return classOfV4(v4);
|
|
136
|
+
}
|
|
137
|
+
const v6 = ipv6(address.replace(/^\[(.*)\]$/, "$1"));
|
|
138
|
+
return v6 ? classOfV6(v6) : null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The ports the Fetch standard blocks, as browsers do, so that a request
|
|
142
|
+
* cannot speak HTTP to a mail, shell or name server; Flash in a browser
|
|
143
|
+
* went through the browser's network and met the same list.
|
|
144
|
+
*/
|
|
145
|
+
const BAD_PORTS = new Set([
|
|
146
|
+
1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79, 87, 95, 101, 102,
|
|
147
|
+
103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137, 139, 143, 161, 179, 389, 427, 465,
|
|
148
|
+
512, 513, 514, 515, 526, 530, 531, 532, 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993,
|
|
149
|
+
995, 1719, 1720, 1723, 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668,
|
|
150
|
+
6669, 6679, 6697, 10080,
|
|
151
|
+
]);
|
|
152
|
+
export function badPort(port) {
|
|
153
|
+
return BAD_PORTS.has(port);
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=addresses.js.map
|