@swf2es/desktop 0.1.20 → 0.1.21

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.
Files changed (54) hide show
  1. package/dist/main/air-bridge.d.ts +7 -0
  2. package/dist/main/air-bridge.d.ts.map +1 -0
  3. package/dist/main/air-bridge.js +166 -0
  4. package/dist/main/air-bridge.js.map +1 -0
  5. package/dist/main/dialogs.d.ts +18 -0
  6. package/dist/main/dialogs.d.ts.map +1 -0
  7. package/dist/main/dialogs.js +128 -0
  8. package/dist/main/dialogs.js.map +1 -0
  9. package/dist/main/main.js +23 -788
  10. package/dist/main/main.js.map +1 -1
  11. package/dist/main/menu.d.ts +2 -0
  12. package/dist/main/menu.d.ts.map +1 -0
  13. package/dist/main/menu.js +80 -0
  14. package/dist/main/menu.js.map +1 -0
  15. package/dist/main/network-rules.d.ts +35 -0
  16. package/dist/main/network-rules.d.ts.map +1 -0
  17. package/dist/main/network-rules.js +167 -0
  18. package/dist/main/network-rules.js.map +1 -0
  19. package/dist/main/network-types.d.ts +131 -0
  20. package/dist/main/network-types.d.ts.map +1 -0
  21. package/dist/main/network-types.js +21 -0
  22. package/dist/main/network-types.js.map +1 -0
  23. package/dist/main/network.d.ts +1 -113
  24. package/dist/main/network.d.ts.map +1 -1
  25. package/dist/main/network.js +8 -181
  26. package/dist/main/network.js.map +1 -1
  27. package/dist/main/open.d.ts +55 -0
  28. package/dist/main/open.d.ts.map +1 -0
  29. package/dist/main/open.js +256 -0
  30. package/dist/main/open.js.map +1 -0
  31. package/dist/main/permissions.d.ts +17 -0
  32. package/dist/main/permissions.d.ts.map +1 -0
  33. package/dist/main/permissions.js +113 -0
  34. package/dist/main/permissions.js.map +1 -0
  35. package/dist/main/state.d.ts +17 -0
  36. package/dist/main/state.d.ts.map +1 -0
  37. package/dist/main/state.js +30 -0
  38. package/dist/main/state.js.map +1 -0
  39. package/dist/main/switches.d.ts +25 -0
  40. package/dist/main/switches.d.ts.map +1 -0
  41. package/dist/main/switches.js +69 -0
  42. package/dist/main/switches.js.map +1 -0
  43. package/package.json +7 -7
  44. package/src/main/air-bridge.ts +185 -0
  45. package/src/main/dialogs.ts +147 -0
  46. package/src/main/main.ts +51 -937
  47. package/src/main/menu.ts +84 -0
  48. package/src/main/network-rules.ts +199 -0
  49. package/src/main/network-types.ts +150 -0
  50. package/src/main/network.ts +30 -337
  51. package/src/main/open.ts +302 -0
  52. package/src/main/permissions.ts +135 -0
  53. package/src/main/state.ts +44 -0
  54. package/src/main/switches.ts +87 -0
@@ -0,0 +1,256 @@
1
+ // What plays, and opening it: a SWF by its path or its URL, or an AIR
2
+ // application by its descriptor, from the command line, the menu, a
3
+ // dialog or a drop; and closing it. Only this module changes what plays;
4
+ // the others read it.
5
+ import { statSync } from "node:fs";
6
+ import { open as openFile, realpath } from "node:fs/promises";
7
+ import { basename, dirname, join, resolve } from "node:path";
8
+ import { fileAttributes } from "@swf2es/format";
9
+ import { app, dialog, safeStorage } from "electron";
10
+ import { airLaunch, EncryptedItems } from "./air.js";
11
+ import { refuse } from "./dialogs.js";
12
+ import { buildMenu } from "./menu.js";
13
+ import { listening, sandbox, settings, TITLE, window } from "./state.js";
14
+ import { network } from "./switches.js";
15
+ /** What the network judges the movie playing as; null for none, or one without networking. */
16
+ export let networkMovie = null;
17
+ export let current = null;
18
+ /** The servers the SWF playing was allowed, or denied, a socket to until it closes: "host:port". */
19
+ export let allowedOnce = new Set();
20
+ export let deniedOnce = new Set();
21
+ /** The longest URL a SWF is opened by. */
22
+ const MAX_URL = 8192;
23
+ /** The AIR application playing, as its command line asked for it; null for none. */
24
+ export let air = null;
25
+ /** The EncryptedLocalStore of the AIR application playing, if one is. */
26
+ export let encryptedItems = null;
27
+ /**
28
+ * `text` as the URL of a remote SWF: http or https, with a host and no
29
+ * credentials, its fragment dropped; null if it is not one.
30
+ */
31
+ export function remoteUrl(text) {
32
+ if (text.length > MAX_URL) {
33
+ return null;
34
+ }
35
+ let url;
36
+ try {
37
+ url = new URL(text.trim());
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ if ((url.protocol !== "http:" && url.protocol !== "https:") || !url.hostname) {
43
+ return null;
44
+ }
45
+ if (url.username || url.password) {
46
+ return null;
47
+ }
48
+ url.hash = "";
49
+ return url;
50
+ }
51
+ /**
52
+ * The SWF named on a command line, from `cwd`: the last argument after the
53
+ * app's own that is an http or https URL or names a .swf file there is.
54
+ * Chromium's and Electron's switches may take values of their own
55
+ * (`--switch value`), so the first argument that is not a switch could be one.
56
+ */
57
+ export function movieFromArguments(argv, cwd = process.cwd()) {
58
+ const named = argv
59
+ .slice(process.defaultApp ? 2 : 1)
60
+ .filter((a) => !a.startsWith("-"))
61
+ .map((a) => remoteUrl(a)?.href ?? (/\.swf$/i.test(a) ? resolve(cwd, a) : null))
62
+ .filter((a) => a !== null);
63
+ return (named.reverse().find((a) => remoteUrl(a) || statSync(a, { throwIfNoEntry: false })?.isFile()) ??
64
+ null);
65
+ }
66
+ /**
67
+ * How much of a SWF the main process reads to choose its sandbox: far more than FileAttributes
68
+ * takes compressed.
69
+ */
70
+ const START = 64 * 1024;
71
+ const USE_NETWORK = 0x01;
72
+ /**
73
+ * The first `length` bytes of the file at `path`, or as many as it has, at least `least`; null
74
+ * otherwise.
75
+ */
76
+ export async function readStart(path, length, least = 8) {
77
+ try {
78
+ const file = await openFile(path);
79
+ try {
80
+ const bytes = new Uint8Array(length);
81
+ const { bytesRead } = await file.read(bytes, 0, length, 0);
82
+ return bytesRead >= Math.min(least, length) ? bytes.subarray(0, bytesRead) : null;
83
+ }
84
+ finally {
85
+ await file.close();
86
+ }
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ }
92
+ /** Open what the recent list, the command line or a reload names: a URL, a SWF's path or a descriptor's. */
93
+ export function openEntry(entry) {
94
+ if (remoteUrl(entry)) {
95
+ return openUrl(entry);
96
+ }
97
+ // A descriptor reopened from the recent list or a reload, with the arguments it was run with.
98
+ if (/\.xml$/i.test(entry)) {
99
+ return openAir(air?.descriptor === entry ? air : { descriptor: entry, root: null, arguments: [] }, process.cwd());
100
+ }
101
+ return open(entry);
102
+ }
103
+ /**
104
+ * Run the AIR application `command` names, as adl does: its content SWF in
105
+ * the window, at the descriptor's size, in AIR's application sandbox, with
106
+ * its launch (shared/api.ts AirLaunch), from `cwd`.
107
+ */
108
+ export async function openAir(command, cwd) {
109
+ const name = basename(command.descriptor);
110
+ let opened;
111
+ try {
112
+ opened = airLaunch(command, cwd, app.getPath("userData"), {
113
+ documents: app.getPath("documents"),
114
+ desktop: app.getPath("desktop"),
115
+ cache: app.getPath("temp"),
116
+ });
117
+ }
118
+ catch (error) {
119
+ refuse(`${name} could not be opened.`, String(error));
120
+ return;
121
+ }
122
+ const head = await readStart(opened.content, START);
123
+ const signature = head ? String.fromCharCode(...head.subarray(0, 3)) : "";
124
+ if (!head || (signature !== "FWS" && signature !== "CWS" && signature !== "ZWS")) {
125
+ refuse(`${name}'s content is not a SWF.`, opened.content);
126
+ return;
127
+ }
128
+ const content = await realpath(opened.content);
129
+ sandbox.playApplication(content);
130
+ air = command;
131
+ // Beside its storage directory, by its id, as AIR keeps it; encrypted by the system's keychain where it has one.
132
+ encryptedItems = new EncryptedItems(join(dirname(opened.launch.directories.applicationStorage), "EncryptedLocalStore"), safeStorage.isEncryptionAvailable()
133
+ ? {
134
+ encrypt: (text) => new Uint8Array(safeStorage.encryptString(text)),
135
+ decrypt: (data) => safeStorage.decryptString(Buffer.from(data)),
136
+ }
137
+ : null);
138
+ if (window && opened.width && opened.height) {
139
+ window.setSize(opened.width, opened.height);
140
+ }
141
+ // Played from app:/, as AIR plays it: its relative URLs, and loaderInfo.url, are the application's.
142
+ const url = `app:/${opened.relative
143
+ .split("/")
144
+ .filter((s) => s !== "")
145
+ .map(encodeURIComponent)
146
+ .join("/")}`;
147
+ show(command.descriptor, { url, name: opened.title, sandbox: "application", air: opened.launch }, { kind: "application" });
148
+ }
149
+ /** Play `movie` in the window, in place of what plays: what the user opened, as `entry`. */
150
+ function show(entry, movie, onNetwork) {
151
+ current = { path: entry, movie };
152
+ playOnNetwork(onNetwork);
153
+ allowedOnce = new Set();
154
+ deniedOnce = new Set();
155
+ settings.opened(entry);
156
+ buildMenu();
157
+ if (window) {
158
+ // An AIR application's window is its own: its title alone, as adl shows it.
159
+ window.setTitle(movie.air ? movie.name : `${movie.name} — ${TITLE}`);
160
+ if (listening) {
161
+ window.webContents.send("desktop:open", movie);
162
+ }
163
+ }
164
+ }
165
+ /**
166
+ * Play the SWF at `text`, an http or https URL, in Flash's remote sandbox:
167
+ * no local file, and the network as its origin's (network.ts). The page
168
+ * fetches it through the main process like anything it loads.
169
+ */
170
+ export async function openUrl(text) {
171
+ const url = remoteUrl(text);
172
+ if (!url) {
173
+ refuse("Only an http or https URL opens.", text.slice(0, 200));
174
+ return;
175
+ }
176
+ const last = url.pathname.split("/").pop() ?? "";
177
+ let name;
178
+ try {
179
+ name = decodeURIComponent(last) || url.host;
180
+ }
181
+ catch {
182
+ name = last;
183
+ }
184
+ air = null;
185
+ sandbox.playRemote(url.href);
186
+ show(url.href, { url: url.href, name, sandbox: "remote" }, { kind: "remote", url: url.href });
187
+ }
188
+ /**
189
+ * Open the file the user chose in the dialog, dropped on the window or
190
+ * opened with the app: an AIR application's descriptor (`.xml`) runs the
191
+ * application, anything else is played as a SWF.
192
+ */
193
+ export async function openChosen(path) {
194
+ if (!/\.xml$/i.test(path)) {
195
+ return open(path);
196
+ }
197
+ // An application has an installed program's reach, which a file chosen in
198
+ // passing should not get unasked: asked once, until it leaves the recent list.
199
+ if (window && !settings.settings.recent.includes(path)) {
200
+ const { response } = await dialog.showMessageBox(window, {
201
+ type: "question",
202
+ message: `Run ${basename(path)} as an AIR application?`,
203
+ detail: "An AIR application reads and writes your files and reaches the network unasked, as an installed program does. Run only one you trust.",
204
+ buttons: ["Run", "Cancel"],
205
+ defaultId: 1,
206
+ cancelId: 1,
207
+ });
208
+ if (response !== 0) {
209
+ return;
210
+ }
211
+ }
212
+ // Run from its own directory, with no arguments, as one started by its icon is.
213
+ return openAir({ descriptor: path, root: null, arguments: [] }, dirname(path));
214
+ }
215
+ /** Play the SWF at `path` in the window, in place of what plays, in its sandbox. */
216
+ async function open(path) {
217
+ const name = basename(path);
218
+ // Its start alone: the main process never decompresses a SWF whole, whose
219
+ // header may name 4 GB. FileAttributes, the first tag, lies in it.
220
+ const head = await readStart(path, START);
221
+ const signature = head ? String.fromCharCode(...head.subarray(0, 3)) : "";
222
+ if (!head || (signature !== "FWS" && signature !== "CWS" && signature !== "ZWS")) {
223
+ refuse(`${name} is not a SWF.`, path);
224
+ return;
225
+ }
226
+ const useNetwork = (fileAttributes(head) & USE_NETWORK) !== 0;
227
+ let url;
228
+ try {
229
+ air = null;
230
+ url = sandbox.play(path, useNetwork);
231
+ }
232
+ catch (error) {
233
+ // Gone, or unreadable, since it was read.
234
+ refuse(`${name} could not be opened.`, String(error));
235
+ return;
236
+ }
237
+ app.addRecentDocument(path);
238
+ show(path, { url, name, sandbox: useNetwork ? "localWithNetwork" : "localWithFile" }, useNetwork ? { kind: "local" } : null);
239
+ }
240
+ /** Judge requests for `movie` from now on: the last one's are aborted. */
241
+ function playOnNetwork(movie) {
242
+ networkMovie = movie;
243
+ network.play(movie);
244
+ }
245
+ export function closeMovie() {
246
+ current = null;
247
+ air = null;
248
+ sandbox.stop();
249
+ playOnNetwork(null);
250
+ buildMenu();
251
+ window?.setTitle(TITLE);
252
+ if (listening) {
253
+ window?.webContents.send("desktop:close");
254
+ }
255
+ }
256
+ //# sourceMappingURL=open.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open.js","sourceRoot":"","sources":["../../src/main/open.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,oEAAoE;AACpE,yEAAyE;AACzE,sBAAsB;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBA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AAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,GAAG,IAAI,CAAC;IACf,GAAG,GAAG,IAAI,CAAC;IACX,OAAO,CAAC,IAAI,EAAE,CAAC;IACf,aAAa,CAAC,IAAI,CAAC,CAAC;IACpB,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxB,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Whether the SWF playing may connect a socket to `host`:`port`, and where
3
+ * to: only with the network, and only as the user allows, once or always
4
+ * for that SWF, when it first asks for that server; and for a remote SWF,
5
+ * as that server's socket policy allows, at the address it came from.
6
+ * Denied where no one can be asked.
7
+ */
8
+ export declare function permitSocket(host: string, port: number): Promise<{
9
+ address?: string;
10
+ } | null>;
11
+ /**
12
+ * Whether what plays may open a WebSocket to `url`: an AIR application,
13
+ * unasked and anywhere, as AIR's application sandbox connects and as its
14
+ * sockets do here. air.net.WebSocket is AIR's alone, so nothing else has one.
15
+ */
16
+ export declare function permitWebSocket(url: string): boolean;
17
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/main/permissions.ts"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA4BtC;AAoED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAYpD"}
@@ -0,0 +1,113 @@
1
+ // Whether the SWF playing may open a socket or a WebSocket, and where to:
2
+ // the user asked once a server, and a remote SWF's socket policy.
3
+ import { dialog } from "electron";
4
+ import { allowedOnce, current, deniedOnce, networkMovie } from "./open.js";
5
+ import { sandbox, settings, window } from "./state.js";
6
+ import { network, proxiedWebSockets, proxy } from "./switches.js";
7
+ import { hasWebSocket } from "./websocket-connections.js";
8
+ /** The prompts on screen, by "host:port": a second connection there waits on the first's answer. */
9
+ const asking = new Map();
10
+ /**
11
+ * Whether the SWF playing may connect a socket to `host`:`port`, and where
12
+ * to: only with the network, and only as the user allows, once or always
13
+ * for that SWF, when it first asks for that server; and for a remote SWF,
14
+ * as that server's socket policy allows, at the address it came from.
15
+ * Denied where no one can be asked.
16
+ */
17
+ export async function permitSocket(host, port) {
18
+ // AIR's application sandbox connects where it likes, unasked, with no socket policy.
19
+ if (sandbox.application) {
20
+ return {};
21
+ }
22
+ const playing = current;
23
+ const swf = sandbox.swf;
24
+ const endpoint = `${host}:${port}`;
25
+ if (!playing || !swf || !sandbox.networkAllowed()) {
26
+ process.stderr.write(`swf2es: no socket to ${endpoint}: the SWF has no network\n`);
27
+ return null;
28
+ }
29
+ if (!(await allowedByUser(playing, swf, endpoint))) {
30
+ return null;
31
+ }
32
+ if (networkMovie?.kind !== "remote") {
33
+ return {};
34
+ }
35
+ try {
36
+ return { address: await network.socketAddress(host, port) };
37
+ }
38
+ catch (error) {
39
+ process.stderr.write(`swf2es: no socket to ${endpoint}: ${error.message}\n`);
40
+ return null;
41
+ }
42
+ }
43
+ /** Whether the user allows the SWF playing a socket to `endpoint`, asked once a server. */
44
+ async function allowedByUser(playing, swf, endpoint) {
45
+ if (settings.socketAllowed(swf, endpoint) || allowedOnce.has(endpoint)) {
46
+ return true;
47
+ }
48
+ if (deniedOnce.has(endpoint)) {
49
+ return false;
50
+ }
51
+ let answer = asking.get(endpoint);
52
+ if (!answer) {
53
+ answer = askForSocket(playing.movie.name, swf, endpoint).finally(() => asking.delete(endpoint));
54
+ asking.set(endpoint, answer);
55
+ }
56
+ return (await answer) && current === playing;
57
+ }
58
+ async function askForSocket(name, swf, endpoint) {
59
+ if (!window) {
60
+ return false;
61
+ }
62
+ const playing = current;
63
+ let response;
64
+ try {
65
+ ({ response } = await dialog.showMessageBox(window, {
66
+ type: "question",
67
+ message: `${name} asks to connect to ${endpoint}.`,
68
+ detail: "A socket lets the SWF send that server whatever it has. " +
69
+ "Allow it only for a server you trust.",
70
+ buttons: ["Allow Once", "Always Allow for This SWF", "Deny"],
71
+ defaultId: 2,
72
+ cancelId: 2,
73
+ noLink: true,
74
+ }));
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ if (current !== playing) {
80
+ return false;
81
+ }
82
+ switch (response) {
83
+ case 0:
84
+ allowedOnce.add(endpoint);
85
+ return true;
86
+ case 1:
87
+ if (!settings.allowSocket(swf, endpoint)) {
88
+ allowedOnce.add(endpoint);
89
+ }
90
+ return true;
91
+ default:
92
+ deniedOnce.add(endpoint);
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * Whether what plays may open a WebSocket to `url`: an AIR application,
98
+ * unasked and anywhere, as AIR's application sandbox connects and as its
99
+ * sockets do here. air.net.WebSocket is AIR's alone, so nothing else has one.
100
+ */
101
+ export function permitWebSocket(url) {
102
+ if (sandbox.application && hasWebSocket() && (!proxy || proxiedWebSockets)) {
103
+ return true;
104
+ }
105
+ const why = !sandbox.application
106
+ ? "only an AIR application has one"
107
+ : !hasWebSocket()
108
+ ? "this Electron has no WebSocket client"
109
+ : "this Electron's WebSocket cannot go through the proxy";
110
+ process.stderr.write(`swf2es: no WebSocket to ${url.slice(0, 2048)}: ${why}\n`);
111
+ return false;
112
+ }
113
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../src/main/permissions.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,kEAAkE;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,OAAO,E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AI,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { BrowserWindow, IpcMainEvent, IpcMainInvokeEvent } from "electron";
2
+ import { Sandbox } from "./sandbox.ts";
3
+ import type { SettingsFile } from "./settings.ts";
4
+ export declare const TITLE = "swf2es";
5
+ export declare const sandbox: Sandbox;
6
+ export declare let settings: SettingsFile;
7
+ export declare let window: BrowserWindow | null;
8
+ /**
9
+ * The page has asked to start and listens for what opens: until then, start() hands it the movie.
10
+ */
11
+ export declare let listening: boolean;
12
+ export declare function setWindow(created: BrowserWindow | null): void;
13
+ export declare function setSettings(read: SettingsFile): void;
14
+ export declare function setListening(now: boolean): void;
15
+ /** Whether a message comes from the window's own page, on swf2es://app/. */
16
+ export declare function trusted(event: IpcMainEvent | IpcMainInvokeEvent): boolean;
17
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/main/state.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,KAAK,WAAW,CAAC;AAE9B,eAAO,MAAM,OAAO,SAAgB,CAAC;AACrC,eAAO,IAAI,QAAQ,EAAE,YAAY,CAAC;AAClC,eAAO,IAAI,MAAM,EAAE,aAAa,GAAG,IAAW,CAAC;AAC/C;;GAEG;AACH,eAAO,IAAI,SAAS,SAAQ,CAAC;AAE7B,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAEpD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAE/C;AAED,4EAA4E;AAC5E,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,kBAAkB,GAAG,OAAO,CAUzE"}
@@ -0,0 +1,30 @@
1
+ import { APP_ORIGIN } from "./protocol.js";
2
+ import { Sandbox } from "./sandbox.js";
3
+ export const TITLE = "swf2es";
4
+ export const sandbox = new Sandbox();
5
+ export let settings;
6
+ export let window = null;
7
+ /**
8
+ * The page has asked to start and listens for what opens: until then, start() hands it the movie.
9
+ */
10
+ export let listening = false;
11
+ export function setWindow(created) {
12
+ window = created;
13
+ }
14
+ export function setSettings(read) {
15
+ settings = read;
16
+ }
17
+ export function setListening(now) {
18
+ listening = now;
19
+ }
20
+ /** Whether a message comes from the window's own page, on swf2es://app/. */
21
+ export function trusted(event) {
22
+ const frame = event.senderFrame;
23
+ return (window !== null &&
24
+ event.sender === window.webContents &&
25
+ frame !== null &&
26
+ frame.parent === null &&
27
+ // Node's URL gives a scheme it does not know no origin: compare the text.
28
+ frame.url.startsWith(`${APP_ORIGIN}/`));
29
+ }
30
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/main/state.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC;AAE9B,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AACrC,MAAM,CAAC,IAAI,QAAsB,CAAC;AAClC,MAAM,CAAC,IAAI,MAAM,GAAyB,IAAI,CAAC;AAC/C;;GAEG;AACH,MAAM,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC;AAE7B,MAAM,UAAU,SAAS,CAAC,OAA6B;IACrD,MAAM,GAAG,OAAO,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAkB;IAC5C,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,SAAS,GAAG,GAAG,CAAC;AAClB,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,OAAO,CAAC,KAAwC;IAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;IAChC,OAAO,CACL,MAAM,KAAK,IAAI;QACf,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW;QACnC,KAAK,KAAK,IAAI;QACd,KAAK,CAAC,MAAM,KAAK,IAAI;QACrB,0EAA0E;QAC1E,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,CACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Network } from "./network.ts";
2
+ import { type Opener } from "./websocket-connections.ts";
3
+ /** --trace: what the page logs, a SWF's trace() among it, goes to the terminal. */
4
+ export declare const trace: boolean;
5
+ export declare const logSockets: boolean;
6
+ export declare const netLog: ((line: string) => boolean) | null;
7
+ /**
8
+ * --proxy=<url>: what the SWF's requests, sockets and WebSockets go
9
+ * through. For this run alone, never kept, and said aloud, without its
10
+ * credentials. One that does not parse stops the app rather than letting
11
+ * it run without.
12
+ */
13
+ export declare const proxied: {
14
+ proxy: import("./proxy.ts").ProxyConfig;
15
+ } | {
16
+ error: string;
17
+ } | null;
18
+ export declare const proxy: import("./proxy.ts").ProxyConfig | null;
19
+ /** What --log-network adds to a line of a connection that went through the proxy. */
20
+ export declare const via: string;
21
+ export declare const warn: (message: string) => boolean;
22
+ export declare const network: Network;
23
+ export declare const proxiedWebSockets: unknown;
24
+ export declare const webSocketOpen: Opener | undefined;
25
+ //# sourceMappingURL=switches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switches.d.ts","sourceRoot":"","sources":["../../src/main/switches.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAEL,KAAK,MAAM,EAIZ,MAAM,4BAA4B,CAAC;AAEpC,mFAAmF;AACnF,eAAO,MAAM,KAAK,SAAmC,CAAC;AAGtD,eAAO,MAAM,UAAU,SAAyC,CAAC;AAEjE,eAAO,MAAM,MAAM,UAAuB,MAAM,oBAA6C,CAAC;AAoB9F;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;;QAAuC,CAAC;AAM5D,eAAO,MAAM,KAAK,yCAAyB,CAAC;AAO5C,qFAAqF;AACrF,eAAO,MAAM,GAAG,QAA4B,CAAC;AAC7C,eAAO,MAAM,IAAI,YAAa,MAAM,YAAiD,CAAC;AACtF,eAAO,MAAM,OAAO,SAAqD,CAAC;AAU1E,eAAO,MAAM,iBAAiB,SAAgE,CAAC;AAE/F,eAAO,MAAM,aAAa,EAAE,MAAM,GAAG,SAQtB,CAAC"}
@@ -0,0 +1,69 @@
1
+ // The command line's switches for this run alone, and what they make:
2
+ // --trace and the network's logs, --ignore-certificate-errors and --proxy,
3
+ // the network judged through them and what opens an AIR application's
4
+ // WebSockets. Each said on stderr as the app starts.
5
+ import { Network } from "./network.js";
6
+ import { unverifiedHosts } from "./network-rules.js";
7
+ import { describeProxy, proxyArgument } from "./proxy.js";
8
+ import { dispatchedOpener, proxiedDispatcher, unverifiedDispatcher, webSocketOpener, } from "./websocket-connections.js";
9
+ /** --trace: what the page logs, a SWF's trace() among it, goes to the terminal. */
10
+ export const trace = process.argv.includes("--trace");
11
+ // Each request and socket of the SWF's said on stderr: the page's DevTools show none of them.
12
+ // --log-sockets says what each socket sends and receives as well, and so the rest too.
13
+ export const logSockets = process.argv.includes("--log-sockets");
14
+ const logNetwork = logSockets || process.argv.includes("--log-network");
15
+ export const netLog = logNetwork ? (line) => process.stderr.write(`${line}\n`) : null;
16
+ /** The SWF's http and https requests, judged as Flash's sandboxes had them. */
17
+ /**
18
+ * --ignore-certificate-errors[=host,...]: HTTPS servers whose certificates go
19
+ * unchecked, for one's own with a certificate it signed itself. For this
20
+ * run alone, never kept, and said aloud: anyone on the way to such a host
21
+ * can read and change what the SWF loads from it.
22
+ */
23
+ const unverified = unverifiedHosts(process.argv.slice(1));
24
+ if (unverified) {
25
+ process.stderr.write(unverified.all
26
+ ? "swf2es: --ignore-certificate-errors: no HTTPS or WSS server's certificate is verified\n"
27
+ : `swf2es: --ignore-certificate-errors: certificates are not verified for ${unverified.hosts.join(", ") || "no host"}\n`);
28
+ }
29
+ const unverifiedHost = (host) => !!unverified && (unverified.all || unverified.hosts.includes(host.toLowerCase()));
30
+ /**
31
+ * --proxy=<url>: what the SWF's requests, sockets and WebSockets go
32
+ * through. For this run alone, never kept, and said aloud, without its
33
+ * credentials. One that does not parse stops the app rather than letting
34
+ * it run without.
35
+ */
36
+ export const proxied = proxyArgument(process.argv.slice(1));
37
+ if (proxied && "error" in proxied) {
38
+ process.stderr.write(`swf2es: ${proxied.error}\n`);
39
+ process.exit(2);
40
+ }
41
+ export const proxy = proxied?.proxy ?? null;
42
+ if (proxy) {
43
+ process.stderr.write(`swf2es: --proxy: the SWF's requests, sockets and WebSockets go through ${describeProxy(proxy)}\n`);
44
+ }
45
+ /** What --log-network adds to a line of a connection that went through the proxy. */
46
+ export const via = proxy ? " via proxy" : "";
47
+ export const warn = (message) => process.stderr.write(`swf2es: ${message}\n`);
48
+ export const network = new Network({ unverified: unverifiedHost, proxy });
49
+ // What opens an AIR application's WebSockets: the global's client, a wss: server's certificate
50
+ // unchecked where the switch names its host; or every one through the proxy.
51
+ const insecureWebSockets = unverified && !proxy ? unverifiedDispatcher() : null;
52
+ if (unverified && !proxy && !insecureWebSockets) {
53
+ process.stderr.write("swf2es: --ignore-certificate-errors: a WebSocket's certificate is verified all the same\n");
54
+ }
55
+ export const proxiedWebSockets = proxy ? proxiedDispatcher(proxy, unverifiedHost, warn) : null;
56
+ // Never past the proxy: where none can be made, no WebSocket opens.
57
+ export const webSocketOpen = proxy
58
+ ? proxiedWebSockets
59
+ ? dispatchedOpener(proxiedWebSockets)
60
+ : () => {
61
+ throw new Error("no WebSocket through the proxy");
62
+ }
63
+ : insecureWebSockets
64
+ ? webSocketOpener(unverifiedHost, insecureWebSockets)
65
+ : undefined;
66
+ if (proxy && !proxiedWebSockets) {
67
+ process.stderr.write("swf2es: --proxy: this Electron's WebSocket cannot go through a proxy\n");
68
+ }
69
+ //# sourceMappingURL=switches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switches.js","sourceRoot":"","sources":["../../src/main/switches.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,qDAAqD;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAEhB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,GAChB,MAAM,4BAA4B,CAAC;AAEpC,mFAAmF;AACnF,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACtD,8FAA8F;AAC9F,uFAAuF;AACvF,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AACjE,MAAM,UAAU,GAAG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9F,+EAA+E;AAC/E;;;;;GAKG;AACH,MAAM,UAAU,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,C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AAC;AACtF,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1E,+FAA+F;AAC/F,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,UAAU,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChF,IAAI,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAChD,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,2FAA2F,CAC5F,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/F,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAuB,KAAK;IACpD,CAAC,CAAC,iBAAiB;QACjB,CAAC,CAAC,gBAAgB,CAAC,iBAAiB,CAAC;QACrC,CAAC,CAAC,GAAG,EAAE;YACH,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;IACL,CAAC,CAAC,kBAAkB;QAClB,CAAC,CAAC,eAAe,CAAC,cAAc,EAAE,kBAAkB,CAAC;QACrD,CAAC,CAAC,SAAS,CAAC;AAChB,IAAI,KAAK,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAChC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;AACjG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swf2es/desktop",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "swf2es's desktop app: local and remote SWFs, and AIR applications, in an Electron window",
5
5
  "keywords": [
6
6
  "swf",
@@ -35,12 +35,12 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "electron": "44.10.2",
38
- "@swf2es/codegen": "0.1.20",
39
- "@swf2es/context3d": "0.1.20",
40
- "@swf2es/format": "0.1.20",
41
- "@swf2es/player": "0.1.20",
42
- "@swf2es/player-hosts": "0.1.20",
43
- "@swf2es/web": "0.1.20"
38
+ "@swf2es/codegen": "0.1.21",
39
+ "@swf2es/context3d": "0.1.21",
40
+ "@swf2es/format": "0.1.21",
41
+ "@swf2es/player": "0.1.21",
42
+ "@swf2es/player-hosts": "0.1.21",
43
+ "@swf2es/web": "0.1.21"
44
44
  },
45
45
  "scripts": {
46
46
  "fetch-electron": "node node_modules/electron/install.js",