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
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ const publishResult = await provider.publish({
|
|
|
87
87
|
|
|
88
88
|
Hermes projects: `bundle` always runs hermesc with `-output-source-map`, so the debug info section is stripped from the bytecode (15–40% smaller, same as React Native's own release builds). The Hermes sourcemap stays in the intermediate directory (`.pushy/intermedia/<platform>/<bundle>.map`, never packed into the ppk) and is composed with the packager map — `--sourcemap` is on by default since 2.23 (`--no-sourcemap` opts out). When `bundle` publishes, that final map is uploaded and archived with the version (`sourceMapKey`), so `pushy symbolicate` can map crash stacks — including Hermes `address at` frames — back to source later. `pushy publish <ppk> --sourcemap <file.map>` archives a map for a ppk built elsewhere; publishing without a map prints a warning.
|
|
89
89
|
|
|
90
|
-
Hermes delta mode (`-base-bytecode`): by default (`--hermesBase auto`) `bundle` compiles against the previous HBC of the same app, which keeps Hermes string IDs stable and makes hot-update patches 5–30× smaller. The base comes from the server (`GET /app/:id/hermesBase`), verified by sha256 and kept in a local cache (`.pushy/cache/<sha256>`, 500 MB / 20 files, `PUSHY_CACHE_DIR` / `--cacheMaxMb` to tune, `pushy cache [clean]` to inspect or clear). `--hermesBase none` disables it; `--hermesBase <file.hbc|.ppk|.apk|.ipa>` uses a local artifact (for example the store build). `--verifyHermesBase` (default on) additionally compiles without the base (concurrently with the base compile) and
|
|
90
|
+
Hermes delta mode (`-base-bytecode`): by default (`--hermesBase auto`) `bundle` compiles against the previous HBC of the same app, which keeps Hermes string IDs stable and makes hot-update patches 5–30× smaller. The base comes from the server (`GET /app/:id/hermesBase`), verified by sha256 and kept in a local cache (`.pushy/cache/<sha256>`, 500 MB / 20 files, `PUSHY_CACHE_DIR` / `--cacheMaxMb` to tune, `pushy cache [clean]` to inspect or clear). `--hermesBase none` disables it; `--hermesBase <file.hbc|.ppk|.apk|.ipa>` uses a local artifact (for example the store build). `--verifyHermesBase` (default on) additionally compiles without the base (concurrently with the base compile) and checks both artifacts in two passes: readable disassembly followed by raw operands resolved against complete binary strings, constants, function references and control-flow targets. Quoted whitespace and branch destinations are preserved; unsupported or unreadable layouts fail closed. On a mismatch, verification failure or compiler timeout the CLI falls back to the plain compile; failures of the plain compiler or the final sourcemap still fail the build. The raw pass adds verification time and holds both HBC files in memory, but does not add another compile. The log names the first difference (function, line, both sides) or, separately, a dump that could not be read; set `PUSHY_HERMES_BASE_DEBUG=1` to keep both disassemblies (`hermes-base-dump-base.txt` / `hermes-base-dump-plain.txt` next to the intermediate directory) for a bug report. Probe, verification and compile/sourcemap process deadlines default to 30/120/300 seconds respectively, configurable in milliseconds via `PUSHY_HERMES_PROBE_TIMEOUT_MS`, `PUSHY_HERMES_VERIFY_TIMEOUT_MS` and `PUSHY_HERMES_COMPILE_TIMEOUT_MS`. What the check covers, what it does not yet, and how to triage a rejection: [docs/hermes-base-verification.md](docs/hermes-base-verification.md). The result is reported at publish (`hermesBaseOutcome`: `used` / `rejected` / `dump-failed` / `none`, plus the first difference) so the server can watch the rejection rate across apps. `HERMESC=<path> bun run fuzz:hermes-base --rounds 300` compiles random programs against random bases and reports any build the check would wrongly reject (differential fuzzing of the normalization rules). Only hermesc builds that include the upstream delta-mode fix are used (classic `react-native/sdks/hermesc`, or `hermes-compiler` ≥ 250829098). If a base compile fails, the full hermesc output is written to `hermes-base-error.log` next to the intermediate directory. `--resetCache false` skips Metro's `--reset-cache` and reuses its transform cache, which makes repeated bundles much faster.
|
|
91
91
|
|
|
92
92
|
### Version
|
|
93
93
|
|
package/README.zh-CN.md
CHANGED
|
@@ -78,7 +78,7 @@ const publishResult = await provider.publish({
|
|
|
78
78
|
|
|
79
79
|
Hermes 工程:`bundle` 调用 hermesc 时始终带 `-output-source-map`,因此字节码不含 debug info 段(小 15%~40%,与 React Native 自身 release 构建一致)。Hermes sourcemap 保留在中间目录(`.pushy/intermedia/<platform>/<bundle>.map`,不会打进 ppk),并与 packager map 合成——自 2.23 起 `--sourcemap` 默认开启(`--no-sourcemap` 关闭)。`bundle` 发布时会把这份最终 map 上传并随版本归档(`sourceMapKey`),之后用 `pushy symbolicate` 即可把崩溃堆栈(含 Hermes 的 `address at` 帧)还原到源码。别处打好的 ppk 可用 `pushy publish <ppk> --sourcemap <file.map>` 归档;不带 map 发布会打印警告。
|
|
80
80
|
|
|
81
|
-
Hermes delta 模式(`-base-bytecode`):默认 `--hermesBase auto`,`bundle` 会以同一应用上一版的 HBC 为 base 编译,让 Hermes 字符串 ID 跨版本稳定,热更 patch 可缩小 5~30 倍。base 由服务端(`GET /app/:id/hermesBase`)给出、按 sha256 校验并存入本地缓存(`.pushy/cache/<sha256>`,默认 500 MB / 20 个,可用 `PUSHY_CACHE_DIR` / `--cacheMaxMb` 调整,`pushy cache [clean]` 查看或清空)。`--hermesBase none` 关闭;`--hermesBase <file.hbc|.ppk|.apk|.ipa>` 指定本地文件(比如商店包)作 base。`--verifyHermesBase
|
|
81
|
+
Hermes delta 模式(`-base-bytecode`):默认 `--hermesBase auto`,`bundle` 会以同一应用上一版的 HBC 为 base 编译,让 Hermes 字符串 ID 跨版本稳定,热更 patch 可缩小 5~30 倍。base 由服务端(`GET /app/:id/hermesBase`)给出、按 sha256 校验并存入本地缓存(`.pushy/cache/<sha256>`,默认 500 MB / 20 个,可用 `PUSHY_CACHE_DIR` / `--cacheMaxMb` 调整,`pushy cache [clean]` 查看或清空)。`--hermesBase none` 关闭;`--hermesBase <file.hbc|.ppk|.apk|.ipa>` 指定本地文件(比如商店包)作 base。`--verifyHermesBase`(默认开)会并行再做一次普通编译并进行两遍校验:先比较易读反汇编,再将 raw 操作数与二进制中的完整字符串、常量、函数引用和控制流目标核对。字符串内部空白和分支目的地不会被抹掉;不支持或无法解析的布局不能判为等价。发现差异、无法完成校验或 base 编译超时会回退到普通编译;真正的 plain 编译或最终 sourcemap 失败仍会使构建失败。raw 核对增加验证时间并在内存中持有两份 HBC,但不增加编译次数。日志会给出第一处差异(函数、行、两侧内容),dump 读取失败会单独说明;设置 `PUSHY_HERMES_BASE_DEBUG=1` 可把两份反汇编保留在中间目录旁(`hermes-base-dump-base.txt` / `hermes-base-dump-plain.txt`)用于提 issue。版本探测、完整验证、单个编译/sourcemap 子进程的期限默认分别为 30/120/300 秒,可用 `PUSHY_HERMES_PROBE_TIMEOUT_MS`、`PUSHY_HERMES_VERIFY_TIMEOUT_MS`、`PUSHY_HERMES_COMPILE_TIMEOUT_MS`(毫秒)调整。校验覆盖什么、还缺什么、如何排查一次拒绝:见 [docs/hermes-base-verification.md](docs/hermes-base-verification.md)。校验结果会随发布上报(`hermesBaseOutcome`:`used` / `rejected` / `dump-failed` / `none`,附第一处差异),服务端可据此观察全体应用的拒绝率。`HERMESC=<path> bun run fuzz:hermes-base --rounds 300` 会用随机程序配随机 base 编译并报告校验误杀的构建(对归一化规则做差分模糊测试)。只有包含上游 delta 模式修复的 hermesc 才会启用(经典 `react-native/sdks/hermesc`,或 `hermes-compiler` ≥ 250829098)。base 编译失败时,完整的 hermesc 输出会写到中间目录旁边的 `hermes-base-error.log`。`--resetCache false` 可跳过 Metro 的 `--reset-cache`,复用其转换缓存,重复打包会快很多。
|
|
82
82
|
|
|
83
83
|
### Version
|
|
84
84
|
|
package/lib/bundle-runner.js
CHANGED
|
@@ -63,6 +63,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
63
63
|
const api_1 = require("./api");
|
|
64
64
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
65
65
|
const hermes_base_1 = require("./utils/hermes-base");
|
|
66
|
+
const hermes_timeout_1 = require("./utils/hermes-timeout");
|
|
66
67
|
const i18n_1 = require("./utils/i18n");
|
|
67
68
|
const runtime_1 = require("./utils/runtime");
|
|
68
69
|
const g2js = require('gradle-to-js/lib/parser');
|
|
@@ -678,6 +679,8 @@ function runProcess(command, args, captureStderr) {
|
|
|
678
679
|
return new Promise((resolve) => {
|
|
679
680
|
const child = (0, child_process_1.spawn)(command, args, {
|
|
680
681
|
stdio: ['ignore', 'ignore', captureStderr ? 'pipe' : 'ignore'],
|
|
682
|
+
timeout: (0, hermes_timeout_1.hermesTimeout)(process.env.PUSHY_HERMES_COMPILE_TIMEOUT_MS, 300_000),
|
|
683
|
+
killSignal: 'SIGKILL',
|
|
681
684
|
});
|
|
682
685
|
// hermesc echoes whole (minified) source lines per diagnostic: keep the
|
|
683
686
|
// head and the tail, never an unbounded transcript
|
|
@@ -723,7 +726,7 @@ const HERMES_BASE_WAIT_MS = 60_000;
|
|
|
723
726
|
* bounded time for it — a stalled download must never hold up the compile.
|
|
724
727
|
*/
|
|
725
728
|
async function awaitPendingBase(pending) {
|
|
726
|
-
const waitMs =
|
|
729
|
+
const waitMs = (0, hermes_timeout_1.hermesTimeout)(process.env.PUSHY_HERMES_BASE_WAIT_MS, HERMES_BASE_WAIT_MS);
|
|
727
730
|
let timer;
|
|
728
731
|
const gaveUp = new Promise((resolve) => {
|
|
729
732
|
timer = setTimeout(() => resolve({
|
|
@@ -842,7 +845,10 @@ async function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput
|
|
|
842
845
|
const fullStderr = attempt.error
|
|
843
846
|
? String(attempt.error.message ?? attempt.error)
|
|
844
847
|
: attempt.stderr;
|
|
845
|
-
const reason = summarizeHermescStderr(fullStderr)
|
|
848
|
+
const reason = summarizeHermescStderr(fullStderr) ||
|
|
849
|
+
(attempt.signal
|
|
850
|
+
? `signal ${attempt.signal} (compiler deadline or external termination)`
|
|
851
|
+
: '');
|
|
846
852
|
console.warn((0, i18n_1.t)('hermesBaseCompileFailed', {
|
|
847
853
|
reason: reason || `exit ${attempt.status}`,
|
|
848
854
|
}));
|
|
@@ -862,7 +868,7 @@ async function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput
|
|
|
862
868
|
// compose the base output's map while the disassembly compare runs; it is
|
|
863
869
|
// redone from the plain map in the rare case the base is rejected
|
|
864
870
|
const speculativeCompose = usedBase && sourcemapOutput
|
|
865
|
-
? composeSourceMaps(packagerMap, hermesMap, sourcemapOutput)
|
|
871
|
+
? composeSourceMaps(packagerMap, hermesMap, sourcemapOutput).then((value) => ({ ok: true, value }), (error) => ({ ok: false, error }))
|
|
866
872
|
: null;
|
|
867
873
|
if (usedBase && wantPlain) {
|
|
868
874
|
if (!plainOk) {
|
|
@@ -921,12 +927,10 @@ async function compileHermesByteCode({ bundleName, outputFolder, sourcemapOutput
|
|
|
921
927
|
}
|
|
922
928
|
}
|
|
923
929
|
if (speculativeCompose) {
|
|
924
|
-
const done = await speculativeCompose
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
});
|
|
929
|
-
composed = usedBase && done;
|
|
930
|
+
const done = await speculativeCompose;
|
|
931
|
+
if (!done.ok && usedBase)
|
|
932
|
+
throw done.error;
|
|
933
|
+
composed = usedBase && done.ok && done.value;
|
|
930
934
|
}
|
|
931
935
|
if (!usedBase) {
|
|
932
936
|
if (plainOk) {
|
package/lib/utils/constants.js
CHANGED
|
@@ -23,4 +23,11 @@ exports.pricingPageUrl = exports.IS_CRESC
|
|
|
23
23
|
: 'https://pushy.reactnative.cn/pricing.html';
|
|
24
24
|
exports.defaultEndpoints = exports.IS_CRESC
|
|
25
25
|
? ['https://api.cresc.dev', 'https://api.cresc.app']
|
|
26
|
-
: [
|
|
26
|
+
: [
|
|
27
|
+
'https://1.rnupdate.online/api',
|
|
28
|
+
'https://2.rnupdate.online/api',
|
|
29
|
+
'https://3.rnupdate.online/api',
|
|
30
|
+
'https://4.rnupdate.online/api',
|
|
31
|
+
'https://update.reactnative.cn/api',
|
|
32
|
+
'https://update.react-native.cn/api',
|
|
33
|
+
];
|
|
@@ -194,8 +194,8 @@ export interface HermesEquivalenceResult {
|
|
|
194
194
|
functions: number;
|
|
195
195
|
/**
|
|
196
196
|
* `instruction`: literals decoded from the binary buffers at each
|
|
197
|
-
* New*WithBuffer instruction (HBC v87–96); `buffer`: the dumped
|
|
198
|
-
* compared as a whole (unknown layout
|
|
197
|
+
* New*WithBuffer instruction (HBC v87–96 and v98); `buffer`: the dumped
|
|
198
|
+
* buffers compared as a whole (unknown layout)
|
|
199
199
|
*/
|
|
200
200
|
literals?: 'instruction' | 'buffer';
|
|
201
201
|
}
|
|
@@ -205,10 +205,13 @@ export interface HermesEquivalenceOptions {
|
|
|
205
205
|
withBase: string;
|
|
206
206
|
plain: string;
|
|
207
207
|
};
|
|
208
|
+
/** Total deadline for both verification passes. */
|
|
209
|
+
timeoutMs?: number;
|
|
210
|
+
signal?: AbortSignal;
|
|
208
211
|
}
|
|
209
212
|
/**
|
|
210
|
-
* Compare two HBC files by disassembly
|
|
211
|
-
*
|
|
213
|
+
* Compare two HBC files by pretty disassembly, then audit the raw operands
|
|
214
|
+
* against full binary strings, literals, function identities and addresses. `-b` forces hermesc
|
|
212
215
|
* to treat inputs as bytecode whatever their extension. Both dumps are
|
|
213
216
|
* consumed as streams so the ~100 MB of text never touches the disk (unless
|
|
214
217
|
* `dumpTo` asks for it). A dump process that fails or ends early is reported
|
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
|
}
|
|
@@ -837,26 +844,43 @@ const STRING_TABLE_LINE = /^\s*[is](\d+)\[[^\]]*\](?: #[0-9A-F]+)?: (.*)$/;
|
|
|
837
844
|
exports.LITERAL_SEPARATOR = '\u001f';
|
|
838
845
|
/**
|
|
839
846
|
* `NewArrayWithBuffer rX, sizeHint, count, offset` and
|
|
840
|
-
* `NewObjectWithBuffer rX, sizeHint, count, keyOffset, valueOffset`
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
847
|
+
* `NewObjectWithBuffer rX, sizeHint, count, keyOffset, valueOffset` (HBC
|
|
848
|
+
* v87–96) or `NewObjectWithBuffer[AndParent] rX, [rP,] shapeIndex,
|
|
849
|
+
* valueOffset` (v98) with the literals decoded from the binary buffers at
|
|
850
|
+
* those offsets, so two builds that lay their buffers out differently still
|
|
851
|
+
* compare by what each instruction builds. The shape index is dropped like an
|
|
852
|
+
* offset: it only locates the keys. Null when the operands do not fit the
|
|
853
|
+
* layout; an offset or reference that cannot be decoded fails closed.
|
|
845
854
|
*/
|
|
846
855
|
function renderBufferInstruction(opcode, operands, literals) {
|
|
847
856
|
const [sizeHint, count] = operands;
|
|
848
857
|
if (opcode.startsWith('NewArray')) {
|
|
849
|
-
if (operands.length
|
|
858
|
+
if (operands.length !== 3)
|
|
850
859
|
return null;
|
|
851
860
|
const entries = literals.array(operands[2], count);
|
|
852
|
-
|
|
861
|
+
if (!entries)
|
|
862
|
+
throw new Error(`undecodable array literal at ${operands[2]}`);
|
|
863
|
+
return `size=${sizeHint} n=${count} [${entries.join(exports.LITERAL_SEPARATOR)}]`;
|
|
864
|
+
}
|
|
865
|
+
if (literals.layout === 'shaped') {
|
|
866
|
+
if (operands.length !== 2)
|
|
867
|
+
return null;
|
|
868
|
+
const [shapeIndex, valueOffset] = operands;
|
|
869
|
+
const shape = literals.shape(shapeIndex);
|
|
870
|
+
const keys = shape && literals.objectKeys(shape.keyOffset, shape.count);
|
|
871
|
+
const values = shape && literals.objectValues(valueOffset, shape.count);
|
|
872
|
+
if (!shape || !keys || !values) {
|
|
873
|
+
throw new Error(`undecodable object literal at shape ${shapeIndex}/${valueOffset}`);
|
|
874
|
+
}
|
|
875
|
+
const pairs = keys.map((k, i) => `${k}: ${values[i]}`);
|
|
876
|
+
return `n=${shape.count} {${pairs.join(exports.LITERAL_SEPARATOR)}}`;
|
|
853
877
|
}
|
|
854
|
-
if (operands.length
|
|
878
|
+
if (operands.length !== 4)
|
|
855
879
|
return null;
|
|
856
880
|
const keys = literals.objectKeys(operands[2], count);
|
|
857
881
|
const values = literals.objectValues(operands[3], count);
|
|
858
882
|
if (!keys || !values) {
|
|
859
|
-
|
|
883
|
+
throw new Error(`undecodable object literal at ${operands[2]}/${operands[3]}`);
|
|
860
884
|
}
|
|
861
885
|
const pairs = keys.map((k, i) => `${k}: ${values[i]}`);
|
|
862
886
|
return `size=${sizeHint} n=${count} {${pairs.join(exports.LITERAL_SEPARATOR)}}`;
|
|
@@ -876,29 +900,38 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
876
900
|
}
|
|
877
901
|
let m;
|
|
878
902
|
if (opcode.startsWith('New') && opcode.includes('WithBuffer')) {
|
|
903
|
+
// v98's AndParent form takes the parent object in a second register,
|
|
904
|
+
// which is compared as is (it is not a buffer operand)
|
|
879
905
|
m =
|
|
880
|
-
/^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(
|
|
906
|
+
/^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(AndParent)?\s+(r\d+)(?:, (r\d+))?(.*)$/.exec(line);
|
|
881
907
|
if (m) {
|
|
882
|
-
const
|
|
908
|
+
const op = `${m[1]}${m[2] ?? ''}`;
|
|
909
|
+
const regs = m[4] ? `${m[3]} ${m[4]}` : m[3];
|
|
910
|
+
const nums = m[5].match(/\d+/g) ?? [];
|
|
883
911
|
if (literals) {
|
|
884
912
|
const rendered = renderBufferInstruction(m[1].trim(), nums.map(Number), literals);
|
|
885
913
|
if (rendered)
|
|
886
|
-
return `${
|
|
914
|
+
return `${op} ${regs} ${rendered}`;
|
|
915
|
+
throw new Error(`unsupported literal operands: ${line.trim()}`);
|
|
887
916
|
}
|
|
888
917
|
// no binary buffers: only the size hint survives; the buffer content
|
|
889
|
-
// is compared as a whole
|
|
890
|
-
return `${
|
|
918
|
+
// is compared as a whole for diagnostics only (never accepted as equivalent)
|
|
919
|
+
return `${op} ${regs} sizes=${nums.slice(0, 1).join(',')}`;
|
|
891
920
|
}
|
|
892
921
|
}
|
|
893
922
|
if (opcode.charCodeAt(0) === 0x4a /* J */) {
|
|
894
923
|
m = /^(\s*J[A-Za-z]+?)(Long)?\s+(L\d+|\d+)(.*)$/.exec(line);
|
|
895
924
|
if (m)
|
|
896
|
-
return `${m[1]}
|
|
925
|
+
return `${m[1]} ${m[3]}${normalizeOperandSpacing(m[4])}`;
|
|
897
926
|
}
|
|
898
927
|
if (opcode.startsWith('DefineOwnById')) {
|
|
899
928
|
m = /^(\s*DefineOwnById\w*\s+r\d+, r\d+, \d+, )(\d+)$/.exec(line);
|
|
900
|
-
if (m)
|
|
901
|
-
|
|
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
|
+
}
|
|
902
935
|
}
|
|
903
936
|
// Operand-width variants of one instruction (GetByIdShort/GetById/GetByIdLong,
|
|
904
937
|
// LoadConstString/LoadConstStringLongIndex, ...) only differ by how wide a
|
|
@@ -908,12 +941,12 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
908
941
|
if (opEnd > indent &&
|
|
909
942
|
(opEnd === line.length || isSpace(line.charCodeAt(opEnd)))) {
|
|
910
943
|
const folded = foldWidthSuffix(opcode);
|
|
911
|
-
line = `${line.slice(0, indent)}${folded}${line.slice(opEnd)
|
|
944
|
+
line = `${line.slice(0, indent)}${folded}${normalizeOperandSpacing(line.slice(opEnd))}`;
|
|
912
945
|
// Switch jump tables sit after the instructions; their relative offset (and
|
|
913
946
|
// the table header hermesc prints for them) moves with instruction widths.
|
|
914
947
|
// The two switch instructions carry that offset in different operands:
|
|
915
948
|
// StringSwitchImm rX, <id>, <jtOffset>, <defaultLabel>, <count>
|
|
916
|
-
// UIntSwitchImm
|
|
949
|
+
// UIntSwitchImm (classic: SwitchImm) rX, <jtOffset>, <defaultLabel>, <min>, <max>
|
|
917
950
|
// Folding only the first shape let a shifted UIntSwitchImm offset read as a
|
|
918
951
|
// real difference and drop an otherwise good delta build.
|
|
919
952
|
if (folded === 'StringSwitchImm') {
|
|
@@ -921,8 +954,8 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
921
954
|
if (m)
|
|
922
955
|
line = `${m[1]}<jt>${m[2]}`;
|
|
923
956
|
}
|
|
924
|
-
else if (folded === 'UIntSwitchImm') {
|
|
925
|
-
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);
|
|
926
959
|
if (m)
|
|
927
960
|
line = `${m[1]}<jt>${m[2]}`;
|
|
928
961
|
}
|
|
@@ -932,6 +965,46 @@ function normalizeDisassemblyLine(line, strings, literals) {
|
|
|
932
965
|
}
|
|
933
966
|
return line;
|
|
934
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
|
+
}
|
|
935
1008
|
function isSpace(code) {
|
|
936
1009
|
return code === 0x20 || code === 0x09 || code === 0x0d;
|
|
937
1010
|
}
|
|
@@ -949,9 +1022,10 @@ function foldWidthSuffix(opcode) {
|
|
|
949
1022
|
}
|
|
950
1023
|
/** Split a readable stream into lines without readline (Bun's readline async iterator misbehaves when pulled manually). */
|
|
951
1024
|
async function* streamLines(stream) {
|
|
1025
|
+
const decoder = new node_string_decoder_1.StringDecoder('utf8');
|
|
952
1026
|
let rest = '';
|
|
953
1027
|
for await (const chunk of stream) {
|
|
954
|
-
rest += typeof chunk === 'string' ? chunk :
|
|
1028
|
+
rest += typeof chunk === 'string' ? chunk : decoder.write(chunk);
|
|
955
1029
|
let index = rest.indexOf('\n');
|
|
956
1030
|
while (index >= 0) {
|
|
957
1031
|
yield rest.slice(0, index);
|
|
@@ -959,6 +1033,7 @@ async function* streamLines(stream) {
|
|
|
959
1033
|
index = rest.indexOf('\n');
|
|
960
1034
|
}
|
|
961
1035
|
}
|
|
1036
|
+
rest += decoder.end();
|
|
962
1037
|
if (rest)
|
|
963
1038
|
yield rest;
|
|
964
1039
|
}
|
|
@@ -973,7 +1048,7 @@ const DUMP_STDERR_KEEP = 4 * 1024;
|
|
|
973
1048
|
/** a diagnostic line is cut to this many characters */
|
|
974
1049
|
const DETAIL_LINE_MAX = 120;
|
|
975
1050
|
function isFunctionHeader(line) {
|
|
976
|
-
return
|
|
1051
|
+
return /^(?:Function|NCFunction|Constructor)</.test(line);
|
|
977
1052
|
}
|
|
978
1053
|
/**
|
|
979
1054
|
* Structured reader over one `hermesc -dump-bytecode -pretty-disassemble`
|
|
@@ -984,6 +1059,7 @@ function isFunctionHeader(line) {
|
|
|
984
1059
|
*/
|
|
985
1060
|
class DumpReader {
|
|
986
1061
|
proc;
|
|
1062
|
+
binaryStrings;
|
|
987
1063
|
iterator;
|
|
988
1064
|
strings = new Map();
|
|
989
1065
|
/** literal buffers by section name, entries with string ids resolved */
|
|
@@ -995,30 +1071,58 @@ class DumpReader {
|
|
|
995
1071
|
finished = false;
|
|
996
1072
|
/** set when the binary literal buffers of this side could be read */
|
|
997
1073
|
literals;
|
|
998
|
-
|
|
1074
|
+
dumpError;
|
|
1075
|
+
debugOutput;
|
|
1076
|
+
debugFinished = Promise.resolve();
|
|
1077
|
+
pass;
|
|
1078
|
+
constructor(proc, dumpTo, buffers, binaryStrings) {
|
|
999
1079
|
this.proc = proc;
|
|
1080
|
+
this.binaryStrings = binaryStrings;
|
|
1000
1081
|
// the string table is filled while the preamble streams by, before the
|
|
1001
1082
|
// first instruction needs it
|
|
1083
|
+
if (binaryStrings) {
|
|
1084
|
+
for (const [id, value] of binaryStrings)
|
|
1085
|
+
this.strings.set(id, value);
|
|
1086
|
+
}
|
|
1002
1087
|
if (buffers)
|
|
1003
1088
|
this.literals = new hermes_literals_1.LiteralResolver(buffers, this.strings);
|
|
1004
|
-
const pass = new stream_1.PassThrough();
|
|
1089
|
+
const pass = (this.pass = new stream_1.PassThrough());
|
|
1005
1090
|
proc.stdout.pipe(pass);
|
|
1006
|
-
if (dumpTo)
|
|
1007
|
-
|
|
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
|
+
}
|
|
1008
1103
|
this.iterator = streamLines(pass);
|
|
1009
1104
|
let stderr = '';
|
|
1010
1105
|
proc.stderr?.on('data', (chunk) => {
|
|
1011
1106
|
stderr = (stderr + chunk.toString()).slice(-DUMP_STDERR_KEEP);
|
|
1012
1107
|
});
|
|
1013
1108
|
this.exit = new Promise((resolve) => {
|
|
1109
|
+
let processError;
|
|
1014
1110
|
// a spawn failure (ENOENT) may leave stdout open and never 'close'
|
|
1015
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();
|
|
1016
1116
|
pass.end();
|
|
1017
|
-
|
|
1117
|
+
this.debugOutput?.end();
|
|
1118
|
+
processError = error;
|
|
1119
|
+
if (!proc.pid)
|
|
1120
|
+
resolve({ code: null, signal: null, error, stderr });
|
|
1018
1121
|
});
|
|
1019
|
-
proc.on('close', (code, signal) => resolve({ code, signal, stderr }));
|
|
1122
|
+
proc.on('close', (code, signal) => resolve({ code, signal, error: processError, stderr }));
|
|
1020
1123
|
});
|
|
1021
1124
|
}
|
|
1125
|
+
/** Consume lookahead first, then the stream; null is reserved for EOF. */
|
|
1022
1126
|
async nextLine() {
|
|
1023
1127
|
if (this.pending !== null) {
|
|
1024
1128
|
const line = this.pending;
|
|
@@ -1053,10 +1157,12 @@ class DumpReader {
|
|
|
1053
1157
|
}
|
|
1054
1158
|
if (this.section === 'Global String Table') {
|
|
1055
1159
|
const m = STRING_TABLE_LINE.exec(line);
|
|
1056
|
-
if (m)
|
|
1160
|
+
if (m && !this.binaryStrings)
|
|
1057
1161
|
this.strings.set(Number(m[1]), m[2]);
|
|
1058
1162
|
}
|
|
1059
|
-
else if (this.
|
|
1163
|
+
else if (!this.literals &&
|
|
1164
|
+
this.section?.endsWith('Buffer') &&
|
|
1165
|
+
line.trim() !== '') {
|
|
1060
1166
|
const entry = line.trim();
|
|
1061
1167
|
const ref = BUFFER_STRING_ENTRY.exec(entry);
|
|
1062
1168
|
const text = ref ? this.strings.get(Number(ref[1])) : undefined;
|
|
@@ -1098,10 +1204,17 @@ class DumpReader {
|
|
|
1098
1204
|
/** drain whatever is left and report how the process ended */
|
|
1099
1205
|
async finish() {
|
|
1100
1206
|
while ((await this.nextLine()) !== null) { }
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
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]);
|
|
1105
1218
|
}
|
|
1106
1219
|
}
|
|
1107
1220
|
function describeExit(exit) {
|
|
@@ -1120,7 +1233,7 @@ function clip(line) {
|
|
|
1120
1233
|
* (the whole line would be clipped before the difference for long literals).
|
|
1121
1234
|
*/
|
|
1122
1235
|
function literalDifference(a, b) {
|
|
1123
|
-
const open = /^(\s*New\w+WithBuffer r\d+ size=\d+ n=\d+ [[{])/;
|
|
1236
|
+
const open = /^(\s*New\w+WithBuffer(?:AndParent)? r\d+(?: r\d+)?(?: size=\d+)? n=\d+ [[{])/;
|
|
1124
1237
|
const ma = open.exec(a);
|
|
1125
1238
|
const mb = open.exec(b);
|
|
1126
1239
|
if (!ma || !mb)
|
|
@@ -1170,8 +1283,8 @@ function compareFunctions(a, b) {
|
|
|
1170
1283
|
return null;
|
|
1171
1284
|
}
|
|
1172
1285
|
/**
|
|
1173
|
-
* Compare two HBC files by disassembly
|
|
1174
|
-
*
|
|
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
|
|
1175
1288
|
* to treat inputs as bytecode whatever their extension. Both dumps are
|
|
1176
1289
|
* consumed as streams so the ~100 MB of text never touches the disk (unless
|
|
1177
1290
|
* `dumpTo` asks for it). A dump process that fails or ends early is reported
|
|
@@ -1180,19 +1293,34 @@ function compareFunctions(a, b) {
|
|
|
1180
1293
|
* turned into a normalization rule or a bug report.
|
|
1181
1294
|
*/
|
|
1182
1295
|
async function compareHermesBytecode(hermesCommand, withBase, plain, options = {}) {
|
|
1183
|
-
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
|
+
});
|
|
1184
1310
|
// The literal buffers are read from both files up front (header + three
|
|
1185
1311
|
// byte ranges). Only when both sides can be read do the instructions
|
|
1186
1312
|
// compare decoded literals; otherwise both fall back to the dumped buffers
|
|
1187
1313
|
// as a whole, so the two sides always normalize the same way.
|
|
1188
|
-
const [buffersA, buffersB] = await Promise.all([
|
|
1314
|
+
const [buffersA, buffersB, dataA, dataB] = await Promise.all([
|
|
1189
1315
|
(0, hermes_literals_1.readLiteralBuffers)(withBase).catch(() => null),
|
|
1190
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),
|
|
1191
1319
|
]);
|
|
1192
1320
|
const binary = buffersA && buffersB && buffersA.version === buffersB.version;
|
|
1193
1321
|
const literals = binary ? 'instruction' : 'buffer';
|
|
1194
|
-
const a = new DumpReader(spawnDump(withBase), options.dumpTo?.withBase, binary ? buffersA : null);
|
|
1195
|
-
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);
|
|
1196
1324
|
let functions = 0;
|
|
1197
1325
|
const different = (detail) => ({
|
|
1198
1326
|
status: 'different',
|
|
@@ -1233,7 +1361,16 @@ async function compareHermesBytecode(hermesCommand, withBase, plain, options = {
|
|
|
1233
1361
|
literals,
|
|
1234
1362
|
};
|
|
1235
1363
|
}
|
|
1236
|
-
|
|
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 };
|
|
1237
1374
|
}
|
|
1238
1375
|
if (functions === 0 && !binary) {
|
|
1239
1376
|
// buffers precede the functions, so both are complete by now. This
|
|
@@ -1250,9 +1387,18 @@ async function compareHermesBytecode(hermesCommand, withBase, plain, options = {
|
|
|
1250
1387
|
functions++;
|
|
1251
1388
|
}
|
|
1252
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
|
+
}
|
|
1253
1398
|
finally {
|
|
1254
|
-
|
|
1255
|
-
|
|
1399
|
+
clearTimeout(timer);
|
|
1400
|
+
options.signal?.removeEventListener('abort', abort);
|
|
1401
|
+
await Promise.all([a.kill(), b.kill()]);
|
|
1256
1402
|
}
|
|
1257
1403
|
}
|
|
1258
1404
|
/** Resolves true when equivalent; see compareHermesBytecode for the details. */
|