@renovatebot/pgp 0.0.0-semantic-release
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 +201 -0
- package/README.md +3 -0
- package/dist/dotnet/.stamp +0 -0
- package/dist/dotnet/_framework/BouncyCastle.Cryptography.wasm +0 -0
- package/dist/dotnet/_framework/System.Collections.Concurrent.wasm +0 -0
- package/dist/dotnet/_framework/System.IO.Compression.wasm +0 -0
- package/dist/dotnet/_framework/System.Linq.wasm +0 -0
- package/dist/dotnet/_framework/System.Private.CoreLib.wasm +0 -0
- package/dist/dotnet/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/dist/dotnet/_framework/System.Security.Cryptography.wasm +0 -0
- package/dist/dotnet/_framework/blazor.boot.json +32 -0
- package/dist/dotnet/_framework/dotnet.js +4 -0
- package/dist/dotnet/_framework/dotnet.native.js +17 -0
- package/dist/dotnet/_framework/dotnet.native.wasm +0 -0
- package/dist/dotnet/_framework/dotnet.runtime.js +4 -0
- package/dist/dotnet/_framework/lib.wasm +0 -0
- package/dist/dotnet/_framework/supportFiles/0_runtimeconfig.bin +1 -0
- package/dist/dotnet/lib.runtimeconfig.json +45 -0
- package/dist/dotnet/main.mjs +20 -0
- package/dist/dotnet/package.json +1 -0
- package/dist/teavm/lib.js +2963 -0
- package/dist/teavm/lib.wasm +0 -0
- package/dist/teavm/lib.wasm-runtime.js +793 -0
- package/index.d.ts +11 -0
- package/package.json +44 -0
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Alexey Andreev.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
let globalsCache = new Map();
|
|
19
|
+
let stackDeobfuscator = null;
|
|
20
|
+
let exceptionFrameRegex = /.+:wasm-function\[[0-9]+]:0x([0-9a-f]+).*/;
|
|
21
|
+
let getGlobalName = function(name) {
|
|
22
|
+
let result = globalsCache.get(name);
|
|
23
|
+
if (typeof result === "undefined") {
|
|
24
|
+
result = new Function("return " + name + ";");
|
|
25
|
+
globalsCache.set(name, result);
|
|
26
|
+
}
|
|
27
|
+
return result();
|
|
28
|
+
}
|
|
29
|
+
let setGlobalName = function(name, value) {
|
|
30
|
+
new Function("value", name + " = value;")(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function defaults(imports, userExports) {
|
|
34
|
+
let context = {
|
|
35
|
+
exports: null,
|
|
36
|
+
userExports: userExports,
|
|
37
|
+
stackDeobfuscator: null
|
|
38
|
+
};
|
|
39
|
+
if (!hasStringBuiltins()) {
|
|
40
|
+
stringImports(imports);
|
|
41
|
+
}
|
|
42
|
+
dateImports(imports);
|
|
43
|
+
consoleImports(imports, context);
|
|
44
|
+
coreImports(imports, context);
|
|
45
|
+
jsoImports(imports, context);
|
|
46
|
+
imports.teavmMath = Math;
|
|
47
|
+
return {
|
|
48
|
+
supplyExports(exports) {
|
|
49
|
+
context.exports = exports;
|
|
50
|
+
},
|
|
51
|
+
supplyStackDeobfuscator(deobfuscator) {
|
|
52
|
+
context.stackDeobfuscator = deobfuscator;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let javaExceptionSymbol = Symbol("javaException");
|
|
58
|
+
class JavaError extends Error {
|
|
59
|
+
#context
|
|
60
|
+
|
|
61
|
+
constructor(context, javaException) {
|
|
62
|
+
super();
|
|
63
|
+
this.#context = context;
|
|
64
|
+
this[javaExceptionSymbol] = javaException;
|
|
65
|
+
context.exports["teavm.setJsException"](javaException, this);
|
|
66
|
+
}
|
|
67
|
+
get message() {
|
|
68
|
+
let exceptionMessage = this.#context.exports["teavm.exceptionMessage"];
|
|
69
|
+
if (typeof exceptionMessage === "function") {
|
|
70
|
+
let message = exceptionMessage(this[javaExceptionSymbol]);
|
|
71
|
+
if (message != null) {
|
|
72
|
+
return message;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return "(could not fetch message)";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function stringImports(imports) {
|
|
80
|
+
imports["wasm:js-string"] = {
|
|
81
|
+
fromCharCode: code => String.fromCharCode(code),
|
|
82
|
+
fromCharCodeArray: () => { throw new Error("Not supported"); },
|
|
83
|
+
intoCharCodeArray: () => { throw new Error("Not supported"); },
|
|
84
|
+
concat: (first, second) => first + second,
|
|
85
|
+
charCodeAt: (string, index) => string.charCodeAt(index),
|
|
86
|
+
length: s => s.length,
|
|
87
|
+
substring: (s, start, end) => s.substring(start, end)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function dateImports(imports) {
|
|
92
|
+
imports.teavmDate = {
|
|
93
|
+
currentTimeMillis: () => new Date().getTime(),
|
|
94
|
+
dateToString: timestamp => new Date(timestamp).toString(),
|
|
95
|
+
getYear: timestamp => new Date(timestamp).getFullYear(),
|
|
96
|
+
setYear(timestamp, year) {
|
|
97
|
+
let date = new Date(timestamp);
|
|
98
|
+
date.setFullYear(year);
|
|
99
|
+
return date.getTime();
|
|
100
|
+
},
|
|
101
|
+
getMonth: timestamp =>new Date(timestamp).getMonth(),
|
|
102
|
+
setMonth(timestamp, month) {
|
|
103
|
+
let date = new Date(timestamp);
|
|
104
|
+
date.setMonth(month);
|
|
105
|
+
return date.getTime();
|
|
106
|
+
},
|
|
107
|
+
getDate: timestamp =>new Date(timestamp).getDate(),
|
|
108
|
+
setDate(timestamp, value) {
|
|
109
|
+
let date = new Date(timestamp);
|
|
110
|
+
date.setDate(value);
|
|
111
|
+
return date.getTime();
|
|
112
|
+
},
|
|
113
|
+
create: (year, month, date, hrs, min, sec) => new Date(year, month, date, hrs, min, sec).getTime(),
|
|
114
|
+
createFromUTC: (year, month, date, hrs, min, sec) => Date.UTC(year, month, date, hrs, min, sec)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function consoleImports(imports) {
|
|
119
|
+
let stderr = "";
|
|
120
|
+
let stdout = "";
|
|
121
|
+
imports.teavmConsole = {
|
|
122
|
+
putcharStderr(c) {
|
|
123
|
+
if (c === 10) {
|
|
124
|
+
console.error(stderr);
|
|
125
|
+
stderr = "";
|
|
126
|
+
} else {
|
|
127
|
+
stderr += String.fromCharCode(c);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
putcharStdout(c) {
|
|
131
|
+
if (c === 10) {
|
|
132
|
+
console.log(stdout);
|
|
133
|
+
stdout = "";
|
|
134
|
+
} else {
|
|
135
|
+
stdout += String.fromCharCode(c);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function coreImports(imports, context) {
|
|
142
|
+
let finalizationRegistry = new FinalizationRegistry(heldValue => {
|
|
143
|
+
let report = context.exports["teavm.reportGarbageCollectedValue"];
|
|
144
|
+
if (typeof report !== "undefined") {
|
|
145
|
+
report(heldValue.queue, heldValue.ref);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
let stringFinalizationRegistry = new FinalizationRegistry(heldValue => {
|
|
149
|
+
let report = context.exports["teavm.reportGarbageCollectedString"];
|
|
150
|
+
if (typeof report === "function") {
|
|
151
|
+
report(heldValue);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
imports.teavm = {
|
|
155
|
+
createWeakRef(value, ref, queue) {
|
|
156
|
+
if (queue !== null) {
|
|
157
|
+
finalizationRegistry.register(value, { ref: ref, queue: queue });
|
|
158
|
+
}
|
|
159
|
+
return new WeakRef(value);
|
|
160
|
+
},
|
|
161
|
+
deref: weakRef => {
|
|
162
|
+
let result = weakRef.deref();
|
|
163
|
+
return result !== void 0 ? result : null;
|
|
164
|
+
},
|
|
165
|
+
createStringWeakRef(value, heldValue) {
|
|
166
|
+
stringFinalizationRegistry.register(value, heldValue)
|
|
167
|
+
return new WeakRef(value);
|
|
168
|
+
},
|
|
169
|
+
stringDeref: weakRef => weakRef.deref(),
|
|
170
|
+
takeStackTrace() {
|
|
171
|
+
let stack = new Error().stack;
|
|
172
|
+
let addresses = [];
|
|
173
|
+
for (let line of stack.split("\n")) {
|
|
174
|
+
let match = exceptionFrameRegex.exec(line);
|
|
175
|
+
if (match !== null && match.length >= 2) {
|
|
176
|
+
let address = parseInt(match[1], 16);
|
|
177
|
+
addresses.push(address);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
getStack() {
|
|
182
|
+
let result;
|
|
183
|
+
if (context.stackDeobfuscator) {
|
|
184
|
+
try {
|
|
185
|
+
result = context.stackDeobfuscator(addresses);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
console.warn("Could not deobfuscate stack", e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!result) {
|
|
191
|
+
result = addresses.map(address => {
|
|
192
|
+
return {
|
|
193
|
+
className: "java.lang.Throwable$FakeClass",
|
|
194
|
+
method: "fakeMethod",
|
|
195
|
+
file: "Throwable.java",
|
|
196
|
+
line: address
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
decorateException(javaException) {
|
|
205
|
+
new JavaError(context, javaException);
|
|
206
|
+
},
|
|
207
|
+
linearMemory() {
|
|
208
|
+
return context.exports["teavm.memory"].buffer;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function jsoImports(imports, context) {
|
|
214
|
+
let javaObjectSymbol = Symbol("javaObject");
|
|
215
|
+
let functionsSymbol = Symbol("functions");
|
|
216
|
+
let functionOriginSymbol = Symbol("functionOrigin");
|
|
217
|
+
let wrapperCallMarkerSymbol = Symbol("wrapperCallMarker");
|
|
218
|
+
|
|
219
|
+
let jsWrappers = new WeakMap();
|
|
220
|
+
let javaWrappers = new WeakMap();
|
|
221
|
+
let primitiveWrappers = new Map();
|
|
222
|
+
let primitiveFinalization = new FinalizationRegistry(token => primitiveWrappers.delete(token));
|
|
223
|
+
let hashCodes = new WeakMap();
|
|
224
|
+
let lastHashCode = 2463534242;
|
|
225
|
+
let nextHashCode = () => {
|
|
226
|
+
let x = lastHashCode;
|
|
227
|
+
x ^= x << 13;
|
|
228
|
+
x ^= x >>> 17;
|
|
229
|
+
x ^= x << 5;
|
|
230
|
+
lastHashCode = x;
|
|
231
|
+
return x;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function identity(value) {
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
function sanitizeName(str) {
|
|
238
|
+
let result = "";
|
|
239
|
+
let firstChar = str.charAt(0);
|
|
240
|
+
result += isIdentifierStart(firstChar) ? firstChar : '_';
|
|
241
|
+
for (let i = 1; i < str.length; ++i) {
|
|
242
|
+
let c = str.charAt(i)
|
|
243
|
+
result += isIdentifierPart(c) ? c : '_';
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
function isIdentifierStart(s) {
|
|
248
|
+
return s >= 'A' && s <= 'Z' || s >= 'a' && s <= 'z' || s === '_' || s === '$';
|
|
249
|
+
}
|
|
250
|
+
function isIdentifierPart(s) {
|
|
251
|
+
return isIdentifierStart(s) || s >= '0' && s <= '9';
|
|
252
|
+
}
|
|
253
|
+
function setProperty(obj, prop, value) {
|
|
254
|
+
if (obj === null) {
|
|
255
|
+
setGlobalName(prop, value);
|
|
256
|
+
} else {
|
|
257
|
+
obj[prop] = value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function javaExceptionToJs(e) {
|
|
261
|
+
if (e instanceof WebAssembly.Exception) {
|
|
262
|
+
let tag = context.exports["teavm.javaException"];
|
|
263
|
+
let getJsException = context.exports["teavm.getJsException"];
|
|
264
|
+
if (e.is(tag)) {
|
|
265
|
+
let javaException = e.getArg(tag, 0);
|
|
266
|
+
let extracted = extractException(javaException);
|
|
267
|
+
if (extracted !== null) {
|
|
268
|
+
return extracted;
|
|
269
|
+
}
|
|
270
|
+
let wrapper = getJsException(javaException);
|
|
271
|
+
if (typeof wrapper === "undefined") {
|
|
272
|
+
wrapper = new JavaError(context, javaException);
|
|
273
|
+
}
|
|
274
|
+
return wrapper;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return e;
|
|
278
|
+
}
|
|
279
|
+
function jsExceptionAsJava(e) {
|
|
280
|
+
if (javaExceptionSymbol in e) {
|
|
281
|
+
return e[javaExceptionSymbol];
|
|
282
|
+
} else {
|
|
283
|
+
return context.exports["teavm.js.wrapException"](e);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function rethrowJsAsJava(e) {
|
|
287
|
+
context.exports["teavm.js.throwException"](jsExceptionAsJava(e));
|
|
288
|
+
}
|
|
289
|
+
function extractException(e) {
|
|
290
|
+
return context.exports["teavm.js.extractException"](e);
|
|
291
|
+
}
|
|
292
|
+
function rethrowJavaAsJs(e) {
|
|
293
|
+
throw javaExceptionToJs(e);
|
|
294
|
+
}
|
|
295
|
+
function getProperty(obj, prop) {
|
|
296
|
+
try {
|
|
297
|
+
return obj !== null ? obj[prop] : getGlobalName(prop)
|
|
298
|
+
} catch (e) {
|
|
299
|
+
rethrowJsAsJava(e);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function defineFunction(fn) {
|
|
303
|
+
let params = [];
|
|
304
|
+
for (let i = 0; i < fn.length; ++i) {
|
|
305
|
+
params.push("p" + i);
|
|
306
|
+
}
|
|
307
|
+
let paramsAsString = params.length === 0 ? "" : params.join(", ");
|
|
308
|
+
return new Function("rethrowJavaAsJs", "fn",
|
|
309
|
+
`return function(${paramsAsString}) {\n` +
|
|
310
|
+
` try {\n` +
|
|
311
|
+
` return fn(${paramsAsString});\n` +
|
|
312
|
+
` } catch (e) {\n` +
|
|
313
|
+
` rethrowJavaAsJs(e);\n` +
|
|
314
|
+
` }\n` +
|
|
315
|
+
`};`
|
|
316
|
+
)(rethrowJavaAsJs, fn);
|
|
317
|
+
}
|
|
318
|
+
function renameConstructor(name, c) {
|
|
319
|
+
return new Function(
|
|
320
|
+
"constructor",
|
|
321
|
+
`return function ${name}(marker, javaObject) {\n` +
|
|
322
|
+
` return constructor.call(this, marker, javaObject);\n` +
|
|
323
|
+
`}\n`
|
|
324
|
+
)(c);
|
|
325
|
+
}
|
|
326
|
+
imports.teavmJso = {
|
|
327
|
+
stringBuiltinsSupported: () => hasStringBuiltins(),
|
|
328
|
+
isUndefined: o => typeof o === "undefined",
|
|
329
|
+
emptyArray: () => [],
|
|
330
|
+
appendToArray: (array, e) => array.push(e),
|
|
331
|
+
unwrapBoolean: value => value ? 1 : 0,
|
|
332
|
+
wrapBoolean: value => !!value,
|
|
333
|
+
getProperty: getProperty,
|
|
334
|
+
setProperty: setProperty,
|
|
335
|
+
setPropertyPure: setProperty,
|
|
336
|
+
global(name) {
|
|
337
|
+
try {
|
|
338
|
+
return getGlobalName(name);
|
|
339
|
+
} catch (e) {
|
|
340
|
+
rethrowJsAsJava(e);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
createClass(name, parent, constructor) {
|
|
344
|
+
name = sanitizeName(name || "JavaObject");
|
|
345
|
+
let action;
|
|
346
|
+
let fn = renameConstructor(name, function (marker, javaObject) {
|
|
347
|
+
if (marker === wrapperCallMarkerSymbol) {
|
|
348
|
+
action.call(this, javaObject);
|
|
349
|
+
} else if (constructor === null) {
|
|
350
|
+
throw new Error("This class can't be instantiated directly");
|
|
351
|
+
} else {
|
|
352
|
+
try {
|
|
353
|
+
return constructor.apply(null, arguments);
|
|
354
|
+
} catch (e) {
|
|
355
|
+
rethrowJavaAsJs(e);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
if (parent === null) {
|
|
360
|
+
action = function (javaObject) {
|
|
361
|
+
this[javaObjectSymbol] = javaObject;
|
|
362
|
+
this[functionsSymbol] = null;
|
|
363
|
+
};
|
|
364
|
+
} else {
|
|
365
|
+
action = function (javaObject) {
|
|
366
|
+
parent.call(this, javaObject);
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
fn.prototype = Object.create(parent ? parent.prototype : Object.prototype);
|
|
370
|
+
fn.prototype.constructor = fn;
|
|
371
|
+
let boundFn = renameConstructor(name, function(javaObject) {
|
|
372
|
+
return fn.call(this, wrapperCallMarkerSymbol, javaObject);
|
|
373
|
+
});
|
|
374
|
+
boundFn[wrapperCallMarkerSymbol] = fn;
|
|
375
|
+
boundFn.prototype = fn.prototype;
|
|
376
|
+
return boundFn;
|
|
377
|
+
},
|
|
378
|
+
exportClass(cls) {
|
|
379
|
+
return cls[wrapperCallMarkerSymbol];
|
|
380
|
+
},
|
|
381
|
+
defineMethod(cls, name, fn) {
|
|
382
|
+
let params = [];
|
|
383
|
+
for (let i = 1; i < fn.length; ++i) {
|
|
384
|
+
params.push("p" + i);
|
|
385
|
+
}
|
|
386
|
+
let paramsAsString = params.length === 0 ? "" : params.join(", ");
|
|
387
|
+
cls.prototype[name] = new Function("rethrowJavaAsJs", "fn",
|
|
388
|
+
`return function(${paramsAsString}) {\n` +
|
|
389
|
+
` try {\n` +
|
|
390
|
+
` return fn(${['this', params].join(", ")});\n` +
|
|
391
|
+
` } catch (e) {\n` +
|
|
392
|
+
` rethrowJavaAsJs(e);\n` +
|
|
393
|
+
` }\n` +
|
|
394
|
+
`};`
|
|
395
|
+
)(rethrowJavaAsJs, fn);
|
|
396
|
+
},
|
|
397
|
+
defineStaticMethod(cls, name, fn) {
|
|
398
|
+
cls[name] = defineFunction(fn);
|
|
399
|
+
},
|
|
400
|
+
defineFunction: defineFunction,
|
|
401
|
+
defineProperty(cls, name, getFn, setFn) {
|
|
402
|
+
let descriptor = {
|
|
403
|
+
get() {
|
|
404
|
+
try {
|
|
405
|
+
return getFn(this);
|
|
406
|
+
} catch (e) {
|
|
407
|
+
rethrowJavaAsJs(e);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
if (setFn !== null) {
|
|
412
|
+
descriptor.set = function(value) {
|
|
413
|
+
try {
|
|
414
|
+
setFn(this, value);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
rethrowJavaAsJs(e);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
Object.defineProperty(cls.prototype, name, descriptor);
|
|
421
|
+
},
|
|
422
|
+
defineStaticProperty(cls, name, getFn, setFn) {
|
|
423
|
+
let descriptor = {
|
|
424
|
+
get() {
|
|
425
|
+
try {
|
|
426
|
+
return getFn();
|
|
427
|
+
} catch (e) {
|
|
428
|
+
rethrowJavaAsJs(e);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
if (setFn !== null) {
|
|
433
|
+
descriptor.set = function(value) {
|
|
434
|
+
try {
|
|
435
|
+
setFn(value);
|
|
436
|
+
} catch (e) {
|
|
437
|
+
rethrowJavaAsJs(e);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
Object.defineProperty(cls, name, descriptor);
|
|
442
|
+
},
|
|
443
|
+
javaObjectToJS(instance, cls) {
|
|
444
|
+
if (instance === null) {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
let existing = jsWrappers.get(instance);
|
|
448
|
+
if (typeof existing != "undefined") {
|
|
449
|
+
let result = existing.deref();
|
|
450
|
+
if (typeof result !== "undefined") {
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
let obj = new cls(instance);
|
|
455
|
+
jsWrappers.set(instance, new WeakRef(obj));
|
|
456
|
+
return obj;
|
|
457
|
+
},
|
|
458
|
+
unwrapJavaObject(instance) {
|
|
459
|
+
return instance[javaObjectSymbol];
|
|
460
|
+
},
|
|
461
|
+
asFunction(instance, propertyName) {
|
|
462
|
+
let functions = instance[functionsSymbol];
|
|
463
|
+
if (functions === null) {
|
|
464
|
+
functions = Object.create(null);
|
|
465
|
+
instance[functionsSymbol] = functions;
|
|
466
|
+
}
|
|
467
|
+
let result = functions[propertyName];
|
|
468
|
+
if (typeof result !== 'function') {
|
|
469
|
+
result = function() {
|
|
470
|
+
return instance[propertyName].apply(instance, arguments);
|
|
471
|
+
}
|
|
472
|
+
result[functionOriginSymbol] = instance;
|
|
473
|
+
functions[propertyName] = result;
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
},
|
|
477
|
+
functionAsObject(fn, property) {
|
|
478
|
+
let origin = fn[functionOriginSymbol];
|
|
479
|
+
if (typeof origin !== 'undefined') {
|
|
480
|
+
let functions = origin[functionsSymbol];
|
|
481
|
+
if (functions !== void 0 && functions[property] === fn) {
|
|
482
|
+
return origin;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return {
|
|
486
|
+
[property]: function(...args) {
|
|
487
|
+
try {
|
|
488
|
+
return fn(...args);
|
|
489
|
+
} catch (e) {
|
|
490
|
+
rethrowJavaAsJs(e);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
},
|
|
495
|
+
wrapObject(obj) {
|
|
496
|
+
if (obj === null) {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
if (typeof obj === "object" || typeof obj === "function" || typeof "obj" === "symbol") {
|
|
500
|
+
let result = obj[javaObjectSymbol];
|
|
501
|
+
if (typeof result === "object") {
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
504
|
+
result = javaWrappers.get(obj);
|
|
505
|
+
if (result !== void 0) {
|
|
506
|
+
result = result.deref();
|
|
507
|
+
if (result !== void 0) {
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
result = context.exports["teavm.jso.createWrapper"](obj);
|
|
512
|
+
javaWrappers.set(obj, new WeakRef(result));
|
|
513
|
+
return result;
|
|
514
|
+
} else {
|
|
515
|
+
let result = primitiveWrappers.get(obj);
|
|
516
|
+
if (result !== void 0) {
|
|
517
|
+
result = result.deref();
|
|
518
|
+
if (result !== void 0) {
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
result = context.exports["teavm.jso.createWrapper"](obj);
|
|
523
|
+
primitiveWrappers.set(obj, new WeakRef(result));
|
|
524
|
+
primitiveFinalization.register(result, obj);
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
isPrimitive: (value, type) => typeof value === type,
|
|
529
|
+
instanceOf: (value, type) => value instanceof type,
|
|
530
|
+
instanceOfOrNull: (value, type) => value === null || value instanceof type,
|
|
531
|
+
sameRef: (a, b) => a === b,
|
|
532
|
+
hashCode: (obj) => {
|
|
533
|
+
if (typeof obj === "object" || typeof obj === "function" || typeof obj === "symbol") {
|
|
534
|
+
let code = hashCodes.get(obj);
|
|
535
|
+
if (typeof code === "number") {
|
|
536
|
+
return code;
|
|
537
|
+
}
|
|
538
|
+
code = nextHashCode();
|
|
539
|
+
hashCodes.set(obj, code);
|
|
540
|
+
return code;
|
|
541
|
+
} else if (typeof obj === "number") {
|
|
542
|
+
return obj | 0;
|
|
543
|
+
} else if (typeof obj === "bigint") {
|
|
544
|
+
return BigInt.asIntN(obj, 32);
|
|
545
|
+
} else if (typeof obj === "boolean") {
|
|
546
|
+
return obj ? 1 : 0;
|
|
547
|
+
} else {
|
|
548
|
+
return 0;
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
apply: (instance, method, args) => {
|
|
552
|
+
try {
|
|
553
|
+
if (instance === null) {
|
|
554
|
+
let fn = getGlobalName(method);
|
|
555
|
+
return fn(...args);
|
|
556
|
+
} else {
|
|
557
|
+
return instance[method](...args);
|
|
558
|
+
}
|
|
559
|
+
} catch (e) {
|
|
560
|
+
rethrowJsAsJava(e);
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
concatArray: (a, b) => [...a, ...b],
|
|
564
|
+
getJavaException: e => e[javaExceptionSymbol],
|
|
565
|
+
getJSException: e => {
|
|
566
|
+
let getJsException = context.exports["teavm.getJsException"]
|
|
567
|
+
return getJsException(e);
|
|
568
|
+
},
|
|
569
|
+
jsExports: () => context.userExports
|
|
570
|
+
};
|
|
571
|
+
for (let name of ["wrapByte", "wrapShort", "wrapChar", "wrapInt", "wrapLong", "wrapFloat", "wrapDouble",
|
|
572
|
+
"unwrapByte", "unwrapShort", "unwrapChar", "unwrapInt", "unwrapLong", "unwrapFloat", "unwrapDouble"]) {
|
|
573
|
+
imports.teavmJso[name] = identity;
|
|
574
|
+
}
|
|
575
|
+
function wrapCallFromJavaToJs(call) {
|
|
576
|
+
try {
|
|
577
|
+
return call();
|
|
578
|
+
} catch (e) {
|
|
579
|
+
rethrowJsAsJava(e);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
let argumentList = [];
|
|
583
|
+
for (let i = 0; i < 32; ++i) {
|
|
584
|
+
let args = argumentList.length === 0 ? "" : argumentList.join(", ");
|
|
585
|
+
let argsAndBody = [...argumentList, "body"].join(", ");
|
|
586
|
+
imports.teavmJso["createFunction" + i] = new Function("wrapCallFromJavaToJs", ...argumentList, "body",
|
|
587
|
+
`return new Function('wrapCallFromJavaToJs', ${argsAndBody}).bind(this, wrapCallFromJavaToJs);`
|
|
588
|
+
).bind(null, wrapCallFromJavaToJs);
|
|
589
|
+
imports.teavmJso["bindFunction" + i] = (f, ...args) => f.bind(null, ...args);
|
|
590
|
+
imports.teavmJso["callFunction" + i] = new Function("rethrowJsAsJava", "fn", ...argumentList,
|
|
591
|
+
`try {\n` +
|
|
592
|
+
` return fn(${args});\n` +
|
|
593
|
+
`} catch (e) {\n` +
|
|
594
|
+
` rethrowJsAsJava(e);\n` +
|
|
595
|
+
`}`
|
|
596
|
+
).bind(null, rethrowJsAsJava);
|
|
597
|
+
imports.teavmJso["callMethod" + i] = new Function("rethrowJsAsJava", "getGlobalName", "instance",
|
|
598
|
+
"method", ...argumentList,
|
|
599
|
+
`try {\n`+
|
|
600
|
+
` return instance !== null\n` +
|
|
601
|
+
` ? instance[method](${args})\n` +
|
|
602
|
+
` : getGlobalName(method)(${args});\n` +
|
|
603
|
+
`} catch (e) {\n` +
|
|
604
|
+
` rethrowJsAsJava(e);\n` +
|
|
605
|
+
`}`
|
|
606
|
+
).bind(null, rethrowJsAsJava, getGlobalName);
|
|
607
|
+
imports.teavmJso["construct" + i] = new Function("rethrowJsAsJava", "constructor", ...argumentList,
|
|
608
|
+
`try {\n` +
|
|
609
|
+
` return new constructor(${args});\n` +
|
|
610
|
+
`} catch (e) {\n` +
|
|
611
|
+
` rethrowJsAsJava(e);\n` +
|
|
612
|
+
`}`
|
|
613
|
+
).bind(null, rethrowJsAsJava);
|
|
614
|
+
imports.teavmJso["arrayOf" + i] = new Function(...argumentList, "return [" + args + "]");
|
|
615
|
+
|
|
616
|
+
let param = "p" + (i + 1);
|
|
617
|
+
argumentList.push(param);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function wrapImport(importObj) {
|
|
622
|
+
return new Proxy(importObj, {
|
|
623
|
+
get(target, prop) {
|
|
624
|
+
let result = target[prop];
|
|
625
|
+
return new WebAssembly.Global({ value: "externref", mutable: false }, result);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
async function wrapImports(wasmModule, imports) {
|
|
631
|
+
let promises = [];
|
|
632
|
+
let propertiesToAdd = {};
|
|
633
|
+
for (let { module, name, kind } of WebAssembly.Module.imports(wasmModule)) {
|
|
634
|
+
if (kind !== "global" || module in imports) {
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
let names = propertiesToAdd[module];
|
|
638
|
+
if (names === void 0) {
|
|
639
|
+
let namesByModule = [];
|
|
640
|
+
names = namesByModule;
|
|
641
|
+
propertiesToAdd[module] = names;
|
|
642
|
+
promises.push((async () => {
|
|
643
|
+
let moduleInstance = await import(module);
|
|
644
|
+
let importsByModule = {};
|
|
645
|
+
for (let name of namesByModule) {
|
|
646
|
+
let importedName = name === "__self__" ? moduleInstance : moduleInstance[name];
|
|
647
|
+
importsByModule[name] = new WebAssembly.Global(
|
|
648
|
+
{ value: "externref", mutable: false },
|
|
649
|
+
importedName
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
imports[module] = importsByModule;
|
|
653
|
+
})());
|
|
654
|
+
}
|
|
655
|
+
names.push(name);
|
|
656
|
+
}
|
|
657
|
+
if (promises.length === 0) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
await Promise.all(promises);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async function load(path, options) {
|
|
664
|
+
if (!options) {
|
|
665
|
+
options = {};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
let deobfuscatorOptions = options.stackDeobfuscator || {};
|
|
669
|
+
let debugInfoLocation = deobfuscatorOptions.infoLocation || "auto";
|
|
670
|
+
let [deobfuscatorFactory, module, debugInfo] = await Promise.all([
|
|
671
|
+
deobfuscatorOptions.enabled ? getDeobfuscator(path, deobfuscatorOptions) : Promise.resolve(null),
|
|
672
|
+
WebAssembly.compileStreaming(fetch(path), { builtins: ["js-string"] }),
|
|
673
|
+
fetchExternalDebugInfo(path, debugInfoLocation, deobfuscatorOptions)
|
|
674
|
+
]);
|
|
675
|
+
|
|
676
|
+
const importObj = {};
|
|
677
|
+
let userExports = {};
|
|
678
|
+
const defaultsResult = defaults(importObj, userExports);
|
|
679
|
+
if (typeof options.installImports !== "undefined") {
|
|
680
|
+
options.installImports(importObj);
|
|
681
|
+
}
|
|
682
|
+
if (!options.noAutoImports) {
|
|
683
|
+
await wrapImports(module, importObj);
|
|
684
|
+
}
|
|
685
|
+
let instance = await WebAssembly.instantiate(module, importObj);
|
|
686
|
+
|
|
687
|
+
defaultsResult.supplyExports(instance.exports);
|
|
688
|
+
if (deobfuscatorFactory) {
|
|
689
|
+
let moduleToPass = debugInfoLocation === "auto" || debugInfoLocation === "embedded" ? module : null;
|
|
690
|
+
let deobfuscator = createDeobfuscator(moduleToPass, debugInfo, deobfuscatorFactory);
|
|
691
|
+
if (deobfuscator !== null) {
|
|
692
|
+
defaultsResult.supplyStackDeobfuscator(deobfuscator);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
let teavm = {
|
|
696
|
+
exports: userExports,
|
|
697
|
+
instance: instance,
|
|
698
|
+
module: instance.module
|
|
699
|
+
};
|
|
700
|
+
for (let key in instance.exports) {
|
|
701
|
+
let exportObj = instance.exports[key];
|
|
702
|
+
if (exportObj instanceof WebAssembly.Global) {
|
|
703
|
+
Object.defineProperty(userExports, key, {
|
|
704
|
+
get: () => exportObj.value
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return teavm;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
let stringBuiltinsCache = null;
|
|
712
|
+
|
|
713
|
+
function hasStringBuiltins() {
|
|
714
|
+
if (stringBuiltinsCache === null) {
|
|
715
|
+
/*
|
|
716
|
+
(module
|
|
717
|
+
(type (func))
|
|
718
|
+
(import "wasm:js-string" "cast" (func (type 0)))
|
|
719
|
+
)
|
|
720
|
+
*/
|
|
721
|
+
let bytes = new Int8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 2, 23, 1, 14, 119, 97,
|
|
722
|
+
115, 109, 58, 106, 115, 45, 115, 116, 114, 105, 110, 103, 4, 99, 97, 115, 116, 0, 0, 3, 1, 0,
|
|
723
|
+
5, 4, 1, 1, 0, 0, 10, -127, -128, -128, 0, 0]);
|
|
724
|
+
stringBuiltinsCache = !WebAssembly.validate(bytes, {builtins: ["js-string"]});
|
|
725
|
+
}
|
|
726
|
+
return stringBuiltinsCache;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
async function getDeobfuscator(path, options) {
|
|
730
|
+
try {
|
|
731
|
+
const importObj = {};
|
|
732
|
+
const defaultsResult = defaults(importObj, {});
|
|
733
|
+
const deobfuscatorPath = options.path || path + "-deobfuscator.wasm";
|
|
734
|
+
const { instance } = await WebAssembly.instantiateStreaming(
|
|
735
|
+
fetch(deobfuscatorPath),
|
|
736
|
+
importObj,
|
|
737
|
+
{
|
|
738
|
+
builtins: ["js-string"]
|
|
739
|
+
}
|
|
740
|
+
);
|
|
741
|
+
defaultsResult.supplyExports(instance.exports)
|
|
742
|
+
return instance;
|
|
743
|
+
} catch (e) {
|
|
744
|
+
console.warn("Could not load deobfuscator", e);
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function createDeobfuscator(module, externalData, deobfuscatorFactory) {
|
|
750
|
+
let deobfuscator = null;
|
|
751
|
+
let deobfuscatorInitialized = false;
|
|
752
|
+
function ensureDeobfuscator() {
|
|
753
|
+
if (!deobfuscatorInitialized) {
|
|
754
|
+
deobfuscatorInitialized = true;
|
|
755
|
+
if (externalData !== null) {
|
|
756
|
+
try {
|
|
757
|
+
deobfuscator = deobfuscatorFactory.exports.createFromExternalFile.value(externalData);
|
|
758
|
+
} catch (e) {
|
|
759
|
+
console.warn("Could not load create deobfuscator", e);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (deobfuscator == null && module !== null) {
|
|
763
|
+
try {
|
|
764
|
+
deobfuscator = deobfuscatorFactory.exports.createForModule.value(module);
|
|
765
|
+
} catch (e) {
|
|
766
|
+
console.warn("Could not create deobfuscator from module data", e);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return addresses => {
|
|
772
|
+
ensureDeobfuscator();
|
|
773
|
+
return deobfuscator !== null ? deobfuscator.deobfuscate(addresses) : [];
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
async function fetchExternalDebugInfo(path, debugInfoLocation, options) {
|
|
778
|
+
if (!options.enabled) {
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
if (debugInfoLocation !== "auto" && debugInfoLocation !== "external") {
|
|
782
|
+
return null;
|
|
783
|
+
}
|
|
784
|
+
let location = options.externalInfoPath || path + ".teadbg";
|
|
785
|
+
let response = await fetch(location);
|
|
786
|
+
if (!response.ok) {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
return new Int8Array(await response.arrayBuffer());
|
|
790
|
+
}
|
|
791
|
+
export { load, defaults, wrapImport };
|
|
792
|
+
import fs from 'node:fs/promises';
|
|
793
|
+
const fetch = async (url) => new Response(await fs.readFile(url), { headers: { 'Content-Type': 'application/wasm' } });
|