fix(native): decode Mach protection bits in their proper positions (#586)

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 00:14:37 +08:00
committed by GitHub
parent ea9c3dab6b
commit 6aba6ae231
2 changed files with 26 additions and 2 deletions
@@ -0,0 +1,24 @@
import { expect, it } from "vitest";
import { parseOtoolLoadCommands } from "../../../../src/native/parsers/otool.js";
it.each([0, 1, 2, 3, 4, 5, 6, 7])(
"decodes Mach VM protection bits for mask %i",
(mask) => {
const parsed = parseOtoolLoadCommands(`Load command 0
cmd LC_SEGMENT_64
segname __DATA
maxprot 0x${mask.toString(16)}
initprot ${mask}
`);
for (const permissions of [
parsed.segments[0]?.maximum_permissions,
parsed.segments[0]?.initial_permissions,
]) {
expect(permissions).toMatchObject({
read: (mask & 1) !== 0,
write: (mask & 2) !== 0,
execute: (mask & 4) !== 0,
});
}
},
);