From a0d2357230bdce24510436ee405d263fceb47870 Mon Sep 17 00:00:00 2001 From: gensokyo-dev Date: Sat, 21 Nov 2026 18:26:42 +0000 Subject: [PATCH] refactor(macho): read LC_BUILD_VERSION fields through BinaryReader The build-version platform and tool count were read through a local DataView after the command-size check. Read them with machoWordReader, as the other load-command decoders do, and drop the now-unused viewOf. Refs #11865 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- scripts/verify/baselines/raw-buffer-read.json | 1 - src/domain/apple/machoLoadCommandReader.ts | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/verify/baselines/raw-buffer-read.json b/scripts/verify/baselines/raw-buffer-read.json index e8a4963fb8..35491d5c81 100644 --- a/scripts/verify/baselines/raw-buffer-read.json +++ b/scripts/verify/baselines/raw-buffer-read.json @@ -1,5 +1,4 @@ { - "src/domain/apple/machoLoadCommandReader.ts": 2, "src/domain/desktop/openPgpKeys.ts": 2, "src/domain/managed/managedMetadataInventoryRows.ts": 2, "src/native/AppleDispatchMetadata.ts": 1, diff --git a/src/domain/apple/machoLoadCommandReader.ts b/src/domain/apple/machoLoadCommandReader.ts index 241715e8ca..903e9a7c6e 100644 --- a/src/domain/apple/machoLoadCommandReader.ts +++ b/src/domain/apple/machoLoadCommandReader.ts @@ -754,14 +754,14 @@ const decodeCommand = ( "malformed", `load command ${index} is too short for LC_BUILD_VERSION`, ); - const view = viewOf(body); - const toolCount = view.getUint32(20, true); + const reader = machoWordReader(body, true); + const toolCount = reader.u32(20); if (toolCount > Math.floor((body.byteLength - 24) / 8)) throw machoIssue( "malformed", `load command ${index} LC_BUILD_VERSION tool records exceed cmdsize`, ); - const platform = view.getUint32(8, true); + const platform = reader.u32(8); slice.platforms.push(platform); return; } @@ -1141,6 +1141,3 @@ const fileTypeName = (fileType: number): MachoSlice["file_type"] => const version = (value: number): string => `${value >>> 16}.${(value >>> 8) & 0xff}.${value & 0xff}`; - -const viewOf = (bytes: Uint8Array): DataView => - new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);