nitro-patcher 0.1.0 → 0.2.1
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/README.md +2 -0
- package/dist/browser.d.ts +29 -1
- package/dist/browser.js +1459 -1431
- package/dist/browser.js.map +4 -4
- package/dist/{chunk-GFF67HX4.js → chunk-GLK3K2HY.js} +221 -282
- package/dist/chunk-GLK3K2HY.js.map +1 -0
- package/dist/{chunk-L7ZM4LLP.js → chunk-IGURDH5L.js} +254 -186
- package/dist/chunk-IGURDH5L.js.map +1 -0
- package/dist/cli.js +106 -26
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -3
- package/dist/nitro-helper.d.ts +78 -78
- package/dist/nitro-helper.js +1 -1
- package/dist/nitro-patch-helper.d.ts +38 -1
- package/dist/nitro-patch-helper.js +18 -4
- package/package.json +9 -2
- package/src/browser/buffer.ts +1 -1
- package/src/browser.ts +49 -4
- package/src/cli.ts +123 -37
- package/src/index.ts +2 -2
- package/src/nitro/banner.ts +28 -31
- package/src/nitro/binary.ts +6 -16
- package/src/nitro/blz.ts +13 -21
- package/src/nitro/crypto.ts +78 -84
- package/src/nitro/filesystem.ts +36 -39
- package/src/nitro/header.ts +58 -71
- package/src/nitro/nds-file.ts +44 -63
- package/src/nitro/twl.ts +59 -100
- package/src/nitro-helper.ts +14 -14
- package/src/nitro-patch-helper.ts +140 -29
- package/src/patch/xdelta.ts +43 -49
- package/src/patch/zip.ts +47 -56
- package/src/runtime/browser.ts +9 -11
- package/src/runtime/node.ts +14 -15
- package/dist/chunk-GFF67HX4.js.map +0 -1
- package/dist/chunk-L7ZM4LLP.js.map +0 -1
package/dist/browser.js
CHANGED
|
@@ -4,11 +4,20 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __esm = (fn, res) => function __init() {
|
|
8
|
-
|
|
7
|
+
var __esm = (fn, res, err2) => function __init() {
|
|
8
|
+
if (err2) throw err2[0];
|
|
9
|
+
try {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw err2 = [e], e;
|
|
13
|
+
}
|
|
9
14
|
};
|
|
10
15
|
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
-
|
|
16
|
+
try {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw mod = 0, e;
|
|
20
|
+
}
|
|
12
21
|
};
|
|
13
22
|
var __copyProps = (to, from, except, desc) => {
|
|
14
23
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -39,11 +48,11 @@ var require_base64_js = __commonJS({
|
|
|
39
48
|
var revLookup = [];
|
|
40
49
|
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
41
50
|
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
42
|
-
for (
|
|
43
|
-
lookup[
|
|
44
|
-
revLookup[code.charCodeAt(
|
|
51
|
+
for (i2 = 0, len = code.length; i2 < len; ++i2) {
|
|
52
|
+
lookup[i2] = code[i2];
|
|
53
|
+
revLookup[code.charCodeAt(i2)] = i2;
|
|
45
54
|
}
|
|
46
|
-
var
|
|
55
|
+
var i2;
|
|
47
56
|
var len;
|
|
48
57
|
revLookup["-".charCodeAt(0)] = 62;
|
|
49
58
|
revLookup["_".charCodeAt(0)] = 63;
|
|
@@ -74,19 +83,19 @@ var require_base64_js = __commonJS({
|
|
|
74
83
|
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
75
84
|
var curByte = 0;
|
|
76
85
|
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
77
|
-
var
|
|
78
|
-
for (
|
|
79
|
-
tmp = revLookup[b64.charCodeAt(
|
|
86
|
+
var i3;
|
|
87
|
+
for (i3 = 0; i3 < len2; i3 += 4) {
|
|
88
|
+
tmp = revLookup[b64.charCodeAt(i3)] << 18 | revLookup[b64.charCodeAt(i3 + 1)] << 12 | revLookup[b64.charCodeAt(i3 + 2)] << 6 | revLookup[b64.charCodeAt(i3 + 3)];
|
|
80
89
|
arr[curByte++] = tmp >> 16 & 255;
|
|
81
90
|
arr[curByte++] = tmp >> 8 & 255;
|
|
82
91
|
arr[curByte++] = tmp & 255;
|
|
83
92
|
}
|
|
84
93
|
if (placeHoldersLen === 2) {
|
|
85
|
-
tmp = revLookup[b64.charCodeAt(
|
|
94
|
+
tmp = revLookup[b64.charCodeAt(i3)] << 2 | revLookup[b64.charCodeAt(i3 + 1)] >> 4;
|
|
86
95
|
arr[curByte++] = tmp & 255;
|
|
87
96
|
}
|
|
88
97
|
if (placeHoldersLen === 1) {
|
|
89
|
-
tmp = revLookup[b64.charCodeAt(
|
|
98
|
+
tmp = revLookup[b64.charCodeAt(i3)] << 10 | revLookup[b64.charCodeAt(i3 + 1)] << 4 | revLookup[b64.charCodeAt(i3 + 2)] >> 2;
|
|
90
99
|
arr[curByte++] = tmp >> 8 & 255;
|
|
91
100
|
arr[curByte++] = tmp & 255;
|
|
92
101
|
}
|
|
@@ -98,8 +107,8 @@ var require_base64_js = __commonJS({
|
|
|
98
107
|
function encodeChunk(uint8, start, end) {
|
|
99
108
|
var tmp;
|
|
100
109
|
var output = [];
|
|
101
|
-
for (var
|
|
102
|
-
tmp = (uint8[
|
|
110
|
+
for (var i3 = start; i3 < end; i3 += 3) {
|
|
111
|
+
tmp = (uint8[i3] << 16 & 16711680) + (uint8[i3 + 1] << 8 & 65280) + (uint8[i3 + 2] & 255);
|
|
103
112
|
output.push(tripletToBase64(tmp));
|
|
104
113
|
}
|
|
105
114
|
return output.join("");
|
|
@@ -110,8 +119,8 @@ var require_base64_js = __commonJS({
|
|
|
110
119
|
var extraBytes = len2 % 3;
|
|
111
120
|
var parts = [];
|
|
112
121
|
var maxChunkLength = 16383;
|
|
113
|
-
for (var
|
|
114
|
-
parts.push(encodeChunk(uint8,
|
|
122
|
+
for (var i3 = 0, len22 = len2 - extraBytes; i3 < len22; i3 += maxChunkLength) {
|
|
123
|
+
parts.push(encodeChunk(uint8, i3, i3 + maxChunkLength > len22 ? len22 : i3 + maxChunkLength));
|
|
115
124
|
}
|
|
116
125
|
if (extraBytes === 1) {
|
|
117
126
|
tmp = uint8[len2 - 1];
|
|
@@ -139,19 +148,19 @@ var require_ieee754 = __commonJS({
|
|
|
139
148
|
var eMax = (1 << eLen) - 1;
|
|
140
149
|
var eBias = eMax >> 1;
|
|
141
150
|
var nBits = -7;
|
|
142
|
-
var
|
|
151
|
+
var i2 = isLE2 ? nBytes - 1 : 0;
|
|
143
152
|
var d = isLE2 ? -1 : 1;
|
|
144
|
-
var s = buffer[offset +
|
|
145
|
-
|
|
153
|
+
var s = buffer[offset + i2];
|
|
154
|
+
i2 += d;
|
|
146
155
|
e = s & (1 << -nBits) - 1;
|
|
147
156
|
s >>= -nBits;
|
|
148
157
|
nBits += eLen;
|
|
149
|
-
for (; nBits > 0; e = e * 256 + buffer[offset +
|
|
158
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
150
159
|
}
|
|
151
160
|
m = e & (1 << -nBits) - 1;
|
|
152
161
|
e >>= -nBits;
|
|
153
162
|
nBits += mLen;
|
|
154
|
-
for (; nBits > 0; m = m * 256 + buffer[offset +
|
|
163
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
155
164
|
}
|
|
156
165
|
if (e === 0) {
|
|
157
166
|
e = 1 - eBias;
|
|
@@ -169,7 +178,7 @@ var require_ieee754 = __commonJS({
|
|
|
169
178
|
var eMax = (1 << eLen) - 1;
|
|
170
179
|
var eBias = eMax >> 1;
|
|
171
180
|
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
172
|
-
var
|
|
181
|
+
var i2 = isLE2 ? 0 : nBytes - 1;
|
|
173
182
|
var d = isLE2 ? 1 : -1;
|
|
174
183
|
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
175
184
|
value = Math.abs(value);
|
|
@@ -202,13 +211,13 @@ var require_ieee754 = __commonJS({
|
|
|
202
211
|
e = 0;
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
|
-
for (; mLen >= 8; buffer[offset +
|
|
214
|
+
for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
|
|
206
215
|
}
|
|
207
216
|
e = e << mLen | m;
|
|
208
217
|
eLen += mLen;
|
|
209
|
-
for (; eLen > 0; buffer[offset +
|
|
218
|
+
for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
|
|
210
219
|
}
|
|
211
|
-
buffer[offset +
|
|
220
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
212
221
|
};
|
|
213
222
|
}
|
|
214
223
|
});
|
|
@@ -368,8 +377,8 @@ var require_buffer = __commonJS({
|
|
|
368
377
|
function fromArrayLike(array) {
|
|
369
378
|
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
370
379
|
const buf = createBuffer(length);
|
|
371
|
-
for (let
|
|
372
|
-
buf[
|
|
380
|
+
for (let i2 = 0; i2 < length; i2 += 1) {
|
|
381
|
+
buf[i2] = array[i2] & 255;
|
|
373
382
|
}
|
|
374
383
|
return buf;
|
|
375
384
|
}
|
|
@@ -442,17 +451,17 @@ var require_buffer = __commonJS({
|
|
|
442
451
|
);
|
|
443
452
|
}
|
|
444
453
|
if (a === b) return 0;
|
|
445
|
-
let
|
|
454
|
+
let x2 = a.length;
|
|
446
455
|
let y = b.length;
|
|
447
|
-
for (let
|
|
448
|
-
if (a[
|
|
449
|
-
|
|
450
|
-
y = b[
|
|
456
|
+
for (let i2 = 0, len = Math.min(x2, y); i2 < len; ++i2) {
|
|
457
|
+
if (a[i2] !== b[i2]) {
|
|
458
|
+
x2 = a[i2];
|
|
459
|
+
y = b[i2];
|
|
451
460
|
break;
|
|
452
461
|
}
|
|
453
462
|
}
|
|
454
|
-
if (
|
|
455
|
-
if (y <
|
|
463
|
+
if (x2 < y) return -1;
|
|
464
|
+
if (y < x2) return 1;
|
|
456
465
|
return 0;
|
|
457
466
|
};
|
|
458
467
|
Buffer3.isEncoding = function isEncoding(encoding) {
|
|
@@ -480,17 +489,17 @@ var require_buffer = __commonJS({
|
|
|
480
489
|
if (list.length === 0) {
|
|
481
490
|
return Buffer3.alloc(0);
|
|
482
491
|
}
|
|
483
|
-
let
|
|
492
|
+
let i2;
|
|
484
493
|
if (length === void 0) {
|
|
485
494
|
length = 0;
|
|
486
|
-
for (
|
|
487
|
-
length += list[
|
|
495
|
+
for (i2 = 0; i2 < list.length; ++i2) {
|
|
496
|
+
length += list[i2].length;
|
|
488
497
|
}
|
|
489
498
|
}
|
|
490
499
|
const buffer = Buffer3.allocUnsafe(length);
|
|
491
500
|
let pos = 0;
|
|
492
|
-
for (
|
|
493
|
-
let buf = list[
|
|
501
|
+
for (i2 = 0; i2 < list.length; ++i2) {
|
|
502
|
+
let buf = list[i2];
|
|
494
503
|
if (isInstance(buf, Uint8Array)) {
|
|
495
504
|
if (pos + buf.length > buffer.length) {
|
|
496
505
|
if (!Buffer3.isBuffer(buf)) buf = Buffer3.from(buf);
|
|
@@ -603,17 +612,17 @@ var require_buffer = __commonJS({
|
|
|
603
612
|
}
|
|
604
613
|
Buffer3.prototype._isBuffer = true;
|
|
605
614
|
function swap(b, n, m) {
|
|
606
|
-
const
|
|
615
|
+
const i2 = b[n];
|
|
607
616
|
b[n] = b[m];
|
|
608
|
-
b[m] =
|
|
617
|
+
b[m] = i2;
|
|
609
618
|
}
|
|
610
619
|
Buffer3.prototype.swap16 = function swap16() {
|
|
611
620
|
const len = this.length;
|
|
612
621
|
if (len % 2 !== 0) {
|
|
613
622
|
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
614
623
|
}
|
|
615
|
-
for (let
|
|
616
|
-
swap(this,
|
|
624
|
+
for (let i2 = 0; i2 < len; i2 += 2) {
|
|
625
|
+
swap(this, i2, i2 + 1);
|
|
617
626
|
}
|
|
618
627
|
return this;
|
|
619
628
|
};
|
|
@@ -622,9 +631,9 @@ var require_buffer = __commonJS({
|
|
|
622
631
|
if (len % 4 !== 0) {
|
|
623
632
|
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
624
633
|
}
|
|
625
|
-
for (let
|
|
626
|
-
swap(this,
|
|
627
|
-
swap(this,
|
|
634
|
+
for (let i2 = 0; i2 < len; i2 += 4) {
|
|
635
|
+
swap(this, i2, i2 + 3);
|
|
636
|
+
swap(this, i2 + 1, i2 + 2);
|
|
628
637
|
}
|
|
629
638
|
return this;
|
|
630
639
|
};
|
|
@@ -633,11 +642,11 @@ var require_buffer = __commonJS({
|
|
|
633
642
|
if (len % 8 !== 0) {
|
|
634
643
|
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
635
644
|
}
|
|
636
|
-
for (let
|
|
637
|
-
swap(this,
|
|
638
|
-
swap(this,
|
|
639
|
-
swap(this,
|
|
640
|
-
swap(this,
|
|
645
|
+
for (let i2 = 0; i2 < len; i2 += 8) {
|
|
646
|
+
swap(this, i2, i2 + 7);
|
|
647
|
+
swap(this, i2 + 1, i2 + 6);
|
|
648
|
+
swap(this, i2 + 2, i2 + 5);
|
|
649
|
+
swap(this, i2 + 3, i2 + 4);
|
|
641
650
|
}
|
|
642
651
|
return this;
|
|
643
652
|
};
|
|
@@ -701,20 +710,20 @@ var require_buffer = __commonJS({
|
|
|
701
710
|
thisStart >>>= 0;
|
|
702
711
|
thisEnd >>>= 0;
|
|
703
712
|
if (this === target) return 0;
|
|
704
|
-
let
|
|
713
|
+
let x2 = thisEnd - thisStart;
|
|
705
714
|
let y = end - start;
|
|
706
|
-
const len = Math.min(
|
|
715
|
+
const len = Math.min(x2, y);
|
|
707
716
|
const thisCopy = this.slice(thisStart, thisEnd);
|
|
708
717
|
const targetCopy = target.slice(start, end);
|
|
709
|
-
for (let
|
|
710
|
-
if (thisCopy[
|
|
711
|
-
|
|
712
|
-
y = targetCopy[
|
|
718
|
+
for (let i2 = 0; i2 < len; ++i2) {
|
|
719
|
+
if (thisCopy[i2] !== targetCopy[i2]) {
|
|
720
|
+
x2 = thisCopy[i2];
|
|
721
|
+
y = targetCopy[i2];
|
|
713
722
|
break;
|
|
714
723
|
}
|
|
715
724
|
}
|
|
716
|
-
if (
|
|
717
|
-
if (y <
|
|
725
|
+
if (x2 < y) return -1;
|
|
726
|
+
if (y < x2) return 1;
|
|
718
727
|
return 0;
|
|
719
728
|
};
|
|
720
729
|
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
@@ -776,36 +785,36 @@ var require_buffer = __commonJS({
|
|
|
776
785
|
byteOffset /= 2;
|
|
777
786
|
}
|
|
778
787
|
}
|
|
779
|
-
function read(buf,
|
|
788
|
+
function read(buf, i3) {
|
|
780
789
|
if (indexSize === 1) {
|
|
781
|
-
return buf[
|
|
790
|
+
return buf[i3];
|
|
782
791
|
} else {
|
|
783
|
-
return buf.readUInt16BE(
|
|
792
|
+
return buf.readUInt16BE(i3 * indexSize);
|
|
784
793
|
}
|
|
785
794
|
}
|
|
786
|
-
let
|
|
795
|
+
let i2;
|
|
787
796
|
if (dir) {
|
|
788
797
|
let foundIndex = -1;
|
|
789
|
-
for (
|
|
790
|
-
if (read(arr,
|
|
791
|
-
if (foundIndex === -1) foundIndex =
|
|
792
|
-
if (
|
|
798
|
+
for (i2 = byteOffset; i2 < arrLength; i2++) {
|
|
799
|
+
if (read(arr, i2) === read(val, foundIndex === -1 ? 0 : i2 - foundIndex)) {
|
|
800
|
+
if (foundIndex === -1) foundIndex = i2;
|
|
801
|
+
if (i2 - foundIndex + 1 === valLength) return foundIndex * indexSize;
|
|
793
802
|
} else {
|
|
794
|
-
if (foundIndex !== -1)
|
|
803
|
+
if (foundIndex !== -1) i2 -= i2 - foundIndex;
|
|
795
804
|
foundIndex = -1;
|
|
796
805
|
}
|
|
797
806
|
}
|
|
798
807
|
} else {
|
|
799
808
|
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
800
|
-
for (
|
|
809
|
+
for (i2 = byteOffset; i2 >= 0; i2--) {
|
|
801
810
|
let found = true;
|
|
802
811
|
for (let j = 0; j < valLength; j++) {
|
|
803
|
-
if (read(arr,
|
|
812
|
+
if (read(arr, i2 + j) !== read(val, j)) {
|
|
804
813
|
found = false;
|
|
805
814
|
break;
|
|
806
815
|
}
|
|
807
816
|
}
|
|
808
|
-
if (found) return
|
|
817
|
+
if (found) return i2;
|
|
809
818
|
}
|
|
810
819
|
}
|
|
811
820
|
return -1;
|
|
@@ -834,13 +843,13 @@ var require_buffer = __commonJS({
|
|
|
834
843
|
if (length > strLen / 2) {
|
|
835
844
|
length = strLen / 2;
|
|
836
845
|
}
|
|
837
|
-
let
|
|
838
|
-
for (
|
|
839
|
-
const parsed = parseInt(string.substr(
|
|
840
|
-
if (numberIsNaN(parsed)) return
|
|
841
|
-
buf[offset +
|
|
846
|
+
let i2;
|
|
847
|
+
for (i2 = 0; i2 < length; ++i2) {
|
|
848
|
+
const parsed = parseInt(string.substr(i2 * 2, 2), 16);
|
|
849
|
+
if (numberIsNaN(parsed)) return i2;
|
|
850
|
+
buf[offset + i2] = parsed;
|
|
842
851
|
}
|
|
843
|
-
return
|
|
852
|
+
return i2;
|
|
844
853
|
}
|
|
845
854
|
function utf8Write(buf, string, offset, length) {
|
|
846
855
|
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
@@ -925,12 +934,12 @@ var require_buffer = __commonJS({
|
|
|
925
934
|
function utf8Slice(buf, start, end) {
|
|
926
935
|
end = Math.min(buf.length, end);
|
|
927
936
|
const res = [];
|
|
928
|
-
let
|
|
929
|
-
while (
|
|
930
|
-
const firstByte = buf[
|
|
937
|
+
let i2 = start;
|
|
938
|
+
while (i2 < end) {
|
|
939
|
+
const firstByte = buf[i2];
|
|
931
940
|
let codePoint = null;
|
|
932
941
|
let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
|
|
933
|
-
if (
|
|
942
|
+
if (i2 + bytesPerSequence <= end) {
|
|
934
943
|
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
935
944
|
switch (bytesPerSequence) {
|
|
936
945
|
case 1:
|
|
@@ -939,7 +948,7 @@ var require_buffer = __commonJS({
|
|
|
939
948
|
}
|
|
940
949
|
break;
|
|
941
950
|
case 2:
|
|
942
|
-
secondByte = buf[
|
|
951
|
+
secondByte = buf[i2 + 1];
|
|
943
952
|
if ((secondByte & 192) === 128) {
|
|
944
953
|
tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
|
|
945
954
|
if (tempCodePoint > 127) {
|
|
@@ -948,8 +957,8 @@ var require_buffer = __commonJS({
|
|
|
948
957
|
}
|
|
949
958
|
break;
|
|
950
959
|
case 3:
|
|
951
|
-
secondByte = buf[
|
|
952
|
-
thirdByte = buf[
|
|
960
|
+
secondByte = buf[i2 + 1];
|
|
961
|
+
thirdByte = buf[i2 + 2];
|
|
953
962
|
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
|
|
954
963
|
tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
|
|
955
964
|
if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
|
|
@@ -958,9 +967,9 @@ var require_buffer = __commonJS({
|
|
|
958
967
|
}
|
|
959
968
|
break;
|
|
960
969
|
case 4:
|
|
961
|
-
secondByte = buf[
|
|
962
|
-
thirdByte = buf[
|
|
963
|
-
fourthByte = buf[
|
|
970
|
+
secondByte = buf[i2 + 1];
|
|
971
|
+
thirdByte = buf[i2 + 2];
|
|
972
|
+
fourthByte = buf[i2 + 3];
|
|
964
973
|
if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
|
|
965
974
|
tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
|
|
966
975
|
if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
|
|
@@ -978,7 +987,7 @@ var require_buffer = __commonJS({
|
|
|
978
987
|
codePoint = 56320 | codePoint & 1023;
|
|
979
988
|
}
|
|
980
989
|
res.push(codePoint);
|
|
981
|
-
|
|
990
|
+
i2 += bytesPerSequence;
|
|
982
991
|
}
|
|
983
992
|
return decodeCodePointsArray(res);
|
|
984
993
|
}
|
|
@@ -989,11 +998,11 @@ var require_buffer = __commonJS({
|
|
|
989
998
|
return String.fromCharCode.apply(String, codePoints);
|
|
990
999
|
}
|
|
991
1000
|
let res = "";
|
|
992
|
-
let
|
|
993
|
-
while (
|
|
1001
|
+
let i2 = 0;
|
|
1002
|
+
while (i2 < len) {
|
|
994
1003
|
res += String.fromCharCode.apply(
|
|
995
1004
|
String,
|
|
996
|
-
codePoints.slice(
|
|
1005
|
+
codePoints.slice(i2, i2 += MAX_ARGUMENTS_LENGTH)
|
|
997
1006
|
);
|
|
998
1007
|
}
|
|
999
1008
|
return res;
|
|
@@ -1001,16 +1010,16 @@ var require_buffer = __commonJS({
|
|
|
1001
1010
|
function asciiSlice(buf, start, end) {
|
|
1002
1011
|
let ret = "";
|
|
1003
1012
|
end = Math.min(buf.length, end);
|
|
1004
|
-
for (let
|
|
1005
|
-
ret += String.fromCharCode(buf[
|
|
1013
|
+
for (let i2 = start; i2 < end; ++i2) {
|
|
1014
|
+
ret += String.fromCharCode(buf[i2] & 127);
|
|
1006
1015
|
}
|
|
1007
1016
|
return ret;
|
|
1008
1017
|
}
|
|
1009
1018
|
function latin1Slice(buf, start, end) {
|
|
1010
1019
|
let ret = "";
|
|
1011
1020
|
end = Math.min(buf.length, end);
|
|
1012
|
-
for (let
|
|
1013
|
-
ret += String.fromCharCode(buf[
|
|
1021
|
+
for (let i2 = start; i2 < end; ++i2) {
|
|
1022
|
+
ret += String.fromCharCode(buf[i2]);
|
|
1014
1023
|
}
|
|
1015
1024
|
return ret;
|
|
1016
1025
|
}
|
|
@@ -1019,16 +1028,16 @@ var require_buffer = __commonJS({
|
|
|
1019
1028
|
if (!start || start < 0) start = 0;
|
|
1020
1029
|
if (!end || end < 0 || end > len) end = len;
|
|
1021
1030
|
let out = "";
|
|
1022
|
-
for (let
|
|
1023
|
-
out += hexSliceLookupTable[buf[
|
|
1031
|
+
for (let i2 = start; i2 < end; ++i2) {
|
|
1032
|
+
out += hexSliceLookupTable[buf[i2]];
|
|
1024
1033
|
}
|
|
1025
1034
|
return out;
|
|
1026
1035
|
}
|
|
1027
1036
|
function utf16leSlice(buf, start, end) {
|
|
1028
1037
|
const bytes2 = buf.slice(start, end);
|
|
1029
1038
|
let res = "";
|
|
1030
|
-
for (let
|
|
1031
|
-
res += String.fromCharCode(bytes2[
|
|
1039
|
+
for (let i2 = 0; i2 < bytes2.length - 1; i2 += 2) {
|
|
1040
|
+
res += String.fromCharCode(bytes2[i2] + bytes2[i2 + 1] * 256);
|
|
1032
1041
|
}
|
|
1033
1042
|
return res;
|
|
1034
1043
|
}
|
|
@@ -1063,9 +1072,9 @@ var require_buffer = __commonJS({
|
|
|
1063
1072
|
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1064
1073
|
let val = this[offset];
|
|
1065
1074
|
let mul3 = 1;
|
|
1066
|
-
let
|
|
1067
|
-
while (++
|
|
1068
|
-
val += this[offset +
|
|
1075
|
+
let i2 = 0;
|
|
1076
|
+
while (++i2 < byteLength2 && (mul3 *= 256)) {
|
|
1077
|
+
val += this[offset + i2] * mul3;
|
|
1069
1078
|
}
|
|
1070
1079
|
return val;
|
|
1071
1080
|
};
|
|
@@ -1137,9 +1146,9 @@ var require_buffer = __commonJS({
|
|
|
1137
1146
|
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1138
1147
|
let val = this[offset];
|
|
1139
1148
|
let mul3 = 1;
|
|
1140
|
-
let
|
|
1141
|
-
while (++
|
|
1142
|
-
val += this[offset +
|
|
1149
|
+
let i2 = 0;
|
|
1150
|
+
while (++i2 < byteLength2 && (mul3 *= 256)) {
|
|
1151
|
+
val += this[offset + i2] * mul3;
|
|
1143
1152
|
}
|
|
1144
1153
|
mul3 *= 128;
|
|
1145
1154
|
if (val >= mul3) val -= Math.pow(2, 8 * byteLength2);
|
|
@@ -1149,11 +1158,11 @@ var require_buffer = __commonJS({
|
|
|
1149
1158
|
offset = offset >>> 0;
|
|
1150
1159
|
byteLength2 = byteLength2 >>> 0;
|
|
1151
1160
|
if (!noAssert) checkOffset(offset, byteLength2, this.length);
|
|
1152
|
-
let
|
|
1161
|
+
let i2 = byteLength2;
|
|
1153
1162
|
let mul3 = 1;
|
|
1154
|
-
let val = this[offset + --
|
|
1155
|
-
while (
|
|
1156
|
-
val += this[offset + --
|
|
1163
|
+
let val = this[offset + --i2];
|
|
1164
|
+
while (i2 > 0 && (mul3 *= 256)) {
|
|
1165
|
+
val += this[offset + --i2] * mul3;
|
|
1157
1166
|
}
|
|
1158
1167
|
mul3 *= 128;
|
|
1159
1168
|
if (val >= mul3) val -= Math.pow(2, 8 * byteLength2);
|
|
@@ -1244,10 +1253,10 @@ var require_buffer = __commonJS({
|
|
|
1244
1253
|
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1245
1254
|
}
|
|
1246
1255
|
let mul3 = 1;
|
|
1247
|
-
let
|
|
1256
|
+
let i2 = 0;
|
|
1248
1257
|
this[offset] = value & 255;
|
|
1249
|
-
while (++
|
|
1250
|
-
this[offset +
|
|
1258
|
+
while (++i2 < byteLength2 && (mul3 *= 256)) {
|
|
1259
|
+
this[offset + i2] = value / mul3 & 255;
|
|
1251
1260
|
}
|
|
1252
1261
|
return offset + byteLength2;
|
|
1253
1262
|
};
|
|
@@ -1259,11 +1268,11 @@ var require_buffer = __commonJS({
|
|
|
1259
1268
|
const maxBytes = Math.pow(2, 8 * byteLength2) - 1;
|
|
1260
1269
|
checkInt(this, value, offset, byteLength2, maxBytes, 0);
|
|
1261
1270
|
}
|
|
1262
|
-
let
|
|
1271
|
+
let i2 = byteLength2 - 1;
|
|
1263
1272
|
let mul3 = 1;
|
|
1264
|
-
this[offset +
|
|
1265
|
-
while (--
|
|
1266
|
-
this[offset +
|
|
1273
|
+
this[offset + i2] = value & 255;
|
|
1274
|
+
while (--i2 >= 0 && (mul3 *= 256)) {
|
|
1275
|
+
this[offset + i2] = value / mul3 & 255;
|
|
1267
1276
|
}
|
|
1268
1277
|
return offset + byteLength2;
|
|
1269
1278
|
};
|
|
@@ -1363,15 +1372,15 @@ var require_buffer = __commonJS({
|
|
|
1363
1372
|
const limit2 = Math.pow(2, 8 * byteLength2 - 1);
|
|
1364
1373
|
checkInt(this, value, offset, byteLength2, limit2 - 1, -limit2);
|
|
1365
1374
|
}
|
|
1366
|
-
let
|
|
1375
|
+
let i2 = 0;
|
|
1367
1376
|
let mul3 = 1;
|
|
1368
1377
|
let sub = 0;
|
|
1369
1378
|
this[offset] = value & 255;
|
|
1370
|
-
while (++
|
|
1371
|
-
if (value < 0 && sub === 0 && this[offset +
|
|
1379
|
+
while (++i2 < byteLength2 && (mul3 *= 256)) {
|
|
1380
|
+
if (value < 0 && sub === 0 && this[offset + i2 - 1] !== 0) {
|
|
1372
1381
|
sub = 1;
|
|
1373
1382
|
}
|
|
1374
|
-
this[offset +
|
|
1383
|
+
this[offset + i2] = (value / mul3 >> 0) - sub & 255;
|
|
1375
1384
|
}
|
|
1376
1385
|
return offset + byteLength2;
|
|
1377
1386
|
};
|
|
@@ -1382,15 +1391,15 @@ var require_buffer = __commonJS({
|
|
|
1382
1391
|
const limit2 = Math.pow(2, 8 * byteLength2 - 1);
|
|
1383
1392
|
checkInt(this, value, offset, byteLength2, limit2 - 1, -limit2);
|
|
1384
1393
|
}
|
|
1385
|
-
let
|
|
1394
|
+
let i2 = byteLength2 - 1;
|
|
1386
1395
|
let mul3 = 1;
|
|
1387
1396
|
let sub = 0;
|
|
1388
|
-
this[offset +
|
|
1389
|
-
while (--
|
|
1390
|
-
if (value < 0 && sub === 0 && this[offset +
|
|
1397
|
+
this[offset + i2] = value & 255;
|
|
1398
|
+
while (--i2 >= 0 && (mul3 *= 256)) {
|
|
1399
|
+
if (value < 0 && sub === 0 && this[offset + i2 + 1] !== 0) {
|
|
1391
1400
|
sub = 1;
|
|
1392
1401
|
}
|
|
1393
|
-
this[offset +
|
|
1402
|
+
this[offset + i2] = (value / mul3 >> 0) - sub & 255;
|
|
1394
1403
|
}
|
|
1395
1404
|
return offset + byteLength2;
|
|
1396
1405
|
};
|
|
@@ -1545,10 +1554,10 @@ var require_buffer = __commonJS({
|
|
|
1545
1554
|
start = start >>> 0;
|
|
1546
1555
|
end = end === void 0 ? this.length : end >>> 0;
|
|
1547
1556
|
if (!val) val = 0;
|
|
1548
|
-
let
|
|
1557
|
+
let i2;
|
|
1549
1558
|
if (typeof val === "number") {
|
|
1550
|
-
for (
|
|
1551
|
-
this[
|
|
1559
|
+
for (i2 = start; i2 < end; ++i2) {
|
|
1560
|
+
this[i2] = val;
|
|
1552
1561
|
}
|
|
1553
1562
|
} else {
|
|
1554
1563
|
const bytes2 = Buffer3.isBuffer(val) ? val : Buffer3.from(val, encoding);
|
|
@@ -1556,8 +1565,8 @@ var require_buffer = __commonJS({
|
|
|
1556
1565
|
if (len === 0) {
|
|
1557
1566
|
throw new TypeError('The value "' + val + '" is invalid for argument "value"');
|
|
1558
1567
|
}
|
|
1559
|
-
for (
|
|
1560
|
-
this[
|
|
1568
|
+
for (i2 = 0; i2 < end - start; ++i2) {
|
|
1569
|
+
this[i2 + start] = bytes2[i2 % len];
|
|
1561
1570
|
}
|
|
1562
1571
|
}
|
|
1563
1572
|
return this;
|
|
@@ -1630,12 +1639,12 @@ var require_buffer = __commonJS({
|
|
|
1630
1639
|
);
|
|
1631
1640
|
function addNumericalSeparator(val) {
|
|
1632
1641
|
let res = "";
|
|
1633
|
-
let
|
|
1642
|
+
let i2 = val.length;
|
|
1634
1643
|
const start = val[0] === "-" ? 1 : 0;
|
|
1635
|
-
for (;
|
|
1636
|
-
res = `_${val.slice(
|
|
1644
|
+
for (; i2 >= start + 4; i2 -= 3) {
|
|
1645
|
+
res = `_${val.slice(i2 - 3, i2)}${res}`;
|
|
1637
1646
|
}
|
|
1638
|
-
return `${val.slice(0,
|
|
1647
|
+
return `${val.slice(0, i2)}${res}`;
|
|
1639
1648
|
}
|
|
1640
1649
|
function checkBounds(buf, offset, byteLength2) {
|
|
1641
1650
|
validateNumber(offset, "offset");
|
|
@@ -1695,14 +1704,14 @@ var require_buffer = __commonJS({
|
|
|
1695
1704
|
const length = string.length;
|
|
1696
1705
|
let leadSurrogate = null;
|
|
1697
1706
|
const bytes2 = [];
|
|
1698
|
-
for (let
|
|
1699
|
-
codePoint = string.charCodeAt(
|
|
1707
|
+
for (let i2 = 0; i2 < length; ++i2) {
|
|
1708
|
+
codePoint = string.charCodeAt(i2);
|
|
1700
1709
|
if (codePoint > 55295 && codePoint < 57344) {
|
|
1701
1710
|
if (!leadSurrogate) {
|
|
1702
1711
|
if (codePoint > 56319) {
|
|
1703
1712
|
if ((units -= 3) > -1) bytes2.push(239, 191, 189);
|
|
1704
1713
|
continue;
|
|
1705
|
-
} else if (
|
|
1714
|
+
} else if (i2 + 1 === length) {
|
|
1706
1715
|
if ((units -= 3) > -1) bytes2.push(239, 191, 189);
|
|
1707
1716
|
continue;
|
|
1708
1717
|
}
|
|
@@ -1751,17 +1760,17 @@ var require_buffer = __commonJS({
|
|
|
1751
1760
|
}
|
|
1752
1761
|
function asciiToBytes(str) {
|
|
1753
1762
|
const byteArray = [];
|
|
1754
|
-
for (let
|
|
1755
|
-
byteArray.push(str.charCodeAt(
|
|
1763
|
+
for (let i2 = 0; i2 < str.length; ++i2) {
|
|
1764
|
+
byteArray.push(str.charCodeAt(i2) & 255);
|
|
1756
1765
|
}
|
|
1757
1766
|
return byteArray;
|
|
1758
1767
|
}
|
|
1759
1768
|
function utf16leToBytes(str, units) {
|
|
1760
1769
|
let c, hi, lo;
|
|
1761
1770
|
const byteArray = [];
|
|
1762
|
-
for (let
|
|
1771
|
+
for (let i2 = 0; i2 < str.length; ++i2) {
|
|
1763
1772
|
if ((units -= 2) < 0) break;
|
|
1764
|
-
c = str.charCodeAt(
|
|
1773
|
+
c = str.charCodeAt(i2);
|
|
1765
1774
|
hi = c >> 8;
|
|
1766
1775
|
lo = c % 256;
|
|
1767
1776
|
byteArray.push(lo);
|
|
@@ -1773,12 +1782,12 @@ var require_buffer = __commonJS({
|
|
|
1773
1782
|
return base64.toByteArray(base64clean(str));
|
|
1774
1783
|
}
|
|
1775
1784
|
function blitBuffer(src, dst, offset, length) {
|
|
1776
|
-
let
|
|
1777
|
-
for (
|
|
1778
|
-
if (
|
|
1779
|
-
dst[
|
|
1785
|
+
let i2;
|
|
1786
|
+
for (i2 = 0; i2 < length; ++i2) {
|
|
1787
|
+
if (i2 + offset >= dst.length || i2 >= src.length) break;
|
|
1788
|
+
dst[i2 + offset] = src[i2];
|
|
1780
1789
|
}
|
|
1781
|
-
return
|
|
1790
|
+
return i2;
|
|
1782
1791
|
}
|
|
1783
1792
|
function isInstance(obj, type) {
|
|
1784
1793
|
return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
|
|
@@ -1789,10 +1798,10 @@ var require_buffer = __commonJS({
|
|
|
1789
1798
|
var hexSliceLookupTable = (function() {
|
|
1790
1799
|
const alphabet = "0123456789abcdef";
|
|
1791
1800
|
const table2 = new Array(256);
|
|
1792
|
-
for (let
|
|
1793
|
-
const i16 =
|
|
1801
|
+
for (let i2 = 0; i2 < 16; ++i2) {
|
|
1802
|
+
const i16 = i2 * 16;
|
|
1794
1803
|
for (let j = 0; j < 16; ++j) {
|
|
1795
|
-
table2[i16 + j] = alphabet[
|
|
1804
|
+
table2[i16 + j] = alphabet[i2] + alphabet[j];
|
|
1796
1805
|
}
|
|
1797
1806
|
}
|
|
1798
1807
|
return table2;
|
|
@@ -1824,24 +1833,10 @@ init_buffer();
|
|
|
1824
1833
|
// src/runtime/browser.ts
|
|
1825
1834
|
init_buffer();
|
|
1826
1835
|
|
|
1827
|
-
// node_modules/.pnpm/@noble+
|
|
1828
|
-
init_buffer();
|
|
1829
|
-
|
|
1830
|
-
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
1831
|
-
init_buffer();
|
|
1832
|
-
|
|
1833
|
-
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
|
|
1836
|
+
// node_modules/.pnpm/@noble+ciphers@2.4.0/node_modules/@noble/ciphers/aes.js
|
|
1834
1837
|
init_buffer();
|
|
1835
|
-
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
1836
|
-
var fromNumL = (n) => n >>> 0;
|
|
1837
|
-
function setU64FromNum(view, byteOffset, n, isLE2) {
|
|
1838
|
-
const h = fromNumH(n);
|
|
1839
|
-
const l = fromNumL(n);
|
|
1840
|
-
view.setUint32(byteOffset, isLE2 ? l : h, isLE2);
|
|
1841
|
-
view.setUint32(byteOffset + 4, isLE2 ? h : l, isLE2);
|
|
1842
|
-
}
|
|
1843
1838
|
|
|
1844
|
-
// node_modules/.pnpm/@noble+
|
|
1839
|
+
// node_modules/.pnpm/@noble+ciphers@2.4.0/node_modules/@noble/ciphers/utils.js
|
|
1845
1840
|
init_buffer();
|
|
1846
1841
|
function isBytes(a) {
|
|
1847
1842
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
@@ -1867,411 +1862,376 @@ function abytes(value, length, title = "") {
|
|
|
1867
1862
|
throw new TypeError(message);
|
|
1868
1863
|
throw new RangeError(message);
|
|
1869
1864
|
}
|
|
1870
|
-
function
|
|
1871
|
-
|
|
1872
|
-
throw new TypeError("expected hash wrapped by utils.createHasher");
|
|
1873
|
-
anumber(h.outputLen);
|
|
1874
|
-
anumber(h.blockLen);
|
|
1875
|
-
if (h.outputLen < 1 || h.blockLen < 1)
|
|
1876
|
-
throw new Error("hash blockLen / outputLen must be >= 1");
|
|
1877
|
-
}
|
|
1878
|
-
var aobject = (value, label) => {
|
|
1879
|
-
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
1880
|
-
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
1881
|
-
};
|
|
1882
|
-
var aopts = (value, label) => {
|
|
1883
|
-
aobject(value, label);
|
|
1884
|
-
const proto = Object.getPrototypeOf(value);
|
|
1885
|
-
if (proto !== Object.prototype && proto !== null)
|
|
1886
|
-
throw new TypeError(`"${label}" expected plain object`);
|
|
1887
|
-
if (Object.hasOwn(value, "__proto__"))
|
|
1888
|
-
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
1889
|
-
};
|
|
1890
|
-
function aexists(instance, checkFinished = true) {
|
|
1891
|
-
if (instance.destroyed)
|
|
1892
|
-
throw new Error("hash was destroyed");
|
|
1893
|
-
if (checkFinished && instance.finished)
|
|
1894
|
-
throw new Error("digest() was already called");
|
|
1865
|
+
function u32(arr) {
|
|
1866
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
1895
1867
|
}
|
|
1896
|
-
function
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
if (!(out.length >= min)) {
|
|
1900
|
-
throw new RangeError('"output" expected length >= ' + min);
|
|
1868
|
+
function clean(...arrays) {
|
|
1869
|
+
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
1870
|
+
arrays[i2].fill(0);
|
|
1901
1871
|
}
|
|
1902
1872
|
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1873
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
1874
|
+
function byteSwap(word) {
|
|
1875
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
1876
|
+
}
|
|
1877
|
+
function byteSwap32(arr) {
|
|
1878
|
+
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
1879
|
+
arr[i2] = byteSwap(arr[i2]);
|
|
1906
1880
|
}
|
|
1881
|
+
return arr;
|
|
1907
1882
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
1883
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
1884
|
+
function overlapBytes(a, b) {
|
|
1885
|
+
if (!a.byteLength || !b.byteLength)
|
|
1886
|
+
return false;
|
|
1887
|
+
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
1888
|
+
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
1889
|
+
b.byteOffset < a.byteOffset + a.byteLength;
|
|
1910
1890
|
}
|
|
1911
|
-
function
|
|
1912
|
-
|
|
1891
|
+
function complexOverlapBytes(input, output) {
|
|
1892
|
+
if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
|
|
1893
|
+
throw new Error("complex overlap of input and output is not supported");
|
|
1913
1894
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1895
|
+
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
1896
|
+
function wrappedCipher(key2, ...args) {
|
|
1897
|
+
abytes(key2, void 0, "key");
|
|
1898
|
+
if (params.nonceLength !== void 0) {
|
|
1899
|
+
const nonce = args[0];
|
|
1900
|
+
abytes(nonce, params.varSizeNonce ? void 0 : params.nonceLength, "nonce");
|
|
1901
|
+
}
|
|
1902
|
+
const tagl = params.tagLength;
|
|
1903
|
+
const aadStart = params.nonceLength !== void 0 ? 1 : 0;
|
|
1904
|
+
if (!params.withAAD) {
|
|
1905
|
+
for (let i2 = aadStart; i2 < args.length; i2++)
|
|
1906
|
+
if (isBytes(args[i2]))
|
|
1907
|
+
throw new Error("AAD not supported");
|
|
1908
|
+
}
|
|
1909
|
+
if (params.withAAD && args[aadStart] !== void 0)
|
|
1910
|
+
abytes(args[aadStart], void 0, "AAD");
|
|
1911
|
+
const cipher = constructor(key2, ...args);
|
|
1912
|
+
const checkOutput = (fnLength, output) => {
|
|
1913
|
+
if (output !== void 0) {
|
|
1914
|
+
if (fnLength !== 2)
|
|
1915
|
+
throw new Error("cipher output not supported");
|
|
1916
|
+
abytes(output, void 0, "output");
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
let called = false;
|
|
1920
|
+
const wrCipher = {
|
|
1921
|
+
encrypt(data, output) {
|
|
1922
|
+
if (called)
|
|
1923
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
1924
|
+
called = true;
|
|
1925
|
+
abytes(data, void 0, "data");
|
|
1926
|
+
checkOutput(cipher.encrypt.length, output);
|
|
1927
|
+
return cipher.encrypt(data, output);
|
|
1928
|
+
},
|
|
1929
|
+
decrypt(data, output) {
|
|
1930
|
+
abytes(data, void 0, "data");
|
|
1931
|
+
if (tagl && data.length < tagl)
|
|
1932
|
+
throw new Error('"ciphertext" expected length >= tagLength=' + tagl);
|
|
1933
|
+
checkOutput(cipher.decrypt.length, output);
|
|
1934
|
+
return cipher.decrypt(data, output);
|
|
1935
|
+
}
|
|
1936
|
+
};
|
|
1937
|
+
return wrCipher;
|
|
1938
|
+
}
|
|
1939
|
+
Object.assign(wrappedCipher, params);
|
|
1940
|
+
return wrappedCipher;
|
|
1941
|
+
};
|
|
1942
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
1943
|
+
if (out === void 0)
|
|
1944
|
+
return new Uint8Array(expectedLength);
|
|
1945
|
+
abytes(out, expectedLength, "output");
|
|
1946
|
+
if (onlyAligned && !isAligned32(out))
|
|
1947
|
+
throw new Error("invalid output, must be aligned");
|
|
1948
|
+
return out;
|
|
1920
1949
|
}
|
|
1921
|
-
function
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
const tmp = hashCons(void 0);
|
|
1927
|
-
hashC.outputLen = tmp.outputLen;
|
|
1928
|
-
hashC.blockLen = tmp.blockLen;
|
|
1929
|
-
hashC.canXOF = tmp.canXOF;
|
|
1930
|
-
hashC.create = (opts) => hashCons(opts);
|
|
1931
|
-
Object.assign(hashC, info);
|
|
1932
|
-
return Object.freeze(hashC);
|
|
1950
|
+
function isAligned32(bytes2) {
|
|
1951
|
+
return bytes2.byteOffset % 4 === 0;
|
|
1952
|
+
}
|
|
1953
|
+
function copyBytes(bytes2) {
|
|
1954
|
+
return Uint8Array.from(abytes(bytes2));
|
|
1933
1955
|
}
|
|
1934
1956
|
|
|
1935
|
-
// node_modules/.pnpm/@noble+
|
|
1936
|
-
|
|
1937
|
-
|
|
1957
|
+
// node_modules/.pnpm/@noble+ciphers@2.4.0/node_modules/@noble/ciphers/aes.js
|
|
1958
|
+
var BLOCK_SIZE = 16;
|
|
1959
|
+
var POLY = 283;
|
|
1960
|
+
function validateKeyLength(key2) {
|
|
1961
|
+
if (![16, 24, 32].includes(key2.length))
|
|
1962
|
+
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key2.length);
|
|
1938
1963
|
}
|
|
1939
|
-
function
|
|
1940
|
-
return
|
|
1964
|
+
function mul2(n) {
|
|
1965
|
+
return n << 1 ^ POLY & -(n >> 7);
|
|
1941
1966
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
isLE;
|
|
1948
|
-
// For partial updates less than block size
|
|
1949
|
-
buffer;
|
|
1950
|
-
view;
|
|
1951
|
-
finished = false;
|
|
1952
|
-
length = 0;
|
|
1953
|
-
pos = 0;
|
|
1954
|
-
destroyed = false;
|
|
1955
|
-
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
1956
|
-
this.blockLen = blockLen;
|
|
1957
|
-
this.outputLen = outputLen;
|
|
1958
|
-
this.padOffset = padOffset;
|
|
1959
|
-
this.isLE = isLE2;
|
|
1960
|
-
this.buffer = new Uint8Array(blockLen);
|
|
1961
|
-
this.view = createView(this.buffer);
|
|
1967
|
+
function mul(a, b) {
|
|
1968
|
+
let res = 0;
|
|
1969
|
+
for (; b > 0; b >>= 1) {
|
|
1970
|
+
res ^= a & -(b & 1);
|
|
1971
|
+
a = mul2(a);
|
|
1962
1972
|
}
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
processed = true;
|
|
1976
|
-
continue;
|
|
1977
|
-
}
|
|
1978
|
-
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
1979
|
-
this.pos += take;
|
|
1980
|
-
pos += take;
|
|
1981
|
-
if (this.pos === blockLen) {
|
|
1982
|
-
this.process(view, 0);
|
|
1983
|
-
this.pos = 0;
|
|
1984
|
-
processed = true;
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
this.length += data.length;
|
|
1988
|
-
if (processed)
|
|
1989
|
-
this.roundClean();
|
|
1990
|
-
return this;
|
|
1973
|
+
return res;
|
|
1974
|
+
}
|
|
1975
|
+
var sbox = /* @__PURE__ */ (() => {
|
|
1976
|
+
const t = new Uint8Array(256);
|
|
1977
|
+
for (let i2 = 0, x2 = 1; i2 < 256; i2++, x2 ^= mul2(x2))
|
|
1978
|
+
t[i2] = x2;
|
|
1979
|
+
const box = new Uint8Array(256);
|
|
1980
|
+
box[0] = 99;
|
|
1981
|
+
for (let i2 = 0; i2 < 255; i2++) {
|
|
1982
|
+
let x2 = t[255 - i2];
|
|
1983
|
+
x2 |= x2 << 8;
|
|
1984
|
+
box[t[i2]] = (x2 ^ x2 >> 4 ^ x2 >> 5 ^ x2 >> 6 ^ x2 >> 7 ^ 99) & 255;
|
|
1991
1985
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
1986
|
+
clean(t);
|
|
1987
|
+
return box;
|
|
1988
|
+
})();
|
|
1989
|
+
var invSbox = /* @__PURE__ */ sbox.map((_, j) => sbox.indexOf(j));
|
|
1990
|
+
var rotr32_8 = (n) => n << 24 | n >>> 8;
|
|
1991
|
+
var rotl32_8 = (n) => n << 8 | n >>> 24;
|
|
1992
|
+
function genTtable(sbox2, fn) {
|
|
1993
|
+
if (sbox2.length !== 256)
|
|
1994
|
+
throw new Error("wrong sbox length");
|
|
1995
|
+
const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
|
|
1996
|
+
const T1 = T0.map(rotl32_8);
|
|
1997
|
+
const T2 = T1.map(rotl32_8);
|
|
1998
|
+
const T3 = T2.map(rotl32_8);
|
|
1999
|
+
const T01 = new Uint32Array(256 * 256);
|
|
2000
|
+
const T23 = new Uint32Array(256 * 256);
|
|
2001
|
+
const sbox22 = new Uint16Array(256 * 256);
|
|
2002
|
+
for (let i2 = 0; i2 < 256; i2++) {
|
|
2003
|
+
for (let j = 0; j < 256; j++) {
|
|
2004
|
+
const idx = i2 * 256 + j;
|
|
2005
|
+
T01[idx] = T0[i2] ^ T1[j];
|
|
2006
|
+
T23[idx] = T2[i2] ^ T3[j];
|
|
2007
|
+
sbox22[idx] = sbox2[i2] << 8 | sbox2[j];
|
|
2003
2008
|
}
|
|
2004
|
-
setU64FromNum(view, blockLen - 8, this.length * 8, isLE2);
|
|
2005
|
-
this.process(view, 0);
|
|
2006
|
-
this.roundClean();
|
|
2007
|
-
const oview = out === buffer ? view : createView(out);
|
|
2008
|
-
const len = this.outputLen;
|
|
2009
|
-
const outLen = len / 4;
|
|
2010
|
-
const state = this.get();
|
|
2011
|
-
if (len % 4 || outLen > state.length)
|
|
2012
|
-
throw new Error("invalid outputLen");
|
|
2013
|
-
for (let i = 0; i < outLen; i++)
|
|
2014
|
-
oview.setUint32(4 * i, state[i], isLE2);
|
|
2015
|
-
}
|
|
2016
|
-
digest() {
|
|
2017
|
-
const { buffer, outputLen } = this;
|
|
2018
|
-
this.digestInto(buffer);
|
|
2019
|
-
const res = buffer.slice(0, outputLen);
|
|
2020
|
-
this.destroy();
|
|
2021
|
-
return res;
|
|
2022
2009
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
constructor() {
|
|
2054
|
-
super(64, 20, 8, false);
|
|
2055
|
-
}
|
|
2056
|
-
get() {
|
|
2057
|
-
const { A, B, C, D, E } = this;
|
|
2058
|
-
return [A, B, C, D, E];
|
|
2010
|
+
return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
|
|
2011
|
+
}
|
|
2012
|
+
var tableEncoding = /* @__PURE__ */ genTtable(sbox, (s) => mul(s, 3) << 24 | s << 16 | s << 8 | mul(s, 2));
|
|
2013
|
+
var tableDecoding = /* @__PURE__ */ genTtable(invSbox, (s) => mul(s, 11) << 24 | mul(s, 13) << 16 | mul(s, 9) << 8 | mul(s, 14));
|
|
2014
|
+
var xPowers = /* @__PURE__ */ (() => {
|
|
2015
|
+
const p = new Uint8Array(16);
|
|
2016
|
+
for (let i2 = 0, x2 = 1; i2 < 16; i2++, x2 = mul2(x2))
|
|
2017
|
+
p[i2] = x2;
|
|
2018
|
+
return p;
|
|
2019
|
+
})();
|
|
2020
|
+
function expandKeyLE(key2) {
|
|
2021
|
+
abytes(key2);
|
|
2022
|
+
const len = key2.length;
|
|
2023
|
+
validateKeyLength(key2);
|
|
2024
|
+
const { sbox2 } = tableEncoding;
|
|
2025
|
+
const toClean = [];
|
|
2026
|
+
if (!isLE || !isAligned32(key2))
|
|
2027
|
+
toClean.push(key2 = copyBytes(key2));
|
|
2028
|
+
const k32 = swap32IfBE(u32(key2));
|
|
2029
|
+
const Nk = k32.length;
|
|
2030
|
+
const subByte = (n) => applySbox(sbox2, n, n, n, n);
|
|
2031
|
+
const xk = new Uint32Array(len + 28);
|
|
2032
|
+
xk.set(k32);
|
|
2033
|
+
for (let i2 = Nk; i2 < xk.length; i2++) {
|
|
2034
|
+
let t = xk[i2 - 1];
|
|
2035
|
+
if (i2 % Nk === 0)
|
|
2036
|
+
t = subByte(rotr32_8(t)) ^ xPowers[i2 / Nk - 1];
|
|
2037
|
+
else if (Nk > 6 && i2 % Nk === 4)
|
|
2038
|
+
t = subByte(t);
|
|
2039
|
+
xk[i2] = xk[i2 - Nk] ^ t;
|
|
2059
2040
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2041
|
+
clean(...toClean);
|
|
2042
|
+
return xk;
|
|
2043
|
+
}
|
|
2044
|
+
function expandKeyDecLE(key2) {
|
|
2045
|
+
const encKey = expandKeyLE(key2);
|
|
2046
|
+
const xk = encKey.slice();
|
|
2047
|
+
const Nk = encKey.length;
|
|
2048
|
+
const { sbox2 } = tableEncoding;
|
|
2049
|
+
const { T0, T1, T2, T3 } = tableDecoding;
|
|
2050
|
+
for (let i2 = 0; i2 < Nk; i2 += 4) {
|
|
2051
|
+
for (let j = 0; j < 4; j++)
|
|
2052
|
+
xk[i2 + j] = encKey[Nk - i2 - 4 + j];
|
|
2066
2053
|
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2054
|
+
clean(encKey);
|
|
2055
|
+
for (let i2 = 4; i2 < Nk - 4; i2++) {
|
|
2056
|
+
const x2 = xk[i2];
|
|
2057
|
+
const w = applySbox(sbox2, x2, x2, x2, x2);
|
|
2058
|
+
xk[i2] = T0[w & 255] ^ T1[w >>> 8 & 255] ^ T2[w >>> 16 & 255] ^ T3[w >>> 24];
|
|
2070
2059
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
K2 = 3395469782;
|
|
2091
|
-
}
|
|
2092
|
-
const T = rotl(A, 5) + F + E + K2 + SHA1_W[i] | 0;
|
|
2093
|
-
E = D;
|
|
2094
|
-
D = C;
|
|
2095
|
-
C = rotl(B, 30);
|
|
2096
|
-
B = A;
|
|
2097
|
-
A = T;
|
|
2098
|
-
}
|
|
2099
|
-
A = A + this.A | 0;
|
|
2100
|
-
B = B + this.B | 0;
|
|
2101
|
-
C = C + this.C | 0;
|
|
2102
|
-
D = D + this.D | 0;
|
|
2103
|
-
E = E + this.E | 0;
|
|
2104
|
-
this.set(A, B, C, D, E);
|
|
2060
|
+
return xk;
|
|
2061
|
+
}
|
|
2062
|
+
function apply0123(T01, T23, s0, s1, s2, s3) {
|
|
2063
|
+
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
2064
|
+
}
|
|
2065
|
+
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
2066
|
+
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
2067
|
+
}
|
|
2068
|
+
function encrypt(xk, s0, s1, s2, s3) {
|
|
2069
|
+
const { sbox2, T01, T23 } = tableEncoding;
|
|
2070
|
+
let k = 0;
|
|
2071
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
2072
|
+
const rounds = xk.length / 4 - 2;
|
|
2073
|
+
for (let i2 = 0; i2 < rounds; i2++) {
|
|
2074
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
2075
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
2076
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
2077
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
2078
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
2105
2079
|
}
|
|
2106
|
-
|
|
2107
|
-
|
|
2080
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
|
|
2081
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
|
|
2082
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
|
|
2083
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
|
|
2084
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
2085
|
+
}
|
|
2086
|
+
function decrypt(xk, s0, s1, s2, s3) {
|
|
2087
|
+
const { sbox2, T01, T23 } = tableDecoding;
|
|
2088
|
+
let k = 0;
|
|
2089
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
2090
|
+
const rounds = xk.length / 4 - 2;
|
|
2091
|
+
for (let i2 = 0; i2 < rounds; i2++) {
|
|
2092
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s3, s2, s1);
|
|
2093
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s0, s3, s2);
|
|
2094
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s1, s0, s3);
|
|
2095
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s2, s1, s0);
|
|
2096
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
2108
2097
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2098
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s3, s2, s1);
|
|
2099
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s0, s3, s2);
|
|
2100
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s1, s0, s3);
|
|
2101
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s2, s1, s0);
|
|
2102
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
2103
|
+
}
|
|
2104
|
+
function validateBlockDecrypt(data, dst) {
|
|
2105
|
+
abytes(data);
|
|
2106
|
+
if (data.length % BLOCK_SIZE !== 0) {
|
|
2107
|
+
throw new Error("ciphertext must be multiple of " + BLOCK_SIZE);
|
|
2113
2108
|
}
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
var K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
|
|
2118
|
-
var MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
|
|
2119
|
-
var MD5_W = /* @__PURE__ */ new Uint32Array(16);
|
|
2120
|
-
var MD5_SHIFTS = /* @__PURE__ */ (() => {
|
|
2121
|
-
const S = [
|
|
2122
|
-
[7, 12, 17, 22],
|
|
2123
|
-
[5, 9, 14, 20],
|
|
2124
|
-
[4, 11, 16, 23],
|
|
2125
|
-
[6, 10, 15, 21]
|
|
2126
|
-
];
|
|
2127
|
-
return Uint8Array.from({ length: 64 }, (_, i) => S[Math.floor(i / 16)][i % 4]);
|
|
2128
|
-
})();
|
|
2129
|
-
var _MD5 = class extends HashMD {
|
|
2130
|
-
A = MD5_IV[0] | 0;
|
|
2131
|
-
B = MD5_IV[1] | 0;
|
|
2132
|
-
C = MD5_IV[2] | 0;
|
|
2133
|
-
D = MD5_IV[3] | 0;
|
|
2134
|
-
constructor() {
|
|
2135
|
-
super(64, 16, 8, true);
|
|
2109
|
+
if (dst !== void 0) {
|
|
2110
|
+
getOutput(data.length, dst);
|
|
2111
|
+
complexOverlapBytes(data, dst);
|
|
2136
2112
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2113
|
+
}
|
|
2114
|
+
function validateBlockEncrypt(plaintext, pkcs5, dst) {
|
|
2115
|
+
abytes(plaintext);
|
|
2116
|
+
let outLen = plaintext.length;
|
|
2117
|
+
const remaining = outLen % BLOCK_SIZE;
|
|
2118
|
+
if (!pkcs5 && remaining !== 0)
|
|
2119
|
+
throw new Error("plaintext must be multiple of " + BLOCK_SIZE);
|
|
2120
|
+
if (pkcs5) {
|
|
2121
|
+
let left = BLOCK_SIZE - remaining;
|
|
2122
|
+
if (!left)
|
|
2123
|
+
left = BLOCK_SIZE;
|
|
2124
|
+
outLen = outLen + left;
|
|
2140
2125
|
}
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
this.C = C | 0;
|
|
2145
|
-
this.D = D | 0;
|
|
2126
|
+
if (dst !== void 0) {
|
|
2127
|
+
getOutput(outLen, dst);
|
|
2128
|
+
complexOverlapBytes(plaintext, dst);
|
|
2146
2129
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2130
|
+
return outLen;
|
|
2131
|
+
}
|
|
2132
|
+
function prepareBlockEncrypt(plaintext, outLen, dst) {
|
|
2133
|
+
if (dst === void 0)
|
|
2134
|
+
dst = new Uint8Array(outLen);
|
|
2135
|
+
if (!isLE || !isAligned32(plaintext))
|
|
2136
|
+
plaintext = copyBytes(plaintext);
|
|
2137
|
+
const o = u32(dst);
|
|
2138
|
+
return { b: plaintext, o, out: dst };
|
|
2139
|
+
}
|
|
2140
|
+
function validatePKCS(data, pkcs5) {
|
|
2141
|
+
if (!pkcs5)
|
|
2142
|
+
return data;
|
|
2143
|
+
const len = data.length;
|
|
2144
|
+
if (len === 0)
|
|
2145
|
+
throw new Error("pkcs7: empty ciphertext not allowed");
|
|
2146
|
+
const lastByte = data[len - 1];
|
|
2147
|
+
let valid = 1;
|
|
2148
|
+
valid &= lastByte - 1 >>> 31 ^ 1;
|
|
2149
|
+
valid &= 16 - lastByte >>> 31 ^ 1;
|
|
2150
|
+
for (let i2 = 0; i2 < 16; i2++) {
|
|
2151
|
+
const shouldCheck = i2 - lastByte >>> 31;
|
|
2152
|
+
const eq = (data[len - 1 - i2] ^ lastByte) === 0 ? 1 : 0;
|
|
2153
|
+
valid &= eq | shouldCheck ^ 1;
|
|
2150
2154
|
}
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2155
|
+
if (!valid)
|
|
2156
|
+
throw new Error("aes: bad decrypt");
|
|
2157
|
+
return data.subarray(0, len - lastByte);
|
|
2158
|
+
}
|
|
2159
|
+
function padPCKS(left) {
|
|
2160
|
+
const tmp = new Uint8Array(16);
|
|
2161
|
+
const tmp32 = u32(tmp);
|
|
2162
|
+
tmp.set(left);
|
|
2163
|
+
const paddingByte = BLOCK_SIZE - left.length;
|
|
2164
|
+
for (let i2 = BLOCK_SIZE - paddingByte; i2 < BLOCK_SIZE; i2++)
|
|
2165
|
+
tmp[i2] = paddingByte;
|
|
2166
|
+
return tmp32;
|
|
2167
|
+
}
|
|
2168
|
+
var ecb = /* @__PURE__ */ wrapCipher({ blockSize: 16 }, function aesecb(key2, opts = {}) {
|
|
2169
|
+
const pkcs5 = !opts.disablePadding;
|
|
2170
|
+
return {
|
|
2171
|
+
encrypt(plaintext, dst) {
|
|
2172
|
+
const outLen = validateBlockEncrypt(plaintext, pkcs5, dst);
|
|
2173
|
+
const xk = expandKeyLE(key2);
|
|
2174
|
+
const { b: input, o, out: _out } = prepareBlockEncrypt(plaintext, outLen, dst);
|
|
2175
|
+
const b = u32(input);
|
|
2176
|
+
swap32IfBE(b);
|
|
2177
|
+
let i2 = 0;
|
|
2178
|
+
for (; i2 + 4 <= b.length; ) {
|
|
2179
|
+
const { s0, s1, s2, s3 } = encrypt(xk, b[i2 + 0], b[i2 + 1], b[i2 + 2], b[i2 + 3]);
|
|
2180
|
+
o[i2++] = s0, o[i2++] = s1, o[i2++] = s2, o[i2++] = s3;
|
|
2169
2181
|
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2182
|
+
if (pkcs5) {
|
|
2183
|
+
const tmp32 = padPCKS(plaintext.subarray(i2 * 4));
|
|
2184
|
+
swap32IfBE(tmp32);
|
|
2185
|
+
const { s0, s1, s2, s3 } = encrypt(xk, tmp32[0], tmp32[1], tmp32[2], tmp32[3]);
|
|
2186
|
+
o[i2++] = s0, o[i2++] = s1, o[i2++] = s2, o[i2++] = s3;
|
|
2187
|
+
clean(tmp32);
|
|
2188
|
+
}
|
|
2189
|
+
swap32IfBE(o);
|
|
2190
|
+
clean(xk);
|
|
2191
|
+
if (input !== plaintext)
|
|
2192
|
+
clean(input);
|
|
2193
|
+
return _out;
|
|
2194
|
+
},
|
|
2195
|
+
decrypt(ciphertext, dst) {
|
|
2196
|
+
validateBlockDecrypt(ciphertext, dst);
|
|
2197
|
+
const xk = expandKeyDecLE(key2);
|
|
2198
|
+
if (dst === void 0)
|
|
2199
|
+
dst = new Uint8Array(ciphertext.length);
|
|
2200
|
+
const toClean = [xk];
|
|
2201
|
+
if (!isLE || !isAligned32(ciphertext))
|
|
2202
|
+
toClean.push(ciphertext = copyBytes(ciphertext));
|
|
2203
|
+
const b = u32(ciphertext);
|
|
2204
|
+
const o = u32(dst);
|
|
2205
|
+
swap32IfBE(b);
|
|
2206
|
+
for (let i2 = 0; i2 + 4 <= b.length; ) {
|
|
2207
|
+
const { s0, s1, s2, s3 } = decrypt(xk, b[i2 + 0], b[i2 + 1], b[i2 + 2], b[i2 + 3]);
|
|
2208
|
+
o[i2++] = s0, o[i2++] = s1, o[i2++] = s2, o[i2++] = s3;
|
|
2209
|
+
}
|
|
2210
|
+
swap32IfBE(o);
|
|
2211
|
+
clean(...toClean);
|
|
2212
|
+
return validatePKCS(dst, pkcs5);
|
|
2175
2213
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
C = C + this.C | 0;
|
|
2179
|
-
D = D + this.D | 0;
|
|
2180
|
-
this.set(A, B, C, D);
|
|
2181
|
-
}
|
|
2182
|
-
roundClean() {
|
|
2183
|
-
clean(MD5_W);
|
|
2184
|
-
}
|
|
2185
|
-
destroy() {
|
|
2186
|
-
this.destroyed = true;
|
|
2187
|
-
this.set(0, 0, 0, 0);
|
|
2188
|
-
clean(this.buffer);
|
|
2189
|
-
}
|
|
2190
|
-
};
|
|
2191
|
-
var md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
2214
|
+
};
|
|
2215
|
+
});
|
|
2192
2216
|
|
|
2193
|
-
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/
|
|
2217
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/legacy.js
|
|
2194
2218
|
init_buffer();
|
|
2195
|
-
var _HMAC = class {
|
|
2196
|
-
oHash;
|
|
2197
|
-
iHash;
|
|
2198
|
-
blockLen;
|
|
2199
|
-
outputLen;
|
|
2200
|
-
canXOF = false;
|
|
2201
|
-
finished = false;
|
|
2202
|
-
destroyed = false;
|
|
2203
|
-
constructor(hash2, key2) {
|
|
2204
|
-
ahash(hash2);
|
|
2205
|
-
abytes(key2, void 0, "key");
|
|
2206
|
-
this.iHash = hash2.create();
|
|
2207
|
-
if (typeof this.iHash.update !== "function")
|
|
2208
|
-
throw new Error("expected Hash instance");
|
|
2209
|
-
this.blockLen = this.iHash.blockLen;
|
|
2210
|
-
this.outputLen = this.iHash.outputLen;
|
|
2211
|
-
const blockLen = this.blockLen;
|
|
2212
|
-
const pad = new Uint8Array(blockLen);
|
|
2213
|
-
pad.set(key2.length > blockLen ? hash2.create().update(key2).digest() : key2);
|
|
2214
|
-
for (let i = 0; i < pad.length; i++)
|
|
2215
|
-
pad[i] ^= 54;
|
|
2216
|
-
this.iHash.update(pad);
|
|
2217
|
-
this.oHash = hash2.create();
|
|
2218
|
-
for (let i = 0; i < pad.length; i++)
|
|
2219
|
-
pad[i] ^= 54 ^ 92;
|
|
2220
|
-
this.oHash.update(pad);
|
|
2221
|
-
clean(pad);
|
|
2222
|
-
}
|
|
2223
|
-
update(buf) {
|
|
2224
|
-
aexists(this);
|
|
2225
|
-
this.iHash.update(buf);
|
|
2226
|
-
return this;
|
|
2227
|
-
}
|
|
2228
|
-
digestInto(out) {
|
|
2229
|
-
aexists(this);
|
|
2230
|
-
aoutput(out, this);
|
|
2231
|
-
this.finished = true;
|
|
2232
|
-
const buf = out.subarray(0, this.outputLen);
|
|
2233
|
-
this.iHash.digestInto(buf);
|
|
2234
|
-
this.oHash.update(buf);
|
|
2235
|
-
this.oHash.digestInto(buf);
|
|
2236
|
-
this.destroy();
|
|
2237
|
-
}
|
|
2238
|
-
digest() {
|
|
2239
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
2240
|
-
this.digestInto(out);
|
|
2241
|
-
return out;
|
|
2242
|
-
}
|
|
2243
|
-
_cloneInto(to) {
|
|
2244
|
-
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
2245
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen, canXOF } = this;
|
|
2246
|
-
to = to;
|
|
2247
|
-
to.finished = finished;
|
|
2248
|
-
to.destroyed = destroyed;
|
|
2249
|
-
to.blockLen = blockLen;
|
|
2250
|
-
to.outputLen = outputLen;
|
|
2251
|
-
to.canXOF = canXOF;
|
|
2252
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
2253
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
2254
|
-
return to;
|
|
2255
|
-
}
|
|
2256
|
-
clone() {
|
|
2257
|
-
return this._cloneInto();
|
|
2258
|
-
}
|
|
2259
|
-
destroy() {
|
|
2260
|
-
this.destroyed = true;
|
|
2261
|
-
this.oHash.destroy();
|
|
2262
|
-
this.iHash.destroy();
|
|
2263
|
-
}
|
|
2264
|
-
};
|
|
2265
|
-
var hmac = /* @__PURE__ */ (() => {
|
|
2266
|
-
const hmac_ = ((hash2, key2, message) => new _HMAC(hash2, key2).update(message).digest());
|
|
2267
|
-
hmac_.create = (hash2, key2) => new _HMAC(hash2, key2);
|
|
2268
|
-
return hmac_;
|
|
2269
|
-
})();
|
|
2270
2219
|
|
|
2271
|
-
// node_modules/.pnpm/@noble+
|
|
2220
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
2272
2221
|
init_buffer();
|
|
2273
2222
|
|
|
2274
|
-
// node_modules/.pnpm/@noble+
|
|
2223
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
|
|
2224
|
+
init_buffer();
|
|
2225
|
+
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
2226
|
+
var fromNumL = (n) => n >>> 0;
|
|
2227
|
+
function setU64FromNum(view, byteOffset, n, isLE2) {
|
|
2228
|
+
const h = fromNumH(n);
|
|
2229
|
+
const l = fromNumL(n);
|
|
2230
|
+
view.setUint32(byteOffset, isLE2 ? l : h, isLE2);
|
|
2231
|
+
view.setUint32(byteOffset + 4, isLE2 ? h : l, isLE2);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/utils.js
|
|
2275
2235
|
init_buffer();
|
|
2276
2236
|
function isBytes2(a) {
|
|
2277
2237
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
@@ -2297,357 +2257,406 @@ function abytes2(value, length, title = "") {
|
|
|
2297
2257
|
throw new TypeError(message);
|
|
2298
2258
|
throw new RangeError(message);
|
|
2299
2259
|
}
|
|
2300
|
-
function
|
|
2301
|
-
|
|
2260
|
+
function ahash(h) {
|
|
2261
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
2262
|
+
throw new TypeError("expected hash wrapped by utils.createHasher");
|
|
2263
|
+
anumber2(h.outputLen);
|
|
2264
|
+
anumber2(h.blockLen);
|
|
2265
|
+
if (h.outputLen < 1 || h.blockLen < 1)
|
|
2266
|
+
throw new Error("hash blockLen / outputLen must be >= 1");
|
|
2267
|
+
}
|
|
2268
|
+
var aobject = (value, label) => {
|
|
2269
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
2270
|
+
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
2271
|
+
};
|
|
2272
|
+
var aopts = (value, label) => {
|
|
2273
|
+
aobject(value, label);
|
|
2274
|
+
const proto = Object.getPrototypeOf(value);
|
|
2275
|
+
if (proto !== Object.prototype && proto !== null)
|
|
2276
|
+
throw new TypeError(`"${label}" expected plain object`);
|
|
2277
|
+
if (Object.hasOwn(value, "__proto__"))
|
|
2278
|
+
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
2279
|
+
};
|
|
2280
|
+
function aexists2(instance, checkFinished = true) {
|
|
2281
|
+
if (instance.destroyed)
|
|
2282
|
+
throw new Error("hash was destroyed");
|
|
2283
|
+
if (checkFinished && instance.finished)
|
|
2284
|
+
throw new Error("digest() was already called");
|
|
2302
2285
|
}
|
|
2303
|
-
function
|
|
2304
|
-
|
|
2305
|
-
|
|
2286
|
+
function aoutput(out, instance) {
|
|
2287
|
+
abytes2(out, void 0, "output");
|
|
2288
|
+
const min = instance.outputLen;
|
|
2289
|
+
if (!(out.length >= min)) {
|
|
2290
|
+
throw new RangeError('"output" expected length >= ' + min);
|
|
2306
2291
|
}
|
|
2307
2292
|
}
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
}
|
|
2312
|
-
function byteSwap32(arr) {
|
|
2313
|
-
for (let i = 0; i < arr.length; i++) {
|
|
2314
|
-
arr[i] = byteSwap(arr[i]);
|
|
2293
|
+
function clean2(...arrays) {
|
|
2294
|
+
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
2295
|
+
arrays[i2].fill(0);
|
|
2315
2296
|
}
|
|
2316
|
-
return arr;
|
|
2317
|
-
}
|
|
2318
|
-
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
2319
|
-
function overlapBytes(a, b) {
|
|
2320
|
-
if (!a.byteLength || !b.byteLength)
|
|
2321
|
-
return false;
|
|
2322
|
-
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
2323
|
-
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
2324
|
-
b.byteOffset < a.byteOffset + a.byteLength;
|
|
2325
2297
|
}
|
|
2326
|
-
function
|
|
2327
|
-
|
|
2328
|
-
throw new Error("complex overlap of input and output is not supported");
|
|
2298
|
+
function createView2(arr) {
|
|
2299
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2329
2300
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
abytes2(key2, void 0, "key");
|
|
2333
|
-
if (params.nonceLength !== void 0) {
|
|
2334
|
-
const nonce = args[0];
|
|
2335
|
-
abytes2(nonce, params.varSizeNonce ? void 0 : params.nonceLength, "nonce");
|
|
2336
|
-
}
|
|
2337
|
-
const tagl = params.tagLength;
|
|
2338
|
-
const aadStart = params.nonceLength !== void 0 ? 1 : 0;
|
|
2339
|
-
if (!params.withAAD) {
|
|
2340
|
-
for (let i = aadStart; i < args.length; i++)
|
|
2341
|
-
if (isBytes2(args[i]))
|
|
2342
|
-
throw new Error("AAD not supported");
|
|
2343
|
-
}
|
|
2344
|
-
if (params.withAAD && args[aadStart] !== void 0)
|
|
2345
|
-
abytes2(args[aadStart], void 0, "AAD");
|
|
2346
|
-
const cipher = constructor(key2, ...args);
|
|
2347
|
-
const checkOutput = (fnLength, output) => {
|
|
2348
|
-
if (output !== void 0) {
|
|
2349
|
-
if (fnLength !== 2)
|
|
2350
|
-
throw new Error("cipher output not supported");
|
|
2351
|
-
abytes2(output, void 0, "output");
|
|
2352
|
-
}
|
|
2353
|
-
};
|
|
2354
|
-
let called = false;
|
|
2355
|
-
const wrCipher = {
|
|
2356
|
-
encrypt(data, output) {
|
|
2357
|
-
if (called)
|
|
2358
|
-
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
2359
|
-
called = true;
|
|
2360
|
-
abytes2(data, void 0, "data");
|
|
2361
|
-
checkOutput(cipher.encrypt.length, output);
|
|
2362
|
-
return cipher.encrypt(data, output);
|
|
2363
|
-
},
|
|
2364
|
-
decrypt(data, output) {
|
|
2365
|
-
abytes2(data, void 0, "data");
|
|
2366
|
-
if (tagl && data.length < tagl)
|
|
2367
|
-
throw new Error('"ciphertext" expected length >= tagLength=' + tagl);
|
|
2368
|
-
checkOutput(cipher.decrypt.length, output);
|
|
2369
|
-
return cipher.decrypt(data, output);
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
return wrCipher;
|
|
2373
|
-
}
|
|
2374
|
-
Object.assign(wrappedCipher, params);
|
|
2375
|
-
return wrappedCipher;
|
|
2376
|
-
};
|
|
2377
|
-
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
2378
|
-
if (out === void 0)
|
|
2379
|
-
return new Uint8Array(expectedLength);
|
|
2380
|
-
abytes2(out, expectedLength, "output");
|
|
2381
|
-
if (onlyAligned && !isAligned32(out))
|
|
2382
|
-
throw new Error("invalid output, must be aligned");
|
|
2383
|
-
return out;
|
|
2301
|
+
function rotl(word, shift) {
|
|
2302
|
+
return word << shift | word >>> 32 - shift >>> 0;
|
|
2384
2303
|
}
|
|
2385
|
-
function
|
|
2386
|
-
|
|
2304
|
+
function checkOpts(defaults, opts, title = "opts") {
|
|
2305
|
+
aopts(defaults, "defaults");
|
|
2306
|
+
if (opts !== void 0)
|
|
2307
|
+
aopts(opts, title);
|
|
2308
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
|
|
2309
|
+
return merged;
|
|
2387
2310
|
}
|
|
2388
|
-
function
|
|
2389
|
-
|
|
2311
|
+
function createHasher(hashCons, info = {}) {
|
|
2312
|
+
if (typeof hashCons !== "function")
|
|
2313
|
+
throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
|
|
2314
|
+
info = checkOpts({}, info, "info");
|
|
2315
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
2316
|
+
const tmp = hashCons(void 0);
|
|
2317
|
+
hashC.outputLen = tmp.outputLen;
|
|
2318
|
+
hashC.blockLen = tmp.blockLen;
|
|
2319
|
+
hashC.canXOF = tmp.canXOF;
|
|
2320
|
+
hashC.create = (opts) => hashCons(opts);
|
|
2321
|
+
Object.assign(hashC, info);
|
|
2322
|
+
return Object.freeze(hashC);
|
|
2390
2323
|
}
|
|
2391
2324
|
|
|
2392
|
-
// node_modules/.pnpm/@noble+
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
function validateKeyLength(key2) {
|
|
2396
|
-
if (![16, 24, 32].includes(key2.length))
|
|
2397
|
-
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key2.length);
|
|
2325
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
2326
|
+
function Chi(a, b, c) {
|
|
2327
|
+
return a & b ^ ~a & c;
|
|
2398
2328
|
}
|
|
2399
|
-
function
|
|
2400
|
-
return
|
|
2329
|
+
function Maj(a, b, c) {
|
|
2330
|
+
return a & b ^ a & c ^ b & c;
|
|
2401
2331
|
}
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2332
|
+
var HashMD = class {
|
|
2333
|
+
blockLen;
|
|
2334
|
+
outputLen;
|
|
2335
|
+
canXOF = false;
|
|
2336
|
+
padOffset;
|
|
2337
|
+
isLE;
|
|
2338
|
+
// For partial updates less than block size
|
|
2339
|
+
buffer;
|
|
2340
|
+
view;
|
|
2341
|
+
finished = false;
|
|
2342
|
+
length = 0;
|
|
2343
|
+
pos = 0;
|
|
2344
|
+
destroyed = false;
|
|
2345
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
2346
|
+
this.blockLen = blockLen;
|
|
2347
|
+
this.outputLen = outputLen;
|
|
2348
|
+
this.padOffset = padOffset;
|
|
2349
|
+
this.isLE = isLE2;
|
|
2350
|
+
this.buffer = new Uint8Array(blockLen);
|
|
2351
|
+
this.view = createView2(this.buffer);
|
|
2407
2352
|
}
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2353
|
+
update(data) {
|
|
2354
|
+
aexists2(this);
|
|
2355
|
+
abytes2(data);
|
|
2356
|
+
const { view, buffer, blockLen } = this;
|
|
2357
|
+
const len = data.length;
|
|
2358
|
+
let processed = false;
|
|
2359
|
+
for (let pos = 0; pos < len; ) {
|
|
2360
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2361
|
+
if (take === blockLen) {
|
|
2362
|
+
const dataView = createView2(data);
|
|
2363
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
2364
|
+
this.process(dataView, pos);
|
|
2365
|
+
processed = true;
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
2369
|
+
this.pos += take;
|
|
2370
|
+
pos += take;
|
|
2371
|
+
if (this.pos === blockLen) {
|
|
2372
|
+
this.process(view, 0);
|
|
2373
|
+
this.pos = 0;
|
|
2374
|
+
processed = true;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
this.length += data.length;
|
|
2378
|
+
if (processed)
|
|
2379
|
+
this.roundClean();
|
|
2380
|
+
return this;
|
|
2420
2381
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
const T2 = T1.map(rotl32_8);
|
|
2433
|
-
const T3 = T2.map(rotl32_8);
|
|
2434
|
-
const T01 = new Uint32Array(256 * 256);
|
|
2435
|
-
const T23 = new Uint32Array(256 * 256);
|
|
2436
|
-
const sbox22 = new Uint16Array(256 * 256);
|
|
2437
|
-
for (let i = 0; i < 256; i++) {
|
|
2438
|
-
for (let j = 0; j < 256; j++) {
|
|
2439
|
-
const idx = i * 256 + j;
|
|
2440
|
-
T01[idx] = T0[i] ^ T1[j];
|
|
2441
|
-
T23[idx] = T2[i] ^ T3[j];
|
|
2442
|
-
sbox22[idx] = sbox2[i] << 8 | sbox2[j];
|
|
2382
|
+
digestInto(out) {
|
|
2383
|
+
aexists2(this);
|
|
2384
|
+
aoutput(out, this);
|
|
2385
|
+
this.finished = true;
|
|
2386
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
2387
|
+
let { pos } = this;
|
|
2388
|
+
buffer[pos++] = 128;
|
|
2389
|
+
buffer.fill(0, pos);
|
|
2390
|
+
if (this.padOffset > blockLen - pos) {
|
|
2391
|
+
this.process(view, 0);
|
|
2392
|
+
buffer.fill(0);
|
|
2443
2393
|
}
|
|
2394
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE2);
|
|
2395
|
+
this.process(view, 0);
|
|
2396
|
+
this.roundClean();
|
|
2397
|
+
const oview = out === buffer ? view : createView2(out);
|
|
2398
|
+
const len = this.outputLen;
|
|
2399
|
+
const outLen = len / 4;
|
|
2400
|
+
const state = this.get();
|
|
2401
|
+
if (len % 4 || outLen > state.length)
|
|
2402
|
+
throw new Error("invalid outputLen");
|
|
2403
|
+
for (let i2 = 0; i2 < outLen; i2++)
|
|
2404
|
+
oview.setUint32(4 * i2, state[i2], isLE2);
|
|
2444
2405
|
}
|
|
2445
|
-
|
|
2446
|
-
}
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2406
|
+
digest() {
|
|
2407
|
+
const { buffer, outputLen } = this;
|
|
2408
|
+
this.digestInto(buffer);
|
|
2409
|
+
const res = buffer.slice(0, outputLen);
|
|
2410
|
+
this.destroy();
|
|
2411
|
+
return res;
|
|
2412
|
+
}
|
|
2413
|
+
_cloneIntoMeta(to) {
|
|
2414
|
+
const { buffer, length, finished, destroyed, pos } = this;
|
|
2415
|
+
to.destroyed = destroyed;
|
|
2416
|
+
to.finished = finished;
|
|
2417
|
+
to.length = length;
|
|
2418
|
+
to.pos = pos;
|
|
2419
|
+
if (pos)
|
|
2420
|
+
to.buffer.set(buffer);
|
|
2421
|
+
return to;
|
|
2422
|
+
}
|
|
2423
|
+
clone() {
|
|
2424
|
+
return this._cloneInto();
|
|
2425
|
+
}
|
|
2426
|
+
};
|
|
2427
|
+
|
|
2428
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/legacy.js
|
|
2429
|
+
var SHA1_IV = /* @__PURE__ */ Uint32Array.from([
|
|
2430
|
+
1732584193,
|
|
2431
|
+
4023233417,
|
|
2432
|
+
2562383102,
|
|
2433
|
+
271733878,
|
|
2434
|
+
3285377520
|
|
2435
|
+
]);
|
|
2436
|
+
var SHA1_W = /* @__PURE__ */ new Uint32Array(80);
|
|
2437
|
+
var _SHA1 = class extends HashMD {
|
|
2438
|
+
A = SHA1_IV[0] | 0;
|
|
2439
|
+
B = SHA1_IV[1] | 0;
|
|
2440
|
+
C = SHA1_IV[2] | 0;
|
|
2441
|
+
D = SHA1_IV[3] | 0;
|
|
2442
|
+
E = SHA1_IV[4] | 0;
|
|
2443
|
+
constructor() {
|
|
2444
|
+
super(64, 20, 8, false);
|
|
2475
2445
|
}
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
function expandKeyDecLE(key2) {
|
|
2480
|
-
const encKey = expandKeyLE(key2);
|
|
2481
|
-
const xk = encKey.slice();
|
|
2482
|
-
const Nk = encKey.length;
|
|
2483
|
-
const { sbox2 } = tableEncoding;
|
|
2484
|
-
const { T0, T1, T2, T3 } = tableDecoding;
|
|
2485
|
-
for (let i = 0; i < Nk; i += 4) {
|
|
2486
|
-
for (let j = 0; j < 4; j++)
|
|
2487
|
-
xk[i + j] = encKey[Nk - i - 4 + j];
|
|
2446
|
+
get() {
|
|
2447
|
+
const { A, B, C, D, E } = this;
|
|
2448
|
+
return [A, B, C, D, E];
|
|
2488
2449
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2450
|
+
set(A, B, C, D, E) {
|
|
2451
|
+
this.A = A | 0;
|
|
2452
|
+
this.B = B | 0;
|
|
2453
|
+
this.C = C | 0;
|
|
2454
|
+
this.D = D | 0;
|
|
2455
|
+
this.E = E | 0;
|
|
2494
2456
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
2499
|
-
}
|
|
2500
|
-
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
2501
|
-
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
2502
|
-
}
|
|
2503
|
-
function encrypt(xk, s0, s1, s2, s3) {
|
|
2504
|
-
const { sbox2, T01, T23 } = tableEncoding;
|
|
2505
|
-
let k = 0;
|
|
2506
|
-
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
2507
|
-
const rounds = xk.length / 4 - 2;
|
|
2508
|
-
for (let i = 0; i < rounds; i++) {
|
|
2509
|
-
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
2510
|
-
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
2511
|
-
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
2512
|
-
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
2513
|
-
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
2457
|
+
_cloneInto(to) {
|
|
2458
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
2459
|
+
return this._cloneIntoMeta(to);
|
|
2514
2460
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
}
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2461
|
+
process(view, offset) {
|
|
2462
|
+
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
2463
|
+
SHA1_W[i2] = view.getUint32(offset, false);
|
|
2464
|
+
for (let i2 = 16; i2 < 80; i2++)
|
|
2465
|
+
SHA1_W[i2] = rotl(SHA1_W[i2 - 3] ^ SHA1_W[i2 - 8] ^ SHA1_W[i2 - 14] ^ SHA1_W[i2 - 16], 1);
|
|
2466
|
+
let { A, B, C, D, E } = this;
|
|
2467
|
+
for (let i2 = 0; i2 < 80; i2++) {
|
|
2468
|
+
let F, K2;
|
|
2469
|
+
if (i2 < 20) {
|
|
2470
|
+
F = Chi(B, C, D);
|
|
2471
|
+
K2 = 1518500249;
|
|
2472
|
+
} else if (i2 < 40) {
|
|
2473
|
+
F = B ^ C ^ D;
|
|
2474
|
+
K2 = 1859775393;
|
|
2475
|
+
} else if (i2 < 60) {
|
|
2476
|
+
F = Maj(B, C, D);
|
|
2477
|
+
K2 = 2400959708;
|
|
2478
|
+
} else {
|
|
2479
|
+
F = B ^ C ^ D;
|
|
2480
|
+
K2 = 3395469782;
|
|
2481
|
+
}
|
|
2482
|
+
const T = rotl(A, 5) + F + E + K2 + SHA1_W[i2] | 0;
|
|
2483
|
+
E = D;
|
|
2484
|
+
D = C;
|
|
2485
|
+
C = rotl(B, 30);
|
|
2486
|
+
B = A;
|
|
2487
|
+
A = T;
|
|
2488
|
+
}
|
|
2489
|
+
A = A + this.A | 0;
|
|
2490
|
+
B = B + this.B | 0;
|
|
2491
|
+
C = C + this.C | 0;
|
|
2492
|
+
D = D + this.D | 0;
|
|
2493
|
+
E = E + this.E | 0;
|
|
2494
|
+
this.set(A, B, C, D, E);
|
|
2532
2495
|
}
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
const t2 = xk[k++] ^ applySbox(sbox2, s2, s1, s0, s3);
|
|
2536
|
-
const t3 = xk[k++] ^ applySbox(sbox2, s3, s2, s1, s0);
|
|
2537
|
-
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
2538
|
-
}
|
|
2539
|
-
function validateBlockDecrypt(data, dst) {
|
|
2540
|
-
abytes2(data);
|
|
2541
|
-
if (data.length % BLOCK_SIZE !== 0) {
|
|
2542
|
-
throw new Error("ciphertext must be multiple of " + BLOCK_SIZE);
|
|
2496
|
+
roundClean() {
|
|
2497
|
+
clean2(SHA1_W);
|
|
2543
2498
|
}
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2499
|
+
destroy() {
|
|
2500
|
+
this.destroyed = true;
|
|
2501
|
+
this.set(0, 0, 0, 0, 0);
|
|
2502
|
+
clean2(this.buffer);
|
|
2547
2503
|
}
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2504
|
+
};
|
|
2505
|
+
var sha1 = /* @__PURE__ */ createHasher(() => new _SHA1());
|
|
2506
|
+
var p32 = /* @__PURE__ */ Math.pow(2, 32);
|
|
2507
|
+
var K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i2) => Math.floor(p32 * Math.abs(Math.sin(i2 + 1))));
|
|
2508
|
+
var MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
|
|
2509
|
+
var MD5_W = /* @__PURE__ */ new Uint32Array(16);
|
|
2510
|
+
var MD5_SHIFTS = /* @__PURE__ */ (() => {
|
|
2511
|
+
const S = [
|
|
2512
|
+
[7, 12, 17, 22],
|
|
2513
|
+
[5, 9, 14, 20],
|
|
2514
|
+
[4, 11, 16, 23],
|
|
2515
|
+
[6, 10, 15, 21]
|
|
2516
|
+
];
|
|
2517
|
+
return Uint8Array.from({ length: 64 }, (_, i2) => S[Math.floor(i2 / 16)][i2 % 4]);
|
|
2518
|
+
})();
|
|
2519
|
+
var _MD5 = class extends HashMD {
|
|
2520
|
+
A = MD5_IV[0] | 0;
|
|
2521
|
+
B = MD5_IV[1] | 0;
|
|
2522
|
+
C = MD5_IV[2] | 0;
|
|
2523
|
+
D = MD5_IV[3] | 0;
|
|
2524
|
+
constructor() {
|
|
2525
|
+
super(64, 16, 8, true);
|
|
2560
2526
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2527
|
+
get() {
|
|
2528
|
+
const { A, B, C, D } = this;
|
|
2529
|
+
return [A, B, C, D];
|
|
2564
2530
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
if (!isLE || !isAligned32(plaintext))
|
|
2571
|
-
plaintext = copyBytes(plaintext);
|
|
2572
|
-
const o = u32(dst);
|
|
2573
|
-
return { b: plaintext, o, out: dst };
|
|
2574
|
-
}
|
|
2575
|
-
function validatePKCS(data, pkcs5) {
|
|
2576
|
-
if (!pkcs5)
|
|
2577
|
-
return data;
|
|
2578
|
-
const len = data.length;
|
|
2579
|
-
if (len === 0)
|
|
2580
|
-
throw new Error("pkcs7: empty ciphertext not allowed");
|
|
2581
|
-
const lastByte = data[len - 1];
|
|
2582
|
-
let valid = 1;
|
|
2583
|
-
valid &= lastByte - 1 >>> 31 ^ 1;
|
|
2584
|
-
valid &= 16 - lastByte >>> 31 ^ 1;
|
|
2585
|
-
for (let i = 0; i < 16; i++) {
|
|
2586
|
-
const shouldCheck = i - lastByte >>> 31;
|
|
2587
|
-
const eq = (data[len - 1 - i] ^ lastByte) === 0 ? 1 : 0;
|
|
2588
|
-
valid &= eq | shouldCheck ^ 1;
|
|
2531
|
+
set(A, B, C, D) {
|
|
2532
|
+
this.A = A | 0;
|
|
2533
|
+
this.B = B | 0;
|
|
2534
|
+
this.C = C | 0;
|
|
2535
|
+
this.D = D | 0;
|
|
2589
2536
|
}
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
let i = 0;
|
|
2613
|
-
for (; i + 4 <= b.length; ) {
|
|
2614
|
-
const { s0, s1, s2, s3 } = encrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
|
|
2615
|
-
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
2616
|
-
}
|
|
2617
|
-
if (pkcs5) {
|
|
2618
|
-
const tmp32 = padPCKS(plaintext.subarray(i * 4));
|
|
2619
|
-
swap32IfBE(tmp32);
|
|
2620
|
-
const { s0, s1, s2, s3 } = encrypt(xk, tmp32[0], tmp32[1], tmp32[2], tmp32[3]);
|
|
2621
|
-
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
2622
|
-
clean2(tmp32);
|
|
2623
|
-
}
|
|
2624
|
-
swap32IfBE(o);
|
|
2625
|
-
clean2(xk);
|
|
2626
|
-
if (input !== plaintext)
|
|
2627
|
-
clean2(input);
|
|
2628
|
-
return _out;
|
|
2629
|
-
},
|
|
2630
|
-
decrypt(ciphertext, dst) {
|
|
2631
|
-
validateBlockDecrypt(ciphertext, dst);
|
|
2632
|
-
const xk = expandKeyDecLE(key2);
|
|
2633
|
-
if (dst === void 0)
|
|
2634
|
-
dst = new Uint8Array(ciphertext.length);
|
|
2635
|
-
const toClean = [xk];
|
|
2636
|
-
if (!isLE || !isAligned32(ciphertext))
|
|
2637
|
-
toClean.push(ciphertext = copyBytes(ciphertext));
|
|
2638
|
-
const b = u32(ciphertext);
|
|
2639
|
-
const o = u32(dst);
|
|
2640
|
-
swap32IfBE(b);
|
|
2641
|
-
for (let i = 0; i + 4 <= b.length; ) {
|
|
2642
|
-
const { s0, s1, s2, s3 } = decrypt(xk, b[i + 0], b[i + 1], b[i + 2], b[i + 3]);
|
|
2643
|
-
o[i++] = s0, o[i++] = s1, o[i++] = s2, o[i++] = s3;
|
|
2537
|
+
_cloneInto(to) {
|
|
2538
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
2539
|
+
return this._cloneIntoMeta(to);
|
|
2540
|
+
}
|
|
2541
|
+
process(view, offset) {
|
|
2542
|
+
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
2543
|
+
MD5_W[i2] = view.getUint32(offset, true);
|
|
2544
|
+
let { A, B, C, D } = this;
|
|
2545
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
2546
|
+
let F, g;
|
|
2547
|
+
if (i2 < 16) {
|
|
2548
|
+
F = Chi(B, C, D);
|
|
2549
|
+
g = i2;
|
|
2550
|
+
} else if (i2 < 32) {
|
|
2551
|
+
F = Chi(D, B, C);
|
|
2552
|
+
g = (5 * i2 + 1) % 16;
|
|
2553
|
+
} else if (i2 < 48) {
|
|
2554
|
+
F = B ^ C ^ D;
|
|
2555
|
+
g = (3 * i2 + 5) % 16;
|
|
2556
|
+
} else {
|
|
2557
|
+
F = C ^ (B | ~D);
|
|
2558
|
+
g = 7 * i2 % 16;
|
|
2644
2559
|
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2560
|
+
F = F + A + K[i2] + MD5_W[g];
|
|
2561
|
+
A = D;
|
|
2562
|
+
D = C;
|
|
2563
|
+
C = B;
|
|
2564
|
+
B = B + rotl(F, MD5_SHIFTS[i2]);
|
|
2648
2565
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
2566
|
+
A = A + this.A | 0;
|
|
2567
|
+
B = B + this.B | 0;
|
|
2568
|
+
C = C + this.C | 0;
|
|
2569
|
+
D = D + this.D | 0;
|
|
2570
|
+
this.set(A, B, C, D);
|
|
2571
|
+
}
|
|
2572
|
+
roundClean() {
|
|
2573
|
+
clean2(MD5_W);
|
|
2574
|
+
}
|
|
2575
|
+
destroy() {
|
|
2576
|
+
this.destroyed = true;
|
|
2577
|
+
this.set(0, 0, 0, 0);
|
|
2578
|
+
clean2(this.buffer);
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
2581
|
+
var md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
2582
|
+
|
|
2583
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/hmac.js
|
|
2584
|
+
init_buffer();
|
|
2585
|
+
var _HMAC = class {
|
|
2586
|
+
oHash;
|
|
2587
|
+
iHash;
|
|
2588
|
+
blockLen;
|
|
2589
|
+
outputLen;
|
|
2590
|
+
canXOF = false;
|
|
2591
|
+
finished = false;
|
|
2592
|
+
destroyed = false;
|
|
2593
|
+
constructor(hash2, key2) {
|
|
2594
|
+
ahash(hash2);
|
|
2595
|
+
abytes2(key2, void 0, "key");
|
|
2596
|
+
this.iHash = hash2.create();
|
|
2597
|
+
if (typeof this.iHash.update !== "function")
|
|
2598
|
+
throw new Error("expected Hash instance");
|
|
2599
|
+
this.blockLen = this.iHash.blockLen;
|
|
2600
|
+
this.outputLen = this.iHash.outputLen;
|
|
2601
|
+
const blockLen = this.blockLen;
|
|
2602
|
+
const pad = new Uint8Array(blockLen);
|
|
2603
|
+
pad.set(key2.length > blockLen ? hash2.create().update(key2).digest() : key2);
|
|
2604
|
+
for (let i2 = 0; i2 < pad.length; i2++)
|
|
2605
|
+
pad[i2] ^= 54;
|
|
2606
|
+
this.iHash.update(pad);
|
|
2607
|
+
this.oHash = hash2.create();
|
|
2608
|
+
for (let i2 = 0; i2 < pad.length; i2++)
|
|
2609
|
+
pad[i2] ^= 54 ^ 92;
|
|
2610
|
+
this.oHash.update(pad);
|
|
2611
|
+
clean2(pad);
|
|
2612
|
+
}
|
|
2613
|
+
update(buf) {
|
|
2614
|
+
aexists2(this);
|
|
2615
|
+
this.iHash.update(buf);
|
|
2616
|
+
return this;
|
|
2617
|
+
}
|
|
2618
|
+
digestInto(out) {
|
|
2619
|
+
aexists2(this);
|
|
2620
|
+
aoutput(out, this);
|
|
2621
|
+
this.finished = true;
|
|
2622
|
+
const buf = out.subarray(0, this.outputLen);
|
|
2623
|
+
this.iHash.digestInto(buf);
|
|
2624
|
+
this.oHash.update(buf);
|
|
2625
|
+
this.oHash.digestInto(buf);
|
|
2626
|
+
this.destroy();
|
|
2627
|
+
}
|
|
2628
|
+
digest() {
|
|
2629
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
2630
|
+
this.digestInto(out);
|
|
2631
|
+
return out;
|
|
2632
|
+
}
|
|
2633
|
+
_cloneInto(to) {
|
|
2634
|
+
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
2635
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen, canXOF } = this;
|
|
2636
|
+
to = to;
|
|
2637
|
+
to.finished = finished;
|
|
2638
|
+
to.destroyed = destroyed;
|
|
2639
|
+
to.blockLen = blockLen;
|
|
2640
|
+
to.outputLen = outputLen;
|
|
2641
|
+
to.canXOF = canXOF;
|
|
2642
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
2643
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
2644
|
+
return to;
|
|
2645
|
+
}
|
|
2646
|
+
clone() {
|
|
2647
|
+
return this._cloneInto();
|
|
2648
|
+
}
|
|
2649
|
+
destroy() {
|
|
2650
|
+
this.destroyed = true;
|
|
2651
|
+
this.oHash.destroy();
|
|
2652
|
+
this.iHash.destroy();
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
var hmac = /* @__PURE__ */ (() => {
|
|
2656
|
+
const hmac_ = ((hash2, key2, message) => new _HMAC(hash2, key2).update(message).digest());
|
|
2657
|
+
hmac_.create = (hash2, key2) => new _HMAC(hash2, key2);
|
|
2658
|
+
return hmac_;
|
|
2659
|
+
})();
|
|
2651
2660
|
|
|
2652
2661
|
// node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
|
|
2653
2662
|
init_buffer();
|
|
@@ -2728,13 +2737,13 @@ var fdeb = new u82([
|
|
|
2728
2737
|
var clim = new u82([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
2729
2738
|
var freb = function(eb, start) {
|
|
2730
2739
|
var b = new u16(31);
|
|
2731
|
-
for (var
|
|
2732
|
-
b[
|
|
2740
|
+
for (var i2 = 0; i2 < 31; ++i2) {
|
|
2741
|
+
b[i2] = start += 1 << eb[i2 - 1];
|
|
2733
2742
|
}
|
|
2734
2743
|
var r = new i32(b[30]);
|
|
2735
|
-
for (var
|
|
2736
|
-
for (var j = b[
|
|
2737
|
-
r[j] = j - b[
|
|
2744
|
+
for (var i2 = 1; i2 < 30; ++i2) {
|
|
2745
|
+
for (var j = b[i2]; j < b[i2 + 1]; ++j) {
|
|
2746
|
+
r[j] = j - b[i2] << 5 | i2;
|
|
2738
2747
|
}
|
|
2739
2748
|
}
|
|
2740
2749
|
return { b, r };
|
|
@@ -2757,25 +2766,25 @@ var x;
|
|
|
2757
2766
|
var i;
|
|
2758
2767
|
var hMap = (function(cd, mb, r) {
|
|
2759
2768
|
var s = cd.length;
|
|
2760
|
-
var
|
|
2769
|
+
var i2 = 0;
|
|
2761
2770
|
var l = new u16(mb);
|
|
2762
|
-
for (;
|
|
2763
|
-
if (cd[
|
|
2764
|
-
++l[cd[
|
|
2771
|
+
for (; i2 < s; ++i2) {
|
|
2772
|
+
if (cd[i2])
|
|
2773
|
+
++l[cd[i2] - 1];
|
|
2765
2774
|
}
|
|
2766
2775
|
var le = new u16(mb);
|
|
2767
|
-
for (
|
|
2768
|
-
le[
|
|
2776
|
+
for (i2 = 1; i2 < mb; ++i2) {
|
|
2777
|
+
le[i2] = le[i2 - 1] + l[i2 - 1] << 1;
|
|
2769
2778
|
}
|
|
2770
2779
|
var co;
|
|
2771
2780
|
if (r) {
|
|
2772
2781
|
co = new u16(1 << mb);
|
|
2773
2782
|
var rvb = 15 - mb;
|
|
2774
|
-
for (
|
|
2775
|
-
if (cd[
|
|
2776
|
-
var sv =
|
|
2777
|
-
var r_1 = mb - cd[
|
|
2778
|
-
var v = le[cd[
|
|
2783
|
+
for (i2 = 0; i2 < s; ++i2) {
|
|
2784
|
+
if (cd[i2]) {
|
|
2785
|
+
var sv = i2 << 4 | cd[i2];
|
|
2786
|
+
var r_1 = mb - cd[i2];
|
|
2787
|
+
var v = le[cd[i2] - 1]++ << r_1;
|
|
2779
2788
|
for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
|
|
2780
2789
|
co[rev[v] >> rvb] = sv;
|
|
2781
2790
|
}
|
|
@@ -2783,9 +2792,9 @@ var hMap = (function(cd, mb, r) {
|
|
|
2783
2792
|
}
|
|
2784
2793
|
} else {
|
|
2785
2794
|
co = new u16(s);
|
|
2786
|
-
for (
|
|
2787
|
-
if (cd[
|
|
2788
|
-
co[
|
|
2795
|
+
for (i2 = 0; i2 < s; ++i2) {
|
|
2796
|
+
if (cd[i2]) {
|
|
2797
|
+
co[i2] = rev[le[cd[i2] - 1]++] >> 15 - cd[i2];
|
|
2789
2798
|
}
|
|
2790
2799
|
}
|
|
2791
2800
|
}
|
|
@@ -2812,9 +2821,9 @@ var flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
|
2812
2821
|
var fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
2813
2822
|
var max = function(a) {
|
|
2814
2823
|
var m = a[0];
|
|
2815
|
-
for (var
|
|
2816
|
-
if (a[
|
|
2817
|
-
m = a[
|
|
2824
|
+
for (var i2 = 1; i2 < a.length; ++i2) {
|
|
2825
|
+
if (a[i2] > m)
|
|
2826
|
+
m = a[i2];
|
|
2818
2827
|
}
|
|
2819
2828
|
return m;
|
|
2820
2829
|
};
|
|
@@ -2907,28 +2916,28 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
2907
2916
|
pos += 14;
|
|
2908
2917
|
var ldt = new u82(tl);
|
|
2909
2918
|
var clt = new u82(19);
|
|
2910
|
-
for (var
|
|
2911
|
-
clt[clim[
|
|
2919
|
+
for (var i2 = 0; i2 < hcLen; ++i2) {
|
|
2920
|
+
clt[clim[i2]] = bits(dat, pos + i2 * 3, 7);
|
|
2912
2921
|
}
|
|
2913
2922
|
pos += hcLen * 3;
|
|
2914
2923
|
var clb = max(clt), clbmsk = (1 << clb) - 1;
|
|
2915
2924
|
var clm = hMap(clt, clb, 1);
|
|
2916
|
-
for (var
|
|
2925
|
+
for (var i2 = 0; i2 < tl; ) {
|
|
2917
2926
|
var r = clm[bits(dat, pos, clbmsk)];
|
|
2918
2927
|
pos += r & 15;
|
|
2919
2928
|
var s = r >> 4;
|
|
2920
2929
|
if (s < 16) {
|
|
2921
|
-
ldt[
|
|
2930
|
+
ldt[i2++] = s;
|
|
2922
2931
|
} else {
|
|
2923
2932
|
var c = 0, n = 0;
|
|
2924
2933
|
if (s == 16)
|
|
2925
|
-
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[
|
|
2934
|
+
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i2 - 1];
|
|
2926
2935
|
else if (s == 17)
|
|
2927
2936
|
n = 3 + bits(dat, pos, 7), pos += 3;
|
|
2928
2937
|
else if (s == 18)
|
|
2929
2938
|
n = 11 + bits(dat, pos, 127), pos += 7;
|
|
2930
2939
|
while (n--)
|
|
2931
|
-
ldt[
|
|
2940
|
+
ldt[i2++] = c;
|
|
2932
2941
|
}
|
|
2933
2942
|
}
|
|
2934
2943
|
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
|
@@ -2966,8 +2975,8 @@ var inflt = function(dat, st, buf, dict) {
|
|
|
2966
2975
|
} else {
|
|
2967
2976
|
var add = sym - 254;
|
|
2968
2977
|
if (sym > 264) {
|
|
2969
|
-
var
|
|
2970
|
-
add = bits(dat, pos, (1 << b) - 1) + fl[
|
|
2978
|
+
var i2 = sym - 257, b = fleb[i2];
|
|
2979
|
+
add = bits(dat, pos, (1 << b) - 1) + fl[i2];
|
|
2971
2980
|
pos += b;
|
|
2972
2981
|
}
|
|
2973
2982
|
var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
|
|
@@ -3058,8 +3067,7 @@ var inflateRawSync = (data, options) => {
|
|
|
3058
3067
|
const output = import_buffer.Buffer.alloc(options.maxOutputLength);
|
|
3059
3068
|
let length = 0;
|
|
3060
3069
|
const stream = new Inflate((chunk) => {
|
|
3061
|
-
if (chunk.length > output.length - length)
|
|
3062
|
-
throw new RangeError("Inflated data exceeds declared size");
|
|
3070
|
+
if (chunk.length > output.length - length) throw new RangeError("Inflated data exceeds declared size");
|
|
3063
3071
|
output.set(chunk, length);
|
|
3064
3072
|
length += chunk.length;
|
|
3065
3073
|
});
|
|
@@ -3076,6 +3084,9 @@ var readFile = nodeOnly;
|
|
|
3076
3084
|
var writeFile = nodeOnly;
|
|
3077
3085
|
var readFileSync = nodeOnly;
|
|
3078
3086
|
|
|
3087
|
+
// src/nitro/banner.ts
|
|
3088
|
+
init_buffer();
|
|
3089
|
+
|
|
3079
3090
|
// src/nitro/binary.ts
|
|
3080
3091
|
init_buffer();
|
|
3081
3092
|
var DEFAULT_MAX_SIZE = 1073741824;
|
|
@@ -3085,15 +3096,11 @@ var bytes = (value, name = "input") => {
|
|
|
3085
3096
|
};
|
|
3086
3097
|
var range = (buffer, offset, size, name = "binary data") => {
|
|
3087
3098
|
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(size) || offset < 0 || size < 0 || offset + size > buffer.length) {
|
|
3088
|
-
throw new RangeError(
|
|
3089
|
-
`Invalid ${name} range: offset=${offset}, size=${size}, available=${buffer.length}`
|
|
3090
|
-
);
|
|
3099
|
+
throw new RangeError(`Invalid ${name} range: offset=${offset}, size=${size}, available=${buffer.length}`);
|
|
3091
3100
|
}
|
|
3092
3101
|
return buffer.subarray(offset, offset + size);
|
|
3093
3102
|
};
|
|
3094
|
-
var align = (value, alignment = 512) =>
|
|
3095
|
-
return Math.ceil(value / alignment) * alignment;
|
|
3096
|
-
};
|
|
3103
|
+
var align = (value, alignment = 512) => Math.ceil(value / alignment) * alignment;
|
|
3097
3104
|
var BinaryWriter = class {
|
|
3098
3105
|
maxSize;
|
|
3099
3106
|
buffer;
|
|
@@ -3117,8 +3124,7 @@ var BinaryWriter = class {
|
|
|
3117
3124
|
}
|
|
3118
3125
|
write(data) {
|
|
3119
3126
|
data = bytes(data);
|
|
3120
|
-
if (!Number.isSafeInteger(this.position) || this.position < 0)
|
|
3121
|
-
throw new RangeError("Invalid writer position");
|
|
3127
|
+
if (!Number.isSafeInteger(this.position) || this.position < 0) throw new RangeError("Invalid writer position");
|
|
3122
3128
|
this.ensure(this.position + data.length);
|
|
3123
3129
|
bytes(data).copy(this.buffer, this.position);
|
|
3124
3130
|
this.position += data.length;
|
|
@@ -3126,273 +3132,44 @@ var BinaryWriter = class {
|
|
|
3126
3132
|
}
|
|
3127
3133
|
fillTo(end, fill = 255) {
|
|
3128
3134
|
this.ensure(end);
|
|
3129
|
-
if (end <= this.position) return;
|
|
3130
|
-
this.buffer.fill(fill, this.position, end);
|
|
3131
|
-
this.position = end;
|
|
3132
|
-
this.length = Math.max(this.length, end);
|
|
3133
|
-
}
|
|
3134
|
-
pad(alignment, fill = 255) {
|
|
3135
|
-
this.fillTo(align(this.position, alignment), fill);
|
|
3136
|
-
}
|
|
3137
|
-
toBuffer() {
|
|
3138
|
-
return this.buffer.subarray(0, this.length);
|
|
3139
|
-
}
|
|
3140
|
-
};
|
|
3141
|
-
|
|
3142
|
-
// src/nitro/
|
|
3143
|
-
init_buffer();
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
}
|
|
3155
|
-
table16[i] = a;
|
|
3156
|
-
table32[i] = b;
|
|
3157
|
-
}
|
|
3158
|
-
var crc16 = (data, initial = 65535) => {
|
|
3159
|
-
let crc = initial;
|
|
3160
|
-
for (const byte of data) crc = crc >>> 8 ^ table16[(crc ^ byte) & 255];
|
|
3161
|
-
return crc;
|
|
3162
|
-
};
|
|
3163
|
-
var crc32 = (data) => {
|
|
3164
|
-
let crc = 4294967295;
|
|
3165
|
-
for (const byte of data) crc = crc >>> 8 ^ table32[(crc ^ byte) & 255];
|
|
3166
|
-
return (crc ^ 4294967295) >>> 0;
|
|
3167
|
-
};
|
|
3168
|
-
|
|
3169
|
-
// src/nitro/crypto.ts
|
|
3170
|
-
init_buffer();
|
|
3171
|
-
var KEY1 = import_buffer.Buffer.from(
|
|
3172
|
-
"99D5205F5744F5B96E19A4D99E6A5A94D8AEF1EB4175E23A9382D03233EE31D5CC57619A3706A21B793972F555AEF6BE5F1B69FBE59DF1E9CE2CD9A15E3205E6FED3FECFD462040D8BF5ECB72B6079BB1295310D6E3FDA2B8884F0F13D127E254522F1BB24061A0611ADDF288B6481342BEB332999AAF2BD9C14959D9FF7F58C7297A1299DD15FCF664D071ADED34A4B85C9A7A31795053A3D490ABF0A898BA24A8249DD2790F10BE9EB1C6A83764505BA817061173F4BDEAECFAB3957F23A564811AD8A40E1453FFA9B0254CAA693FBEF4DFE6FA3D8879C08BAD5486A8D2DFD6E15F874BDBE528B18228A9EFB7437071B366C4A19BA4262B97991107B676596FE0223E8EE998C773E5C86644D6D7886A54F65E21EB2DF5A0AD07E0814B071ACBDDB831CB9D7A162CDC6637C5269C3E6BF75CE12445D2104FAFBD33C381163D4958541494609F2084311DC1F76C0156D1F3C6370EA87806CC3BD638BC2372137DCEE09232E376A4D7390F75030AC1C92041023914FD207AA683E4F9AC964606AC81421F3D62241124424CFE68A56DD0D534DE1851E8C525A9C1984C20357F16FE300BE58F64CEDD521649C1FBE55033C4ADCFFAAC9DAE05D5EBFE6DEF5D8B1F8FF36B3B9626795DB315F37ED4C70679990B518316C3D9999E442DAD3254213A0AED7706CB155CFC7D746D54361173D4428E93385D5D0A293AA25121FFBC50B46F597765645A6BE87B1946BE8B1FE3399AE1F3E6C39711D09009037E4103E7574FF8C833BB0F1B0F90105474295F1D6AC7E38E69E9574263FB4685018D04330B44C4BE368BFE54DB6958B0AA074253277CFA1F72CD871135AABEAC951E80DEEEFE9937E19A71E433881162CA148E373CC29216CD35DCEA0D9617143A01513B56492CF2A19DCADB7A59F8665F81A9FE7FBF7FDB8136C27DB6FDF351CF78D2C5B9B12AB386406CCDE31E84E751164E3FAEAEB3454C2AD3F34EB932C7D26369D56F35AE1F6B398634A9E3283E49A84607D902E130EEE934B36A285EC1638E8880602BFF0A03AEDD76A9A73E157CFF844B8DC2E2359D1DF9552719961A04BD57F6E78BAA9C530D34086329D320C9C37B7022FBA5498A9C41304C98DBEC8E75D97502E93D622590C27BC2292E0A7200F936F7F4C9FD3B5A62A0B7467497D1026CBD1C58671E78CA09CE95BB21AF601EE8C9E5E83F21ADBE6E5EA845976D27CF68DA5493648C21652BB83A374B9070C3BFF6128E161E9E4EF6E15AA4EBAE85D0596BB3256B0FB72520F0EC84225657689AFF2DE1027F0014B74A79707D5265454091F820A867D30390EB3269B0B57BB360631AFFD79FCD930102B0CB3E19BD77BDC5FEFD2F813454D4775BD46963C7E75F33EB567C59A3BB05B296BDE805BC81505B131B6CE49DDAD84B5AE60DC67313430FE4EBD802FA6BF63392186D9357F1668220554E990268C076C51A43155D70907A83E2E5366C1F8F27BC4F258CFF187C5A2E7278F308758A064622318B9887CFACEC498AEAD17CC4A5BF3E948D556D30DF2C892738CDBD72F56AC81F992694DC632F6E6C08D21E276806111BCDC6C93AF19699BD0BFB9319F0267A351EE8306227B0CAB494240B8D5017DCE5EF7555339C59946D8879FBAF764B4E39AFAA16D90681030CA8A54A79F60C319F56B0D7A5198E6984351B4D635E94FC3DF0F7BD62F5CBD3A156119F14BCBAADC6D64C9D3C61E56EF384C50718675CC0D0D4EE928F6065D701BAAD345CFA839AC95A62EB4E422D474A8375F487A04CCA54C40D828B428080D1C725241F07D47193A534E5884626B93B58A81214E0DDCB43FA2C6FCC92B40DA3804E95E5A866B0C22258568118D7C921D95554DAB8EBBDAA6E6B751B6325A0541DD052A0A5650911747CCC9E67EB5614ADB736751C833F5DA6E742E54C3370D6DAF08E8158A5FE25921CDA8DE0C065A776B5FDB18653EC850DE78E0B882B35D4E7232074FC13423BA96B7674EA4281E3462EB2D6A70E92F42C4704E5A319CF95B4728AADA716F381FB378C4926B1C9EF6359AB74D0EBFCC1829410348355D55D02BC629AF5C6074698E5E9B7CD4BD7B44647D3F925D69B61F004BD48335CF7E644E17AE8DD52E9A28124E2E2B49085CAEC64685AE41611E6F82D25137161F0BF659A49ACA5AAF0DD4338B2063F184805CCBCF08B4B9D31605BD6283319B5651989FBAB25BAAB2226B2CB5D448FA632B5F58FA61FA6409BB38E0B89D9260A80D676F0E37F50D019FC277D4FEECF1733039E07DF56198E42C2855045655DB2F6BECE55806B664806A2A1A4E5B0FD8C40A2E5219D962F53048BE8C7B4F389BA2C3AFC9D3C7C1624186B96121576F994FC1BACE7BB53B4D5E8A8B44575F135F706D5B2947DC38E2EC045565122AE81743E18EDD2AB3E294F7096E5CE6EB8AF86D89495448F52FADBFEA944BCAFC3987825F8A01F275F2E671D6D842DEF12D1D28A6887EA3A0471D30D9A371DF491CCB01F836B1F2F022585D456BBDA0BBB28842C78C28CE93E8906308907C893CF57DB7042D4F555116FD7E79E8BEC1F212D4F8B4840523A0CCD22BFDE1ABAD0DD1556C2341944D77374F05280CBF17B312676C8CC35AF741842A6DD09412272CB4ED9C4DEC478297D567B91B9DC055077EE58EE2A8E73E12E40E3A2A455534A2F92D5A1BAB527C83105F55D2F15A432BC6A7A4891595E8B44B9DF875E39F60785BD6E60D44E62106BD472253A400AD8D43138539F7AAFC38AF7BEDFCE42B5450984CFC8580F7DF3C8022E194DADE24C6B07A3938DC0FA1A7F4F96F6318578B84412A2ED453F2D9000FD0DD996E19A60AD0EC5B5824ABC0CB0665EC1A1338940A67032F3FF7E377447733C61439D0E3C0A20879BB409957410B0190CDE1CC4867DBB3AF8874F34C828F72B1B52329C4126C19FC8E46A49CC4256587D36DBE8A93110338ED832BF346A493EA3B53851DCED4F1088327EDFC9B1A18BCF98BAEDC24AB5038E9724B1022177B465DAB5964F340AEF8BBE5C8F926034E557DEBEBFEF739E6E00A11BE2E28FF98EDC0C9425642C3FD00F6AF87A25B013F329247959A72A5323DAE6BD09B07D24992E3784AFAA1067DF241CF77740414B20C86846416D5BB51A1E56FF1D1F2E2F75F58204DB857C7CFDDC5D8BE763DF65F7EE72A8B88241B383F0E412377F5F04BD40C1FFAA40B805FCF45F6E0DA2F345953FB203C52625E35B562FE8B6063E3865A151A6ED14745BC32B4EB6738ABE46E333AB5EDA3AD67E04E4195EE626271261D31EF6230AFD782ACC2DC0504F59707BF11592307C06402E897E53EAF18AC59A68B4A33901C6E7C9C207E4C3C3E6164BBC56B7C7E3E9FC54C9FEA73F5D789C04CF4FBF42DEC141B51D5C112C810DF0B4A8B9CBC93456A3E3E7DC1A9BACDC1B407E4E1688643B26D38F3FB0C5C663771DE56EF6EA0104065A798F7D0BE0EC83736EC10CA7C9CAB841E051776021C4F52AA5FC1C6A056B9D80484444DA759D8DE60E6380E058F03E13B6D8104336F300BCE69052133FB26BB897DB6AE877E5107E0ACF7960A6BF9C45C1DE44447B85EFAE3788455424B485EF77D4735861D2B430503EC8AB81E063C760C481A43A7B78AED1E13C643EE10EFDBECFB3C83B29544EFD854514E2D11441DFB36591E7A34C1C3CA570061EA67A5169B55D055E17FD936D24076AEDC01CEB07A83D5CB2098EC6BC1729234F3825737628A32360C9043AEAE5C9B788E136502FD6871C1FEB031A02482B0C3B17969A7F5D2EBD082C032DC9EC7263C6D8D98C1BB22D4D00F33EC3EB9CCE1DC6A4C7736141CF9BF819F285F71853229907548C4B34ACED8448F142FFD4057EFAA0875D946D1D66E32551FC318FE841FFC84D5FF715E1B48C386950E280827D33883717B4C8063549A56B0ACCF80CA3109EFFEF3BEAF247EA6FE533FC28D4A3368D122A666AD7BEADEB643B0A1259500A33F7546141144ECD795BC92F04FA916536297602A0F41F17124BEEE947F08CD6093B3855B07003FD80F28839AD1699FD1DA2EC39001A2B96B4E2A669DDAAEA6EA2AD3682F0C0C9CD28C4AEDE29E57659D0987A3B4C4325DC9D4322BB1E0711E644DE69071E31E40ED7DF3840EEDC87876AEC0712772BB05EA0264FBF3486BB542933FED9F1353D2F7FE2AEC1D4725DB3C9186C68EF011FD237436F7A4F59E7A7E535044D447CAD3EB386DE6D971947F4AC6694B11F452EA22FE8AB036678B59E8E6802AEB650413EEECDC9E5FB1EC056A59E69F5E596B89BFF71ACA44F95B6A718503E42962E0706F41C4CFB2B1CCE37EA607A887E77F8493DB524B6CEC7EDDD4244810699F046074E64818F3E42CB94F2E507ADFD454692B8BA7F3CEFF1FF33E26013917958489B0F04C4B82919FC44BAC9DA574AF1725C9CA32D3BC898A8489CC0DAE7CA2DB9C6A7891EEEA765D4E8760F5691567D402CFAF483607EABF6F662D068FC49AFEF9F6908775B8F7AD0F76105A3D59B02EB3C7352CCC70562BCBE33796C52F461B8A2246C788A726329861DF86228AF41C2F87A109AACCA9AED3BD00451C9A5487865287EFFF1E8FA18FC1895C351BDA2D3A2C16B2C2F156E278C16B6397C5568FC9327F2CAAAFA6A8AC20912288DEE4608BF94B42251AE37F9C2C19893A7E05D436CC6958C2C1328B2F9085EB7A3950A5A12792C566B0204F587E5583432B45E29CE4D812902C168356167903B3AD2D61181A131F37E2E19C737B80D5FD2D5187FC7BAAD71F2C7A8EAFF48DBBCD95117C720BEE6FE2B9AFDE3783DE8C8D620567B796C68D56B60DD762BAD64636BD8EC8E6EA2A6C1014FF6B5BFA823C46B1304346518A7D9B923E83795B555DB26C5ECE90628E5398C90D6DE52D57CDC58157BAE1E8B88F72E54F13DCEA9D711510B21188D509D47F5B657F2C3B384C1168508DFB9EB059BF9480894AC51A18128953D14A1029E88C1CECB6EA46C7178B251531A8A26B43B19DE2DB0B879BB011040E71D2297789820A66417F1D0B48FF72BB24FDC248A19BFE7B7FCE88DB86D9853B1CB0DCA83307BF512EE30E9A00971E06C097439DD8B645C486675F00F8889AA4529EC7AA8A8375ECC518AECEC32F1A2BF918FFAE1AF5530BB53351A7FDE8A8E1A264B622174380CC0AD8AE3BBA40D7D9924A89DF0410EE9B182B6A77698A68F4F9B9A221156EE61E3B0362309B60417E259B9E8FC5521008F8C269A1211188375E793566FF1042186EED97B66B1C4E36E56D7DB4E4BF20B9E0053A69D5B8E3D5DCE0B9AC533E07A457AD77FF4818762AAC492A8E47756D9F676330358C390539D56F643A5BADCA0BBB82529945B193363699AF13204436D8024409399285FF4A4A9787A663D7C7B5B524ED0FB46F0C585214D9A67BD379BC3858A1BD3B8406D81A06FD6BA8EA4B69280437AD8299FB0E1B85BDA85D73CDDC58750ABE636C48E74CE4302B0460B915D8DA8681758F96D48D1C5D70857C1C677BD50867A6CE4B0A6670B7E563D45B8A82EA1067CAE2F4EF17852F2A5F8A9782F86AD63410EAEBC95C3CE149F846EBDEBDF6A992F1AAA6A018B03AD30F1FF36FFF31454344D3509AF7880996C1CE76CCF22C2CBAAD82778F1884C0D2079C3690834E0BA54F433E04AB784FD6FB09012490DA6F3C3A610D7F694AEB2B3002B4DBE084A9ECD735BF377D8558CEA94EE480C7A8D3306748EB29AF2F746AB4A73F0F3F92AFF3CAACAF4BD994C043CA810D2F48A1B027D5D2EF4B0585A3DE4D93303CF0BB4A8F30274CEBE33E64ED9A2F3BF182F0BAF4CF7F40CBB0E17FBCAA57D3C974F2FA430D22D0F4774E93D785701F99BFB6DE35F130A75E71F06B012D7B64F033530A3988F36B3AA66B35D22F43CD02FDB5E9BC5BAAD8A4197E0E5D94819E6F77ADD60E749396E7C4185FADF519",
|
|
3173
|
-
"hex"
|
|
3174
|
-
);
|
|
3175
|
-
var aes128CtrCrypt = (key2, counter, data) => {
|
|
3176
|
-
if (key2.length !== 16 || counter.length !== 16)
|
|
3177
|
-
throw new RangeError("AES key and counter must have 16 bytes");
|
|
3178
|
-
const ctr = import_buffer.Buffer.from(counter).reverse();
|
|
3179
|
-
const aes = createAesBlockCipher(import_buffer.Buffer.from(key2).reverse());
|
|
3180
|
-
const output = import_buffer.Buffer.alloc(data.length);
|
|
3181
|
-
for (let p = 0; p < data.length; p += 16) {
|
|
3182
|
-
const mask = aes(ctr);
|
|
3183
|
-
for (let j = 0; j < 16 && p + j < data.length; j++) output[p + j] = data[p + j] ^ mask[15 - j];
|
|
3184
|
-
for (let j = 15; j >= 0; j--) {
|
|
3185
|
-
ctr[j] = ctr[j] + 1 & 255;
|
|
3186
|
-
if (ctr[j]) break;
|
|
3187
|
-
}
|
|
3188
|
-
}
|
|
3189
|
-
return output;
|
|
3190
|
-
};
|
|
3191
|
-
var modcryptKey = (header) => {
|
|
3192
|
-
if (typeof header.gameCode !== "string" || header.gameCode.length !== 4)
|
|
3193
|
-
throw new Error("Expected four-character game code");
|
|
3194
|
-
if (header.twlInternalFlags & 4 || (header.appflags?.[3] ?? 0) & 128) {
|
|
3195
|
-
const key2 = import_buffer.Buffer.alloc(16);
|
|
3196
|
-
key2.write(header.gameTitle, 0, 12, "ascii");
|
|
3197
|
-
key2.write(header.gameCode, 12, 4, "ascii");
|
|
3198
|
-
return key2;
|
|
3199
|
-
}
|
|
3200
|
-
if (!header.hmac_arm9i || header.hmac_arm9i.length < 16)
|
|
3201
|
-
throw new Error("Missing ARM9i HMAC for modcrypt key");
|
|
3202
|
-
const x = import_buffer.Buffer.from(
|
|
3203
|
-
"Nintendo" + header.gameCode + [...header.gameCode].reverse().join(""),
|
|
3204
|
-
"ascii"
|
|
3205
|
-
);
|
|
3206
|
-
for (let i = 0; i < 16; i++) x[i] ^= header.hmac_arm9i[i];
|
|
3207
|
-
const mask = (1n << 128n) - 1n;
|
|
3208
|
-
let v = x.readBigUInt64LE(0) | x.readBigUInt64LE(8) << 64n;
|
|
3209
|
-
v = v + 0xfffefb4e295902582a680f5f1a4f3e79n & mask;
|
|
3210
|
-
v = (v << 42n | v >> 86n) & mask;
|
|
3211
|
-
const out = import_buffer.Buffer.alloc(16);
|
|
3212
|
-
out.writeBigUInt64LE(v & (1n << 64n) - 1n);
|
|
3213
|
-
out.writeBigUInt64LE(v >> 64n, 8);
|
|
3214
|
-
return out;
|
|
3215
|
-
};
|
|
3216
|
-
var encryptSecureArea = (gameCode, input) => {
|
|
3217
|
-
if (typeof gameCode !== "string" || gameCode.length !== 4)
|
|
3218
|
-
throw new Error("Expected four-character game code");
|
|
3219
|
-
if (input.length < 2048) throw new RangeError("Secure area must contain at least 0x800 bytes");
|
|
3220
|
-
const output = import_buffer.Buffer.from(input);
|
|
3221
|
-
let magic = new Uint32Array(1042);
|
|
3222
|
-
let args = [0, 0, 0];
|
|
3223
|
-
function encrypt2(a2, b2) {
|
|
3224
|
-
for (let i = 0; i < 16; i++) {
|
|
3225
|
-
const c = (magic[i] ^ a2) >>> 0;
|
|
3226
|
-
const sum = magic[18 + (c >>> 24)] + magic[274 + (c >>> 16 & 255)] >>> 0;
|
|
3227
|
-
const f = magic[786 + (c & 255)] + (magic[530 + (c >>> 8 & 255)] ^ sum) >>> 0;
|
|
3228
|
-
a2 = (b2 ^ f) >>> 0;
|
|
3229
|
-
b2 = c;
|
|
3230
|
-
}
|
|
3231
|
-
return [(b2 ^ magic[17]) >>> 0, (a2 ^ magic[16]) >>> 0];
|
|
3232
|
-
}
|
|
3233
|
-
function init2() {
|
|
3234
|
-
[args[2], args[1]] = encrypt2(args[2], args[1]);
|
|
3235
|
-
[args[1], args[0]] = encrypt2(args[1], args[0]);
|
|
3236
|
-
const key2 = import_buffer.Buffer.alloc(12);
|
|
3237
|
-
args.forEach((v, i) => key2.writeUInt32LE(v, i * 4));
|
|
3238
|
-
for (let j = 0; j < 18; j++) magic[j] ^= key2.readUInt32BE(j * 4 & 7);
|
|
3239
|
-
let a2 = 0, b2 = 0;
|
|
3240
|
-
for (let i = 0; i < 1042; i += 2) {
|
|
3241
|
-
[a2, b2] = encrypt2(a2, b2);
|
|
3242
|
-
magic[i] = a2;
|
|
3243
|
-
magic[i + 1] = b2;
|
|
3244
|
-
}
|
|
3245
|
-
}
|
|
3246
|
-
function init1() {
|
|
3247
|
-
magic = Uint32Array.from({ length: 1042 }, (_, i) => KEY1.readUInt32LE(i * 4));
|
|
3248
|
-
const code = import_buffer.Buffer.from(gameCode, "ascii").readUInt32LE();
|
|
3249
|
-
args = [code, code >>> 1, code << 1 >>> 0];
|
|
3250
|
-
init2();
|
|
3251
|
-
init2();
|
|
3252
|
-
}
|
|
3253
|
-
init1();
|
|
3254
|
-
args[1] = args[1] << 1 >>> 0;
|
|
3255
|
-
args[2] >>>= 1;
|
|
3256
|
-
init2();
|
|
3257
|
-
for (let p = 8; p < 2048; p += 8) {
|
|
3258
|
-
const [b2, a2] = encrypt2(output.readUInt32LE(p + 4), output.readUInt32LE(p));
|
|
3259
|
-
output.writeUInt32LE(a2, p);
|
|
3260
|
-
output.writeUInt32LE(b2, p + 4);
|
|
3261
|
-
}
|
|
3262
|
-
let [b, a] = encrypt2(1784827769, 1919118949);
|
|
3263
|
-
init1();
|
|
3264
|
-
[b, a] = encrypt2(b, a);
|
|
3265
|
-
output.writeUInt32LE(a, 0);
|
|
3266
|
-
output.writeUInt32LE(b, 4);
|
|
3267
|
-
return output;
|
|
3268
|
-
};
|
|
3269
|
-
|
|
3270
|
-
// src/nitro/header.ts
|
|
3271
|
-
var UnitCode = Object.freeze({ NDS: 0, NDS_DSi: 2, DSi: 3 });
|
|
3272
|
-
var Header = class {
|
|
3273
|
-
raw;
|
|
3274
|
-
trimmedRom;
|
|
3275
|
-
doublePadding;
|
|
3276
|
-
nitrocode;
|
|
3277
|
-
decrypted;
|
|
3278
|
-
headerCRC;
|
|
3279
|
-
logoCRC;
|
|
3280
|
-
secureCRC;
|
|
3281
|
-
dlp_signature;
|
|
3282
|
-
constructor(input) {
|
|
3283
|
-
const data = bytes(input, "header");
|
|
3284
|
-
range(data, 0, 368, "header");
|
|
3285
|
-
const size = data.readUInt32LE(132);
|
|
3286
|
-
if (size < 368 || size > data.length) throw new RangeError(`Invalid header size: ${size}`);
|
|
3287
|
-
this.raw = import_buffer.Buffer.from(data.subarray(0, size));
|
|
3288
|
-
if (this.unitCode & 2 && size > 512) range(this.raw, 0, 4096, "DSi header");
|
|
3289
|
-
this.trimmedRom = this.total_rom_size ? this.total_rom_size >= data.length : data.length !== this.size;
|
|
3290
|
-
this.doublePadding = this.ARM9size % 1024 < 512 && this.ARM7romOffset % 1024 === 0 && this.ARM9overlayOffset % 1024 === 0 || this.ARM7size % 1024 < 512 && this.FNToffset % 1024 === 0 && this.ARM7overlayOffset % 1024 === 0 || this.FNTsize % 1024 < 512 && this.FAToffset % 1024 === 0 || this.FATsize % 1024 < 512 && this.bannerOffset % 1024 === 0;
|
|
3291
|
-
const nitroOffset = this.ARM9romOffset + this.ARM9size;
|
|
3292
|
-
this.nitrocode = nitroOffset >= size && nitroOffset + 4 <= data.length && data.readUInt32LE(nitroOffset) === 3737126433;
|
|
3293
|
-
this.decrypted = data.length >= 16392 && data.readBigUInt64LE(16384) === 0xe7ffdeffe7ffdeffn;
|
|
3294
|
-
this.headerCRC = crc16(this.raw.subarray(0, 350)) === this.headerCRC16;
|
|
3295
|
-
this.logoCRC = crc16(this.logo) === this.logoCRC16;
|
|
3296
|
-
const secure = data.subarray(16384, 32768);
|
|
3297
|
-
this.secureCRC = secure.length > 0 && crc16(this.decrypted ? encryptSecureArea(this.gameCode, secure) : secure) === this.secureCRC16;
|
|
3298
|
-
this.dlp_signature = import_buffer.Buffer.alloc(0);
|
|
3299
|
-
if (this.ROMsize >= size && this.ROMsize + 136 <= data.length && data.readUInt32LE(this.ROMsize) === 90977) {
|
|
3300
|
-
this.dlp_signature = import_buffer.Buffer.from(data.subarray(this.ROMsize, this.ROMsize + 136));
|
|
3301
|
-
}
|
|
3302
|
-
}
|
|
3303
|
-
get size() {
|
|
3304
|
-
return 2 ** (17 + this.raw[20]);
|
|
3305
|
-
}
|
|
3306
|
-
set size(value) {
|
|
3307
|
-
const power = Math.log2(value);
|
|
3308
|
-
if (!Number.isInteger(power) || power < 17 || power > 32)
|
|
3309
|
-
throw new RangeError("ROM capacity must be a power of two from 128 KiB to 4 GiB");
|
|
3310
|
-
this.raw[20] = power - 17;
|
|
3311
|
-
}
|
|
3312
|
-
toBuffer() {
|
|
3313
|
-
const data = import_buffer.Buffer.from(this.raw);
|
|
3314
|
-
data.writeUInt16LE(crc16(data.subarray(192, 348)), 348);
|
|
3315
|
-
data.writeUInt16LE(crc16(data.subarray(0, 350)), 350);
|
|
3316
|
-
return data;
|
|
3317
|
-
}
|
|
3318
|
-
toString() {
|
|
3319
|
-
return `NDS header: ${this.gameTitle.replace(/\0+$/, "")} (${this.gameCode})`;
|
|
3320
|
-
}
|
|
3321
|
-
};
|
|
3322
|
-
function field(name, offset, length, type = "buffer", dsi = false) {
|
|
3323
|
-
Object.defineProperty(Header.prototype, name, {
|
|
3324
|
-
enumerable: true,
|
|
3325
|
-
get() {
|
|
3326
|
-
if (dsi && (!(this.unitCode & 2) || this.raw.length <= 512))
|
|
3327
|
-
return type === "buffer" ? import_buffer.Buffer.alloc(length) : 0;
|
|
3328
|
-
const data = range(this.raw, offset, length, `header ${name}`);
|
|
3329
|
-
if (type === "string") return data.toString("latin1");
|
|
3330
|
-
if (type === "buffer") return data;
|
|
3331
|
-
return length === 8 ? data.readBigUInt64LE() : data.readUIntLE(0, length);
|
|
3332
|
-
},
|
|
3333
|
-
set(value) {
|
|
3334
|
-
const target = range(this.raw, offset, length, `header ${name}`);
|
|
3335
|
-
if (type === "string") {
|
|
3336
|
-
if (typeof value !== "string" || import_buffer.Buffer.byteLength(value, "latin1") > length)
|
|
3337
|
-
throw new TypeError(`Invalid ${name}`);
|
|
3338
|
-
target.fill(0);
|
|
3339
|
-
target.write(value, "latin1");
|
|
3340
|
-
} else if (type === "buffer") {
|
|
3341
|
-
if (!(value instanceof Uint8Array)) throw new TypeError(`Invalid ${name}`);
|
|
3342
|
-
const source = bytes(value, name);
|
|
3343
|
-
if (source.length !== length) throw new RangeError(`${name} must contain ${length} bytes`);
|
|
3344
|
-
source.copy(target);
|
|
3345
|
-
} else if (length === 8) {
|
|
3346
|
-
if (typeof value !== "bigint") throw new TypeError(`Invalid ${name}`);
|
|
3347
|
-
target.writeBigUInt64LE(value);
|
|
3348
|
-
} else {
|
|
3349
|
-
if (typeof value !== "number") throw new TypeError(`Invalid ${name}`);
|
|
3350
|
-
target.writeUIntLE(value, 0, length);
|
|
3351
|
-
}
|
|
3352
|
-
}
|
|
3353
|
-
});
|
|
3135
|
+
if (end <= this.position) return;
|
|
3136
|
+
this.buffer.fill(fill, this.position, end);
|
|
3137
|
+
this.position = end;
|
|
3138
|
+
this.length = Math.max(this.length, end);
|
|
3139
|
+
}
|
|
3140
|
+
pad(alignment, fill = 255) {
|
|
3141
|
+
this.fillTo(align(this.position, alignment), fill);
|
|
3142
|
+
}
|
|
3143
|
+
toBuffer() {
|
|
3144
|
+
return this.buffer.subarray(0, this.length);
|
|
3145
|
+
}
|
|
3146
|
+
};
|
|
3147
|
+
|
|
3148
|
+
// src/nitro/crc.ts
|
|
3149
|
+
init_buffer();
|
|
3150
|
+
var table16 = new Uint16Array(256);
|
|
3151
|
+
var table32 = new Uint32Array(256);
|
|
3152
|
+
for (let i2 = 0; i2 < 256; i2++) {
|
|
3153
|
+
let a = i2, b = i2;
|
|
3154
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
3155
|
+
a = a >>> 1 ^ (a & 1 ? 40961 : 0);
|
|
3156
|
+
b = b >>> 1 ^ (b & 1 ? 3988292384 : 0);
|
|
3157
|
+
}
|
|
3158
|
+
table16[i2] = a;
|
|
3159
|
+
table32[i2] = b;
|
|
3354
3160
|
}
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
}))
|
|
3366
|
-
field(name, offset, 1, "number");
|
|
3367
|
-
field("reserved", 21, 7);
|
|
3368
|
-
var ntr32 = "ARM9romOffset ARM9entryAddress ARM9ramAddress ARM9size ARM7romOffset ARM7entryAddress ARM7ramAddress ARM7size FNToffset FNTsize FAToffset FATsize ARM9overlayOffset ARM9overlaySize ARM7overlayOffset ARM7overlaySize flagsRead flagsInit bannerOffset".split(
|
|
3369
|
-
" "
|
|
3370
|
-
);
|
|
3371
|
-
ntr32.forEach((name, i) => field(name, 32 + i * 4, 4, "number"));
|
|
3372
|
-
field("secureCRC16", 108, 2, "number");
|
|
3373
|
-
field("ROMtimeout", 110, 2, "number");
|
|
3374
|
-
field("ARM9autoload", 112, 4, "number");
|
|
3375
|
-
field("ARM7autoload", 116, 4, "number");
|
|
3376
|
-
field("secureDisable", 120, 8, "number");
|
|
3377
|
-
field("ROMsize", 128, 4, "number");
|
|
3378
|
-
field("headerSize", 132, 4, "number");
|
|
3379
|
-
field("reserved2", 136, 56);
|
|
3380
|
-
field("logo", 192, 156);
|
|
3381
|
-
field("logoCRC16", 348, 2, "number");
|
|
3382
|
-
field("headerCRC16", 350, 2, "number");
|
|
3383
|
-
"debug_romOffset debug_size debug_ramAddress reserved3".split(" ").forEach((name, i) => field(name, 352 + i * 4, 4, "number"));
|
|
3384
|
-
field("appflags", 444, 4, "buffer", true);
|
|
3385
|
-
"mbk9_wramcnt_setting region_flags access_control scfg_ext_mask".split(" ").forEach((name, i) => field(name, 428 + i * 4, 4, "number", true));
|
|
3386
|
-
var twl32 = "dsi9_rom_offset offset_0x1C4 dsi9_ram_address dsi9_size dsi7_rom_offset offset_0x1D4 dsi7_ram_address dsi7_size digest_ntr_start digest_ntr_size digest_twl_start digest_twl_size sector_hashtable_start sector_hashtable_size block_hashtable_start block_hashtable_size digest_sector_size digest_block_sectorcount banner_size offset_0x20C total_rom_size offset_0x214 offset_0x218 offset_0x21C modcrypt1_start modcrypt1_size modcrypt2_start modcrypt2_size tid_low tid_high public_sav_size private_sav_size".split(
|
|
3387
|
-
" "
|
|
3388
|
-
);
|
|
3389
|
-
twl32.forEach((name, i) => field(name, 448 + i * 4, 4, "number", true));
|
|
3390
|
-
"hmac_arm9 hmac_arm7 hmac_digest_master hmac_icon_title hmac_arm9i hmac_arm7i".split(" ").forEach((name, i) => field(name, 768 + i * 20, 20, "buffer", true));
|
|
3391
|
-
field("hmac_arm9_no_secure", 928, 20, "buffer", true);
|
|
3392
|
-
field("rsa_signature", 3968, 128, "buffer", true);
|
|
3161
|
+
var crc16 = (data, initial = 65535) => {
|
|
3162
|
+
let crc = initial;
|
|
3163
|
+
for (const byte of data) crc = crc >>> 8 ^ table16[(crc ^ byte) & 255];
|
|
3164
|
+
return crc;
|
|
3165
|
+
};
|
|
3166
|
+
var crc32 = (data) => {
|
|
3167
|
+
let crc = 4294967295;
|
|
3168
|
+
for (const byte of data) crc = crc >>> 8 ^ table32[(crc ^ byte) & 255];
|
|
3169
|
+
return (crc ^ 4294967295) >>> 0;
|
|
3170
|
+
};
|
|
3393
3171
|
|
|
3394
3172
|
// src/nitro/banner.ts
|
|
3395
|
-
init_buffer();
|
|
3396
3173
|
var titles = [
|
|
3397
3174
|
"japaneseTitle",
|
|
3398
3175
|
"englishTitle",
|
|
@@ -3421,14 +3198,13 @@ var Banner = class {
|
|
|
3421
3198
|
const data = bytes(input, "banner");
|
|
3422
3199
|
this.version = range(data, offset, 2, "banner").readUInt16LE();
|
|
3423
3200
|
let size = this.getDefSize(hardSize);
|
|
3424
|
-
if (this.version >>> 8 === 1)
|
|
3425
|
-
size = hardSize > 0 && hardSize !== 4294967295 ? Math.min(hardSize, 9152) : 9152;
|
|
3201
|
+
if (this.version >>> 8 === 1) size = hardSize > 0 && hardSize !== 4294967295 ? Math.min(hardSize, 9152) : 9152;
|
|
3426
3202
|
this.raw = import_buffer.Buffer.from(range(data, offset, size, "banner"));
|
|
3427
3203
|
this.bannerCRC = crc16(this.raw.subarray(32, 2112)) === this.raw.readUInt16LE(2);
|
|
3428
3204
|
this.tileData = import_buffer.Buffer.from(this.raw.subarray(32, 544));
|
|
3429
3205
|
this.palette = import_buffer.Buffer.from(this.raw.subarray(544, 576));
|
|
3430
|
-
for (const [
|
|
3431
|
-
this[title] =
|
|
3206
|
+
for (const [i2, title] of titles.entries())
|
|
3207
|
+
this[title] = i2 < this.titleCount ? this.raw.subarray(576 + i2 * 256, 832 + i2 * 256).toString("utf16le").split("\0")[0] : "";
|
|
3432
3208
|
}
|
|
3433
3209
|
get titleCount() {
|
|
3434
3210
|
return this.version >= 3 ? 8 : this.version >= 2 ? 7 : 6;
|
|
@@ -3442,16 +3218,14 @@ var Banner = class {
|
|
|
3442
3218
|
toBuffer() {
|
|
3443
3219
|
const output = import_buffer.Buffer.from(this.raw);
|
|
3444
3220
|
output.writeUInt16LE(this.version);
|
|
3445
|
-
if (this.tileData.length !== 512 || this.palette.length !== 32)
|
|
3446
|
-
throw new RangeError("Invalid banner icon size");
|
|
3221
|
+
if (this.tileData.length !== 512 || this.palette.length !== 32) throw new RangeError("Invalid banner icon size");
|
|
3447
3222
|
this.tileData.copy(output, 32);
|
|
3448
3223
|
this.palette.copy(output, 544);
|
|
3449
|
-
for (let
|
|
3450
|
-
const text = import_buffer.Buffer.from(this[titles[
|
|
3451
|
-
if (text.length > 256)
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
text.copy(output, 576 + i * 256);
|
|
3224
|
+
for (let i2 = 0; i2 < this.titleCount; i2++) {
|
|
3225
|
+
const text = import_buffer.Buffer.from(this[titles[i2]], "utf16le");
|
|
3226
|
+
if (text.length > 256) throw new RangeError(`Banner ${titles[i2]} exceeds 128 UTF-16 code units`);
|
|
3227
|
+
output.fill(0, 576 + i2 * 256, 832 + i2 * 256);
|
|
3228
|
+
text.copy(output, 576 + i2 * 256);
|
|
3455
3229
|
}
|
|
3456
3230
|
output.writeUInt16LE(crc16(output.subarray(32, 2112)), 2);
|
|
3457
3231
|
if (this.version >= 2) output.writeUInt16LE(crc16(output.subarray(32, 2368)), 4);
|
|
@@ -3461,6 +3235,101 @@ var Banner = class {
|
|
|
3461
3235
|
}
|
|
3462
3236
|
};
|
|
3463
3237
|
|
|
3238
|
+
// src/nitro/crypto.ts
|
|
3239
|
+
init_buffer();
|
|
3240
|
+
var KEY1 = import_buffer.Buffer.from(
|
|
3241
|
+
"99D5205F5744F5B96E19A4D99E6A5A94D8AEF1EB4175E23A9382D03233EE31D5CC57619A3706A21B793972F555AEF6BE5F1B69FBE59DF1E9CE2CD9A15E3205E6FED3FECFD462040D8BF5ECB72B6079BB1295310D6E3FDA2B8884F0F13D127E254522F1BB24061A0611ADDF288B6481342BEB332999AAF2BD9C14959D9FF7F58C7297A1299DD15FCF664D071ADED34A4B85C9A7A31795053A3D490ABF0A898BA24A8249DD2790F10BE9EB1C6A83764505BA817061173F4BDEAECFAB3957F23A564811AD8A40E1453FFA9B0254CAA693FBEF4DFE6FA3D8879C08BAD5486A8D2DFD6E15F874BDBE528B18228A9EFB7437071B366C4A19BA4262B97991107B676596FE0223E8EE998C773E5C86644D6D7886A54F65E21EB2DF5A0AD07E0814B071ACBDDB831CB9D7A162CDC6637C5269C3E6BF75CE12445D2104FAFBD33C381163D4958541494609F2084311DC1F76C0156D1F3C6370EA87806CC3BD638BC2372137DCEE09232E376A4D7390F75030AC1C92041023914FD207AA683E4F9AC964606AC81421F3D62241124424CFE68A56DD0D534DE1851E8C525A9C1984C20357F16FE300BE58F64CEDD521649C1FBE55033C4ADCFFAAC9DAE05D5EBFE6DEF5D8B1F8FF36B3B9626795DB315F37ED4C70679990B518316C3D9999E442DAD3254213A0AED7706CB155CFC7D746D54361173D4428E93385D5D0A293AA25121FFBC50B46F597765645A6BE87B1946BE8B1FE3399AE1F3E6C39711D09009037E4103E7574FF8C833BB0F1B0F90105474295F1D6AC7E38E69E9574263FB4685018D04330B44C4BE368BFE54DB6958B0AA074253277CFA1F72CD871135AABEAC951E80DEEEFE9937E19A71E433881162CA148E373CC29216CD35DCEA0D9617143A01513B56492CF2A19DCADB7A59F8665F81A9FE7FBF7FDB8136C27DB6FDF351CF78D2C5B9B12AB386406CCDE31E84E751164E3FAEAEB3454C2AD3F34EB932C7D26369D56F35AE1F6B398634A9E3283E49A84607D902E130EEE934B36A285EC1638E8880602BFF0A03AEDD76A9A73E157CFF844B8DC2E2359D1DF9552719961A04BD57F6E78BAA9C530D34086329D320C9C37B7022FBA5498A9C41304C98DBEC8E75D97502E93D622590C27BC2292E0A7200F936F7F4C9FD3B5A62A0B7467497D1026CBD1C58671E78CA09CE95BB21AF601EE8C9E5E83F21ADBE6E5EA845976D27CF68DA5493648C21652BB83A374B9070C3BFF6128E161E9E4EF6E15AA4EBAE85D0596BB3256B0FB72520F0EC84225657689AFF2DE1027F0014B74A79707D5265454091F820A867D30390EB3269B0B57BB360631AFFD79FCD930102B0CB3E19BD77BDC5FEFD2F813454D4775BD46963C7E75F33EB567C59A3BB05B296BDE805BC81505B131B6CE49DDAD84B5AE60DC67313430FE4EBD802FA6BF63392186D9357F1668220554E990268C076C51A43155D70907A83E2E5366C1F8F27BC4F258CFF187C5A2E7278F308758A064622318B9887CFACEC498AEAD17CC4A5BF3E948D556D30DF2C892738CDBD72F56AC81F992694DC632F6E6C08D21E276806111BCDC6C93AF19699BD0BFB9319F0267A351EE8306227B0CAB494240B8D5017DCE5EF7555339C59946D8879FBAF764B4E39AFAA16D90681030CA8A54A79F60C319F56B0D7A5198E6984351B4D635E94FC3DF0F7BD62F5CBD3A156119F14BCBAADC6D64C9D3C61E56EF384C50718675CC0D0D4EE928F6065D701BAAD345CFA839AC95A62EB4E422D474A8375F487A04CCA54C40D828B428080D1C725241F07D47193A534E5884626B93B58A81214E0DDCB43FA2C6FCC92B40DA3804E95E5A866B0C22258568118D7C921D95554DAB8EBBDAA6E6B751B6325A0541DD052A0A5650911747CCC9E67EB5614ADB736751C833F5DA6E742E54C3370D6DAF08E8158A5FE25921CDA8DE0C065A776B5FDB18653EC850DE78E0B882B35D4E7232074FC13423BA96B7674EA4281E3462EB2D6A70E92F42C4704E5A319CF95B4728AADA716F381FB378C4926B1C9EF6359AB74D0EBFCC1829410348355D55D02BC629AF5C6074698E5E9B7CD4BD7B44647D3F925D69B61F004BD48335CF7E644E17AE8DD52E9A28124E2E2B49085CAEC64685AE41611E6F82D25137161F0BF659A49ACA5AAF0DD4338B2063F184805CCBCF08B4B9D31605BD6283319B5651989FBAB25BAAB2226B2CB5D448FA632B5F58FA61FA6409BB38E0B89D9260A80D676F0E37F50D019FC277D4FEECF1733039E07DF56198E42C2855045655DB2F6BECE55806B664806A2A1A4E5B0FD8C40A2E5219D962F53048BE8C7B4F389BA2C3AFC9D3C7C1624186B96121576F994FC1BACE7BB53B4D5E8A8B44575F135F706D5B2947DC38E2EC045565122AE81743E18EDD2AB3E294F7096E5CE6EB8AF86D89495448F52FADBFEA944BCAFC3987825F8A01F275F2E671D6D842DEF12D1D28A6887EA3A0471D30D9A371DF491CCB01F836B1F2F022585D456BBDA0BBB28842C78C28CE93E8906308907C893CF57DB7042D4F555116FD7E79E8BEC1F212D4F8B4840523A0CCD22BFDE1ABAD0DD1556C2341944D77374F05280CBF17B312676C8CC35AF741842A6DD09412272CB4ED9C4DEC478297D567B91B9DC055077EE58EE2A8E73E12E40E3A2A455534A2F92D5A1BAB527C83105F55D2F15A432BC6A7A4891595E8B44B9DF875E39F60785BD6E60D44E62106BD472253A400AD8D43138539F7AAFC38AF7BEDFCE42B5450984CFC8580F7DF3C8022E194DADE24C6B07A3938DC0FA1A7F4F96F6318578B84412A2ED453F2D9000FD0DD996E19A60AD0EC5B5824ABC0CB0665EC1A1338940A67032F3FF7E377447733C61439D0E3C0A20879BB409957410B0190CDE1CC4867DBB3AF8874F34C828F72B1B52329C4126C19FC8E46A49CC4256587D36DBE8A93110338ED832BF346A493EA3B53851DCED4F1088327EDFC9B1A18BCF98BAEDC24AB5038E9724B1022177B465DAB5964F340AEF8BBE5C8F926034E557DEBEBFEF739E6E00A11BE2E28FF98EDC0C9425642C3FD00F6AF87A25B013F329247959A72A5323DAE6BD09B07D24992E3784AFAA1067DF241CF77740414B20C86846416D5BB51A1E56FF1D1F2E2F75F58204DB857C7CFDDC5D8BE763DF65F7EE72A8B88241B383F0E412377F5F04BD40C1FFAA40B805FCF45F6E0DA2F345953FB203C52625E35B562FE8B6063E3865A151A6ED14745BC32B4EB6738ABE46E333AB5EDA3AD67E04E4195EE626271261D31EF6230AFD782ACC2DC0504F59707BF11592307C06402E897E53EAF18AC59A68B4A33901C6E7C9C207E4C3C3E6164BBC56B7C7E3E9FC54C9FEA73F5D789C04CF4FBF42DEC141B51D5C112C810DF0B4A8B9CBC93456A3E3E7DC1A9BACDC1B407E4E1688643B26D38F3FB0C5C663771DE56EF6EA0104065A798F7D0BE0EC83736EC10CA7C9CAB841E051776021C4F52AA5FC1C6A056B9D80484444DA759D8DE60E6380E058F03E13B6D8104336F300BCE69052133FB26BB897DB6AE877E5107E0ACF7960A6BF9C45C1DE44447B85EFAE3788455424B485EF77D4735861D2B430503EC8AB81E063C760C481A43A7B78AED1E13C643EE10EFDBECFB3C83B29544EFD854514E2D11441DFB36591E7A34C1C3CA570061EA67A5169B55D055E17FD936D24076AEDC01CEB07A83D5CB2098EC6BC1729234F3825737628A32360C9043AEAE5C9B788E136502FD6871C1FEB031A02482B0C3B17969A7F5D2EBD082C032DC9EC7263C6D8D98C1BB22D4D00F33EC3EB9CCE1DC6A4C7736141CF9BF819F285F71853229907548C4B34ACED8448F142FFD4057EFAA0875D946D1D66E32551FC318FE841FFC84D5FF715E1B48C386950E280827D33883717B4C8063549A56B0ACCF80CA3109EFFEF3BEAF247EA6FE533FC28D4A3368D122A666AD7BEADEB643B0A1259500A33F7546141144ECD795BC92F04FA916536297602A0F41F17124BEEE947F08CD6093B3855B07003FD80F28839AD1699FD1DA2EC39001A2B96B4E2A669DDAAEA6EA2AD3682F0C0C9CD28C4AEDE29E57659D0987A3B4C4325DC9D4322BB1E0711E644DE69071E31E40ED7DF3840EEDC87876AEC0712772BB05EA0264FBF3486BB542933FED9F1353D2F7FE2AEC1D4725DB3C9186C68EF011FD237436F7A4F59E7A7E535044D447CAD3EB386DE6D971947F4AC6694B11F452EA22FE8AB036678B59E8E6802AEB650413EEECDC9E5FB1EC056A59E69F5E596B89BFF71ACA44F95B6A718503E42962E0706F41C4CFB2B1CCE37EA607A887E77F8493DB524B6CEC7EDDD4244810699F046074E64818F3E42CB94F2E507ADFD454692B8BA7F3CEFF1FF33E26013917958489B0F04C4B82919FC44BAC9DA574AF1725C9CA32D3BC898A8489CC0DAE7CA2DB9C6A7891EEEA765D4E8760F5691567D402CFAF483607EABF6F662D068FC49AFEF9F6908775B8F7AD0F76105A3D59B02EB3C7352CCC70562BCBE33796C52F461B8A2246C788A726329861DF86228AF41C2F87A109AACCA9AED3BD00451C9A5487865287EFFF1E8FA18FC1895C351BDA2D3A2C16B2C2F156E278C16B6397C5568FC9327F2CAAAFA6A8AC20912288DEE4608BF94B42251AE37F9C2C19893A7E05D436CC6958C2C1328B2F9085EB7A3950A5A12792C566B0204F587E5583432B45E29CE4D812902C168356167903B3AD2D61181A131F37E2E19C737B80D5FD2D5187FC7BAAD71F2C7A8EAFF48DBBCD95117C720BEE6FE2B9AFDE3783DE8C8D620567B796C68D56B60DD762BAD64636BD8EC8E6EA2A6C1014FF6B5BFA823C46B1304346518A7D9B923E83795B555DB26C5ECE90628E5398C90D6DE52D57CDC58157BAE1E8B88F72E54F13DCEA9D711510B21188D509D47F5B657F2C3B384C1168508DFB9EB059BF9480894AC51A18128953D14A1029E88C1CECB6EA46C7178B251531A8A26B43B19DE2DB0B879BB011040E71D2297789820A66417F1D0B48FF72BB24FDC248A19BFE7B7FCE88DB86D9853B1CB0DCA83307BF512EE30E9A00971E06C097439DD8B645C486675F00F8889AA4529EC7AA8A8375ECC518AECEC32F1A2BF918FFAE1AF5530BB53351A7FDE8A8E1A264B622174380CC0AD8AE3BBA40D7D9924A89DF0410EE9B182B6A77698A68F4F9B9A221156EE61E3B0362309B60417E259B9E8FC5521008F8C269A1211188375E793566FF1042186EED97B66B1C4E36E56D7DB4E4BF20B9E0053A69D5B8E3D5DCE0B9AC533E07A457AD77FF4818762AAC492A8E47756D9F676330358C390539D56F643A5BADCA0BBB82529945B193363699AF13204436D8024409399285FF4A4A9787A663D7C7B5B524ED0FB46F0C585214D9A67BD379BC3858A1BD3B8406D81A06FD6BA8EA4B69280437AD8299FB0E1B85BDA85D73CDDC58750ABE636C48E74CE4302B0460B915D8DA8681758F96D48D1C5D70857C1C677BD50867A6CE4B0A6670B7E563D45B8A82EA1067CAE2F4EF17852F2A5F8A9782F86AD63410EAEBC95C3CE149F846EBDEBDF6A992F1AAA6A018B03AD30F1FF36FFF31454344D3509AF7880996C1CE76CCF22C2CBAAD82778F1884C0D2079C3690834E0BA54F433E04AB784FD6FB09012490DA6F3C3A610D7F694AEB2B3002B4DBE084A9ECD735BF377D8558CEA94EE480C7A8D3306748EB29AF2F746AB4A73F0F3F92AFF3CAACAF4BD994C043CA810D2F48A1B027D5D2EF4B0585A3DE4D93303CF0BB4A8F30274CEBE33E64ED9A2F3BF182F0BAF4CF7F40CBB0E17FBCAA57D3C974F2FA430D22D0F4774E93D785701F99BFB6DE35F130A75E71F06B012D7B64F033530A3988F36B3AA66B35D22F43CD02FDB5E9BC5BAAD8A4197E0E5D94819E6F77ADD60E749396E7C4185FADF519",
|
|
3242
|
+
"hex"
|
|
3243
|
+
);
|
|
3244
|
+
var aes128CtrCrypt = (key2, counter, data) => {
|
|
3245
|
+
if (key2.length !== 16 || counter.length !== 16) throw new RangeError("AES key and counter must have 16 bytes");
|
|
3246
|
+
const ctr = import_buffer.Buffer.from(counter).reverse();
|
|
3247
|
+
const aes = createAesBlockCipher(import_buffer.Buffer.from(key2).reverse());
|
|
3248
|
+
const output = import_buffer.Buffer.alloc(data.length);
|
|
3249
|
+
for (let p = 0; p < data.length; p += 16) {
|
|
3250
|
+
const mask = aes(ctr);
|
|
3251
|
+
for (let j = 0; j < 16 && p + j < data.length; j++) output[p + j] = data[p + j] ^ mask[15 - j];
|
|
3252
|
+
for (let j = 15; j >= 0; j--) {
|
|
3253
|
+
ctr[j] = ctr[j] + 1 & 255;
|
|
3254
|
+
if (ctr[j]) break;
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
return output;
|
|
3258
|
+
};
|
|
3259
|
+
var modcryptKey = (header) => {
|
|
3260
|
+
if (typeof header.gameCode !== "string" || header.gameCode.length !== 4)
|
|
3261
|
+
throw new Error("Expected four-character game code");
|
|
3262
|
+
if (header.twlInternalFlags & 4 || (header.appflags?.[3] ?? 0) & 128) {
|
|
3263
|
+
const key2 = import_buffer.Buffer.alloc(16);
|
|
3264
|
+
key2.write(header.gameTitle, 0, 12, "ascii");
|
|
3265
|
+
key2.write(header.gameCode, 12, 4, "ascii");
|
|
3266
|
+
return key2;
|
|
3267
|
+
}
|
|
3268
|
+
if (!header.hmac_arm9i || header.hmac_arm9i.length < 16) throw new Error("Missing ARM9i HMAC for modcrypt key");
|
|
3269
|
+
const x2 = import_buffer.Buffer.from(`Nintendo${header.gameCode}${[...header.gameCode].reverse().join("")}`, "ascii");
|
|
3270
|
+
for (let i2 = 0; i2 < 16; i2++) x2[i2] ^= header.hmac_arm9i[i2];
|
|
3271
|
+
const mask = (1n << 128n) - 1n;
|
|
3272
|
+
let v = x2.readBigUInt64LE(0) | x2.readBigUInt64LE(8) << 64n;
|
|
3273
|
+
v = v + 0xfffefb4e295902582a680f5f1a4f3e79n & mask;
|
|
3274
|
+
v = (v << 42n | v >> 86n) & mask;
|
|
3275
|
+
const out = import_buffer.Buffer.alloc(16);
|
|
3276
|
+
out.writeBigUInt64LE(v & (1n << 64n) - 1n);
|
|
3277
|
+
out.writeBigUInt64LE(v >> 64n, 8);
|
|
3278
|
+
return out;
|
|
3279
|
+
};
|
|
3280
|
+
var encryptSecureArea = (gameCode, input) => {
|
|
3281
|
+
if (typeof gameCode !== "string" || gameCode.length !== 4) throw new Error("Expected four-character game code");
|
|
3282
|
+
if (input.length < 2048) throw new RangeError("Secure area must contain at least 0x800 bytes");
|
|
3283
|
+
const output = import_buffer.Buffer.from(input);
|
|
3284
|
+
let magic = new Uint32Array(1042);
|
|
3285
|
+
let args = [0, 0, 0];
|
|
3286
|
+
function encrypt2(a2, b2) {
|
|
3287
|
+
for (let i2 = 0; i2 < 16; i2++) {
|
|
3288
|
+
const c = (magic[i2] ^ a2) >>> 0;
|
|
3289
|
+
const sum = magic[18 + (c >>> 24)] + magic[274 + (c >>> 16 & 255)] >>> 0;
|
|
3290
|
+
const f = magic[786 + (c & 255)] + (magic[530 + (c >>> 8 & 255)] ^ sum) >>> 0;
|
|
3291
|
+
a2 = (b2 ^ f) >>> 0;
|
|
3292
|
+
b2 = c;
|
|
3293
|
+
}
|
|
3294
|
+
return [(b2 ^ magic[17]) >>> 0, (a2 ^ magic[16]) >>> 0];
|
|
3295
|
+
}
|
|
3296
|
+
function init2() {
|
|
3297
|
+
[args[2], args[1]] = encrypt2(args[2], args[1]);
|
|
3298
|
+
[args[1], args[0]] = encrypt2(args[1], args[0]);
|
|
3299
|
+
const key2 = import_buffer.Buffer.alloc(12);
|
|
3300
|
+
args.forEach((v, i2) => key2.writeUInt32LE(v, i2 * 4));
|
|
3301
|
+
for (let j = 0; j < 18; j++) magic[j] ^= key2.readUInt32BE(j * 4 & 7);
|
|
3302
|
+
let a2 = 0, b2 = 0;
|
|
3303
|
+
for (let i2 = 0; i2 < 1042; i2 += 2) {
|
|
3304
|
+
[a2, b2] = encrypt2(a2, b2);
|
|
3305
|
+
magic[i2] = a2;
|
|
3306
|
+
magic[i2 + 1] = b2;
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
function init1() {
|
|
3310
|
+
magic = Uint32Array.from({ length: 1042 }, (_, i2) => KEY1.readUInt32LE(i2 * 4));
|
|
3311
|
+
const code = import_buffer.Buffer.from(gameCode, "ascii").readUInt32LE();
|
|
3312
|
+
args = [code, code >>> 1, code << 1 >>> 0];
|
|
3313
|
+
init2();
|
|
3314
|
+
init2();
|
|
3315
|
+
}
|
|
3316
|
+
init1();
|
|
3317
|
+
args[1] = args[1] << 1 >>> 0;
|
|
3318
|
+
args[2] >>>= 1;
|
|
3319
|
+
init2();
|
|
3320
|
+
for (let p = 8; p < 2048; p += 8) {
|
|
3321
|
+
const [b2, a2] = encrypt2(output.readUInt32LE(p + 4), output.readUInt32LE(p));
|
|
3322
|
+
output.writeUInt32LE(a2, p);
|
|
3323
|
+
output.writeUInt32LE(b2, p + 4);
|
|
3324
|
+
}
|
|
3325
|
+
let [b, a] = encrypt2(1784827769, 1919118949);
|
|
3326
|
+
init1();
|
|
3327
|
+
[b, a] = encrypt2(b, a);
|
|
3328
|
+
output.writeUInt32LE(a, 0);
|
|
3329
|
+
output.writeUInt32LE(b, 4);
|
|
3330
|
+
return output;
|
|
3331
|
+
};
|
|
3332
|
+
|
|
3464
3333
|
// src/nitro/filesystem.ts
|
|
3465
3334
|
init_buffer();
|
|
3466
3335
|
var FileAllocationTable = class {
|
|
@@ -3491,8 +3360,7 @@ var FileNameTable = class _FileNameTable {
|
|
|
3491
3360
|
const visited = /* @__PURE__ */ new Set();
|
|
3492
3361
|
const fileIds = /* @__PURE__ */ new Set();
|
|
3493
3362
|
const parse = (index, name, depth) => {
|
|
3494
|
-
if (depth > 256 || index >= count || visited.has(index))
|
|
3495
|
-
throw new Error("Invalid FNT directory tree or cycle");
|
|
3363
|
+
if (depth > 256 || index >= count || visited.has(index)) throw new Error("Invalid FNT directory tree or cycle");
|
|
3496
3364
|
visited.add(index);
|
|
3497
3365
|
let cursor = table2.readUInt32LE(index * 8);
|
|
3498
3366
|
let fileId = table2.readUInt16LE(index * 8 + 4);
|
|
@@ -3572,6 +3440,7 @@ var OverlayTable = class {
|
|
|
3572
3440
|
});
|
|
3573
3441
|
}
|
|
3574
3442
|
}
|
|
3443
|
+
isArm9;
|
|
3575
3444
|
entries = [];
|
|
3576
3445
|
readBasicOverlays(fat) {
|
|
3577
3446
|
return this.entries.map((item) => {
|
|
@@ -3586,12 +3455,137 @@ var OverlayTable = class {
|
|
|
3586
3455
|
toBuffer() {
|
|
3587
3456
|
const data = import_buffer.Buffer.alloc(this.entries.length * 32);
|
|
3588
3457
|
this.entries.forEach(
|
|
3589
|
-
(entry,
|
|
3458
|
+
(entry, i2) => overlayFields.forEach((field2, j) => data.writeUInt32LE(entry[field2], i2 * 32 + j * 4))
|
|
3590
3459
|
);
|
|
3591
3460
|
return data;
|
|
3592
3461
|
}
|
|
3593
3462
|
};
|
|
3594
3463
|
|
|
3464
|
+
// src/nitro/header.ts
|
|
3465
|
+
init_buffer();
|
|
3466
|
+
var UnitCode = Object.freeze({ NDS: 0, NDS_DSi: 2, DSi: 3 });
|
|
3467
|
+
var Header = class {
|
|
3468
|
+
raw;
|
|
3469
|
+
trimmedRom;
|
|
3470
|
+
doublePadding;
|
|
3471
|
+
nitrocode;
|
|
3472
|
+
decrypted;
|
|
3473
|
+
headerCRC;
|
|
3474
|
+
logoCRC;
|
|
3475
|
+
secureCRC;
|
|
3476
|
+
dlp_signature;
|
|
3477
|
+
constructor(input) {
|
|
3478
|
+
const data = bytes(input, "header");
|
|
3479
|
+
range(data, 0, 368, "header");
|
|
3480
|
+
const size = data.readUInt32LE(132);
|
|
3481
|
+
if (size < 368 || size > data.length) throw new RangeError(`Invalid header size: ${size}`);
|
|
3482
|
+
this.raw = import_buffer.Buffer.from(data.subarray(0, size));
|
|
3483
|
+
if (this.unitCode & 2 && size > 512) range(this.raw, 0, 4096, "DSi header");
|
|
3484
|
+
this.trimmedRom = this.total_rom_size ? this.total_rom_size >= data.length : data.length !== this.size;
|
|
3485
|
+
this.doublePadding = this.ARM9size % 1024 < 512 && this.ARM7romOffset % 1024 === 0 && this.ARM9overlayOffset % 1024 === 0 || this.ARM7size % 1024 < 512 && this.FNToffset % 1024 === 0 && this.ARM7overlayOffset % 1024 === 0 || this.FNTsize % 1024 < 512 && this.FAToffset % 1024 === 0 || this.FATsize % 1024 < 512 && this.bannerOffset % 1024 === 0;
|
|
3486
|
+
const nitroOffset = this.ARM9romOffset + this.ARM9size;
|
|
3487
|
+
this.nitrocode = nitroOffset >= size && nitroOffset + 4 <= data.length && data.readUInt32LE(nitroOffset) === 3737126433;
|
|
3488
|
+
this.decrypted = data.length >= 16392 && data.readBigUInt64LE(16384) === 0xe7ffdeffe7ffdeffn;
|
|
3489
|
+
this.headerCRC = crc16(this.raw.subarray(0, 350)) === this.headerCRC16;
|
|
3490
|
+
this.logoCRC = crc16(this.logo) === this.logoCRC16;
|
|
3491
|
+
const secure = data.subarray(16384, 32768);
|
|
3492
|
+
this.secureCRC = secure.length > 0 && crc16(this.decrypted ? encryptSecureArea(this.gameCode, secure) : secure) === this.secureCRC16;
|
|
3493
|
+
this.dlp_signature = import_buffer.Buffer.alloc(0);
|
|
3494
|
+
if (this.ROMsize >= size && this.ROMsize + 136 <= data.length && data.readUInt32LE(this.ROMsize) === 90977) {
|
|
3495
|
+
this.dlp_signature = import_buffer.Buffer.from(data.subarray(this.ROMsize, this.ROMsize + 136));
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
get size() {
|
|
3499
|
+
return 2 ** (17 + this.raw[20]);
|
|
3500
|
+
}
|
|
3501
|
+
set size(value) {
|
|
3502
|
+
const power = Math.log2(value);
|
|
3503
|
+
if (!Number.isInteger(power) || power < 17 || power > 32)
|
|
3504
|
+
throw new RangeError("ROM capacity must be a power of two from 128 KiB to 4 GiB");
|
|
3505
|
+
this.raw[20] = power - 17;
|
|
3506
|
+
}
|
|
3507
|
+
toBuffer() {
|
|
3508
|
+
const data = import_buffer.Buffer.from(this.raw);
|
|
3509
|
+
data.writeUInt16LE(crc16(data.subarray(192, 348)), 348);
|
|
3510
|
+
data.writeUInt16LE(crc16(data.subarray(0, 350)), 350);
|
|
3511
|
+
return data;
|
|
3512
|
+
}
|
|
3513
|
+
toString() {
|
|
3514
|
+
return `NDS header: ${this.gameTitle.replace(/\0+$/, "")} (${this.gameCode})`;
|
|
3515
|
+
}
|
|
3516
|
+
};
|
|
3517
|
+
function field(name, offset, length, type = "buffer", dsi = false) {
|
|
3518
|
+
Object.defineProperty(Header.prototype, name, {
|
|
3519
|
+
enumerable: true,
|
|
3520
|
+
get() {
|
|
3521
|
+
if (dsi && (!(this.unitCode & 2) || this.raw.length <= 512))
|
|
3522
|
+
return type === "buffer" ? import_buffer.Buffer.alloc(length) : 0;
|
|
3523
|
+
const data = range(this.raw, offset, length, `header ${name}`);
|
|
3524
|
+
if (type === "string") return data.toString("latin1");
|
|
3525
|
+
if (type === "buffer") return data;
|
|
3526
|
+
return length === 8 ? data.readBigUInt64LE() : data.readUIntLE(0, length);
|
|
3527
|
+
},
|
|
3528
|
+
set(value) {
|
|
3529
|
+
const target = range(this.raw, offset, length, `header ${name}`);
|
|
3530
|
+
if (type === "string") {
|
|
3531
|
+
if (typeof value !== "string" || import_buffer.Buffer.byteLength(value, "latin1") > length)
|
|
3532
|
+
throw new TypeError(`Invalid ${name}`);
|
|
3533
|
+
target.fill(0);
|
|
3534
|
+
target.write(value, "latin1");
|
|
3535
|
+
} else if (type === "buffer") {
|
|
3536
|
+
if (!(value instanceof Uint8Array)) throw new TypeError(`Invalid ${name}`);
|
|
3537
|
+
const source = bytes(value, name);
|
|
3538
|
+
if (source.length !== length) throw new RangeError(`${name} must contain ${length} bytes`);
|
|
3539
|
+
source.copy(target);
|
|
3540
|
+
} else if (length === 8) {
|
|
3541
|
+
if (typeof value !== "bigint") throw new TypeError(`Invalid ${name}`);
|
|
3542
|
+
target.writeBigUInt64LE(value);
|
|
3543
|
+
} else {
|
|
3544
|
+
if (typeof value !== "number") throw new TypeError(`Invalid ${name}`);
|
|
3545
|
+
target.writeUIntLE(value, 0, length);
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
});
|
|
3549
|
+
}
|
|
3550
|
+
field("gameTitle", 0, 12, "string");
|
|
3551
|
+
field("gameCode", 12, 4, "string");
|
|
3552
|
+
field("makerCode", 16, 2, "string");
|
|
3553
|
+
for (const [name, offset] of Object.entries({
|
|
3554
|
+
unitCode: 18,
|
|
3555
|
+
encryptionSeed: 19,
|
|
3556
|
+
twlInternalFlags: 28,
|
|
3557
|
+
permitsFlags: 29,
|
|
3558
|
+
ROMversion: 30,
|
|
3559
|
+
internalFlags: 31
|
|
3560
|
+
}))
|
|
3561
|
+
field(name, offset, 1, "number");
|
|
3562
|
+
field("reserved", 21, 7);
|
|
3563
|
+
var ntr32 = "ARM9romOffset ARM9entryAddress ARM9ramAddress ARM9size ARM7romOffset ARM7entryAddress ARM7ramAddress ARM7size FNToffset FNTsize FAToffset FATsize ARM9overlayOffset ARM9overlaySize ARM7overlayOffset ARM7overlaySize flagsRead flagsInit bannerOffset".split(
|
|
3564
|
+
" "
|
|
3565
|
+
);
|
|
3566
|
+
ntr32.forEach((name, i2) => field(name, 32 + i2 * 4, 4, "number"));
|
|
3567
|
+
field("secureCRC16", 108, 2, "number");
|
|
3568
|
+
field("ROMtimeout", 110, 2, "number");
|
|
3569
|
+
field("ARM9autoload", 112, 4, "number");
|
|
3570
|
+
field("ARM7autoload", 116, 4, "number");
|
|
3571
|
+
field("secureDisable", 120, 8, "number");
|
|
3572
|
+
field("ROMsize", 128, 4, "number");
|
|
3573
|
+
field("headerSize", 132, 4, "number");
|
|
3574
|
+
field("reserved2", 136, 56);
|
|
3575
|
+
field("logo", 192, 156);
|
|
3576
|
+
field("logoCRC16", 348, 2, "number");
|
|
3577
|
+
field("headerCRC16", 350, 2, "number");
|
|
3578
|
+
"debug_romOffset debug_size debug_ramAddress reserved3".split(" ").forEach((name, i2) => field(name, 352 + i2 * 4, 4, "number"));
|
|
3579
|
+
field("appflags", 444, 4, "buffer", true);
|
|
3580
|
+
"mbk9_wramcnt_setting region_flags access_control scfg_ext_mask".split(" ").forEach((name, i2) => field(name, 428 + i2 * 4, 4, "number", true));
|
|
3581
|
+
var twl32 = "dsi9_rom_offset offset_0x1C4 dsi9_ram_address dsi9_size dsi7_rom_offset offset_0x1D4 dsi7_ram_address dsi7_size digest_ntr_start digest_ntr_size digest_twl_start digest_twl_size sector_hashtable_start sector_hashtable_size block_hashtable_start block_hashtable_size digest_sector_size digest_block_sectorcount banner_size offset_0x20C total_rom_size offset_0x214 offset_0x218 offset_0x21C modcrypt1_start modcrypt1_size modcrypt2_start modcrypt2_size tid_low tid_high public_sav_size private_sav_size".split(
|
|
3582
|
+
" "
|
|
3583
|
+
);
|
|
3584
|
+
twl32.forEach((name, i2) => field(name, 448 + i2 * 4, 4, "number", true));
|
|
3585
|
+
"hmac_arm9 hmac_arm7 hmac_digest_master hmac_icon_title hmac_arm9i hmac_arm7i".split(" ").forEach((name, i2) => field(name, 768 + i2 * 20, 20, "buffer", true));
|
|
3586
|
+
field("hmac_arm9_no_secure", 928, 20, "buffer", true);
|
|
3587
|
+
field("rsa_signature", 3968, 128, "buffer", true);
|
|
3588
|
+
|
|
3595
3589
|
// src/nitro/twl.ts
|
|
3596
3590
|
init_buffer();
|
|
3597
3591
|
|
|
@@ -3617,8 +3611,7 @@ var decompressBLZ = (input, maxSize = 268435456) => {
|
|
|
3617
3611
|
if (src - 2 < prefix) throw new Error("Truncated BLZ reference");
|
|
3618
3612
|
const high = input[--src], low = input[--src];
|
|
3619
3613
|
const count = (high >>> 4) + 3, offset = ((high & 15) << 8 | low) + 3;
|
|
3620
|
-
if (dst - count < prefix || dst - 1 + offset >= size)
|
|
3621
|
-
throw new Error("Invalid BLZ reference");
|
|
3614
|
+
if (dst - count < prefix || dst - 1 + offset >= size) throw new Error("Invalid BLZ reference");
|
|
3622
3615
|
for (let j = 0; j < count; j++) {
|
|
3623
3616
|
--dst;
|
|
3624
3617
|
out[dst] = out[dst + offset];
|
|
@@ -3712,10 +3705,7 @@ var decompressArm9 = (data, header) => {
|
|
|
3712
3705
|
const compressed = ptr > header.ARM9ramAddress && ptr + nitro >= header.ARM9ramAddress + data.length;
|
|
3713
3706
|
return {
|
|
3714
3707
|
compressed,
|
|
3715
|
-
data: compressed ? import_buffer.Buffer.concat([
|
|
3716
|
-
decompressBLZ(data.subarray(0, data.length - nitro)),
|
|
3717
|
-
data.subarray(data.length - nitro)
|
|
3718
|
-
]) : import_buffer.Buffer.from(data)
|
|
3708
|
+
data: compressed ? import_buffer.Buffer.concat([decompressBLZ(data.subarray(0, data.length - nitro)), data.subarray(data.length - nitro)]) : import_buffer.Buffer.from(data)
|
|
3719
3709
|
};
|
|
3720
3710
|
};
|
|
3721
3711
|
var compressArm9 = (data, header, postSize = 0) => {
|
|
@@ -3765,8 +3755,7 @@ function validate(h) {
|
|
|
3765
3755
|
}
|
|
3766
3756
|
}
|
|
3767
3757
|
const s = h.digest_sector_size;
|
|
3768
|
-
if (!Number.isSafeInteger(s) || s <= 0 || s > 16384 || 16384 % s)
|
|
3769
|
-
throw new Error("Invalid TWL digest sector size");
|
|
3758
|
+
if (!Number.isSafeInteger(s) || s <= 0 || s > 16384 || 16384 % s) throw new Error("Invalid TWL digest sector size");
|
|
3770
3759
|
if (!Number.isSafeInteger(h.digest_block_sectorcount) || h.digest_block_sectorcount <= 0 || h.digest_block_sectorcount > 1048576)
|
|
3771
3760
|
throw new Error("Invalid TWL digest block sector count");
|
|
3772
3761
|
if (h.digest_ntr_size < 16384 || h.digest_ntr_size % s || h.digest_twl_size % s)
|
|
@@ -3796,45 +3785,25 @@ var TWL = class {
|
|
|
3796
3785
|
this.Hashtable2Data = import_buffer.Buffer.from(
|
|
3797
3786
|
slice(original, h.block_hashtable_start, h.block_hashtable_size, "Block hash table")
|
|
3798
3787
|
);
|
|
3799
|
-
this.DSi9Data = import_buffer.Buffer.from(
|
|
3800
|
-
|
|
3801
|
-
);
|
|
3802
|
-
this.DSi7Data = import_buffer.Buffer.from(
|
|
3803
|
-
slice(original, h.dsi7_rom_offset, Math.max(h.modcrypt2_size, h.dsi7_size), "ARM7i")
|
|
3804
|
-
);
|
|
3788
|
+
this.DSi9Data = import_buffer.Buffer.from(slice(original, h.dsi9_rom_offset, Math.max(h.modcrypt1_size, h.dsi9_size), "ARM9i"));
|
|
3789
|
+
this.DSi7Data = import_buffer.Buffer.from(slice(original, h.dsi7_rom_offset, Math.max(h.modcrypt2_size, h.dsi7_size), "ARM7i"));
|
|
3805
3790
|
this.Header2Data = h.trimmedRom ? null : Array.from(
|
|
3806
3791
|
{ length: 3 },
|
|
3807
|
-
(_,
|
|
3808
|
-
slice(original, h.digest_twl_start - 12288 + 4096 * i, 4096, "Secondary header")
|
|
3809
|
-
)
|
|
3810
|
-
);
|
|
3811
|
-
this.Overlays9Sha1Hmac = overlays.map(
|
|
3812
|
-
(o) => hash(slice(original, o.offset, o.size, "ARM9 overlay"))
|
|
3792
|
+
(_, i2) => import_buffer.Buffer.from(slice(original, h.digest_twl_start - 12288 + 4096 * i2, 4096, "Secondary header"))
|
|
3813
3793
|
);
|
|
3794
|
+
this.Overlays9Sha1Hmac = overlays.map((o) => hash(slice(original, o.offset, o.size, "ARM9 overlay")));
|
|
3814
3795
|
let encrypted = false;
|
|
3815
3796
|
const modcryptStart = [
|
|
3816
3797
|
{ start: h.modcrypt1_start, size: h.modcrypt1_size },
|
|
3817
3798
|
{ start: h.modcrypt2_start, size: h.modcrypt2_size }
|
|
3818
|
-
].find(
|
|
3819
|
-
({ start, size }) => size > 0 && start >= h.digest_twl_start && start < 4294967295
|
|
3820
|
-
)?.start;
|
|
3799
|
+
].find(({ start, size }) => size > 0 && start >= h.digest_twl_start && start < 4294967295)?.start;
|
|
3821
3800
|
if (modcryptStart !== void 0) {
|
|
3822
3801
|
const index = Math.floor((modcryptStart - h.digest_twl_start) / h.digest_sector_size);
|
|
3823
3802
|
const actual = hash(
|
|
3824
|
-
slice(
|
|
3825
|
-
original,
|
|
3826
|
-
h.digest_twl_start + index * h.digest_sector_size,
|
|
3827
|
-
h.digest_sector_size,
|
|
3828
|
-
"Modcrypt sector"
|
|
3829
|
-
)
|
|
3803
|
+
slice(original, h.digest_twl_start + index * h.digest_sector_size, h.digest_sector_size, "Modcrypt sector")
|
|
3830
3804
|
);
|
|
3831
3805
|
encrypted = !actual.equals(
|
|
3832
|
-
slice(
|
|
3833
|
-
this.Hashtable1Data,
|
|
3834
|
-
this.firstDSiHashOffset + index * 20,
|
|
3835
|
-
20,
|
|
3836
|
-
"Modcrypt sector hash"
|
|
3837
|
-
)
|
|
3806
|
+
slice(this.Hashtable1Data, this.firstDSiHashOffset + index * 20, 20, "Modcrypt sector hash")
|
|
3838
3807
|
);
|
|
3839
3808
|
}
|
|
3840
3809
|
if (encrypted) this.cryptSections(h);
|
|
@@ -3878,7 +3847,7 @@ var TWL = class {
|
|
|
3878
3847
|
if (overlays.length !== this.Overlays9Sha1Hmac.length)
|
|
3879
3848
|
throw new Error("Changing ARM9 overlay count is unsupported");
|
|
3880
3849
|
const hashes = overlays.map(hash);
|
|
3881
|
-
if (hashes.every((h,
|
|
3850
|
+
if (hashes.every((h, i2) => h.equals(this.Overlays9Sha1Hmac[i2]))) return import_buffer.Buffer.from(arm9Data);
|
|
3882
3851
|
const init = header.reserved2.readUInt32LE(0) & 16383;
|
|
3883
3852
|
const hdrptr = arm9Data.readUInt32LE(init + 20) - header.ARM9ramAddress;
|
|
3884
3853
|
const unpacked = decompressArm9(arm9Data, header);
|
|
@@ -3890,9 +3859,8 @@ var TWL = class {
|
|
|
3890
3859
|
break;
|
|
3891
3860
|
}
|
|
3892
3861
|
}
|
|
3893
|
-
if (found < 0)
|
|
3894
|
-
|
|
3895
|
-
hashes.forEach((h, i) => h.copy(unpacked.data, found + i * 20));
|
|
3862
|
+
if (found < 0) throw new Error("ARM9 overlay hashes changed but original hash table was not found");
|
|
3863
|
+
hashes.forEach((h, i2) => h.copy(unpacked.data, found + i2 * 20));
|
|
3896
3864
|
return unpacked.compressed ? compressArm9(unpacked.data, header, arm9Data.length - hdrptr) : unpacked.data;
|
|
3897
3865
|
}
|
|
3898
3866
|
writeTo(writer, h) {
|
|
@@ -3930,8 +3898,7 @@ var TWL = class {
|
|
|
3930
3898
|
writer.position = h.sector_hashtable_start + index++ * 20;
|
|
3931
3899
|
writer.write(hash(b));
|
|
3932
3900
|
};
|
|
3933
|
-
for (let p = 0; p < 16384; p += h.digest_sector_size)
|
|
3934
|
-
put(secure.subarray(p, p + h.digest_sector_size));
|
|
3901
|
+
for (let p = 0; p < 16384; p += h.digest_sector_size) put(secure.subarray(p, p + h.digest_sector_size));
|
|
3935
3902
|
for (let p = h.digest_ntr_start + 16384; p < h.digest_ntr_start + h.digest_ntr_size; p += h.digest_sector_size)
|
|
3936
3903
|
put(read(p, h.digest_sector_size));
|
|
3937
3904
|
for (let p = h.digest_twl_start; p < h.digest_twl_start + h.digest_twl_size; p += h.digest_sector_size)
|
|
@@ -3975,18 +3942,8 @@ var NDSFile = class _NDSFile {
|
|
|
3975
3942
|
this.fatTable = new FileAllocationTable(this.original, h.FAToffset, h.FATsize);
|
|
3976
3943
|
this.fntTable = new FileNameTable(this.fatTable, this.original, h.FNToffset, h.FNTsize);
|
|
3977
3944
|
this.root = this.fntTable.root;
|
|
3978
|
-
this.overlay9Table = new OverlayTable(
|
|
3979
|
-
|
|
3980
|
-
h.ARM9overlayOffset,
|
|
3981
|
-
h.ARM9overlaySize,
|
|
3982
|
-
true
|
|
3983
|
-
);
|
|
3984
|
-
this.overlay7Table = new OverlayTable(
|
|
3985
|
-
this.original,
|
|
3986
|
-
h.ARM7overlayOffset,
|
|
3987
|
-
h.ARM7overlaySize,
|
|
3988
|
-
false
|
|
3989
|
-
);
|
|
3945
|
+
this.overlay9Table = new OverlayTable(this.original, h.ARM9overlayOffset, h.ARM9overlaySize, true);
|
|
3946
|
+
this.overlay7Table = new OverlayTable(this.original, h.ARM7overlayOffset, h.ARM7overlaySize, false);
|
|
3990
3947
|
const arm9Overlays = this.overlay9Table.readBasicOverlays(this.fatTable);
|
|
3991
3948
|
this.root.folders.push({
|
|
3992
3949
|
name: "overlay",
|
|
@@ -4012,7 +3969,7 @@ var NDSFile = class _NDSFile {
|
|
|
4012
3969
|
if (this.paths.has(key(path))) throw new Error(`Duplicate ROM path: ${path}`);
|
|
4013
3970
|
this.paths.set(key(path), { path, file });
|
|
4014
3971
|
}
|
|
4015
|
-
for (const child of folder.folders) visit(child, prefix + child.name
|
|
3972
|
+
for (const child of folder.folders) visit(child, `${prefix + child.name}/`);
|
|
4016
3973
|
};
|
|
4017
3974
|
visit(this.root, "");
|
|
4018
3975
|
if (h.unitCode & 2 && h.twlInternalFlags & 1 && h.tid_high && h.tid_high !== 4294967295) {
|
|
@@ -4057,15 +4014,8 @@ var NDSFile = class _NDSFile {
|
|
|
4057
4014
|
toBuffer() {
|
|
4058
4015
|
const fntReplacement = this.root.files.find((file) => file.name === "fnt.bin")?.replacement;
|
|
4059
4016
|
if (fntReplacement) {
|
|
4060
|
-
const replacementTree = new FileNameTable(
|
|
4061
|
-
|
|
4062
|
-
fntReplacement,
|
|
4063
|
-
0,
|
|
4064
|
-
fntReplacement.length
|
|
4065
|
-
);
|
|
4066
|
-
const collect = (folder) => [...folder.files.map((file) => file.id), ...folder.folders.flatMap(collect)].sort(
|
|
4067
|
-
(a, b) => a - b
|
|
4068
|
-
);
|
|
4017
|
+
const replacementTree = new FileNameTable(this.fatTable, fntReplacement, 0, fntReplacement.length);
|
|
4018
|
+
const collect = (folder) => [...folder.files.map((file) => file.id), ...folder.folders.flatMap(collect)].sort((a, b) => a - b);
|
|
4069
4019
|
if (collect(replacementTree.root).join(",") !== collect(this.data).join(","))
|
|
4070
4020
|
throw new Error("Replacement FNT must preserve existing file IDs");
|
|
4071
4021
|
}
|
|
@@ -4110,8 +4060,7 @@ var NDSFile = class _NDSFile {
|
|
|
4110
4060
|
item.reserved = (item.reserved & 4278190080 | size & 16777215) >>> 0;
|
|
4111
4061
|
overlayIds.add(file.id);
|
|
4112
4062
|
}
|
|
4113
|
-
if (table2.entries.length !== files.length)
|
|
4114
|
-
throw new Error("Changing overlay file count is unsupported");
|
|
4063
|
+
if (table2.entries.length !== files.length) throw new Error("Changing overlay file count is unsupported");
|
|
4115
4064
|
const encoded = table2.toBuffer();
|
|
4116
4065
|
if (arm92) {
|
|
4117
4066
|
h.ARM9overlayOffset = writer.position;
|
|
@@ -4195,158 +4144,10 @@ var NDSFile = class _NDSFile {
|
|
|
4195
4144
|
// src/nitro-patch-helper.ts
|
|
4196
4145
|
init_buffer();
|
|
4197
4146
|
|
|
4198
|
-
// src/patch/zip.ts
|
|
4199
|
-
init_buffer();
|
|
4200
|
-
var fail = (message) => {
|
|
4201
|
-
throw new Error(`ZIP: ${message}`);
|
|
4202
|
-
};
|
|
4203
|
-
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
4204
|
-
var cp437 = "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
|
|
4205
|
-
function decodeUtf8(bytes2) {
|
|
4206
|
-
try {
|
|
4207
|
-
return utf8.decode(bytes2);
|
|
4208
|
-
} catch {
|
|
4209
|
-
return fail("invalid UTF-8 filename");
|
|
4210
|
-
}
|
|
4211
|
-
}
|
|
4212
|
-
function boundOption(value, fallback, label) {
|
|
4213
|
-
value ??= fallback;
|
|
4214
|
-
if (!Number.isSafeInteger(value) || value < 0)
|
|
4215
|
-
throw new RangeError(`${label} must be a non-negative safe integer`);
|
|
4216
|
-
return value;
|
|
4217
|
-
}
|
|
4218
|
-
function checkRange(bytes2, offset, length, end = bytes2.length) {
|
|
4219
|
-
if (offset < 0 || offset > end || length > end - offset)
|
|
4220
|
-
fail(`truncated or out-of-bounds record at ${offset} (length ${length})`);
|
|
4221
|
-
}
|
|
4222
|
-
function extras(bytes2) {
|
|
4223
|
-
const fields = /* @__PURE__ */ new Map();
|
|
4224
|
-
let offset = 0;
|
|
4225
|
-
while (offset < bytes2.length) {
|
|
4226
|
-
checkRange(bytes2, offset, 4);
|
|
4227
|
-
const id = bytes2.readUInt16LE(offset), length = bytes2.readUInt16LE(offset + 2);
|
|
4228
|
-
offset += 4;
|
|
4229
|
-
checkRange(bytes2, offset, length);
|
|
4230
|
-
if (id === 1) fail("ZIP64 archives are unsupported");
|
|
4231
|
-
fields.set(id, bytes2.subarray(offset, offset + length));
|
|
4232
|
-
offset += length;
|
|
4233
|
-
}
|
|
4234
|
-
return fields;
|
|
4235
|
-
}
|
|
4236
|
-
function filename(raw, flags, fields) {
|
|
4237
|
-
if (flags & 2048) return decodeUtf8(raw);
|
|
4238
|
-
const unicode = fields.get(28789);
|
|
4239
|
-
if (unicode && unicode.length >= 5 && unicode[0] === 1 && unicode.readUInt32LE(1) === crc32(raw))
|
|
4240
|
-
return decodeUtf8(unicode.subarray(5));
|
|
4241
|
-
let result = "";
|
|
4242
|
-
for (const byte of raw) result += byte < 128 ? String.fromCharCode(byte) : cp437[byte - 128];
|
|
4243
|
-
return result;
|
|
4244
|
-
}
|
|
4245
|
-
var readZip = (input, options = {}) => {
|
|
4246
|
-
if (!(input instanceof Uint8Array))
|
|
4247
|
-
throw new TypeError("ZIP input must be a Buffer or Uint8Array");
|
|
4248
|
-
const bytes2 = import_buffer.Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
4249
|
-
const maxSize = boundOption(
|
|
4250
|
-
options.maxUncompressedSize,
|
|
4251
|
-
1024 * 1024 * 1024,
|
|
4252
|
-
"maxUncompressedSize"
|
|
4253
|
-
);
|
|
4254
|
-
const maxEntries = boundOption(options.maxEntries, 1e5, "maxEntries");
|
|
4255
|
-
let eocd = -1;
|
|
4256
|
-
for (let offset2 = bytes2.length - 22; offset2 >= Math.max(0, bytes2.length - 65557); offset2--) {
|
|
4257
|
-
if (bytes2.readUInt32LE(offset2) === 101010256 && offset2 + 22 + bytes2.readUInt16LE(offset2 + 20) === bytes2.length) {
|
|
4258
|
-
eocd = offset2;
|
|
4259
|
-
break;
|
|
4260
|
-
}
|
|
4261
|
-
}
|
|
4262
|
-
if (eocd < 0) fail("end of central directory not found or truncated");
|
|
4263
|
-
const disk = bytes2.readUInt16LE(eocd + 4), centralDisk = bytes2.readUInt16LE(eocd + 6);
|
|
4264
|
-
const diskEntries = bytes2.readUInt16LE(eocd + 8), count = bytes2.readUInt16LE(eocd + 10);
|
|
4265
|
-
const centralSize = bytes2.readUInt32LE(eocd + 12), centralOffset = bytes2.readUInt32LE(eocd + 16);
|
|
4266
|
-
if (count === 65535 || diskEntries === 65535 || centralSize === 4294967295 || centralOffset === 4294967295 || eocd >= 20 && bytes2.readUInt32LE(eocd - 20) === 117853008)
|
|
4267
|
-
fail("ZIP64 archives are unsupported");
|
|
4268
|
-
if (disk || centralDisk || diskEntries !== count)
|
|
4269
|
-
fail("split or multiple-disk archives are unsupported");
|
|
4270
|
-
if (count > maxEntries) fail(`entry count exceeds limit ${maxEntries}`);
|
|
4271
|
-
checkRange(bytes2, centralOffset, centralSize, eocd);
|
|
4272
|
-
if (centralOffset + centralSize !== eocd) fail("central directory size/offset mismatch");
|
|
4273
|
-
if (count > Math.floor(centralSize / 46)) fail("entry count exceeds central directory size");
|
|
4274
|
-
const result = /* @__PURE__ */ new Map();
|
|
4275
|
-
const ranges = [];
|
|
4276
|
-
let offset = centralOffset, totalSize = 0;
|
|
4277
|
-
for (let index = 0; index < count; index++) {
|
|
4278
|
-
checkRange(bytes2, offset, 46, eocd);
|
|
4279
|
-
if (bytes2.readUInt32LE(offset) !== 33639248) fail("invalid central directory signature");
|
|
4280
|
-
const flags = bytes2.readUInt16LE(offset + 8), method = bytes2.readUInt16LE(offset + 10);
|
|
4281
|
-
const checksum = bytes2.readUInt32LE(offset + 16), compressedSize = bytes2.readUInt32LE(offset + 20), size = bytes2.readUInt32LE(offset + 24);
|
|
4282
|
-
const nameLength = bytes2.readUInt16LE(offset + 28), extraLength = bytes2.readUInt16LE(offset + 30), commentLength = bytes2.readUInt16LE(offset + 32);
|
|
4283
|
-
const startDisk = bytes2.readUInt16LE(offset + 34), localOffset = bytes2.readUInt32LE(offset + 42);
|
|
4284
|
-
if (size === 4294967295 || compressedSize === 4294967295 || localOffset === 4294967295 || startDisk === 65535)
|
|
4285
|
-
fail("ZIP64 entry is unsupported");
|
|
4286
|
-
if (startDisk) fail("split or multiple-disk entry is unsupported");
|
|
4287
|
-
if (flags & 8257) fail("encrypted entries are unsupported");
|
|
4288
|
-
if (flags & ~2062) fail("unsupported general purpose flags");
|
|
4289
|
-
if (method !== 0 && method !== 8) fail(`unsupported compression method ${method}`);
|
|
4290
|
-
if (size > maxSize - totalSize) fail(`uncompressed size exceeds limit ${maxSize}`);
|
|
4291
|
-
totalSize += size;
|
|
4292
|
-
checkRange(bytes2, offset + 46, nameLength + extraLength + commentLength, eocd);
|
|
4293
|
-
const rawName = bytes2.subarray(offset + 46, offset + 46 + nameLength);
|
|
4294
|
-
const fields = extras(
|
|
4295
|
-
bytes2.subarray(offset + 46 + nameLength, offset + 46 + nameLength + extraLength)
|
|
4296
|
-
);
|
|
4297
|
-
const name = filename(rawName, flags, fields).replaceAll("\\", "/").toLowerCase();
|
|
4298
|
-
offset += 46 + nameLength + extraLength + commentLength;
|
|
4299
|
-
checkRange(bytes2, localOffset, 30, centralOffset);
|
|
4300
|
-
if (bytes2.readUInt32LE(localOffset) !== 67324752) fail("invalid local header signature");
|
|
4301
|
-
if (bytes2.readUInt16LE(localOffset + 6) !== flags || bytes2.readUInt16LE(localOffset + 8) !== method)
|
|
4302
|
-
fail("local header flags/compression method mismatch");
|
|
4303
|
-
const localNameLength = bytes2.readUInt16LE(localOffset + 26), localExtraLength = bytes2.readUInt16LE(localOffset + 28);
|
|
4304
|
-
const dataOffset = localOffset + 30 + localNameLength + localExtraLength;
|
|
4305
|
-
checkRange(bytes2, localOffset + 30, localNameLength + localExtraLength, centralOffset);
|
|
4306
|
-
if (!rawName.equals(bytes2.subarray(localOffset + 30, localOffset + 30 + localNameLength)))
|
|
4307
|
-
fail("local filename differs from central directory");
|
|
4308
|
-
extras(bytes2.subarray(localOffset + 30 + localNameLength, dataOffset));
|
|
4309
|
-
if (!(flags & 8) && (bytes2.readUInt32LE(localOffset + 14) !== checksum || bytes2.readUInt32LE(localOffset + 18) !== compressedSize || bytes2.readUInt32LE(localOffset + 22) !== size))
|
|
4310
|
-
fail("local header CRC/size mismatch");
|
|
4311
|
-
checkRange(bytes2, dataOffset, compressedSize, centralOffset);
|
|
4312
|
-
let dataEnd = dataOffset + compressedSize;
|
|
4313
|
-
if (flags & 8) {
|
|
4314
|
-
checkRange(bytes2, dataEnd, 12, centralOffset);
|
|
4315
|
-
const matches = (at) => at + 12 <= centralOffset && bytes2.readUInt32LE(at) === checksum && bytes2.readUInt32LE(at + 4) === compressedSize && bytes2.readUInt32LE(at + 8) === size;
|
|
4316
|
-
if (matches(dataEnd)) dataEnd += 12;
|
|
4317
|
-
else if (bytes2.readUInt32LE(dataEnd) === 134695760 && matches(dataEnd + 4)) dataEnd += 16;
|
|
4318
|
-
else fail("data descriptor CRC/size mismatch");
|
|
4319
|
-
}
|
|
4320
|
-
ranges.push({ start: localOffset, end: dataEnd });
|
|
4321
|
-
const compressed = bytes2.subarray(dataOffset, dataOffset + compressedSize);
|
|
4322
|
-
let data;
|
|
4323
|
-
if (method === 0) {
|
|
4324
|
-
if (compressedSize !== size) fail("stored entry compressed/uncompressed size mismatch");
|
|
4325
|
-
data = import_buffer.Buffer.from(compressed);
|
|
4326
|
-
} else {
|
|
4327
|
-
try {
|
|
4328
|
-
data = inflateRawSync(compressed, { maxOutputLength: Math.max(1, size) });
|
|
4329
|
-
} catch (error) {
|
|
4330
|
-
return fail(
|
|
4331
|
-
`cannot inflate entry ${JSON.stringify(name)} within declared size: ${error instanceof Error ? error.message : String(error)}`
|
|
4332
|
-
);
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
if (data.length !== size) fail(`uncompressed size mismatch for ${JSON.stringify(name)}`);
|
|
4336
|
-
if (crc32(data) !== checksum) fail(`CRC32 mismatch for ${JSON.stringify(name)}`);
|
|
4337
|
-
if (name && !name.endsWith("/")) result.set(name, data);
|
|
4338
|
-
}
|
|
4339
|
-
if (offset !== eocd) fail("central directory entry count/length mismatch");
|
|
4340
|
-
ranges.sort((a, b) => a.start - b.start);
|
|
4341
|
-
for (let i = 1; i < ranges.length; i++)
|
|
4342
|
-
if (ranges[i].start < ranges[i - 1].end) fail("overlapping local entry ranges");
|
|
4343
|
-
return result;
|
|
4344
|
-
};
|
|
4345
|
-
|
|
4346
4147
|
// src/patch/xdelta.ts
|
|
4347
4148
|
init_buffer();
|
|
4348
4149
|
var UINT32_MAX = 4294967295;
|
|
4349
|
-
var
|
|
4150
|
+
var fail = (message) => {
|
|
4350
4151
|
throw new Error(`VCDIFF: ${message}`);
|
|
4351
4152
|
};
|
|
4352
4153
|
var Reader = class {
|
|
@@ -4354,12 +4155,14 @@ var Reader = class {
|
|
|
4354
4155
|
this.bytes = bytes2;
|
|
4355
4156
|
this.label = label;
|
|
4356
4157
|
}
|
|
4158
|
+
bytes;
|
|
4159
|
+
label;
|
|
4357
4160
|
pos = 0;
|
|
4358
4161
|
get remaining() {
|
|
4359
4162
|
return this.bytes.length - this.pos;
|
|
4360
4163
|
}
|
|
4361
4164
|
byte() {
|
|
4362
|
-
if (!this.remaining)
|
|
4165
|
+
if (!this.remaining) fail(`truncated ${this.label}`);
|
|
4363
4166
|
return this.bytes[this.pos++];
|
|
4364
4167
|
}
|
|
4365
4168
|
integer() {
|
|
@@ -4367,14 +4170,13 @@ var Reader = class {
|
|
|
4367
4170
|
for (let count = 0; count < 5; count++) {
|
|
4368
4171
|
const byte = this.byte();
|
|
4369
4172
|
value = value * 128 + (byte & 127);
|
|
4370
|
-
if (value > UINT32_MAX)
|
|
4173
|
+
if (value > UINT32_MAX) fail(`integer exceeds 32-bit limit in ${this.label}`);
|
|
4371
4174
|
if (!(byte & 128)) return value;
|
|
4372
4175
|
}
|
|
4373
|
-
return
|
|
4176
|
+
return fail(`invalid variable-length integer in ${this.label}`);
|
|
4374
4177
|
}
|
|
4375
4178
|
take(size) {
|
|
4376
|
-
if (size > this.remaining)
|
|
4377
|
-
fail2(`truncated ${this.label}: requested ${size} bytes, ${this.remaining} remain`);
|
|
4179
|
+
if (size > this.remaining) fail(`truncated ${this.label}: requested ${size} bytes, ${this.remaining} remain`);
|
|
4378
4180
|
const result = this.bytes.subarray(this.pos, this.pos + size);
|
|
4379
4181
|
this.pos += size;
|
|
4380
4182
|
return result;
|
|
@@ -4401,8 +4203,8 @@ function adler32(bytes2) {
|
|
|
4401
4203
|
let a = 1, b = 0;
|
|
4402
4204
|
for (let start = 0; start < bytes2.length; start += 5552) {
|
|
4403
4205
|
const end = Math.min(start + 5552, bytes2.length);
|
|
4404
|
-
for (let
|
|
4405
|
-
a += bytes2[
|
|
4206
|
+
for (let i2 = start; i2 < end; i2++) {
|
|
4207
|
+
a += bytes2[i2];
|
|
4406
4208
|
b += a;
|
|
4407
4209
|
}
|
|
4408
4210
|
a %= 65521;
|
|
@@ -4425,27 +4227,26 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4425
4227
|
const reader = new Reader(asBuffer(patch, "patch"));
|
|
4426
4228
|
const maxOutput = limit(options.maxOutputSize, 1024 * 1024 * 1024, "maxOutputSize");
|
|
4427
4229
|
const maxWindow = limit(options.maxWindowSize, 16 * 1024 * 1024, "maxWindowSize");
|
|
4428
|
-
if (!reader.take(3).equals(import_buffer.Buffer.from([214, 195, 196])))
|
|
4429
|
-
if (reader.byte() !== 0)
|
|
4230
|
+
if (!reader.take(3).equals(import_buffer.Buffer.from([214, 195, 196]))) fail("invalid file signature");
|
|
4231
|
+
if (reader.byte() !== 0) fail("unsupported version (expected 0)");
|
|
4430
4232
|
const header = reader.byte();
|
|
4431
|
-
if (header & ~7)
|
|
4432
|
-
if (header & 1)
|
|
4433
|
-
|
|
4434
|
-
if (header & 2) fail2("custom code table is unsupported");
|
|
4233
|
+
if (header & ~7) fail("unrecognized header indicator bits");
|
|
4234
|
+
if (header & 1) fail("secondary compression is unsupported; recreate the patch using xdelta3 -S none");
|
|
4235
|
+
if (header & 2) fail("custom code table is unsupported");
|
|
4435
4236
|
if (header & 4) reader.take(reader.integer());
|
|
4436
4237
|
const windows = [];
|
|
4437
4238
|
let total = 0;
|
|
4438
4239
|
while (reader.remaining) {
|
|
4439
4240
|
const indicator = reader.byte();
|
|
4440
4241
|
if (indicator & ~7 || (indicator & 3) === 3)
|
|
4441
|
-
|
|
4242
|
+
fail("invalid window indicator: source and target are mutually exclusive");
|
|
4442
4243
|
let dictionary = import_buffer.Buffer.alloc(0);
|
|
4443
4244
|
if (indicator & 3) {
|
|
4444
4245
|
const length = reader.integer();
|
|
4445
4246
|
const offset = reader.integer();
|
|
4446
4247
|
const available = indicator & 1 ? sourceBytes.length : total;
|
|
4447
4248
|
if (offset > available || length > available - offset)
|
|
4448
|
-
|
|
4249
|
+
fail("source segment exceeds available source/target bounds");
|
|
4449
4250
|
if (indicator & 1) dictionary = sourceBytes.subarray(offset, offset + length);
|
|
4450
4251
|
else {
|
|
4451
4252
|
dictionary = import_buffer.Buffer.allocUnsafe(length);
|
|
@@ -4461,20 +4262,18 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4461
4262
|
const deltaLength = reader.integer();
|
|
4462
4263
|
const delta = new Reader(reader.take(deltaLength), "delta window");
|
|
4463
4264
|
const targetLength = delta.integer();
|
|
4464
|
-
if (targetLength > maxWindow)
|
|
4465
|
-
|
|
4466
|
-
if (targetLength >
|
|
4467
|
-
if (dictionary.length + targetLength > UINT32_MAX)
|
|
4468
|
-
fail2("window address space exceeds 32-bit limit");
|
|
4265
|
+
if (targetLength > maxWindow) fail(`window size ${targetLength} exceeds maximum limit ${maxWindow}`);
|
|
4266
|
+
if (targetLength > maxOutput - total) fail(`output size exceeds maximum limit ${maxOutput}`);
|
|
4267
|
+
if (dictionary.length + targetLength > UINT32_MAX) fail("window address space exceeds 32-bit limit");
|
|
4469
4268
|
const compressed = delta.byte();
|
|
4470
|
-
if (compressed & ~7)
|
|
4471
|
-
if (compressed)
|
|
4269
|
+
if (compressed & ~7) fail("unrecognized delta indicator bits");
|
|
4270
|
+
if (compressed) fail("secondary compression in delta sections is unsupported");
|
|
4472
4271
|
const dataLength = delta.integer(), instructionLength = delta.integer(), addressLength = delta.integer();
|
|
4473
4272
|
const checksum = indicator & 4 ? delta.take(4).readUInt32BE() : null;
|
|
4474
4273
|
const data = new Reader(delta.take(dataLength), "data section");
|
|
4475
4274
|
const instructions = new Reader(delta.take(instructionLength), "instruction section");
|
|
4476
4275
|
const addresses = new Reader(delta.take(addressLength), "address section");
|
|
4477
|
-
if (delta.remaining)
|
|
4276
|
+
if (delta.remaining) fail("delta encoding length does not match section lengths");
|
|
4478
4277
|
const target = import_buffer.Buffer.allocUnsafe(targetLength);
|
|
4479
4278
|
const near = new Uint32Array(4), same = new Uint32Array(768);
|
|
4480
4279
|
let nearIndex = 0, position = 0;
|
|
@@ -4482,7 +4281,7 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4482
4281
|
const operations = table[instructions.byte()];
|
|
4483
4282
|
for (const { type, size: fixedSize, mode } of operations) {
|
|
4484
4283
|
const size = fixedSize || instructions.integer();
|
|
4485
|
-
if (size > targetLength - position)
|
|
4284
|
+
if (size > targetLength - position) fail(`${type} size exceeds target window length`);
|
|
4486
4285
|
if (type === "ADD") {
|
|
4487
4286
|
data.take(size).copy(target, position);
|
|
4488
4287
|
} else if (type === "RUN") {
|
|
@@ -4494,8 +4293,7 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4494
4293
|
else if (mode === 1) address = here - addresses.integer();
|
|
4495
4294
|
else if (mode < 6) address = near[mode - 2] + addresses.integer();
|
|
4496
4295
|
else address = same[(mode - 6) * 256 + addresses.byte()];
|
|
4497
|
-
if (address < 0 || address >= here)
|
|
4498
|
-
fail2(`COPY address ${address} is outside decoded address space ${here}`);
|
|
4296
|
+
if (address < 0 || address >= here) fail(`COPY address ${address} is outside decoded address space ${here}`);
|
|
4499
4297
|
near[nearIndex] = address;
|
|
4500
4298
|
nearIndex = (nearIndex + 1) % near.length;
|
|
4501
4299
|
same[address % same.length] = address;
|
|
@@ -4507,7 +4305,7 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4507
4305
|
const from = Math.max(0, address - dictionary.length);
|
|
4508
4306
|
while (copied < size) {
|
|
4509
4307
|
const count = Math.min(size - copied, position + copied - from);
|
|
4510
|
-
if (count <= 0)
|
|
4308
|
+
if (count <= 0) fail("COPY references unavailable target bytes");
|
|
4511
4309
|
target.copy(target, position + copied, from, from + count);
|
|
4512
4310
|
copied += count;
|
|
4513
4311
|
}
|
|
@@ -4515,31 +4313,237 @@ var decodeXdelta = (source, patch, options = {}) => {
|
|
|
4515
4313
|
position += size;
|
|
4516
4314
|
}
|
|
4517
4315
|
}
|
|
4518
|
-
if (position !== targetLength)
|
|
4519
|
-
|
|
4520
|
-
if (
|
|
4521
|
-
if (checksum !== null && adler32(target) !== checksum) fail2("Adler32 checksum mismatch");
|
|
4316
|
+
if (position !== targetLength) fail(`target window length mismatch: decoded ${position}, expected ${targetLength}`);
|
|
4317
|
+
if (data.remaining || addresses.remaining) fail("unused bytes in data/address section");
|
|
4318
|
+
if (checksum !== null && adler32(target) !== checksum) fail("Adler32 checksum mismatch");
|
|
4522
4319
|
windows.push(target);
|
|
4523
4320
|
total += targetLength;
|
|
4524
4321
|
}
|
|
4525
4322
|
return import_buffer.Buffer.concat(windows, total);
|
|
4526
4323
|
};
|
|
4527
4324
|
|
|
4325
|
+
// src/patch/zip.ts
|
|
4326
|
+
init_buffer();
|
|
4327
|
+
var fail2 = (message) => {
|
|
4328
|
+
throw new Error(`ZIP: ${message}`);
|
|
4329
|
+
};
|
|
4330
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
4331
|
+
var cp437 = "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
|
|
4332
|
+
function decodeUtf8(bytes2) {
|
|
4333
|
+
try {
|
|
4334
|
+
return utf8.decode(bytes2);
|
|
4335
|
+
} catch {
|
|
4336
|
+
return fail2("invalid UTF-8 filename");
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
function boundOption(value, fallback, label) {
|
|
4340
|
+
value ??= fallback;
|
|
4341
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new RangeError(`${label} must be a non-negative safe integer`);
|
|
4342
|
+
return value;
|
|
4343
|
+
}
|
|
4344
|
+
function checkRange(bytes2, offset, length, end = bytes2.length) {
|
|
4345
|
+
if (offset < 0 || offset > end || length > end - offset)
|
|
4346
|
+
fail2(`truncated or out-of-bounds record at ${offset} (length ${length})`);
|
|
4347
|
+
}
|
|
4348
|
+
function extras(bytes2) {
|
|
4349
|
+
const fields = /* @__PURE__ */ new Map();
|
|
4350
|
+
let offset = 0;
|
|
4351
|
+
while (offset < bytes2.length) {
|
|
4352
|
+
checkRange(bytes2, offset, 4);
|
|
4353
|
+
const id = bytes2.readUInt16LE(offset), length = bytes2.readUInt16LE(offset + 2);
|
|
4354
|
+
offset += 4;
|
|
4355
|
+
checkRange(bytes2, offset, length);
|
|
4356
|
+
if (id === 1) fail2("ZIP64 archives are unsupported");
|
|
4357
|
+
fields.set(id, bytes2.subarray(offset, offset + length));
|
|
4358
|
+
offset += length;
|
|
4359
|
+
}
|
|
4360
|
+
return fields;
|
|
4361
|
+
}
|
|
4362
|
+
function filename(raw, flags, fields) {
|
|
4363
|
+
if (flags & 2048) return decodeUtf8(raw);
|
|
4364
|
+
const unicode = fields.get(28789);
|
|
4365
|
+
if (unicode && unicode.length >= 5 && unicode[0] === 1 && unicode.readUInt32LE(1) === crc32(raw))
|
|
4366
|
+
return decodeUtf8(unicode.subarray(5));
|
|
4367
|
+
let result = "";
|
|
4368
|
+
for (const byte of raw) result += byte < 128 ? String.fromCharCode(byte) : cp437[byte - 128];
|
|
4369
|
+
return result;
|
|
4370
|
+
}
|
|
4371
|
+
var readZip = (input, options = {}) => {
|
|
4372
|
+
if (!(input instanceof Uint8Array)) throw new TypeError("ZIP input must be a Buffer or Uint8Array");
|
|
4373
|
+
const bytes2 = import_buffer.Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
4374
|
+
const maxSize = boundOption(options.maxUncompressedSize, 1024 * 1024 * 1024, "maxUncompressedSize");
|
|
4375
|
+
const maxEntries = boundOption(options.maxEntries, 1e5, "maxEntries");
|
|
4376
|
+
let eocd = -1;
|
|
4377
|
+
for (let offset2 = bytes2.length - 22; offset2 >= Math.max(0, bytes2.length - 65557); offset2--) {
|
|
4378
|
+
if (bytes2.readUInt32LE(offset2) === 101010256 && offset2 + 22 + bytes2.readUInt16LE(offset2 + 20) === bytes2.length) {
|
|
4379
|
+
eocd = offset2;
|
|
4380
|
+
break;
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
if (eocd < 0) fail2("end of central directory not found or truncated");
|
|
4384
|
+
const disk = bytes2.readUInt16LE(eocd + 4), centralDisk = bytes2.readUInt16LE(eocd + 6);
|
|
4385
|
+
const diskEntries = bytes2.readUInt16LE(eocd + 8), count = bytes2.readUInt16LE(eocd + 10);
|
|
4386
|
+
const centralSize = bytes2.readUInt32LE(eocd + 12), centralOffset = bytes2.readUInt32LE(eocd + 16);
|
|
4387
|
+
if (count === 65535 || diskEntries === 65535 || centralSize === 4294967295 || centralOffset === 4294967295 || eocd >= 20 && bytes2.readUInt32LE(eocd - 20) === 117853008)
|
|
4388
|
+
fail2("ZIP64 archives are unsupported");
|
|
4389
|
+
if (disk || centralDisk || diskEntries !== count) fail2("split or multiple-disk archives are unsupported");
|
|
4390
|
+
if (count > maxEntries) fail2(`entry count exceeds limit ${maxEntries}`);
|
|
4391
|
+
checkRange(bytes2, centralOffset, centralSize, eocd);
|
|
4392
|
+
if (centralOffset + centralSize !== eocd) fail2("central directory size/offset mismatch");
|
|
4393
|
+
if (count > Math.floor(centralSize / 46)) fail2("entry count exceeds central directory size");
|
|
4394
|
+
const result = /* @__PURE__ */ new Map();
|
|
4395
|
+
const ranges = [];
|
|
4396
|
+
let offset = centralOffset, totalSize = 0;
|
|
4397
|
+
for (let index = 0; index < count; index++) {
|
|
4398
|
+
checkRange(bytes2, offset, 46, eocd);
|
|
4399
|
+
if (bytes2.readUInt32LE(offset) !== 33639248) fail2("invalid central directory signature");
|
|
4400
|
+
const flags = bytes2.readUInt16LE(offset + 8), method = bytes2.readUInt16LE(offset + 10);
|
|
4401
|
+
const checksum = bytes2.readUInt32LE(offset + 16), compressedSize = bytes2.readUInt32LE(offset + 20), size = bytes2.readUInt32LE(offset + 24);
|
|
4402
|
+
const nameLength = bytes2.readUInt16LE(offset + 28), extraLength = bytes2.readUInt16LE(offset + 30), commentLength = bytes2.readUInt16LE(offset + 32);
|
|
4403
|
+
const startDisk = bytes2.readUInt16LE(offset + 34), localOffset = bytes2.readUInt32LE(offset + 42);
|
|
4404
|
+
if (size === 4294967295 || compressedSize === 4294967295 || localOffset === 4294967295 || startDisk === 65535)
|
|
4405
|
+
fail2("ZIP64 entry is unsupported");
|
|
4406
|
+
if (startDisk) fail2("split or multiple-disk entry is unsupported");
|
|
4407
|
+
if (flags & 8257) fail2("encrypted entries are unsupported");
|
|
4408
|
+
if (flags & ~2062) fail2("unsupported general purpose flags");
|
|
4409
|
+
if (method !== 0 && method !== 8) fail2(`unsupported compression method ${method}`);
|
|
4410
|
+
if (size > maxSize - totalSize) fail2(`uncompressed size exceeds limit ${maxSize}`);
|
|
4411
|
+
totalSize += size;
|
|
4412
|
+
checkRange(bytes2, offset + 46, nameLength + extraLength + commentLength, eocd);
|
|
4413
|
+
const rawName = bytes2.subarray(offset + 46, offset + 46 + nameLength);
|
|
4414
|
+
const fields = extras(bytes2.subarray(offset + 46 + nameLength, offset + 46 + nameLength + extraLength));
|
|
4415
|
+
const name = filename(rawName, flags, fields).replaceAll("\\", "/").toLowerCase();
|
|
4416
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
4417
|
+
checkRange(bytes2, localOffset, 30, centralOffset);
|
|
4418
|
+
if (bytes2.readUInt32LE(localOffset) !== 67324752) fail2("invalid local header signature");
|
|
4419
|
+
if (bytes2.readUInt16LE(localOffset + 6) !== flags || bytes2.readUInt16LE(localOffset + 8) !== method)
|
|
4420
|
+
fail2("local header flags/compression method mismatch");
|
|
4421
|
+
const localNameLength = bytes2.readUInt16LE(localOffset + 26), localExtraLength = bytes2.readUInt16LE(localOffset + 28);
|
|
4422
|
+
const dataOffset = localOffset + 30 + localNameLength + localExtraLength;
|
|
4423
|
+
checkRange(bytes2, localOffset + 30, localNameLength + localExtraLength, centralOffset);
|
|
4424
|
+
if (!rawName.equals(bytes2.subarray(localOffset + 30, localOffset + 30 + localNameLength)))
|
|
4425
|
+
fail2("local filename differs from central directory");
|
|
4426
|
+
extras(bytes2.subarray(localOffset + 30 + localNameLength, dataOffset));
|
|
4427
|
+
if (!(flags & 8) && (bytes2.readUInt32LE(localOffset + 14) !== checksum || bytes2.readUInt32LE(localOffset + 18) !== compressedSize || bytes2.readUInt32LE(localOffset + 22) !== size))
|
|
4428
|
+
fail2("local header CRC/size mismatch");
|
|
4429
|
+
checkRange(bytes2, dataOffset, compressedSize, centralOffset);
|
|
4430
|
+
let dataEnd = dataOffset + compressedSize;
|
|
4431
|
+
if (flags & 8) {
|
|
4432
|
+
checkRange(bytes2, dataEnd, 12, centralOffset);
|
|
4433
|
+
const matches = (at) => at + 12 <= centralOffset && bytes2.readUInt32LE(at) === checksum && bytes2.readUInt32LE(at + 4) === compressedSize && bytes2.readUInt32LE(at + 8) === size;
|
|
4434
|
+
if (matches(dataEnd)) dataEnd += 12;
|
|
4435
|
+
else if (bytes2.readUInt32LE(dataEnd) === 134695760 && matches(dataEnd + 4)) dataEnd += 16;
|
|
4436
|
+
else fail2("data descriptor CRC/size mismatch");
|
|
4437
|
+
}
|
|
4438
|
+
ranges.push({ start: localOffset, end: dataEnd });
|
|
4439
|
+
const compressed = bytes2.subarray(dataOffset, dataOffset + compressedSize);
|
|
4440
|
+
let data;
|
|
4441
|
+
if (method === 0) {
|
|
4442
|
+
if (compressedSize !== size) fail2("stored entry compressed/uncompressed size mismatch");
|
|
4443
|
+
data = import_buffer.Buffer.from(compressed);
|
|
4444
|
+
} else {
|
|
4445
|
+
try {
|
|
4446
|
+
data = inflateRawSync(compressed, { maxOutputLength: Math.max(1, size) });
|
|
4447
|
+
} catch (error) {
|
|
4448
|
+
return fail2(
|
|
4449
|
+
`cannot inflate entry ${JSON.stringify(name)} within declared size: ${error instanceof Error ? error.message : String(error)}`
|
|
4450
|
+
);
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
if (data.length !== size) fail2(`uncompressed size mismatch for ${JSON.stringify(name)}`);
|
|
4454
|
+
if (crc32(data) !== checksum) fail2(`CRC32 mismatch for ${JSON.stringify(name)}`);
|
|
4455
|
+
if (name && !name.endsWith("/")) result.set(name, data);
|
|
4456
|
+
}
|
|
4457
|
+
if (offset !== eocd) fail2("central directory entry count/length mismatch");
|
|
4458
|
+
ranges.sort((a, b) => a.start - b.start);
|
|
4459
|
+
for (let i2 = 1; i2 < ranges.length; i2++)
|
|
4460
|
+
if (ranges[i2].start < ranges[i2 - 1].end) fail2("overlapping local entry ranges");
|
|
4461
|
+
return result;
|
|
4462
|
+
};
|
|
4463
|
+
var extractZipEntry = (input, entryName, options = {}) => {
|
|
4464
|
+
if (typeof entryName !== "string" || !entryName) throw new TypeError("ZIP entry name must be a non-empty string");
|
|
4465
|
+
const normalized = entryName.replaceAll("\\", "/").toLowerCase();
|
|
4466
|
+
if (normalized.endsWith("/")) fail2(`entry ${JSON.stringify(entryName)} is a directory`);
|
|
4467
|
+
const entry = readZip(input, options).get(normalized);
|
|
4468
|
+
if (entry === void 0) return fail2(`entry ${JSON.stringify(entryName)} not found`);
|
|
4469
|
+
return entry;
|
|
4470
|
+
};
|
|
4471
|
+
|
|
4528
4472
|
// src/nitro-patch-helper.ts
|
|
4529
4473
|
var PatchReturnValue = Object.freeze({
|
|
4530
4474
|
SUCCESS: "SUCCESS",
|
|
4531
4475
|
MD5_MISMATCH: "MD5_MISMATCH"
|
|
4532
4476
|
});
|
|
4533
4477
|
var md52 = (data) => hashDigest("md5", data).toString("hex");
|
|
4478
|
+
var invalidMetadata = (message) => {
|
|
4479
|
+
console.warn(`\u5FFD\u7565 metadata.json\uFF1A${message}`);
|
|
4480
|
+
return null;
|
|
4481
|
+
};
|
|
4482
|
+
var invalidMetadataField = (field2, message) => {
|
|
4483
|
+
console.warn(`\u5FFD\u7565 metadata.json \u7684 ${field2}\uFF1A${message}`);
|
|
4484
|
+
};
|
|
4485
|
+
var readMetadata = (files) => {
|
|
4486
|
+
const file = files.get("metadata.json");
|
|
4487
|
+
if (!file) return null;
|
|
4488
|
+
let metadata;
|
|
4489
|
+
try {
|
|
4490
|
+
metadata = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(file));
|
|
4491
|
+
} catch (error) {
|
|
4492
|
+
return invalidMetadata(
|
|
4493
|
+
`\u683C\u5F0F\u9519\u8BEF\uFF0C\u53EF\u80FD\u662F\u56E0\u4E3A\u8865\u4E01\u5305\u5DF2\u635F\u574F\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4494
|
+
);
|
|
4495
|
+
}
|
|
4496
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata))
|
|
4497
|
+
return invalidMetadata("\u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
|
|
4498
|
+
const value = metadata;
|
|
4499
|
+
const result = {};
|
|
4500
|
+
for (const field2 of ["id", "author", "name", "homepage", "version"]) {
|
|
4501
|
+
const fieldValue = value[field2];
|
|
4502
|
+
if (fieldValue === void 0) continue;
|
|
4503
|
+
if (typeof fieldValue === "string") result[field2] = fieldValue;
|
|
4504
|
+
else invalidMetadataField(field2, "\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002");
|
|
4505
|
+
}
|
|
4506
|
+
if (value.isBeta === void 0) return result;
|
|
4507
|
+
if (typeof value.isBeta === "boolean") result.isBeta = value.isBeta;
|
|
4508
|
+
else invalidMetadataField("isBeta", "\u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002");
|
|
4509
|
+
return result;
|
|
4510
|
+
};
|
|
4511
|
+
var readReadme = (files) => {
|
|
4512
|
+
for (const [filename2, format] of [
|
|
4513
|
+
["README.md", "markdown"],
|
|
4514
|
+
["README.txt", "plaintext"]
|
|
4515
|
+
]) {
|
|
4516
|
+
const file = files.get(filename2.toLowerCase());
|
|
4517
|
+
if (!file) continue;
|
|
4518
|
+
try {
|
|
4519
|
+
return {
|
|
4520
|
+
format,
|
|
4521
|
+
content: new TextDecoder("utf-8", { fatal: true }).decode(file)
|
|
4522
|
+
};
|
|
4523
|
+
} catch (error) {
|
|
4524
|
+
console.warn(
|
|
4525
|
+
`\u5FFD\u7565 ${filename2}\uFF1A\u4E0D\u662F\u6709\u6548\u7684 UTF-8 \u6587\u672C\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
return null;
|
|
4530
|
+
};
|
|
4531
|
+
var readPatchMetadata = (patch, options = {}) => readMetadata(readZip(patch, options));
|
|
4532
|
+
var readPatchReadme = (patch, options = {}) => readReadme(readZip(patch, options));
|
|
4533
|
+
var readPatchInfo = (patch, options = {}) => {
|
|
4534
|
+
const files = readZip(patch, options);
|
|
4535
|
+
return { metadata: readMetadata(files), readme: readReadme(files) };
|
|
4536
|
+
};
|
|
4537
|
+
var extractZipEntry2 = (archive, entryName, options = {}) => extractZipEntry(archive, entryName, options);
|
|
4538
|
+
var readPatchMetadataFile = async (patchPath, options = {}) => readPatchMetadata(await readFile(patchPath), options);
|
|
4539
|
+
var readPatchReadmeFile = async (patchPath, options = {}) => readPatchReadme(await readFile(patchPath), options);
|
|
4540
|
+
var readPatchInfoFile = async (patchPath, options = {}) => readPatchInfo(await readFile(patchPath), options);
|
|
4534
4541
|
var patchBuffer = (original, patch, options = {}) => {
|
|
4535
4542
|
const input = bytes(original, "original ROM");
|
|
4536
4543
|
const patches = readZip(patch, options);
|
|
4537
4544
|
const inputMd5 = md52(input);
|
|
4538
4545
|
const preprocessing = patches.get(`preprocessing/${inputMd5}.xdelta`);
|
|
4539
|
-
const rom = new NDSFile(
|
|
4540
|
-
preprocessing ? decodeXdelta(input, preprocessing, options) : input,
|
|
4541
|
-
options
|
|
4542
|
-
);
|
|
4546
|
+
const rom = new NDSFile(preprocessing ? decodeXdelta(input, preprocessing, options) : input, options);
|
|
4543
4547
|
let matched = true;
|
|
4544
4548
|
const md5File = patches.get("md5.txt");
|
|
4545
4549
|
if (md5File) {
|
|
@@ -4572,7 +4576,17 @@ var patchIt = async (originalPath, patchPath, options = {}) => {
|
|
|
4572
4576
|
const [original, patch] = await Promise.all([readFile(originalPath), readFile(patchPath)]);
|
|
4573
4577
|
return patchBuffer(original, patch, options);
|
|
4574
4578
|
};
|
|
4575
|
-
var PatchHelper = Object.freeze({
|
|
4579
|
+
var PatchHelper = Object.freeze({
|
|
4580
|
+
extractZipEntry: extractZipEntry2,
|
|
4581
|
+
patchBuffer,
|
|
4582
|
+
patchIt,
|
|
4583
|
+
readPatchInfo,
|
|
4584
|
+
readPatchInfoFile,
|
|
4585
|
+
readPatchMetadata,
|
|
4586
|
+
readPatchMetadataFile,
|
|
4587
|
+
readPatchReadme,
|
|
4588
|
+
readPatchReadmeFile
|
|
4589
|
+
});
|
|
4576
4590
|
|
|
4577
4591
|
// src/browser.ts
|
|
4578
4592
|
var inspectRom = (bytes2) => {
|
|
@@ -4604,13 +4618,27 @@ var patchBuffer2 = (original, archive, options = {}) => {
|
|
|
4604
4618
|
outputMd5: result.outputMd5
|
|
4605
4619
|
};
|
|
4606
4620
|
};
|
|
4607
|
-
var
|
|
4621
|
+
var readPatchMetadata2 = (archive, options = {}) => readPatchMetadata(archive, options);
|
|
4622
|
+
var readPatchReadme2 = (archive, options = {}) => readPatchReadme(archive, options);
|
|
4623
|
+
var readPatchInfo2 = (archive, options = {}) => readPatchInfo(archive, options);
|
|
4624
|
+
var extractZipEntry3 = (archive, entryName, options = {}) => new Uint8Array(extractZipEntry2(archive, entryName, options));
|
|
4625
|
+
var PatchHelper2 = Object.freeze({
|
|
4626
|
+
extractZipEntry: extractZipEntry3,
|
|
4627
|
+
patchBuffer: patchBuffer2,
|
|
4628
|
+
readPatchInfo: readPatchInfo2,
|
|
4629
|
+
readPatchMetadata: readPatchMetadata2,
|
|
4630
|
+
readPatchReadme: readPatchReadme2
|
|
4631
|
+
});
|
|
4608
4632
|
var NitroHelper = Object.freeze({ inspectRom });
|
|
4609
4633
|
export {
|
|
4610
4634
|
NitroHelper,
|
|
4611
4635
|
PatchHelper2 as PatchHelper,
|
|
4636
|
+
extractZipEntry3 as extractZipEntry,
|
|
4612
4637
|
inspectRom,
|
|
4613
|
-
patchBuffer2 as patchBuffer
|
|
4638
|
+
patchBuffer2 as patchBuffer,
|
|
4639
|
+
readPatchInfo2 as readPatchInfo,
|
|
4640
|
+
readPatchMetadata2 as readPatchMetadata,
|
|
4641
|
+
readPatchReadme2 as readPatchReadme
|
|
4614
4642
|
};
|
|
4615
4643
|
/*! For license information please see browser.js.LEGAL.txt */
|
|
4616
4644
|
//# sourceMappingURL=browser.js.map
|