From 6fa8e2ee3d312073484d232af232cf6d45a7ebe7 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 27 Oct 2026 10:44:51 +0800 Subject: [PATCH] refactor(node-sea): reuse Mach-O segment facts --- src/artifacts/nodeSea/NodeSeaLocation.ts | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/artifacts/nodeSea/NodeSeaLocation.ts b/src/artifacts/nodeSea/NodeSeaLocation.ts index 0d3a1c81b4..45095003f3 100644 --- a/src/artifacts/nodeSea/NodeSeaLocation.ts +++ b/src/artifacts/nodeSea/NodeSeaLocation.ts @@ -272,22 +272,24 @@ const locateThinMachO = async ( } if (cmd === LC_SEGMENT || cmd === LC_SEGMENT_64) { const segment64 = cmd === LC_SEGMENT_64; - const segmentHeader = segment64 ? 72 : 56; const sectionSize = segment64 ? 80 : 68; - const name = cString(commands, offset + 8, 16); + const parsedSegment = readMachoSegmentHeader( + commands.subarray(offset, offset + cmdsize), + segment64, + little, + ); + // Incomplete segments cannot establish a SEA carrier. Interpret names + // and section framing only from the shared fixed-record observation. + const segment = parsedSegment.ok ? parsedSegment.value : undefined; + const name = + segment === undefined ? undefined : cString(segment.nameBytes, 0, 16); if ( - (name === "NODE_SEA" || name === "__NODE_SEA") && - cmdsize >= segmentHeader + segment !== undefined && + (name === "NODE_SEA" || name === "__NODE_SEA") ) { - const parsedSegment = readMachoSegmentHeader( - commands.subarray(offset, offset + cmdsize), - segment64, - little, - ); - if (!parsedSegment.ok) - throw formatFailure(NODE_SEA_MACHO_SEGMENT_TRUNCATED); - const nsects = parsedSegment.value.sectionCount; - const table = offset + parsedSegment.value.headerSize; + const segmentHeader = segment.headerSize; + const nsects = segment.sectionCount; + const table = offset + segmentHeader; if ( nsects > Math.floor((cmdsize - segmentHeader) / sectionSize) || table + nsects * sectionSize > offset + cmdsize