mirror of
https://github.com/Momoko-Ayase/Senbei.git
synced 2026-11-24 02:52:47 +08:00
feat(web): show recovery profiles and export guarded local reports
This commit is contained in:
1 parent
7e6664d89e
commit
dfbbef5226
12 files changed
+1882
-71
No files matched your search
+68
-12
@@ -1,7 +1,8 @@
|
||||
// One-shot unpack worker: each unpack runs in a fresh worker with its own
|
||||
// wasm instance. Two reasons:
|
||||
// One-shot worker: each job runs in a fresh worker with its own wasm instance.
|
||||
// Two reasons:
|
||||
//
|
||||
// 1. UI stays responsive — unpacking a 100 MB+ module blocks for seconds.
|
||||
// 1. UI stays responsive — unpacking a 100 MB+ module (or rewriting a large
|
||||
// `global-metadata.dat`) blocks for seconds.
|
||||
// 2. Trap isolation — the senbei DLL-first routing probe relies on
|
||||
// catch_unwind to reject EXE-shell-layout DLLs, and panics cannot be
|
||||
// caught in WebAssembly: the probe traps the whole call. A trap kills
|
||||
@@ -9,33 +10,88 @@
|
||||
// retries with the forced-EXE pipeline in a NEW worker (the trapped
|
||||
// instance is never reused). That reproduces the CLI's
|
||||
// dll-first/exe-fallback routing without a catchable panic.
|
||||
//
|
||||
// Every reply carries the recovery profile (see `profile_json`), including
|
||||
// failures: the page shows which route ran and why it was rejected.
|
||||
|
||||
import init, { unpack_file, unpack_file_force_exe } from './pkg/senbei_wasm.js';
|
||||
import init, {
|
||||
deobfuscate_metadata_reported,
|
||||
unpack_file_reported,
|
||||
} from './pkg/senbei_wasm.js';
|
||||
|
||||
let ready = null;
|
||||
|
||||
/** Parse the profile JSON into a plain object for structured cloning. */
|
||||
function profileOf(doc) {
|
||||
if (!doc) return null;
|
||||
try {
|
||||
return JSON.parse(doc);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Post a failure reply, keeping the trap flag the main thread retries on. */
|
||||
function postFailure(err, profile) {
|
||||
const trap = err instanceof WebAssembly.RuntimeError;
|
||||
self.postMessage({
|
||||
ok: false,
|
||||
trap,
|
||||
message: String(err?.message ?? err),
|
||||
profile,
|
||||
});
|
||||
}
|
||||
|
||||
self.onmessage = async (e) => {
|
||||
const { input, companion, forceExe } = e.data;
|
||||
const { mode, input, companion, forceExe } = e.data;
|
||||
let profile = null;
|
||||
try {
|
||||
ready ??= init();
|
||||
await ready;
|
||||
const r = forceExe
|
||||
? unpack_file_force_exe(input, companion ?? undefined)
|
||||
: unpack_file(input, companion ?? undefined);
|
||||
|
||||
if (mode === 'metadata') {
|
||||
const r = deobfuscate_metadata_reported(input);
|
||||
profile = profileOf(r.profile_json);
|
||||
const bytes = r.bytes;
|
||||
self.postMessage(
|
||||
{
|
||||
ok: r.ok,
|
||||
mode: 'metadata',
|
||||
metadata: {
|
||||
version: r.version,
|
||||
methods: r.methods,
|
||||
remapped: r.remapped,
|
||||
modules: r.modules,
|
||||
},
|
||||
error: r.error ?? null,
|
||||
profile,
|
||||
bytes,
|
||||
},
|
||||
r.ok ? [bytes.buffer] : [],
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const r = unpack_file_reported(input, companion ?? undefined, forceExe === true);
|
||||
profile = profileOf(r.profile_json);
|
||||
const bytes = r.bytes;
|
||||
self.postMessage(
|
||||
{
|
||||
ok: true,
|
||||
ok: r.ok,
|
||||
mode: 'unpack',
|
||||
kind: r.kind,
|
||||
suspect: r.suspect,
|
||||
issues: r.issues,
|
||||
severities: r.severities,
|
||||
fatal: r.fatal,
|
||||
companion: r.companion,
|
||||
error: r.error ?? null,
|
||||
profile,
|
||||
bytes,
|
||||
},
|
||||
[bytes.buffer],
|
||||
r.ok ? [bytes.buffer] : [],
|
||||
);
|
||||
} catch (err) {
|
||||
const trap = err instanceof WebAssembly.RuntimeError;
|
||||
self.postMessage({ ok: false, trap, message: String(err?.message ?? err) });
|
||||
postFailure(err, profile);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user