react-native-update-cli 2.26.0 → 2.26.2
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/bundle-runner.js +13 -9
- package/lib/utils/constants.js +8 -1
- package/lib/utils/hermes-base.d.ts +7 -4
- package/lib/utils/hermes-base.js +202 -56
- package/lib/utils/hermes-literals.d.ts +22 -9
- package/lib/utils/hermes-literals.js +90 -35
- package/lib/utils/hermes-raw.d.ts +40 -0
- package/lib/utils/hermes-raw.js +486 -0
- package/lib/utils/hermes-timeout.d.ts +2 -0
- package/lib/utils/hermes-timeout.js +10 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type LiteralValue = {
|
|
2
|
-
kind: 'null' | 'true' | 'false';
|
|
2
|
+
kind: 'null' | 'true' | 'false' | 'undefined';
|
|
3
3
|
} | {
|
|
4
4
|
kind: 'number';
|
|
5
5
|
value: number;
|
|
@@ -10,29 +10,36 @@ export type LiteralValue = {
|
|
|
10
10
|
kind: 'string';
|
|
11
11
|
id: number;
|
|
12
12
|
};
|
|
13
|
-
/** The
|
|
14
|
-
export
|
|
13
|
+
/** The literal buffers of an HBC file, in one of the two layouts. */
|
|
14
|
+
export type LiteralBuffers = {
|
|
15
|
+
layout: 'split';
|
|
15
16
|
version: number;
|
|
16
17
|
array: Buffer;
|
|
17
18
|
objectKeys: Buffer;
|
|
18
19
|
objectValues: Buffer;
|
|
19
|
-
}
|
|
20
|
+
} | {
|
|
21
|
+
layout: 'shaped';
|
|
22
|
+
version: number;
|
|
23
|
+
values: Buffer;
|
|
24
|
+
objectKeys: Buffer;
|
|
25
|
+
shapes: Buffer;
|
|
26
|
+
};
|
|
20
27
|
/**
|
|
21
28
|
* Read only the literal buffers of an HBC file (header + three byte ranges,
|
|
22
|
-
* never the whole file). Null for a file whose layout is unknown
|
|
23
|
-
* HBC v98 (literalValueBuffer + objShapeTable, not decoded yet): the caller
|
|
29
|
+
* never the whole file). Null for a file whose layout is unknown: the caller
|
|
24
30
|
* then falls back to comparing the dumped buffers as a whole.
|
|
25
31
|
*/
|
|
26
32
|
export declare function readLiteralBuffers(file: string): Promise<LiteralBuffers | null>;
|
|
27
33
|
/**
|
|
28
34
|
* Decode `count` literal values starting at byte `offset`. Null when the
|
|
29
35
|
* offset or a run reaches outside the buffer or a tag type is unknown; the
|
|
30
|
-
* caller
|
|
36
|
+
* caller fails verification rather than treating two failures as equivalent. `layout` decides
|
|
37
|
+
* what type 6 means (see the file comment).
|
|
31
38
|
*/
|
|
32
|
-
export declare function decodeSerializedLiterals(buffer: Buffer, offset: number, count: number): LiteralValue[] | null;
|
|
39
|
+
export declare function decodeSerializedLiterals(buffer: Buffer, offset: number, count: number, layout?: LiteralBuffers['layout']): LiteralValue[] | null;
|
|
33
40
|
/**
|
|
34
41
|
* One literal as text, string ids resolved through the dump's string table
|
|
35
|
-
* (an unknown id
|
|
42
|
+
* (an unknown id fails closed). Doubles keep their exact bits in
|
|
36
43
|
* the text so -0 and 0, or two NaNs, never collide by accident.
|
|
37
44
|
*/
|
|
38
45
|
export declare function renderLiteral(value: LiteralValue, strings: Map<number, string>): string;
|
|
@@ -45,7 +52,13 @@ export declare class LiteralResolver {
|
|
|
45
52
|
private readonly strings;
|
|
46
53
|
constructor(buffers: LiteralBuffers, strings: Map<number, string>);
|
|
47
54
|
private decode;
|
|
55
|
+
get layout(): LiteralBuffers['layout'];
|
|
48
56
|
array(offset: number, count: number): string[] | null;
|
|
49
57
|
objectKeys(offset: number, count: number): string[] | null;
|
|
50
58
|
objectValues(offset: number, count: number): string[] | null;
|
|
59
|
+
/** Shape table entry (HBC v98); null out of range or in the split layout. */
|
|
60
|
+
shape(index: number): {
|
|
61
|
+
keyOffset: number;
|
|
62
|
+
count: number;
|
|
63
|
+
} | null;
|
|
51
64
|
}
|
|
@@ -22,7 +22,19 @@ exports.renderLiteral = renderLiteral;
|
|
|
22
22
|
* the next byte", bits 3..0 = low 4 bits of the run length (high 8 bits in
|
|
23
23
|
* the next byte when bit 7 is set). Values follow the tag, fixed width per
|
|
24
24
|
* type: none (null/true/false), 8-byte little-endian double, 4/2/1-byte
|
|
25
|
-
* string id, 4-byte little-endian int32.
|
|
25
|
+
* string id, 4-byte little-endian int32. HBC v98 reuses type 6 (the 1-byte
|
|
26
|
+
* string id before) for `undefined`, which takes no value bytes; string ids
|
|
27
|
+
* there are always 2 or 4 bytes wide.
|
|
28
|
+
*
|
|
29
|
+
* Two file layouts use that format:
|
|
30
|
+
* - HBC v87–96 (`split`): arrayBuffer, objKeyBuffer, objValueBuffer.
|
|
31
|
+
* `NewArrayWithBuffer dst, sizeHint, count, arrayOffset`;
|
|
32
|
+
* `NewObjectWithBuffer dst, sizeHint, count, keyOffset, valueOffset`.
|
|
33
|
+
* - HBC v98 (`shaped`): literalValueBuffer (array elements and object values
|
|
34
|
+
* alike), objKeyBuffer, objShapeTable (8-byte entries: keyOffset u32,
|
|
35
|
+
* numProps u32). `NewArrayWithBuffer dst, sizeHint, count, valueOffset`;
|
|
36
|
+
* `NewObjectWithBuffer dst, shapeIndex, valueOffset` and
|
|
37
|
+
* `NewObjectWithBufferAndParent dst, parent, shapeIndex, valueOffset`.
|
|
26
38
|
*/
|
|
27
39
|
const promises_1 = require("node:fs/promises");
|
|
28
40
|
const hbcTransform_1 = require("./hbcTransform");
|
|
@@ -38,13 +50,14 @@ var Tag;
|
|
|
38
50
|
Tag[Tag["Number"] = 48] = "Number";
|
|
39
51
|
Tag[Tag["LongString"] = 64] = "LongString";
|
|
40
52
|
Tag[Tag["ShortString"] = 80] = "ShortString";
|
|
41
|
-
|
|
53
|
+
/** HBC ≤96: 1-byte string id; HBC v98: `undefined` */
|
|
54
|
+
Tag[Tag["ByteStringOrUndefined"] = 96] = "ByteStringOrUndefined";
|
|
42
55
|
Tag[Tag["Integer"] = 112] = "Integer";
|
|
43
56
|
})(Tag || (Tag = {}));
|
|
57
|
+
const SHAPE_ENTRY_SIZE = 8;
|
|
44
58
|
/**
|
|
45
59
|
* Read only the literal buffers of an HBC file (header + three byte ranges,
|
|
46
|
-
* never the whole file). Null for a file whose layout is unknown
|
|
47
|
-
* HBC v98 (literalValueBuffer + objShapeTable, not decoded yet): the caller
|
|
60
|
+
* never the whole file). Null for a file whose layout is unknown: the caller
|
|
48
61
|
* then falls back to comparing the dumped buffers as a whole.
|
|
49
62
|
*/
|
|
50
63
|
async function readLiteralBuffers(file) {
|
|
@@ -60,32 +73,40 @@ async function readLiteralBuffers(file) {
|
|
|
60
73
|
const resolved = (0, hbcTransform_1.resolveHbcSections)(header, size);
|
|
61
74
|
if (!resolved)
|
|
62
75
|
return null;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return buf;
|
|
73
|
-
|
|
74
|
-
return
|
|
76
|
+
const readRanges = async (names) => {
|
|
77
|
+
const ranges = names.map((name) => resolved.sections.get(name));
|
|
78
|
+
if (ranges.some((r) => !r))
|
|
79
|
+
return null;
|
|
80
|
+
const bufs = await Promise.all(ranges.map(async (r) => {
|
|
81
|
+
const buf = Buffer.alloc(r.size);
|
|
82
|
+
if (r.size === 0)
|
|
83
|
+
return buf;
|
|
84
|
+
const { bytesRead } = await handle.read(buf, 0, r.size, r.start);
|
|
85
|
+
return bytesRead === r.size ? buf : null;
|
|
86
|
+
}));
|
|
87
|
+
return bufs.some((b) => !b) ? null : bufs;
|
|
75
88
|
};
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
const { version } = resolved;
|
|
90
|
+
if (resolved.sections.has('objShapeTable')) {
|
|
91
|
+
const bufs = await readRanges([
|
|
92
|
+
'literalValueBuffer',
|
|
93
|
+
'objKeyBuffer',
|
|
94
|
+
'objShapeTable',
|
|
95
|
+
]);
|
|
96
|
+
if (!bufs)
|
|
97
|
+
return null;
|
|
98
|
+
const [values, objectKeys, shapes] = bufs;
|
|
99
|
+
return { layout: 'shaped', version, values, objectKeys, shapes };
|
|
100
|
+
}
|
|
101
|
+
const bufs = await readRanges([
|
|
102
|
+
'arrayBuffer',
|
|
103
|
+
'objKeyBuffer',
|
|
104
|
+
'objValueBuffer',
|
|
80
105
|
]);
|
|
81
|
-
if (!
|
|
106
|
+
if (!bufs)
|
|
82
107
|
return null;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
array: a,
|
|
86
|
-
objectKeys: k,
|
|
87
|
-
objectValues: v,
|
|
88
|
-
};
|
|
108
|
+
const [array, objectKeys, objectValues] = bufs;
|
|
109
|
+
return { layout: 'split', version, array, objectKeys, objectValues };
|
|
89
110
|
}
|
|
90
111
|
finally {
|
|
91
112
|
await handle.close();
|
|
@@ -94,9 +115,16 @@ async function readLiteralBuffers(file) {
|
|
|
94
115
|
/**
|
|
95
116
|
* Decode `count` literal values starting at byte `offset`. Null when the
|
|
96
117
|
* offset or a run reaches outside the buffer or a tag type is unknown; the
|
|
97
|
-
* caller
|
|
118
|
+
* caller fails verification rather than treating two failures as equivalent. `layout` decides
|
|
119
|
+
* what type 6 means (see the file comment).
|
|
98
120
|
*/
|
|
99
|
-
function decodeSerializedLiterals(buffer, offset, count) {
|
|
121
|
+
function decodeSerializedLiterals(buffer, offset, count, layout = 'split') {
|
|
122
|
+
if (!Number.isSafeInteger(offset) ||
|
|
123
|
+
!Number.isSafeInteger(count) ||
|
|
124
|
+
offset < 0 ||
|
|
125
|
+
count < 0 ||
|
|
126
|
+
count > 1_000_000)
|
|
127
|
+
return null;
|
|
100
128
|
const values = [];
|
|
101
129
|
let pos = offset;
|
|
102
130
|
while (values.length < count) {
|
|
@@ -109,6 +137,8 @@ function decodeSerializedLiterals(buffer, offset, count) {
|
|
|
109
137
|
return null;
|
|
110
138
|
length = (length << 8) | buffer[pos++];
|
|
111
139
|
}
|
|
140
|
+
if (length === 0)
|
|
141
|
+
return null;
|
|
112
142
|
const type = tag & TAG_TYPE_MASK;
|
|
113
143
|
for (let i = 0; i < length && values.length < count; i++) {
|
|
114
144
|
switch (type) {
|
|
@@ -139,7 +169,11 @@ function decodeSerializedLiterals(buffer, offset, count) {
|
|
|
139
169
|
values.push({ kind: 'string', id: buffer.readUInt16LE(pos) });
|
|
140
170
|
pos += 2;
|
|
141
171
|
break;
|
|
142
|
-
case Tag.
|
|
172
|
+
case Tag.ByteStringOrUndefined:
|
|
173
|
+
if (layout === 'shaped') {
|
|
174
|
+
values.push({ kind: 'undefined' });
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
143
177
|
if (pos + 1 > buffer.length)
|
|
144
178
|
return null;
|
|
145
179
|
values.push({ kind: 'string', id: buffer[pos] });
|
|
@@ -160,7 +194,7 @@ function decodeSerializedLiterals(buffer, offset, count) {
|
|
|
160
194
|
}
|
|
161
195
|
/**
|
|
162
196
|
* One literal as text, string ids resolved through the dump's string table
|
|
163
|
-
* (an unknown id
|
|
197
|
+
* (an unknown id fails closed). Doubles keep their exact bits in
|
|
164
198
|
* the text so -0 and 0, or two NaNs, never collide by accident.
|
|
165
199
|
*/
|
|
166
200
|
function renderLiteral(value, strings) {
|
|
@@ -168,6 +202,7 @@ function renderLiteral(value, strings) {
|
|
|
168
202
|
case 'null':
|
|
169
203
|
case 'true':
|
|
170
204
|
case 'false':
|
|
205
|
+
case 'undefined':
|
|
171
206
|
return value.kind;
|
|
172
207
|
case 'int':
|
|
173
208
|
return `[int ${value.value}]`;
|
|
@@ -178,7 +213,9 @@ function renderLiteral(value, strings) {
|
|
|
178
213
|
}
|
|
179
214
|
case 'string': {
|
|
180
215
|
const text = strings.get(value.id);
|
|
181
|
-
|
|
216
|
+
if (text === undefined)
|
|
217
|
+
throw new Error(`unresolved string id ${value.id}`);
|
|
218
|
+
return `[String ${JSON.stringify(text)}]`;
|
|
182
219
|
}
|
|
183
220
|
}
|
|
184
221
|
}
|
|
@@ -194,17 +231,35 @@ class LiteralResolver {
|
|
|
194
231
|
this.strings = strings;
|
|
195
232
|
}
|
|
196
233
|
decode(buffer, offset, count) {
|
|
197
|
-
const values = decodeSerializedLiterals(buffer, offset, count);
|
|
234
|
+
const values = decodeSerializedLiterals(buffer, offset, count, this.buffers.layout);
|
|
198
235
|
return values ? values.map((v) => renderLiteral(v, this.strings)) : null;
|
|
199
236
|
}
|
|
237
|
+
get layout() {
|
|
238
|
+
return this.buffers.layout;
|
|
239
|
+
}
|
|
200
240
|
array(offset, count) {
|
|
201
|
-
|
|
241
|
+
const b = this.buffers;
|
|
242
|
+
return this.decode(b.layout === 'split' ? b.array : b.values, offset, count);
|
|
202
243
|
}
|
|
203
244
|
objectKeys(offset, count) {
|
|
204
245
|
return this.decode(this.buffers.objectKeys, offset, count);
|
|
205
246
|
}
|
|
206
247
|
objectValues(offset, count) {
|
|
207
|
-
|
|
248
|
+
const b = this.buffers;
|
|
249
|
+
return this.decode(b.layout === 'split' ? b.objectValues : b.values, offset, count);
|
|
250
|
+
}
|
|
251
|
+
/** Shape table entry (HBC v98); null out of range or in the split layout. */
|
|
252
|
+
shape(index) {
|
|
253
|
+
const b = this.buffers;
|
|
254
|
+
if (b.layout !== 'shaped' || !Number.isSafeInteger(index) || index < 0)
|
|
255
|
+
return null;
|
|
256
|
+
const at = index * SHAPE_ENTRY_SIZE;
|
|
257
|
+
if (at + SHAPE_ENTRY_SIZE > b.shapes.length)
|
|
258
|
+
return null;
|
|
259
|
+
return {
|
|
260
|
+
keyOffset: b.shapes.readUInt32LE(at),
|
|
261
|
+
count: b.shapes.readUInt32LE(at + 4),
|
|
262
|
+
};
|
|
208
263
|
}
|
|
209
264
|
}
|
|
210
265
|
exports.LiteralResolver = LiteralResolver;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lossless operand audit accompanying the human-readable Hermes comparison.
|
|
3
|
+
* Pretty disassembly truncates strings and BigInts, prints function names in
|
|
4
|
+
* place of IDs, and renders -0 as 0. Never use those spellings as identities.
|
|
5
|
+
*
|
|
6
|
+
* The raw dump supplies instruction/operand boundaries; referenced data and
|
|
7
|
+
* doubles come from the HBC itself. Bytecode layouts are intentionally bounded
|
|
8
|
+
* to the layouts already supported by hbcTransform. Unknown data fails closed.
|
|
9
|
+
*/
|
|
10
|
+
import { type LiteralBuffers } from './hermes-literals';
|
|
11
|
+
export declare class UnverifiableHermesBytecode extends Error {
|
|
12
|
+
}
|
|
13
|
+
interface FunctionData {
|
|
14
|
+
offset: number;
|
|
15
|
+
size: number;
|
|
16
|
+
metadata: string;
|
|
17
|
+
}
|
|
18
|
+
export interface HermesSemanticData {
|
|
19
|
+
bytes: Buffer;
|
|
20
|
+
version: number;
|
|
21
|
+
strings: Map<number, string>;
|
|
22
|
+
functions: FunctionData[];
|
|
23
|
+
bigints: Buffer[];
|
|
24
|
+
regexps: Buffer[];
|
|
25
|
+
metadata: string;
|
|
26
|
+
}
|
|
27
|
+
/** Read exact strings (including UTF-16 code units) and function identities. */
|
|
28
|
+
export declare function readHermesSemanticData(file: string): Promise<HermesSemanticData>;
|
|
29
|
+
/** Canonicalize one complete function; addresses become instruction ordinals. */
|
|
30
|
+
export declare function normalizeRawHermesFunction(lines: string[], data: HermesSemanticData, functionIndex: number, buffers: LiteralBuffers): string[];
|
|
31
|
+
export interface RawAuditResult {
|
|
32
|
+
status: 'equivalent' | 'different' | 'dump-failed';
|
|
33
|
+
detail?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Audit a pair of raw dumps while retaining one function per side plus HBC data.
|
|
37
|
+
* Cancellation/errors fail closed; both subprocesses are terminated and reaped.
|
|
38
|
+
*/
|
|
39
|
+
export declare function auditRawHermesBytecode(command: string, files: [string, string], data: [HermesSemanticData, HermesSemanticData], buffers: [LiteralBuffers, LiteralBuffers], signal: AbortSignal): Promise<RawAuditResult>;
|
|
40
|
+
export {};
|