react-native-update-cli 2.26.1 → 2.27.0
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/account-worker.d.ts +1 -0
- package/lib/account-worker.js +45 -0
- package/lib/account.d.ts +11 -0
- package/lib/account.js +100 -0
- package/lib/bin.js +4 -0
- package/lib/bundle-runner.js +13 -9
- package/lib/locales/en.d.ts +5 -0
- package/lib/locales/en.js +5 -0
- package/lib/locales/zh.d.ts +5 -0
- package/lib/locales/zh.js +5 -0
- package/lib/user.js +2 -0
- package/lib/utils/constants.js +8 -1
- package/lib/utils/hermes-base.d.ts +5 -2
- package/lib/utils/hermes-base.js +173 -47
- package/lib/utils/hermes-literals.d.ts +2 -2
- package/lib/utils/hermes-literals.js +14 -4
- 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
package/lib/utils/hermes-base.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Hermes `-base-bytecode` (delta optimizing mode) support.
|
|
3
|
+
//
|
|
4
|
+
// Hermes re-sorts its string table by identifier frequency on every compile, so
|
|
5
|
+
// any source change renumbers most string IDs and the bytecode diff explodes
|
|
6
|
+
// (see hermes-base-bytecode-方案.md). Compiling with the previous HBC of the
|
|
7
|
+
// same app as `-base-bytecode` keeps old IDs stable and shrinks patches 5-30×.
|
|
8
|
+
// This module resolves that base: gating by hermesc build, HBC version probe,
|
|
9
|
+
// server lookup, a sha256-named local cache, download + verification, and the
|
|
10
|
+
// optional disassembly equivalence check. Every failure degrades to the plain
|
|
11
|
+
// compile — nothing here may block a release.
|
|
2
12
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
13
|
if (k2 === undefined) k2 = k;
|
|
4
14
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -62,16 +72,7 @@ exports.truncateHermesBaseDetail = truncateHermesBaseDetail;
|
|
|
62
72
|
exports.normalizeDisassemblyLine = normalizeDisassemblyLine;
|
|
63
73
|
exports.compareHermesBytecode = compareHermesBytecode;
|
|
64
74
|
exports.verifyHermesBaseEquivalence = verifyHermesBaseEquivalence;
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
// Hermes re-sorts its string table by identifier frequency on every compile, so
|
|
68
|
-
// any source change renumbers most string IDs and the bytecode diff explodes
|
|
69
|
-
// (see hermes-base-bytecode-方案.md). Compiling with the previous HBC of the
|
|
70
|
-
// same app as `-base-bytecode` keeps old IDs stable and shrinks patches 5-30×.
|
|
71
|
-
// This module resolves that base: gating by hermesc build, HBC version probe,
|
|
72
|
-
// server lookup, a sha256-named local cache, download + verification, and the
|
|
73
|
-
// optional disassembly equivalence check. Every failure degrades to the plain
|
|
74
|
-
// compile — nothing here may block a release.
|
|
75
|
+
const node_string_decoder_1 = require("node:string_decoder");
|
|
75
76
|
const child_process_1 = require("child_process");
|
|
76
77
|
const crypto_1 = require("crypto");
|
|
77
78
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -82,6 +83,8 @@ const promises_1 = require("stream/promises");
|
|
|
82
83
|
const constants_1 = require("./constants");
|
|
83
84
|
const hbcTransform_1 = require("./hbcTransform");
|
|
84
85
|
const hermes_literals_1 = require("./hermes-literals");
|
|
86
|
+
const hermes_raw_1 = require("./hermes-raw");
|
|
87
|
+
const hermes_timeout_1 = require("./hermes-timeout");
|
|
85
88
|
const i18n_1 = require("./i18n");
|
|
86
89
|
const runtime_1 = require("./runtime");
|
|
87
90
|
const zip_entries_1 = require("./zip-entries");
|
|
@@ -276,7 +279,11 @@ function compileProbe(hermesCommand) {
|
|
|
276
279
|
const input = path_1.default.join(dir, 'probe.js');
|
|
277
280
|
const output = path_1.default.join(dir, 'probe.hbc');
|
|
278
281
|
fs_extra_1.default.writeFileSync(input, '');
|
|
279
|
-
const result = (0, child_process_1.spawnSync)(hermesCommand, ['-emit-binary', '-out', output, input, '-O', '-w'], {
|
|
282
|
+
const result = (0, child_process_1.spawnSync)(hermesCommand, ['-emit-binary', '-out', output, input, '-O', '-w'], {
|
|
283
|
+
stdio: 'ignore',
|
|
284
|
+
timeout: (0, hermes_timeout_1.hermesTimeout)(process.env.PUSHY_HERMES_PROBE_TIMEOUT_MS, 30_000),
|
|
285
|
+
killSignal: 'SIGKILL',
|
|
286
|
+
});
|
|
280
287
|
if (result.status !== 0 || !fs_extra_1.default.existsSync(output)) {
|
|
281
288
|
return null;
|
|
282
289
|
}
|
|
@@ -843,8 +850,7 @@ exports.LITERAL_SEPARATOR = '\u001f';
|
|
|
843
850
|
* those offsets, so two builds that lay their buffers out differently still
|
|
844
851
|
* compare by what each instruction builds. The shape index is dropped like an
|
|
845
852
|
* offset: it only locates the keys. Null when the operands do not fit the
|
|
846
|
-
* layout; an offset that cannot be decoded
|
|
847
|
-
* equals a decoded one).
|
|
853
|
+
* layout; an offset or reference that cannot be decoded fails closed.
|
|
848
854
|
*/
|
|
849
855
|
function renderBufferInstruction(opcode, operands, literals) {
|
|
850
856
|
const [sizeHint, count] = operands;
|
|
@@ -852,7 +858,9 @@ function renderBufferInstruction(opcode, operands, literals) {
|
|
|
852
858
|
if (operands.length !== 3)
|
|
853
859
|
return null;
|
|
854
860
|
const entries = literals.array(operands[2], count);
|
|
855
|
-
|
|
861
|
+
if (!entries)
|
|
862
|
+
throw new Error(`undecodable array literal at ${operands[2]}`);
|
|
863
|
+
return `size=${sizeHint} n=${count} [${entries.join(exports.LITERAL_SEPARATOR)}]`;
|
|
856
864
|
}
|
|
857
865
|
if (literals.layout === 'shaped') {
|
|
858
866
|
if (operands.length !== 2)
|
|
@@ -862,7 +870,7 @@ function renderBufferInstruction(opcode, operands, literals) {
|
|
|
862
870
|
const keys = shape && literals.objectKeys(shape.keyOffset, shape.count);
|
|
863
871
|
const values = shape && literals.objectValues(valueOffset, shape.count);
|
|
864
872
|
if (!shape || !keys || !values) {
|
|
865
|
-
|
|
873
|
+
throw new Error(`undecodable object literal at shape ${shapeIndex}/${valueOffset}`);
|
|
866
874
|
}
|
|
867
875
|
const pairs = keys.map((k, i) => `${k}: ${values[i]}`);
|
|
868
876
|
return `n=${shape.count} {${pairs.join(exports.LITERAL_SEPARATOR)}}`;
|
|
@@ -872,7 +880,7 @@ function renderBufferInstruction(opcode, operands, literals) {
|
|
|
872
880
|
const keys = literals.objectKeys(operands[2], count);
|
|
873
881
|
const values = literals.objectValues(operands[3], count);
|
|
874
882
|
if (!keys || !values) {
|
|
875
|
-
|
|
883
|
+
throw new Error(`undecodable object literal at ${operands[2]}/${operands[3]}`);
|
|
876
884
|
}
|
|
877
885
|
const pairs = keys.map((k, i) => `${k}: ${values[i]}`);
|
|
878
886
|
return `size=${sizeHint} n=${count} {${pairs.join(exports.LITERAL_SEPARATOR)}}`;
|
|
@@ -904,21 +912,26 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
904
912
|
const rendered = renderBufferInstruction(m[1].trim(), nums.map(Number), literals);
|
|
905
913
|
if (rendered)
|
|
906
914
|
return `${op} ${regs} ${rendered}`;
|
|
915
|
+
throw new Error(`unsupported literal operands: ${line.trim()}`);
|
|
907
916
|
}
|
|
908
917
|
// no binary buffers: only the size hint survives; the buffer content
|
|
909
|
-
// is compared as a whole
|
|
918
|
+
// is compared as a whole for diagnostics only (never accepted as equivalent)
|
|
910
919
|
return `${op} ${regs} sizes=${nums.slice(0, 1).join(',')}`;
|
|
911
920
|
}
|
|
912
921
|
}
|
|
913
922
|
if (opcode.charCodeAt(0) === 0x4a /* J */) {
|
|
914
923
|
m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
|
|
915
924
|
if (m)
|
|
916
|
-
return `${m[1]}
|
|
925
|
+
return `${m[1]} ${m[3]}${normalizeOperandSpacing(m[4])}`;
|
|
917
926
|
}
|
|
918
927
|
if (opcode.startsWith('DefineOwnById')) {
|
|
919
928
|
m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
|
|
920
|
-
if (m)
|
|
921
|
-
|
|
929
|
+
if (m) {
|
|
930
|
+
const text = strings.get(Number(m[2]));
|
|
931
|
+
if (text === undefined)
|
|
932
|
+
throw new Error(`unresolved string id ${m[2]}`);
|
|
933
|
+
line = `${m[1]}${JSON.stringify(text)}`;
|
|
934
|
+
}
|
|
922
935
|
}
|
|
923
936
|
// Operand-width variants of one instruction (GetByIdShort/GetById/GetByIdLong,
|
|
924
937
|
// LoadConstString/LoadConstStringLongIndex, ...) only differ by how wide a
|
|
@@ -928,12 +941,12 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
928
941
|
if (opEnd > indent &&
|
|
929
942
|
(opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
|
|
930
943
|
const folded = foldWidthSuffix(opcode);
|
|
931
|
-
line = `${line.slice(0, indent)}${folded}${line.slice(opEnd)
|
|
944
|
+
line = `${line.slice(0, indent)}${folded}${normalizeOperandSpacing(line.slice(opEnd))}`;
|
|
932
945
|
// Switch jump tables sit after the instructions; their relative offset (and
|
|
933
946
|
// the table header hermesc prints for them) moves with instruction widths.
|
|
934
947
|
// The two switch instructions carry that offset in different operands:
|
|
935
948
|
// StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
|
|
936
|
-
// UIntSwitchImm
|
|
949
|
+
// UIntSwitchImm (classic: SwitchImm) rX, <jtOffset>, <defaultLabel>, <min>, <max>
|
|
937
950
|
// Folding only the first shape let a shifted UIntSwitchImm offset read as a
|
|
938
951
|
// real difference and drop an otherwise good delta build.
|
|
939
952
|
if (folded === 'StringSwitchImm') {
|
|
@@ -941,8 +954,8 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
941
954
|
if (m)
|
|
942
955
|
line = `${m[1]}<jt>${m[2]}`;
|
|
943
956
|
}
|
|
944
|
-
else if (folded === 'UIntSwitchImm') {
|
|
945
|
-
m = /^(\s*UIntSwitchImm r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
|
|
957
|
+
else if (folded === 'UIntSwitchImm' || folded === 'SwitchImm') {
|
|
958
|
+
m = /^(\s*(?:UIntSwitchImm|SwitchImm) r\d+, )\d+(, L\d+, \d+, \d+)$/.exec(line);
|
|
946
959
|
if (m)
|
|
947
960
|
line = `${m[1]}<jt>${m[2]}`;
|
|
948
961
|
}
|
|
@@ -952,6 +965,46 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
952
965
|
}
|
|
953
966
|
return line;
|
|
954
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
* Collapse formatting outside quoted operands without altering literal code units.
|
|
970
|
+
* ASCII dump spacing takes the char-code fast path; uncommon Unicode characters
|
|
971
|
+
* retain the complete runtime `\s` semantics instead of a narrower space list.
|
|
972
|
+
*/
|
|
973
|
+
function normalizeOperandSpacing(text) {
|
|
974
|
+
let result = '';
|
|
975
|
+
let quoted = false;
|
|
976
|
+
let escaped = false;
|
|
977
|
+
let spacing = false;
|
|
978
|
+
for (let i = 0; i < text.length; i++) {
|
|
979
|
+
const char = text[i];
|
|
980
|
+
if (quoted) {
|
|
981
|
+
result += char;
|
|
982
|
+
if (escaped)
|
|
983
|
+
escaped = false;
|
|
984
|
+
else if (char === '\\')
|
|
985
|
+
escaped = true;
|
|
986
|
+
else if (char === '"')
|
|
987
|
+
quoted = false;
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
const code = text.charCodeAt(i);
|
|
991
|
+
const whitespace = code <= 0x7f
|
|
992
|
+
? isSpace(code) || (code >= 0x0a && code <= 0x0c)
|
|
993
|
+
: /\s/.test(char);
|
|
994
|
+
if (whitespace) {
|
|
995
|
+
if (!spacing)
|
|
996
|
+
result += ' ';
|
|
997
|
+
spacing = true;
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
result += char;
|
|
1001
|
+
spacing = false;
|
|
1002
|
+
if (char === '"')
|
|
1003
|
+
quoted = true;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return result;
|
|
1007
|
+
}
|
|
955
1008
|
function isSpace(code) {
|
|
956
1009
|
return code === 0x20 || code === 0x09 || code === 0x0d;
|
|
957
1010
|
}
|
|
@@ -969,9 +1022,10 @@ function foldWidthSuffix(opcode) {
|
|
|
969
1022
|
}
|
|
970
1023
|
/** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
|
|
971
1024
|
async function* streamLines(stream) {
|
|
1025
|
+
const decoder = new node_string_decoder_1.StringDecoder('utf8');
|
|
972
1026
|
let rest = '';
|
|
973
1027
|
for await (const chunk of stream) {
|
|
974
|
-
rest += typeof chunk === 'string' ? chunk :
|
|
1028
|
+
rest += typeof chunk === 'string' ? chunk : decoder.write(chunk);
|
|
975
1029
|
let index = rest.indexOf('\n');
|
|
976
1030
|
while (index >= 0) {
|
|
977
1031
|
yield rest.slice(0, index);
|
|
@@ -979,6 +1033,7 @@ async function* streamLines(stream) {
|
|
|
979
1033
|
index = rest.indexOf('\n');
|
|
980
1034
|
}
|
|
981
1035
|
}
|
|
1036
|
+
rest += decoder.end();
|
|
982
1037
|
if (rest)
|
|
983
1038
|
yield rest;
|
|
984
1039
|
}
|
|
@@ -993,7 +1048,7 @@ const DUMP_STDERR_KEEP = 4 * 1024;
|
|
|
993
1048
|
/** a diagnostic line is cut to this many characters */
|
|
994
1049
|
const DETAIL_LINE_MAX = 120;
|
|
995
1050
|
function isFunctionHeader(line) {
|
|
996
|
-
return
|
|
1051
|
+
return /^(?:Function|NCFunction|Constructor)</.test(line);
|
|
997
1052
|
}
|
|
998
1053
|
/**
|
|
999
1054
|
* Structured reader over one `hermesc -dump-bytecode -pretty-disassemble`
|
|
@@ -1004,6 +1059,7 @@ function isFunctionHeader(line) {
|
|
|
1004
1059
|
*/
|
|
1005
1060
|
class DumpReader {
|
|
1006
1061
|
proc;
|
|
1062
|
+
binaryStrings;
|
|
1007
1063
|
iterator;
|
|
1008
1064
|
strings = new Map();
|
|
1009
1065
|
/** literal buffers by section name, entries with string ids resolved */
|
|
@@ -1015,30 +1071,58 @@ class DumpReader {
|
|
|
1015
1071
|
finished = false;
|
|
1016
1072
|
/** set when the binary literal buffers of this side could be read */
|
|
1017
1073
|
literals;
|
|
1018
|
-
|
|
1074
|
+
dumpError;
|
|
1075
|
+
debugOutput;
|
|
1076
|
+
debugFinished = Promise.resolve();
|
|
1077
|
+
pass;
|
|
1078
|
+
constructor(proc, dumpTo, buffers, binaryStrings) {
|
|
1019
1079
|
this.proc = proc;
|
|
1080
|
+
this.binaryStrings = binaryStrings;
|
|
1020
1081
|
// the string table is filled while the preamble streams by, before the
|
|
1021
1082
|
// first instruction needs it
|
|
1083
|
+
if (binaryStrings) {
|
|
1084
|
+
for (const [id, value] of binaryStrings)
|
|
1085
|
+
this.strings.set(id, value);
|
|
1086
|
+
}
|
|
1022
1087
|
if (buffers)
|
|
1023
1088
|
this.literals = new hermes_literals_1.LiteralResolver(buffers, this.strings);
|
|
1024
|
-
const pass = new stream_1.PassThrough();
|
|
1089
|
+
const pass = (this.pass = new stream_1.PassThrough());
|
|
1025
1090
|
proc.stdout.pipe(pass);
|
|
1026
|
-
if (dumpTo)
|
|
1027
|
-
|
|
1091
|
+
if (dumpTo) {
|
|
1092
|
+
const output = (this.debugOutput = fs_extra_1.default.createWriteStream(dumpTo));
|
|
1093
|
+
this.debugFinished = new Promise((resolve) => {
|
|
1094
|
+
output.once('finish', resolve);
|
|
1095
|
+
output.once('error', (error) => {
|
|
1096
|
+
this.dumpError = error;
|
|
1097
|
+
proc.kill('SIGKILL');
|
|
1098
|
+
resolve();
|
|
1099
|
+
});
|
|
1100
|
+
});
|
|
1101
|
+
proc.stdout.pipe(output);
|
|
1102
|
+
}
|
|
1028
1103
|
this.iterator = streamLines(pass);
|
|
1029
1104
|
let stderr = '';
|
|
1030
1105
|
proc.stderr?.on('data', (chunk) => {
|
|
1031
1106
|
stderr = (stderr + chunk.toString()).slice(-DUMP_STDERR_KEEP);
|
|
1032
1107
|
});
|
|
1033
1108
|
this.exit = new Promise((resolve) => {
|
|
1109
|
+
let processError;
|
|
1034
1110
|
// a spawn failure (ENOENT) may leave stdout open and never 'close'
|
|
1035
1111
|
proc.on('error', (error) => {
|
|
1112
|
+
// destroy() need not emit end, so pipe() will not finish its sinks.
|
|
1113
|
+
// End the debug file here: finish() awaits it before finally/kill().
|
|
1114
|
+
proc.stdout?.unpipe();
|
|
1115
|
+
proc.stdout?.destroy();
|
|
1036
1116
|
pass.end();
|
|
1037
|
-
|
|
1117
|
+
this.debugOutput?.end();
|
|
1118
|
+
processError = error;
|
|
1119
|
+
if (!proc.pid)
|
|
1120
|
+
resolve({ code: null, signal: null, error, stderr });
|
|
1038
1121
|
});
|
|
1039
|
-
proc.on('close', (code, signal) => resolve({ code, signal, stderr }));
|
|
1122
|
+
proc.on('close', (code, signal) => resolve({ code, signal, error: processError, stderr }));
|
|
1040
1123
|
});
|
|
1041
1124
|
}
|
|
1125
|
+
/** Consume lookahead first, then the stream; null is reserved for EOF. */
|
|
1042
1126
|
async nextLine() {
|
|
1043
1127
|
if (this.pending !== null) {
|
|
1044
1128
|
const line = this.pending;
|
|
@@ -1073,10 +1157,12 @@ class DumpReader {
|
|
|
1073
1157
|
}
|
|
1074
1158
|
if (this.section === 'Global String Table') {
|
|
1075
1159
|
const m = STRING_TABLE_LINE.exec(line);
|
|
1076
|
-
if (m)
|
|
1160
|
+
if (m && !this.binaryStrings)
|
|
1077
1161
|
this.strings.set(Number(m[1]), m[2]);
|
|
1078
1162
|
}
|
|
1079
|
-
else if (this.
|
|
1163
|
+
else if (!this.literals &&
|
|
1164
|
+
this.section?.endsWith('Buffer') &&
|
|
1165
|
+
line.trim() !== '') {
|
|
1080
1166
|
const entry = line.trim();
|
|
1081
1167
|
const ref = BUFFER_STRING_ENTRY.exec(entry);
|
|
1082
1168
|
const text = ref ? this.strings.get(Number(ref[1])) : undefined;
|
|
@@ -1118,10 +1204,17 @@ class DumpReader {
|
|
|
1118
1204
|
/** drain whatever is left and report how the process ended */
|
|
1119
1205
|
async finish() {
|
|
1120
1206
|
while ((await this.nextLine()) !== null) { }
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1207
|
+
const exit = await this.exit;
|
|
1208
|
+
await this.debugFinished;
|
|
1209
|
+
return this.dumpError ? { ...exit, error: this.dumpError } : exit;
|
|
1210
|
+
}
|
|
1211
|
+
async kill() {
|
|
1212
|
+
this.proc.stdout?.unpipe();
|
|
1213
|
+
this.pass.destroy();
|
|
1214
|
+
this.proc.stdout?.destroy();
|
|
1215
|
+
this.proc.kill('SIGKILL');
|
|
1216
|
+
this.debugOutput?.end();
|
|
1217
|
+
await Promise.all([this.exit, this.debugFinished]);
|
|
1125
1218
|
}
|
|
1126
1219
|
}
|
|
1127
1220
|
function describeExit(exit) {
|
|
@@ -1190,8 +1283,8 @@ function compareFunctions(a, b) {
|
|
|
1190
1283
|
return null;
|
|
1191
1284
|
}
|
|
1192
1285
|
/**
|
|
1193
|
-
* Compare two HBC files by disassembly
|
|
1194
|
-
*
|
|
1286
|
+
* Compare two HBC files by pretty disassembly, then audit the raw operands
|
|
1287
|
+
* against full binary strings, literals, function identities and addresses. `-b` forces hermesc
|
|
1195
1288
|
* to treat inputs as bytecode whatever their extension. Both dumps are
|
|
1196
1289
|
* consumed as streams so the ~100 MB of text never touches the disk (unless
|
|
1197
1290
|
* `dumpTo` asks for it). A dump process that fails or ends early is reported
|
|
@@ -1200,19 +1293,34 @@ function compareFunctions(a, b) {
|
|
|
1200
1293
|
* turned into a normalization rule or a bug report.
|
|
1201
1294
|
*/
|
|
1202
1295
|
async function compareHermesBytecode(hermesCommand, withBase, plain, options = {}) {
|
|
1203
|
-
const
|
|
1296
|
+
const controller = new AbortController();
|
|
1297
|
+
const timeoutMs = (0, hermes_timeout_1.hermesTimeout)(options.timeoutMs ?? process.env.PUSHY_HERMES_VERIFY_TIMEOUT_MS, 120_000);
|
|
1298
|
+
const abort = () => controller.abort(options.signal?.reason);
|
|
1299
|
+
if (options.signal?.aborted)
|
|
1300
|
+
abort();
|
|
1301
|
+
else
|
|
1302
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
1303
|
+
const timer = setTimeout(() => controller.abort(new Error(`Hermes verification timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
1304
|
+
timer.unref();
|
|
1305
|
+
const spawnDump = (file) => (0, child_process_1.spawn)(hermesCommand, ['-b', '-dump-bytecode', '-pretty-disassemble', file], {
|
|
1306
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1307
|
+
signal: controller.signal,
|
|
1308
|
+
killSignal: 'SIGKILL',
|
|
1309
|
+
});
|
|
1204
1310
|
// The literal buffers are read from both files up front (header + three
|
|
1205
1311
|
// byte ranges). Only when both sides can be read do the instructions
|
|
1206
1312
|
// compare decoded literals; otherwise both fall back to the dumped buffers
|
|
1207
1313
|
// as a whole, so the two sides always normalize the same way.
|
|
1208
|
-
const [buffersA, buffersB] = await Promise.all([
|
|
1314
|
+
const [buffersA, buffersB, dataA, dataB] = await Promise.all([
|
|
1209
1315
|
(0, hermes_literals_1.readLiteralBuffers)(withBase).catch(() => null),
|
|
1210
1316
|
(0, hermes_literals_1.readLiteralBuffers)(plain).catch(() => null),
|
|
1317
|
+
(0, hermes_raw_1.readHermesSemanticData)(withBase).catch(() => null),
|
|
1318
|
+
(0, hermes_raw_1.readHermesSemanticData)(plain).catch(() => null),
|
|
1211
1319
|
]);
|
|
1212
1320
|
const binary = buffersA && buffersB && buffersA.version === buffersB.version;
|
|
1213
1321
|
const literals = binary ? 'instruction' : 'buffer';
|
|
1214
|
-
const a = new DumpReader(spawnDump(withBase), options.dumpTo?.withBase, binary ? buffersA : null);
|
|
1215
|
-
const b = new DumpReader(spawnDump(plain), options.dumpTo?.plain, binary ? buffersB : null);
|
|
1322
|
+
const a = new DumpReader(spawnDump(withBase), options.dumpTo?.withBase, binary ? buffersA : null, dataA?.strings);
|
|
1323
|
+
const b = new DumpReader(spawnDump(plain), options.dumpTo?.plain, binary ? buffersB : null, dataB?.strings);
|
|
1216
1324
|
let functions = 0;
|
|
1217
1325
|
const different = (detail) => ({
|
|
1218
1326
|
status: 'different',
|
|
@@ -1253,7 +1361,16 @@ async function compareHermesBytecode(hermesCommand, withBase, plain, options = {
|
|
|
1253
1361
|
literals,
|
|
1254
1362
|
};
|
|
1255
1363
|
}
|
|
1256
|
-
|
|
1364
|
+
if (!binary || !dataA || !dataB) {
|
|
1365
|
+
return {
|
|
1366
|
+
status: 'dump-failed',
|
|
1367
|
+
detail: 'unsupported or unreadable HBC layout; text-only comparison cannot verify equivalence',
|
|
1368
|
+
functions,
|
|
1369
|
+
literals,
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
const audit = await (0, hermes_raw_1.auditRawHermesBytecode)(hermesCommand, [withBase, plain], [dataA, dataB], [buffersA, buffersB], controller.signal);
|
|
1373
|
+
return { ...audit, functions, literals };
|
|
1257
1374
|
}
|
|
1258
1375
|
if (functions === 0 && !binary) {
|
|
1259
1376
|
// buffers precede the functions, so both are complete by now. This
|
|
@@ -1270,9 +1387,18 @@ async function compareHermesBytecode(hermesCommand, withBase, plain, options = {
|
|
|
1270
1387
|
functions++;
|
|
1271
1388
|
}
|
|
1272
1389
|
}
|
|
1390
|
+
catch (error) {
|
|
1391
|
+
return {
|
|
1392
|
+
status: 'dump-failed',
|
|
1393
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
1394
|
+
functions,
|
|
1395
|
+
literals,
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1273
1398
|
finally {
|
|
1274
|
-
|
|
1275
|
-
|
|
1399
|
+
clearTimeout(timer);
|
|
1400
|
+
options.signal?.removeEventListener('abort', abort);
|
|
1401
|
+
await Promise.all([a.kill(), b.kill()]);
|
|
1276
1402
|
}
|
|
1277
1403
|
}
|
|
1278
1404
|
/** Resolves true when equivalent; see compareHermesBytecode for the details. */
|
|
@@ -33,13 +33,13 @@ export declare function readLiteralBuffers(file: string): Promise<LiteralBuffers
|
|
|
33
33
|
/**
|
|
34
34
|
* Decode `count` literal values starting at byte `offset`. Null when the
|
|
35
35
|
* offset or a run reaches outside the buffer or a tag type is unknown; the
|
|
36
|
-
* caller
|
|
36
|
+
* caller fails verification rather than treating two failures as equivalent. `layout` decides
|
|
37
37
|
* what type 6 means (see the file comment).
|
|
38
38
|
*/
|
|
39
39
|
export declare function decodeSerializedLiterals(buffer: Buffer, offset: number, count: number, layout?: LiteralBuffers['layout']): LiteralValue[] | null;
|
|
40
40
|
/**
|
|
41
41
|
* One literal as text, string ids resolved through the dump's string table
|
|
42
|
-
* (an unknown id
|
|
42
|
+
* (an unknown id fails closed). Doubles keep their exact bits in
|
|
43
43
|
* the text so -0 and 0, or two NaNs, never collide by accident.
|
|
44
44
|
*/
|
|
45
45
|
export declare function renderLiteral(value: LiteralValue, strings: Map<number, string>): string;
|
|
@@ -115,10 +115,16 @@ async function readLiteralBuffers(file) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Decode `count` literal values starting at byte `offset`. Null when the
|
|
117
117
|
* offset or a run reaches outside the buffer or a tag type is unknown; the
|
|
118
|
-
* caller
|
|
118
|
+
* caller fails verification rather than treating two failures as equivalent. `layout` decides
|
|
119
119
|
* what type 6 means (see the file comment).
|
|
120
120
|
*/
|
|
121
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;
|
|
122
128
|
const values = [];
|
|
123
129
|
let pos = offset;
|
|
124
130
|
while (values.length < count) {
|
|
@@ -131,6 +137,8 @@ function decodeSerializedLiterals(buffer, offset, count, layout = 'split') {
|
|
|
131
137
|
return null;
|
|
132
138
|
length = (length << 8) | buffer[pos++];
|
|
133
139
|
}
|
|
140
|
+
if (length === 0)
|
|
141
|
+
return null;
|
|
134
142
|
const type = tag & TAG_TYPE_MASK;
|
|
135
143
|
for (let i = 0; i < length && values.length < count; i++) {
|
|
136
144
|
switch (type) {
|
|
@@ -186,7 +194,7 @@ function decodeSerializedLiterals(buffer, offset, count, layout = 'split') {
|
|
|
186
194
|
}
|
|
187
195
|
/**
|
|
188
196
|
* One literal as text, string ids resolved through the dump's string table
|
|
189
|
-
* (an unknown id
|
|
197
|
+
* (an unknown id fails closed). Doubles keep their exact bits in
|
|
190
198
|
* the text so -0 and 0, or two NaNs, never collide by accident.
|
|
191
199
|
*/
|
|
192
200
|
function renderLiteral(value, strings) {
|
|
@@ -205,7 +213,9 @@ function renderLiteral(value, strings) {
|
|
|
205
213
|
}
|
|
206
214
|
case 'string': {
|
|
207
215
|
const text = strings.get(value.id);
|
|
208
|
-
|
|
216
|
+
if (text === undefined)
|
|
217
|
+
throw new Error(`unresolved string id ${value.id}`);
|
|
218
|
+
return `[String ${JSON.stringify(text)}]`;
|
|
209
219
|
}
|
|
210
220
|
}
|
|
211
221
|
}
|
|
@@ -241,7 +251,7 @@ class LiteralResolver {
|
|
|
241
251
|
/** Shape table entry (HBC v98); null out of range or in the split layout. */
|
|
242
252
|
shape(index) {
|
|
243
253
|
const b = this.buffers;
|
|
244
|
-
if (b.layout !== 'shaped' || index < 0)
|
|
254
|
+
if (b.layout !== 'shaped' || !Number.isSafeInteger(index) || index < 0)
|
|
245
255
|
return null;
|
|
246
256
|
const at = index * SHAPE_ENTRY_SIZE;
|
|
247
257
|
if (at + SHAPE_ENTRY_SIZE > b.shapes.length)
|
|
@@ -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 {};
|